/* ---------- Tokens ---------- */
:root {
  --bg: #f5f4ef;
  --bg-elev: #ffffff;
  --bg-sunk: #ecebe4;
  --text: #121418;
  --muted: #585d68;
  --line: #dddbd2;
  --accent: #0b7a5f;
  --accent-2: #b4530f;
  --accent-soft: rgba(11, 122, 95, 0.1);
  --sev1: #c0392b;
  --sev2: #b4530f;
  --sev3: #2563c9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  --grid-line: rgba(0, 0, 0, 0.045);
  --radius: 16px;
  --gutter: clamp(16px, 4.2vw, 80px);
  --maxw: 1840px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", var(--font);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c10;
    --bg-elev: #11141a;
    --bg-sunk: #0d1015;
    --text: #e9eaee;
    --muted: #949aa7;
    --line: #232832;
    --accent: #3ddc97;
    --accent-2: #f5a524;
    --accent-soft: rgba(61, 220, 151, 0.1);
    --sev1: #ff6b5e;
    --sev2: #f5a524;
    --sev3: #6aa6ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.3);
    --grid-line: rgba(255, 255, 255, 0.035);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a0c10;
  --bg-elev: #11141a;
  --bg-sunk: #0d1015;
  --text: #e9eaee;
  --muted: #949aa7;
  --line: #232832;
  --accent: #3ddc97;
  --accent-2: #f5a524;
  --accent-soft: rgba(61, 220, 151, 0.1);
  --sev1: #ff6b5e;
  --sev2: #f5a524;
  --sev3: #6aa6ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.3);
  --grid-line: rgba(255, 255, 255, 0.035);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-width: 320px;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(16px, 0.35vw + 14.8px, 18px);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
p { margin: 0 0 1em; }
ul, ol { margin: 0; padding: 0; list-style: none; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--bg-sunk); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; overflow-wrap: anywhere; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; background: var(--bg-elev); color: var(--muted); }
.mono { font-family: var(--mono); }
.dim { color: var(--muted); }
.ok { color: var(--accent); }

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
}
@media (min-width: 2400px) { :root { --maxw: 2200px; } body { font-size: 19px; } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.skip-link { position: absolute; left: 16px; top: -60px; z-index: 100; background: var(--accent); color: var(--bg); padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.site-header.scrolled { border-bottom-color: var(--line); }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--mono); font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--text); color: var(--bg); font-size: 13px; }

.nav-links { display: flex; align-items: center; gap: 2px; }
.nav-links a { text-decoration: none; font-size: 15px; color: var(--muted); padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.nav-links a:hover, .nav-links a.active { color: var(--text); background: var(--accent-soft); }

.nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn, .kbd-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; min-width: 40px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-elev); color: var(--text); cursor: pointer;
  font: inherit;
}
.icon-btn:hover, .kbd-btn:hover { border-color: var(--accent); }
.icon-btn svg, .kbd-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.kbd-hint { display: inline-flex; gap: 3px; }

.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

.nav-toggle { display: none; flex-direction: column; gap: 6px; padding: 0 11px; }
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; transition: transform .2s; }
.nav-toggle[aria-expanded="true"] span:first-child { transform: translateY(4px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:last-child { transform: translateY(-4px) rotate(-45deg); }

@media (max-width: 1080px) {
  .nav-toggle { display: inline-flex; }
  .nav-links {
    position: absolute; top: 68px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    padding: 8px var(--gutter) 16px; background: var(--bg); border-bottom: 1px solid var(--line);
    display: none;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 12px; font-size: 17px; }
}
@media (max-width: 560px) {
  .kbd-hint { display: none; }
  .brand-name { display: none; }
}

/* ---------- Hero ---------- */
.hero {
  display: grid; gap: clamp(32px, 5vw, 80px);
  padding-top: clamp(32px, 5vh, 80px); padding-bottom: clamp(28px, 4vh, 56px);
  align-items: center;
}
@media (min-width: 1100px) { .hero { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }

.status-pill {
  display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 12.5px; color: var(--muted);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
  margin-bottom: clamp(20px, 2.4vw, 32px);
}
.status-pill b { color: var(--accent); font-weight: 600; }
@media (max-width: 480px) { .hide-sm { display: none; } .status-pill { font-size: 11.5px; gap: 6px; } }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.hero h1 { font-size: clamp(52px, min(7.4vw, 13.5vh), 150px); font-weight: 700; letter-spacing: -0.045em; line-height: 0.92; }
.hero-role { font-family: var(--display); font-size: clamp(19px, min(1.6vw, 3vh), 30px); font-weight: 500; line-height: 1.3; margin: clamp(18px, 2vw, 28px) 0 14px; max-width: 30ch; }
.hero-role em { font-style: normal; color: var(--accent); }
.hero-lede { color: var(--muted); max-width: 56ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0 18px; }

.link-row { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 14px; }
.link-row a { color: var(--muted); text-decoration: none; }
.link-row a::before { content: "→ "; color: var(--accent); }
.link-row a:hover { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 10px 22px; border-radius: 11px;
  font: 600 15px/1.2 var(--font); text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text);
  transition: transform .15s, background .15s, border-color .15s, color .15s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); color: var(--text); }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.btn-lg { min-height: 56px; font-size: 16px; overflow-wrap: anywhere; }

/* Architecture diagram */
.arch { margin: 0; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.arch-bar { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.arch-live { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); }
.arch-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 2s infinite; }
.arch-svg { width: 100%; height: auto; padding: clamp(8px, 1.6vw, 20px); }
.arch-svg .edges use { fill: none; stroke: var(--line); stroke-width: 2; stroke-dasharray: 5 5; }
.arch-svg .nodes rect { fill: var(--bg-sunk); stroke: var(--line); stroke-width: 1.5; }
.arch-svg .nodes .hot rect { stroke: var(--accent); stroke-width: 2; }
.arch-svg text { font-family: var(--mono); font-size: 14px; font-weight: 600; fill: var(--text); text-anchor: middle; }
.arch-svg text.sub { font-size: 11px; font-weight: 400; fill: var(--muted); }
.arch-svg .labels text { font-size: 11px; font-weight: 500; fill: var(--muted); }
.arch-svg .packets circle { fill: var(--accent); }
.arch-svg .packets circle.alt { fill: var(--accent-2); }
/* Small screens: the diagram scales down, so enlarge its text and drop the edge labels. */
@media (max-width: 600px) {
  .arch-svg text { font-size: 17px; }
  .arch-svg text.sub, .arch-svg .labels { display: none; }
  .arch-svg .nodes text:not(.sub) { transform: translateY(8px); }
}
.arch figcaption { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* ---------- Metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; }
.metric { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px; padding: clamp(16px, 1.6vw, 24px); }
.metric strong { display: block; font-family: var(--display); font-size: clamp(28px, 2.6vw, 44px); letter-spacing: -0.03em; color: var(--accent); line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric span { display: block; margin-top: 6px; font-size: 13.5px; line-height: 1.4; color: var(--muted); }

/* ---------- Sections ---------- */
.section { padding-top: clamp(64px, 7vw, 112px); }
.section-head { margin-bottom: clamp(28px, 3.4vw, 48px); max-width: 920px; }
.section-tag { font-size: 13px; color: var(--accent); margin-bottom: 10px; }
.section-head h2 { font-size: clamp(30px, 3.6vw, 56px); letter-spacing: -0.035em; }
.section-sub { margin: 14px 0 0; color: var(--muted); max-width: 64ch; }

.about-grid { display: grid; gap: clamp(28px, 4vw, 72px); }
@media (min-width: 1000px) { .about-grid { grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); } }
.prose p { color: var(--muted); max-width: 70ch; }
.prose .lead { font-size: 1.18em; color: var(--text); }
.prose strong { color: var(--text); font-weight: 600; }

.spec-sheet { margin: 0; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 20px; align-self: start; font-size: 13.5px; }
.spec-sheet div { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.spec-sheet div:last-child { border-bottom: 0; }
.spec-sheet dt { color: var(--muted); flex-shrink: 0; }
.spec-sheet dt::after { content: ":"; }
.spec-sheet dd { margin: 0; text-align: right; }
@media (max-width: 480px) {
  .spec-sheet div { flex-direction: column; gap: 2px; }
  .spec-sheet dd { text-align: left; }
}

/* ---------- Incidents ---------- */
.incidents { display: grid; gap: clamp(14px, 1.4vw, 22px); }
@media (min-width: 820px) { .incidents { grid-template-columns: repeat(2, minmax(0, 1fr)); } .incident-lead { grid-column: 1 / -1; } }
@media (min-width: 1280px) {
  .incidents { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .incident-lead .pm { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
  .incident-lead .pm div { border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 18px; }
}
.incident {
  position: relative; display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(20px, 2vw, 32px); box-shadow: var(--shadow);
}
.incident-lead { border-color: color-mix(in srgb, var(--sev1) 45%, var(--line)); }
.incident-lead::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; border-radius: var(--radius) 0 0 var(--radius); background: var(--sev1); }
.incident-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.sev { padding: 2px 8px; border-radius: 6px; font-weight: 600; color: #fff; }
.sev-1 { background: var(--sev1); }
.sev-2 { background: var(--sev2); }
.sev-3 { background: var(--sev3); }
.incident h3 { font-size: clamp(21px, 1.7vw, 30px); margin-bottom: 18px; }
.incident-lead h3 { font-size: clamp(24px, 2.4vw, 40px); }
.pm { display: grid; gap: 14px; margin: 0 0 18px; flex: 1; }
.pm div { border-top: 1px solid var(--line); padding-top: 12px; }
.pm dt { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 4px; }
.pm dd { margin: 0; color: var(--muted); font-size: 15.5px; }
.pm dd strong, .pm dd em { color: var(--text); }

/* ---------- Principles ---------- */
.readme { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.readme-bar { display: flex; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 13px; }
.rules { counter-reset: rule; display: grid; padding: clamp(8px, 1vw, 16px) clamp(16px, 2vw, 32px); }
@media (min-width: 1000px) { .rules { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 48px; } }
.rules li { counter-increment: rule; position: relative; padding: 16px 0 16px 48px; border-bottom: 1px dashed var(--line); color: var(--muted); }
.rules li::before { content: counter(rule, decimal-leading-zero); position: absolute; left: 0; top: 16px; font-family: var(--mono); font-size: 13px; color: var(--accent); }
.rules b { color: var(--text); font-weight: 600; }

/* ---------- Timeline ---------- */
.timeline { display: grid; gap: clamp(20px, 2vw, 28px); }
.job { display: grid; gap: 10px 32px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(20px, 2vw, 32px); }
@media (min-width: 900px) { .job { grid-template-columns: 180px minmax(0, 1fr); } }
.job-side { font-size: 13px; line-height: 1.7; }
.job-body h3 { font-size: clamp(21px, 1.7vw, 28px); margin-bottom: 16px; }
.job-body h3 a { color: var(--accent); text-decoration: none; }
.job-cols { display: grid; gap: 0 36px; }
@media (min-width: 1240px) { .job-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.job-points { display: grid; gap: 10px; margin-bottom: 18px; align-content: start; }
.job-points li { position: relative; padding-left: 20px; color: var(--muted); }
.job-points li::before { content: "▹"; position: absolute; left: 0; color: var(--accent); }
.job-points strong { color: var(--text); font-weight: 600; }

/* ---------- Tags ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tags li { font-family: var(--mono); font-size: 12px; padding: 4px 10px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }

/* ---------- Projects ---------- */
.projects { display: grid; gap: clamp(14px, 1.4vw, 22px); grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(20px, 2vw, 30px); box-shadow: var(--shadow); }
.project { display: flex; flex-direction: column; transition: transform .2s, border-color .2s; }
.project:hover { transform: translateY(-3px); border-color: var(--accent); }
.project-kind { font-size: 12px; color: var(--accent-2); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.project h3 { font-size: clamp(21px, 1.6vw, 28px); margin-bottom: 12px; }
.project h3 a { text-decoration: none; }
.project p { color: var(--muted); flex: 1; }
.project p strong { color: var(--text); font-weight: 600; }

/* ---------- Stack ---------- */
.stack { display: grid; gap: 14px; }
@media (min-width: 640px) { .stack { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .stack { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stack-group { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.stack-group h3 { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 500; letter-spacing: 0; margin-bottom: 14px; }
.stack-group h3::before { content: "# "; color: var(--accent); }

/* ---------- Contact ---------- */
.contact { padding-bottom: clamp(64px, 7vw, 112px); }
.contact-card {
  text-align: center; padding: clamp(36px, 6vw, 96px) clamp(20px, 4vw, 64px);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: calc(var(--radius) + 8px); box-shadow: var(--shadow);
}
.contact-card h2 { font-size: clamp(32px, 4.6vw, 72px); letter-spacing: -0.035em; max-width: 18ch; margin: 0 auto 16px; }
.contact-card > p:not(.section-tag) { color: var(--muted); max-width: 58ch; margin: 0 auto 28px; }
.contact-card p strong { color: var(--text); }
.contact-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 24px; }
.contact .link-row { justify-content: center; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 24px 0; font-size: 13px; color: var(--muted); background: var(--bg); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; }
.footer-inner p { margin: 0; }

/* ---------- Command palette ---------- */
.palette { width: min(640px, calc(100vw - 32px)); max-height: min(70vh, 520px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-elev); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); margin-top: 12vh; }
.palette::backdrop { background: rgba(5, 7, 10, 0.55); backdrop-filter: blur(3px); }
.palette-inner { display: flex; flex-direction: column; max-height: inherit; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.palette-input input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 16px var(--font); }
.palette-list { overflow-y: auto; padding: 6px; }
.palette-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.palette-list li span { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.palette-list li[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.palette-list .empty { color: var(--muted); cursor: default; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 90; padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font: 500 14px var(--mono); transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Reveal on scroll (only when JS is running) ---------- */
.js .reveal { opacity: 0; transform: translateY(16px); transition: opacity .6s ease, transform .6s ease; }
.js .reveal.visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal { opacity: 1; transform: none; }
  .arch-svg .packets { display: none; }
}

/* ---------- 404 ---------- */
.notfound { min-height: 70vh; display: grid; place-content: center; text-align: center; gap: 16px; }
.notfound h1 { font-size: clamp(64px, 14vw, 120px); color: var(--accent); }
