:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --line: #d6dfec;
  --text: #0f1b2d;
  --muted: #4d5f78;
  --accent: #9a5a00;
  --accent-soft: rgba(154, 90, 0, .10);
  --btn-bg: #0f1b2d;
  --btn-fg: #f3f6fb;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 18px 40px -18px rgba(15, 27, 45, .28);

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* The code editor stays dark in both themes, like a real IDE. */
  --ed-bg: #091220;
  --ed-bar: #0f1c31;
  --ed-line: #22344f;
  --ed-text: #d5e0ef;
  --ed-gutter: #5a6f8c;
  --syn-k: #c6a0ff;
  --syn-s: #8fd694;
  --syn-p: #7cc4ff;
  --syn-c: #7186a3;
  --syn-n: #9fb2cc;
  --syn-f: #f2b35b;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1828;
    --surface: #13223a;
    --line: #25395a;
    --text: #e8eef7;
    --muted: #9db0c8;
    --accent: #f2b35b;
    --accent-soft: rgba(242, 179, 91, .12);
    --btn-bg: #e8eef7;
    --btn-fg: #0d1828;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 24px 48px -20px rgba(0, 0, 0, .65);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1828;
  --surface: #13223a;
  --line: #25395a;
  --text: #e8eef7;
  --muted: #9db0c8;
  --accent: #f2b35b;
  --accent-soft: rgba(242, 179, 91, .12);
  --btn-bg: #e8eef7;
  --btn-fg: #0d1828;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 24px 48px -20px rgba(0, 0, 0, .65);
}

html { scroll-behavior: smooth; scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 84px); }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s ease, color .3s ease;
  overflow-x: hidden;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.wrap { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-in { display: flex; align-items: center; gap: 1.5rem; min-height: 64px; flex-wrap: wrap; }
.brand { font-family: var(--font-mono); font-weight: 500; text-decoration: none; letter-spacing: -.01em; }
.brand .br { color: var(--accent); }
.nav-links { display: flex; gap: 1.5rem; margin-left: auto; }
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: .95rem;
  padding: .25rem 0;
  border-bottom: 2px solid transparent;
  transition: color .2s ease, border-color .2s ease;
}
.nav-links a:hover { color: var(--text); }
.nav-links a[aria-current="true"] { color: var(--text); border-bottom-color: var(--accent); }
.theme-switch {
  position: relative;
  flex: none;
  width: 64px; height: 34px;
  padding: 0;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .2s ease, background-color .3s ease;
}
.theme-switch:hover { border-color: var(--accent); }
.theme-switch svg { position: absolute; top: 8px; width: 16px; height: 16px; }
.theme-switch .ic-sun { left: 9px; }
.theme-switch .ic-moon { right: 9px; }
.theme-switch .thumb {
  position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px;
  background: var(--btn-bg);
  border-radius: 50%;
  transition: transform .3s cubic-bezier(.3, .8, .3, 1), background-color .3s ease;
}
:root[data-theme="dark"] .theme-switch .thumb { transform: translateX(30px); }
:root:not([data-theme="dark"]) .theme-switch .ic-sun { color: var(--btn-fg); z-index: 1; }
:root[data-theme="dark"] .theme-switch .ic-moon { color: var(--btn-fg); z-index: 1; }

/* ---------- Hero ---------- */
.hero { position: relative; isolation: isolate; padding-block: clamp(3rem, 8vw, 6.5rem); }
.hero::before {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(to bottom, #000 25%, transparent 90%);
  mask-image: linear-gradient(to bottom, #000 25%, transparent 90%);
}
.hero-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 3.5rem; align-items: center; }
.hero h1 {
  font-size: clamp(2.4rem, 5.4vw, 4.2rem);
  line-height: 1.04;
  letter-spacing: -.03em;
  font-weight: 700;
  margin: 0 0 1.4rem;
}
.lead { max-width: 46ch; color: var(--muted); font-size: 1.15rem; margin: 0; }
.cta { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 2rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .8rem 1.3rem;
  border-radius: 10px;
  border: 1px solid var(--btn-bg);
  font-weight: 600;
  font-size: .98rem;
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease, background-color .2s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--btn-bg); color: var(--btn-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--btn-bg) 88%, var(--accent)); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--text); }

/* ---------- Code editor ---------- */
.editor {
  background: var(--ed-bg);
  border: 1px solid var(--ed-line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: .86rem;
  color: var(--ed-text);
}
.ed-bar {
  display: flex; align-items: center; gap: .45rem;
  background: var(--ed-bar);
  border-bottom: 1px solid var(--ed-line);
  padding: .65rem .9rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f57; } .dot.y { background: #febc2e; } .dot.g { background: #28c840; }
.ed-tab { margin-left: .75rem; font-size: .78rem; color: var(--ed-text); opacity: .85; }
.code { counter-reset: ln; padding: 1rem 1rem 1.1rem; line-height: 1.75; overflow-x: auto; }
.code.lines-11 { min-height: calc(11 * 1.75em + 2.1rem); }
.code.lines-7 { min-height: calc(7 * 1.75em + 2.1rem); }
.ln { white-space: pre; min-height: 1.75em; }
.ln::before {
  counter-increment: ln;
  content: counter(ln);
  display: inline-block;
  width: 2ch; margin-right: 1.5ch;
  text-align: right;
  color: var(--ed-gutter);
  user-select: none;
}
.term { border-top: 1px solid var(--ed-line); background: rgba(0, 0, 0, .22); padding: .9rem 1rem; line-height: 1.7; overflow-x: auto; }
.term.lines-3 { min-height: calc(3 * 1.7em + 1.8rem); }
.term.lines-4 { min-height: calc(4 * 1.7em + 1.8rem); }
.tl { white-space: pre; min-height: 1.7em; }
.k { color: var(--syn-k); } .s { color: var(--syn-s); } .p { color: var(--syn-p); }
.c { color: var(--syn-c); font-style: italic; } .n { color: var(--syn-n); } .f { color: var(--syn-f); }
.caret {
  display: inline-block; width: .55ch; height: 1.1em;
  vertical-align: text-bottom;
  background: var(--syn-f);
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.caption { margin: .75rem 0 0; font-size: .85rem; color: var(--muted); }

/* ---------- Sections ---------- */
.section { padding-block: clamp(3.5rem, 8vw, 6rem); border-top: 1px solid var(--line); }
.section h2 {
  font-size: clamp(1.8rem, 3.6vw, 2.6rem);
  line-height: 1.12;
  letter-spacing: -.025em;
  font-weight: 700;
  margin: 0 0 2.25rem;
}

/* About */
.about-grid { display: grid; grid-template-columns: 340px 1fr; gap: 4rem; align-items: start; }
.portrait-wrap { position: relative; margin: 0 16px 16px 0; }
.portrait-wrap::after {
  content: "";
  position: absolute; inset: 16px -16px -16px 16px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  z-index: 0;
}
.portrait {
  position: relative; z-index: 1;
  display: block; width: 100%; height: auto;
  aspect-ratio: 1 / 1; object-fit: cover; object-position: center 22%;
  border-radius: 20px;
  background: var(--surface);
}
.about-text p { max-width: 62ch; font-size: 1.08rem; margin: 0 0 1.1rem; }
.facts { margin: 2rem 0 0; max-width: 62ch; }
.facts div { display: grid; grid-template-columns: 8rem 1fr; gap: 1rem; padding: .8rem 0; border-top: 1px solid var(--line); }
.facts div:last-child { border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: .95rem; }
.facts dd { margin: 0; font-weight: 500; }

/* Experience log */
.log { list-style: none; margin: 0; padding: 0 0 0 1.75rem; border-left: 1px solid var(--line); max-width: 760px; }
.log li { position: relative; padding-bottom: 2.25rem; }
.log li:last-child { padding-bottom: 0; }
.log li::before {
  content: "";
  position: absolute; left: calc(-1.75rem - 5px); top: .55rem;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--muted);
}
.log li.now::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.log h3 { font-size: 1.25rem; letter-spacing: -.01em; margin: 0; line-height: 1.3; }
.meta { font-family: var(--font-mono); font-size: .8rem; color: var(--muted); margin: .3rem 0 .6rem; }
.log p { margin: 0; color: var(--muted); max-width: 58ch; }
.log .now-tag { color: var(--accent); }
.meta a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); transition: color .2s ease, text-decoration-color .2s ease; }
.meta a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* Projects */
.featured { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; align-items: center; margin-bottom: 3.5rem; }
.featured h3 { font-size: 1.7rem; letter-spacing: -.02em; line-height: 1.2; margin: 0 0 .9rem; }
.featured p { color: var(--muted); max-width: 52ch; margin: 0 0 1.25rem; }
.tags { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: .8rem; color: var(--accent); }
.rows { border-bottom: 1px solid var(--line); }
.row {
  display: grid; grid-template-columns: 1.1fr 1.6fr 1fr; gap: 1.5rem; align-items: baseline;
  padding: 1.25rem .75rem;
  border-top: 1px solid var(--line);
  transition: background-color .2s ease;
}
.row:hover { background: var(--surface); }
.row h3 { margin: 0; font-size: 1.1rem; letter-spacing: -.01em; }
.row p { margin: 0; color: var(--muted); }
.row .tags { justify-content: flex-end; }
.rows-title { font-size: 1.1rem; margin: 0 0 1rem; color: var(--muted); font-weight: 500; }

/* Skills */
.skill-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3rem; }
.skill-grid h3 { font-size: 1.1rem; margin: 0 0 1rem; letter-spacing: -.01em; }
.skill-grid ul { list-style: none; margin: 0; padding: 0; }
.skill-grid li { padding: .6rem 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; }
.skill-grid li:last-child { border-bottom: 1px solid var(--line); }
.learning { font-family: var(--font-mono); font-size: .75rem; color: var(--accent); align-self: center; }

/* Contact */
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3.5rem; align-items: center; }
.contact-grid h2 { margin-bottom: 1rem; }
.contact-copy { color: var(--muted); max-width: 44ch; font-size: 1.1rem; margin: 0 0 1.75rem; }
button.btn { font-family: inherit; cursor: pointer; }
.contact-links { display: flex; flex-wrap: wrap; gap: .75rem; }
.contact-details { margin: 1.25rem 0 0; font-family: var(--font-mono); font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }

.site-footer { border-top: 1px solid var(--line); padding-block: 2rem; color: var(--muted); font-size: .9rem; }
.footer-in { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-grid, .about-grid, .featured, .contact-grid { grid-template-columns: 1fr; gap: 2.5rem; }
  .about-grid .portrait-wrap { max-width: 320px; }
  .skill-grid { grid-template-columns: 1fr; gap: 2.25rem; }
  .row { grid-template-columns: 1fr; gap: .4rem; }
  .row .tags { justify-content: flex-start; margin-top: .4rem; }
  .featured .editor { order: 2; }
}
@media (max-width: 720px) {
  .header-in { gap: .5rem 1rem; padding-block: .6rem 0; }
  .theme-switch { margin-left: auto; }
  .nav-links { order: 3; width: 100%; margin-left: 0; overflow-x: auto; gap: 1.25rem; padding-bottom: .55rem; }
  .nav-links a { white-space: nowrap; }
  .editor { font-size: .76rem; }
  .facts div { grid-template-columns: 6rem 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
  .caret { animation: none; }
}
