/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --page: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: #e3edfb;
  --s1: #2a78d6;        /* series blue */
  --s2: #eb6834;        /* series orange */
  --critical: #d03b3b;
  --watch: #b87a00;
  --watch-bg: #fdf1d6;
  --critical-bg: #fbe4e3;
  --good: #006300;
  --good-bg: #e2f2e2;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #97958e;
    --line: #2c2c2a;
    --axis: #45453f;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #6da7ec;
    --accent-ink: #0b0b0b;
    --accent-soft: #16263b;
    --s1: #3987e5;
    --s2: #d95926;
    --critical: #e66767;
    --watch: #fab219;
    --watch-bg: #2e2510;
    --critical-bg: #321a1a;
    --good: #0ca30c;
    --good-bg: #13261a;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #97958e;
  --line: #2c2c2a;
  --axis: #45453f;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #6da7ec;
  --accent-ink: #0b0b0b;
  --accent-soft: #16263b;
  --s1: #3987e5;
  --s2: #d95926;
  --critical: #e66767;
  --watch: #fab219;
  --watch-bg: #2e2510;
  --critical-bg: #321a1a;
  --good: #0ca30c;
  --good-bg: #13261a;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3, h4, h5 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.wrap { width: 100%; max-width: 1160px; margin-inline: auto; padding-inline: clamp(16px, 4vw, 32px); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

.eyebrow {
  font: 600 12px/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); text-decoration: none; margin-right: auto; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font: 700 12px/1 var(--mono);
}
.nav-links { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav-links a {
  display: block; padding: 6px 12px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav-links a:hover, .nav-links a.active { color: var(--ink); background: var(--surface-2); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  color: var(--ink); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-toggle { display: none; }

@media (max-width: 980px) {
  .nav-toggle { display: grid; }
  .topbar nav { position: absolute; inset: 100% 0 auto 0; }
  .nav-links {
    display: none; flex-direction: column; padding: 8px clamp(16px, 4vw, 32px) 16px;
    background: var(--page); border-bottom: 1px solid var(--border);
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 10px 12px; font-size: 16px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; min-height: 42px; padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: 15px; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }

/* ---------- Hero ---------- */
.hero {
  display: grid; grid-template-columns: 1.35fr 1fr; gap: clamp(28px, 5vw, 64px); align-items: center;
  padding-block: clamp(48px, 9vw, 104px) clamp(40px, 7vw, 80px);
}
.hero h1 { font-size: clamp(30px, 4.4vw, 50px); font-weight: 700; letter-spacing: -0.025em; text-wrap: balance; }
.lede { margin-top: 20px; font-size: clamp(16px, 1.6vw, 18px); color: var(--ink-2); max-width: 58ch; }
.cta-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

.hero-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; box-shadow: var(--shadow);
}
.hero-card-label { font: 600 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hero-card-title { margin-top: 10px; font-size: 20px; font-weight: 650; }
.hero-card-sub { font-size: 14px; color: var(--ink-2); }
.hero-big { margin: 22px 0; padding: 18px 0; border-block: 1px solid var(--line); }
.hero-big-num { display: block; font-size: clamp(52px, 7vw, 72px); font-weight: 700; letter-spacing: -0.04em; line-height: 1; color: var(--critical); }
.hero-big-cap { display: block; margin-top: 10px; color: var(--ink-2); font-size: 15px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0; }
.hero-stats dt { font-size: 12px; color: var(--muted); }
.hero-stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 650; }

/* ---------- Sections ---------- */
.section { padding-block: clamp(56px, 8vw, 96px); border-top: 1px solid var(--border); }
.section-head { margin-bottom: 32px; }
.section-head h2 { font-size: clamp(26px, 3.2vw, 36px); font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
.section-lede { margin-top: 14px; color: var(--ink-2); font-size: 17px; max-width: 68ch; }

/* ---------- Case study ---------- */
.case { background: var(--surface-2); }
.brief { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.brief > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.brief h3 { font-size: 14px; font-weight: 650; margin-bottom: 8px; }
.brief p { font-size: 14.5px; color: var(--ink-2); }

.kpis { list-style: none; margin: 0 0 20px; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.kpis li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi-label { display: block; font: 600 10.5px/1.3 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi-val { display: block; margin-top: 6px; font-size: clamp(20px, 2.2vw, 26px); font-weight: 700; letter-spacing: -0.02em; }
.kpi-val small { font-size: 13px; font-weight: 500; color: var(--muted); }

.report { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.report-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.report-title { display: flex; align-items: center; gap: 8px; font: 600 12px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.report-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--s1); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2); font: 600 14px/1 var(--font);
  padding: 9px 14px; border-radius: 8px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.panel { padding: clamp(16px, 2.5vw, 24px); }
.panel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }

.chart-card { margin: 0; border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.chart-card h4 { font-size: 15px; font-weight: 650; }
.chart-card figcaption p { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.chart { margin-top: 12px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

/* chart marks & chrome */
.grid-line { stroke: var(--line); stroke-width: 1; }
.base-line { stroke: var(--axis); stroke-width: 1; }
.ref-line { stroke: var(--ink-2); stroke-width: 1; }
.tick { fill: var(--muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.lbl { fill: var(--ink); font: 600 11.5px var(--font); font-variant-numeric: tabular-nums; }
.lbl, .lbl-2 { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.lbl-2 { fill: var(--ink-2); font: 11.5px var(--font); }
.m-s1 { fill: var(--s1); }
.m-s2 { fill: var(--s2); }
.m-bad { fill: var(--critical); }
.m-mute { fill: var(--axis); }
.ln-s1 { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ln-s2 { fill: none; stroke: var(--s2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area-s1 { fill: var(--s1); opacity: .1; }
.hover-dot { stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; }
.hit { fill: transparent; cursor: default; }
.bar-hover { opacity: .8; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .sw-line { height: 2px; width: 14px; border-radius: 1px; }
.m-s1-bg { background: var(--s1); }
.m-s2-bg { background: var(--s2); }

.tooltip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--ink); color: var(--page); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.45; box-shadow: 0 6px 18px rgba(0,0,0,.2);
  max-width: 240px;
}
.tooltip b { font-weight: 650; }

.findings { display: flex; flex-direction: column; gap: 14px; padding: 16px; border-radius: 12px; background: var(--surface-2); }
.findings-label { font: 600 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.findings h5 { font-size: 15px; font-weight: 650; margin-top: 6px; }
.findings p { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; }
.tag { display: inline-flex; align-items: center; gap: 5px; font: 700 10.5px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; padding: 4px 7px; border-radius: 5px; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-critical { color: var(--critical); background: var(--critical-bg); }
.tag-watch { color: var(--watch); background: var(--watch-bg); }
.tag-good { color: var(--good); background: var(--good-bg); }

.shot + .shot { margin-top: 16px; }
.shot { margin: 20px 0 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.shot img { width: 100%; height: auto; }
.shot > a { display: block; cursor: zoom-in; }
.shot figcaption { padding: 10px 14px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }

.recs, .method { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(20px, 3vw, 28px); }
.recs h3, .method h3 { font-size: 18px; font-weight: 650; margin-bottom: 14px; }
.recs ol { margin: 0; padding-left: 22px; display: grid; gap: 12px; }
.recs li { color: var(--ink-2); padding-left: 4px; }
.recs li strong { color: var(--ink); }

/* ---------- Chips ---------- */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { font-size: 13.5px; padding: 6px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); }
.chips.small li { font-size: 12px; padding: 4px 9px; }

/* ---------- Projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.project { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.project-meta { font: 600 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.project h3 { font-size: 19px; font-weight: 650; }
.project > p { color: var(--ink-2); font-size: 15px; }
.project .chips { margin-top: auto; }
.link { font-weight: 600; font-size: 14.5px; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- Experience ---------- */
.two-col { display: grid; grid-template-columns: 1.5fr 1fr; gap: clamp(32px, 6vw, 72px); }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline > li { position: relative; padding: 0 0 32px 24px; }
.timeline > li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--page); }
.tl-when { font: 600 12px/1.4 var(--mono); color: var(--muted); }
.timeline h3 { font-size: 18px; font-weight: 650; margin-top: 4px; }
.timeline h3 span { font-weight: 500; color: var(--ink-2); }
.timeline ul { margin: 10px 0 0; padding-left: 18px; color: var(--ink-2); display: grid; gap: 6px; font-size: 15px; }
.cred { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; }
.cred h3 { font-size: 17px; font-weight: 650; }
.cred p { color: var(--ink-2); font-size: 14.5px; margin-top: 4px; }
.cred .cred-badge { display: inline-block; margin: 0 0 10px; font: 700 10.5px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; padding: 5px 8px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); }

/* ---------- Skills ---------- */
.skill-groups { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.skill-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.skill-group h3 { font-size: 15px; font-weight: 650; margin-bottom: 12px; }

/* ---------- Contact ---------- */
.contact-card {
  display: grid; grid-template-columns: 1fr 1fr; gap: clamp(24px, 5vw, 56px); align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: clamp(24px, 4vw, 44px); box-shadow: var(--shadow);
}
.contact-card h2 { font-size: clamp(26px, 3.2vw, 36px); font-weight: 700; letter-spacing: -0.02em; }
.contact-card > div > p:last-child { margin-top: 12px; color: var(--ink-2); }
.contact-list { list-style: none; margin: 0; padding: 0; }
.contact-list li { display: flex; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; overflow-wrap: anywhere; }
.contact-list li:last-child { border-bottom: 0; }
.contact-list span { flex: 0 0 76px; color: var(--muted); font-size: 13px; padding-top: 2px; }

.footer { padding-block: 28px calc(28px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.footer a { color: inherit; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: 1 / -1; }
  .panel-grid .findings { grid-column: 1 / -1; }
  .project-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .hero, .two-col, .contact-card, .brief, .project-grid, .skill-groups { grid-template-columns: 1fr; }
  .panel-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
.hero-card-link { display: inline-block; margin-top: 18px; }

/* ---------- Excel case study ---------- */
.note { margin-top: 16px; font-size: 14px; color: var(--ink-2); max-width: 75ch; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 8px 8px 0; }
.method .note { margin-top: 16px; background: var(--surface-2); }
.macros { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.macros li { border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.macros h4 { font-size: 15px; font-weight: 650; }
.macros p { margin-top: 6px; font-size: 13.5px; color: var(--ink-2); }
.chart-card .legend .sw-bar { width: 10px; height: 10px; border-radius: 3px; }
@media (max-width: 1000px) { .macros { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .macros { grid-template-columns: 1fr; } }
.xl-live { margin: 20px 0 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.xl-live-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-size: 13px; color: var(--ink-2); }
.xl-live-bar b { color: var(--ink); font-weight: 650; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.live-tag { font: 700 10.5px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; padding: 4px 7px; border-radius: 5px; color: var(--good); background: var(--good-bg); }
.live-hint { flex-basis: 100%; }
.xl-live iframe { display: block; width: 100%; height: clamp(460px, 70vh, 660px); border: 0; background: #fff; }

/* Records system screenshots */
.shot-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.shot-grid .shot, .shot-grid .shot + .shot { margin: 0; }
@media (max-width: 1000px) { .shot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .shot-grid { grid-template-columns: 1fr; } }

/* Project pages (one per case study, built by tools/build_pages.py) */
.nav-links a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.byline { padding-top: 20px; font-size: 14px; color: var(--ink-2); }
.byline a { font-weight: 600; }
.project-page > .section:first-of-type { border-top: 0; padding-top: 28px; }
.hero-big-num.is-accent { color: var(--accent); }
