/* Layout concept: an analyst's notebook. Plain paper, ink text, and two data colors
   (teal = baseline series, amber = the effect that matters) reused by every chart. */
:root {
  --paper: #f3f5f2;
  --surface: #ffffff;
  --ink: #13202e;
  --muted: #586776;
  --rule: #d6ddd8;
  --teal: #0b7a75;
  --amber: #b85e14;
  --teal-soft: rgba(11, 122, 117, 0.10);
  --amber-soft: rgba(184, 94, 20, 0.12);
  --code-bg: #e9eeea;

  --font-display: "Libre Franklin", "Franklin Gothic Medium", "Segoe UI", system-ui, sans-serif;
  --font-body: "Libre Franklin", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Source Code Pro", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --step--1: 0.84rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.5rem;
  --step-3: clamp(1.8rem, 1.4rem + 1.6vw, 2.4rem);
  --step-4: clamp(2.4rem, 1.6rem + 3.4vw, 4rem);

  --measure: 66ch;
  --wrap: 1120px;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1621; --surface: #142030; --ink: #e3e9f0; --muted: #94a3b3; --rule: #24364a;
    --teal: #45c1b5; --amber: #f0a058; --teal-soft: rgba(69, 193, 181, 0.12);
    --amber-soft: rgba(240, 160, 88, 0.14); --code-bg: #101b29; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1621; --surface: #142030; --ink: #e3e9f0; --muted: #94a3b3; --rule: #24364a;
  --teal: #45c1b5; --amber: #f0a058; --teal-soft: rgba(69, 193, 181, 0.12);
  --amber-soft: rgba(240, 160, 88, 0.14); --code-bg: #101b29; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { animation: none !important; transition: none !important; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.6 var(--font-body);
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--teal); text-underline-offset: 3px; }
a:hover { color: var(--amber); }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.12; text-wrap: balance; margin: 0; letter-spacing: -0.02em; }
h1 { font-size: var(--step-4); font-weight: 700; }
h2 { font-size: var(--step-3); font-weight: 650; }
h3 { font-size: var(--step-1); font-weight: 600; }
p { margin: 0; max-width: var(--measure); }
code, pre, .mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.label {
  font: 500 var(--step--1)/1.3 var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 16px; background: var(--surface); padding: 8px 12px; z-index: 20; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap { display: flex; align-items: center; gap: 24px; padding-block: 14px; }
.brand { font: 700 1.1rem/1 var(--font-display); color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--ink); color: var(--paper); font: 600 0.8rem/1 var(--font-mono);
}
.brand-role { font-weight: 400; color: var(--muted); white-space: nowrap; }
.brand-sep { margin-inline: 2px; color: var(--rule); font-weight: 300; }
/* phones: the nav needs the room, so show just the name */
@media (max-width: 560px) { .brand-role { display: none; } }
.nav { display: flex; gap: 20px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.theme-toggle {
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
}
.theme-toggle svg { width: 16px; height: 16px; }
@media (max-width: 640px) { .nav .hide-sm { display: none; } .site-header .wrap { gap: 12px; } .nav { gap: 14px; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px;
  font-weight: 500; text-decoration: none; border: 1px solid var(--ink); color: var(--ink); background: transparent;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--teal); border-color: var(--teal); color: var(--paper); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- home: hero ---------- */
.hero .wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 48px; align-items: center; padding-block: 56px 32px; }
.hero-copy { display: grid; gap: 22px; min-width: 0; }
.hero-copy .lede { font-size: var(--step-1); color: var(--muted); }
.portrait {
  width: 240px; max-width: 100%; height: auto; aspect-ratio: 4 / 5;
  object-fit: cover; border-radius: 14px; border: 1px solid var(--rule);
}
@media (max-width: 480px) { .portrait { width: 180px; } }
/* the hero already ends with space; don't stack a full section gap on top of it */
.hero + .section { padding-top: 32px; }
.figure-card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 18px 18px 12px; min-width: 0;
}
.figure-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.figure-head h2 { font-size: 1rem; font-family: var(--font-body); font-weight: 600; letter-spacing: 0; }
.legend { display: flex; gap: 14px; font-size: var(--step--1); color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.chart-box { position: relative; width: 100%; aspect-ratio: 16 / 11; max-width: 100%; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--paper);
  font: 500 0.78rem/1.35 var(--font-mono); padding: 6px 8px; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}
.figure-note { font-size: var(--step--1); color: var(--muted); margin-top: 6px; }
@media (max-width: 860px) { .hero .wrap { grid-template-columns: 1fr; padding-block: 40px 32px; gap: 32px; } }

/* ---------- stats strip ---------- */
.stats { border-block: 1px solid var(--rule); background: var(--surface); }
.stats .wrap { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding-block: 0; }
.stat { padding: 22px 20px; border-left: 1px solid var(--rule); display: grid; gap: 4px; }
.stat:first-child { border-left: 0; padding-left: 0; }
.stat b { font: 600 var(--step-2)/1.1 var(--font-mono); font-variant-numeric: tabular-nums; }
.stat span { font-size: var(--step--1); color: var(--muted); }
@media (max-width: 720px) {
  .stats .wrap { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding-left: 0; border-left: 0; border-top: 1px solid var(--rule); }
  .stat:nth-child(-n+2) { border-top: 0; }
}

/* ---------- sections ---------- */
.section { padding-block: 72px; }
.section + .section { border-top: 1px solid var(--rule); }
.section-head { display: grid; gap: 10px; margin-bottom: 36px; }
.section-head p { color: var(--muted); }

/* ---------- project list (home) ---------- */
.projects { display: grid; gap: 20px; }
.project {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 32px; align-items: center;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 28px;
  text-decoration: none; color: inherit; transition: border-color .2s, transform .2s;
}
.project:hover { border-color: var(--teal); transform: translateY(-2px); color: inherit; }
.project-body { display: grid; gap: 14px; min-width: 0; }
.project-body p { color: var(--muted); }
.project-thumb { border-radius: 8px; overflow: hidden; border: 1px solid var(--rule); background: #fff; aspect-ratio: 16 / 10; }
.project-thumb img { width: 100%; height: 100%; object-fit: contain; }
.project-thumb.code { background: var(--code-bg); display: flex; align-items: center; padding: 18px; }
.project-thumb.code pre { margin: 0; font-size: 0.78rem; line-height: 1.55; color: var(--ink); white-space: pre-wrap; }
.project-thumb.code .k { color: var(--teal); font-weight: 600; }
.project-thumb.code .c { color: var(--muted); }
.more { font-weight: 500; color: var(--teal); }
@media (max-width: 760px) { .project { grid-template-columns: 1fr; padding: 20px; gap: 20px; } .project-thumb { order: -1; } }

.metrics { display: flex; flex-wrap: wrap; gap: 8px; }
.metric {
  font: 500 var(--step--1)/1 var(--font-mono); padding: 7px 10px; border-radius: 6px;
  background: var(--teal-soft); color: var(--ink); font-variant-numeric: tabular-nums;
}
.metric b { color: var(--teal); font-weight: 600; }
.metric.warn { background: var(--amber-soft); }
.metric.warn b { color: var(--amber); }
.tags { display: flex; flex-wrap: wrap; gap: 6px 14px; font: 400 var(--step--1)/1.4 var(--font-mono); color: var(--muted); }

/* ---------- skills / education ---------- */
.skills { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--rule); }
.skill { padding: 24px 24px 24px 0; border-bottom: 1px solid var(--rule); display: grid; gap: 10px; align-content: start; }
.skill:nth-child(even) { padding-left: 24px; border-left: 1px solid var(--rule); }
.skill p { color: var(--muted); }
@media (max-width: 720px) { .skills { grid-template-columns: 1fr; } .skill:nth-child(even) { padding-left: 0; border-left: 0; } }

.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 24px; padding-block: 18px; border-bottom: 1px solid var(--rule); }
.tl-item:first-child { border-top: 1px solid var(--rule); }
.tl-item .when { font: 500 var(--step--1)/1.6 var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-item p { color: var(--muted); }
@media (max-width: 560px) { .tl-item { grid-template-columns: 1fr; gap: 4px; } }

/* ---------- contact / footer ---------- */
.contact { background: var(--ink); color: var(--paper); }
.contact .wrap { padding-block: 64px; display: grid; gap: 20px; }
.contact h2 { color: var(--paper); }
.contact p { color: color-mix(in srgb, var(--paper) 75%, var(--ink)); }
.contact .btn { border-color: var(--paper); color: var(--paper); }
.contact .btn:hover, .contact .btn.primary { background: var(--paper); color: var(--ink); }
.contact .btn.primary:hover { background: var(--teal); border-color: var(--teal); color: var(--paper); }
.site-footer .wrap { padding-block: 24px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: var(--step--1); color: var(--muted); }

/* ---------- case study pages ---------- */
.case-hero .wrap { padding-block: 56px 40px; display: grid; gap: 20px; }
.case-hero .crumb { font-size: var(--step--1); }
.case-hero .lede { font-size: var(--step-1); color: var(--muted); }
.model-card {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
}
.model-card > div { padding: 18px 20px; border-left: 1px solid var(--rule); display: grid; gap: 6px; align-content: start; min-width: 0; }
.model-card > div:first-child { border-left: 0; }
.model-card dd { margin: 0; font-size: 0.95rem; }
.model-card dt { margin: 0; }
@media (max-width: 760px) {
  .model-card { grid-template-columns: 1fr 1fr; }
  .model-card > div:nth-child(3) { border-left: 0; }
  .model-card > div:nth-child(n+3) { border-top: 1px solid var(--rule); }
}

.prose { display: grid; gap: 18px; }
.prose > * { max-width: var(--measure); }
.prose ul, .prose ol { margin: 0; padding-left: 1.2rem; display: grid; gap: 6px; }
.prose li::marker { color: var(--teal); }
.prose h2 { margin-top: 36px; }
.prose h3 { margin-top: 12px; }
.prose .wide { max-width: none; }
.callout {
  border-left: 3px solid var(--amber); background: var(--amber-soft); padding: 14px 18px; border-radius: 0 8px 8px 0;
}
.callout.teal { border-color: var(--teal); background: var(--teal-soft); }

figure { margin: 0; display: grid; gap: 10px; }
figure img { border: 1px solid var(--rule); border-radius: 8px; background: #fff; }
figcaption { font-size: var(--step--1); color: var(--muted); max-width: var(--measure); }
.fig-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 760px) { .fig-grid { grid-template-columns: 1fr; } }

.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font: 500 var(--step--1)/1.3 var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
tr:last-child td { border-bottom: 0; }
tr.best td { background: var(--teal-soft); font-weight: 600; }

pre.code {
  margin: 0; background: var(--code-bg); border: 1px solid var(--rule); border-radius: 8px;
  padding: 16px 18px; overflow-x: auto; font-size: 0.84rem; line-height: 1.6; max-width: none;
}
pre.code .k { color: var(--teal); font-weight: 600; }
pre.code .c { color: var(--muted); font-style: italic; }
:not(pre) > code { background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }

/* bar chart (SVG, drawn by script from real values) */
.bars svg { width: 100%; height: auto; display: block; overflow: visible; }
.bars text { fill: var(--ink); font-family: var(--font-mono); font-size: 12px; }
.bars .axis { stroke: var(--rule); }
.bars .zero { stroke: var(--muted); }
.bars .pos { fill: var(--teal); }
.bars .neg { fill: var(--amber); }

/* adstock explorer */
.explorer { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; max-width: none; }
.explorer-controls { display: flex; flex-wrap: wrap; gap: 20px 32px; align-items: center; }
.explorer label { display: grid; gap: 4px; font-size: var(--step--1); color: var(--muted); }
.explorer input[type="range"] { width: min(260px, 70vw); accent-color: var(--teal); }
.explorer output { font: 600 1rem/1 var(--font-mono); color: var(--ink); }

.next-case { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-block: 32px; border-top: 1px solid var(--rule); margin-top: 56px; }

.embed { border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: #fff; max-width: none; }
.embed iframe { width: 100%; height: 820px; border: 0; display: block; }
@media (max-width: 760px) { .embed iframe { height: 560px; } }

.diagram { display: flex; flex-wrap: wrap; align-items: stretch; gap: 10px; max-width: none; }
.diagram .node { flex: 1 1 180px; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; display: grid; gap: 6px; min-width: 0; }
.diagram .node.hl { border-color: var(--teal); background: var(--teal-soft); }
.diagram .arrow { align-self: center; color: var(--muted); font-family: var(--font-mono); }
@media (max-width: 760px) { .diagram .arrow { width: 100%; text-align: center; } }
