:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #888888;
  --border: #e0e0e0;
  --accent: #111111;
  --code-bg: #f7f7f7;
  --max-width: 680px;
  --font: "JetBrains Mono", "Fira Mono", "Cascadia Code", "Menlo", monospace;
}

/* System dark preference — only when no explicit choice is stored */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f;
    --fg: #e8e8e8;
    --muted: #666666;
    --border: #2a2a2a;
    --accent: #e8e8e8;
    --code-bg: #1a1a1a;
  }
}

/* Explicit dark override (user toggled) */
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --fg: #e8e8e8;
  --muted: #666666;
  --border: #2a2a2a;
  --accent: #e8e8e8;
  --code-bg: #1a1a1a;
}

/* Theme toggle button — label driven by CSS so it works before DOM is ready */
#theme-toggle {
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}

#theme-toggle:hover {
  color: var(--fg);
}

/* Show opposite mode as the label (what you'll switch to) */
#theme-toggle::after { content: 'dark'; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle::after { content: 'light'; }
}

:root[data-theme="dark"]  #theme-toggle::after { content: 'light'; }
:root[data-theme="light"] #theme-toggle::after { content: 'dark'; }


/* ── Reading time ── */

.reading-time {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Giscus comments ── */

.comments {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.comments .section-label {
  margin-bottom: 1.5rem;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.7;
  padding: 0 1.5rem;
}

/* ── Layout ── */

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 4rem 0 6rem;
}

/* ── Header ── */

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.site-name {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--fg);
}

nav {
  display: flex;
  gap: 1.5rem;
}

nav a {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}

nav a:hover {
  color: var(--fg);
}

/* ── Hero / Intro ── */

.intro {
  display: flex;
  align-items: flex-end;
  gap: 2.5rem;
  margin-bottom: 4rem;
}

.intro-text {
  flex: 1;
}

/* ── Avatar Animation ── */

.avatar-scene {
  position: relative;
  flex-shrink: 0;
  width: 120px;
}

.avatar-img {
  width: 120px;
  height: 127px;
  border-radius: 50%;
  display: block;
  animation: avatarPopup 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

.hi-bubble {
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.7rem;
  border-radius: 10px 10px 10px 2px;
  white-space: nowrap;
  opacity: 0;
  animation: bubbleAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) 1.1s forwards;
}

@keyframes avatarPopup {
  from {
    transform: translateY(70px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes bubbleAppear {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.5);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

.intro h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  letter-spacing: -0.01em;
}

.intro .role {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.6rem;
}

.intro p {
  font-size: 0.9rem;
  color: var(--fg);
  max-width: 560px;
  line-height: 1.8;
  opacity: 0.8;
}

/* ── Sections ── */

section {
  margin-bottom: 4rem;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

/* ── About ── */

.about p {
  font-size: 0.9rem;
  color: var(--fg);
  opacity: 0.8;
  line-height: 1.85;
  margin-bottom: 0.8rem;
}

.about p:last-child {
  margin-bottom: 0;
}

/* ── Projects List ── */

.projects-list {
  list-style: none;
}

.projects-list li {
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--border);
}

.projects-list li:first-child {
  border-top: 1px solid var(--border);
}

.project-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
  group: true;
}

.project-link:hover .project-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.project-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.project-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--fg);
}

.project-desc {
  font-size: 0.8rem;
  color: var(--muted);
}

.project-year {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Tags ── */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.tag {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.1rem 0.5rem;
  border-radius: 2px;
  letter-spacing: 0.02em;
}

/* ── Links / Contact ── */

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.links a {
  font-size: 0.85rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: border-color 0.15s;
}

.links a:hover {
  border-color: var(--fg);
}

/* ── Project Detail Page ── */

.back-link {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 3rem;
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--fg);
}

.project-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.project-header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.project-header .subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.project-header .project-links {
  display: flex;
  gap: 1.2rem;
  margin-top: 1rem;
}

.project-header .project-links a {
  font-size: 0.8rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: border-color 0.15s;
}

.project-header .project-links a:hover {
  border-color: var(--fg);
}

.content {
  font-size: 0.9rem;
  line-height: 1.85;
  color: var(--fg);
  opacity: 0.85;
}

.content h2 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2.5rem 0 1rem;
}

.content p {
  margin-bottom: 1rem;
}

.content ul {
  list-style: none;
  margin-bottom: 1rem;
}

.content ul li {
  padding-left: 1.2rem;
  position: relative;
  margin-bottom: 0.4rem;
}

.content ul li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--muted);
}

.content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1.2rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.82rem;
  line-height: 1.6;
}

.content code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
  border-radius: 2px;
}

.content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.85rem;
}

.content table th {
  text-align: left;
  padding: 0.5rem 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.content table td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}

.content table tr:last-child td {
  border-bottom: none;
}

/* ── Footer ── */

footer {
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-links {
  display: flex;
  gap: 1.2rem;
  margin-bottom: 0.8rem;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--fg);
}

/* ── Experience ── */

.experience-list {
  list-style: none;
}

.experience-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.experience-list li:first-child {
  border-top: 1px solid var(--border);
}

.exp-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.exp-role {
  font-size: 0.92rem;
  font-weight: 600;
}

.exp-company {
  font-size: 0.82rem;
  color: var(--muted);
}

.exp-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* ── Education ── */

.education-list {
  list-style: none;
}

.education-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.education-list li:first-child {
  border-top: 1px solid var(--border);
}

.exp-university {
  font-size: 0.92rem;
  font-weight: 600;
}

.exp-degree {
  font-size: 0.82rem;
  color: var(--muted);
}

.exp-period {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Writing List ── */

.writing-list {
  list-style: none;
}

.writing-list li {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
}

.writing-list li:first-child {
  border-top: 1px solid var(--border);
}

.writing-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
}

.writing-link:hover .writing-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.writing-title {
  font-size: 0.92rem;
  font-weight: 600;
}

.writing-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.writing-date {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Now / Uses / Reading pages ── */

.simple-list {
  list-style: none;
  margin-bottom: 1rem;
}

.simple-list li {
  font-size: 0.9rem;
  padding: 0.35rem 0;
  padding-left: 1.2rem;
  position: relative;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  opacity: 0.85;
}

.simple-list li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--muted);
}

.simple-list li a {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: border-color 0.15s;
}

.simple-list li a:hover {
  border-color: var(--fg);
}

.page-intro {
  font-size: 0.9rem;
  color: var(--fg);
  opacity: 0.75;
  line-height: 1.8;
  margin-bottom: 3rem;
  max-width: 540px;
}

.updated {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 3rem;
}

/* ── Responsive ── */

@media (max-width: 500px) {
  header {
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 3rem;
  }

  .intro {
    flex-direction: column-reverse;
    align-items: center;
  }

  .avatar-scene {
    width: 90px;
  }

  .avatar-img {
    width: 90px;
    height: 90px;
  }

  .project-link,
  .writing-link,
  .experience-list li {
    flex-direction: column;
    gap: 0.2rem;
  }

  .project-year,
  .writing-date,
  .exp-period {
    font-size: 0.75rem;
  }
}

/* ── AI Chat Widget ── */

/* Hero avatar is the toggle: pointer + subtle hover lift */
#heroAvatar {
  cursor: pointer;
  transition: transform 0.2s ease;
}

#heroAvatar:hover {
  transform: translateY(-3px) scale(1.02);
}

/* While waiting for a response: gentle bob-and-tilt */
#heroAvatar.is-thinking {
  animation: avatarThink 2s ease-in-out infinite !important;
}

@keyframes avatarThink {
  0%,  100% { transform: scale(1)    rotate(0deg);   }
  30%        { transform: scale(0.97) rotate(-1.5deg);}
  70%        { transform: scale(0.98) rotate(1deg);   }
}

/* ── intro-left: flex:1 wrapper holding bio and chat ── */
.intro-left {
  flex: 1;
}

/* Bio text: slides down + fades when chat opens */
.intro-text {
  transition: opacity 0.35s ease, transform 0.38s ease;
}

.intro-text--out {
  opacity: 0;
  transform: translateY(28px);
  pointer-events: none;
}

/* ── Inline chat panel (replaces bio text in the same cell) ── */
.chat-inline {
  display: none;
  flex-direction: column;
  height: 260px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.82rem;
  background: var(--bg);
}

.chat-inline--open {
  display: flex;
  animation: chatSlideIn 0.38s ease forwards;
}

/* Closing: fades up before bio slides back */
.chat-inline--closing {
  display: flex;
  animation: chatSlideOut 0.2s ease forwards;
}

@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes chatSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-10px); }
}

.chat-inline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0;
  font-family: var(--font);
  transition: color 0.15s;
  line-height: 1;
}

.chat-close:hover { color: var(--fg); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
}

.chat-bubble {
  max-width: 90%;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  line-height: 1.55;
  word-break: break-word;
  font-size: 0.82rem;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 2px;
}

.chat-bubble.bot {
  align-self: flex-start;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

/* Loading dots inside the message list */
.chat-loading {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.4rem 0.65rem;
}

.chat-loading span {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatDot 1.2s infinite ease-in-out;
}

.chat-loading span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1;   }
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 0.4rem 0.6rem;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s;
}

.chat-textarea:focus { border-color: var(--fg); }

.chat-send {
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
  font-family: var(--font);
}

.chat-send:hover    { opacity: 0.75; }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Mobile: chat takes full width, slightly taller */
@media (max-width: 500px) {
  .chat-inline {
    height: 220px;
  }
}

/* ── Print ── */

@media print {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --muted: #555555;
    --border: #cccccc;
    --code-bg: #f5f5f5;
  }

  body {
    font-size: 11pt;
    padding: 0;
  }

  .container {
    padding: 0;
    max-width: 100%;
  }

  header {
    margin-bottom: 1.5rem;
  }

  nav,
  .back-link,
  footer {
    display: none;
  }

  .intro {
    margin-bottom: 1.5rem;
  }

  section {
    margin-bottom: 1.5rem;
  }

  .projects-list li,
  .experience-list li {
    page-break-inside: avoid;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  .links a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: var(--muted);
  }
}

/* ── Public Key (PGP) ── */

.pgp-intro {
  font-size: 0.9rem;
  color: var(--fg);
  opacity: 0.8;
  line-height: 1.85;
  margin-bottom: 1.5rem;
  max-width: 540px;
}

.pgp-meta {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.pgp-meta:first-of-type {
  border-top: 1px solid var(--border);
}

.pgp-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
  width: 110px;
}

.pgp-value {
  font-family: var(--font);
  font-size: 0.82rem;
  background: none;
  border: none;
  padding: 0;
  color: var(--fg);
  letter-spacing: 0.04em;
  word-break: break-all;
  user-select: all;
}

.pgp-block {
  margin-top: 1.8rem;
}

.pgp-block summary {
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 0.02em;
  padding: 0.4rem 0;
  list-style: none;
  transition: color 0.15s;
  user-select: none;
}

.pgp-block summary::-webkit-details-marker { display: none; }

.pgp-block summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.5rem;
  transition: transform 0.15s;
}

.pgp-block[open] summary::before {
  transform: rotate(90deg);
}

.pgp-block summary:hover { color: var(--fg); }

.pgp-block pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1.2rem;
  overflow-x: auto;
  margin-top: 0.8rem;
  font-size: 0.72rem;
  line-height: 1.5;
  border-radius: 2px;
  user-select: all;
  white-space: pre;
}

.pgp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 1.8rem;
}

.pgp-actions a {
  font-size: 0.85rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: border-color 0.15s;
}

.pgp-actions a:hover {
  border-color: var(--fg);
}

@media (max-width: 500px) {
  .pgp-meta {
    flex-direction: column;
    gap: 0.2rem;
    align-items: flex-start;
  }

  .pgp-label {
    width: auto;
  }

  .pgp-block pre {
    font-size: 0.65rem;
  }
}