:root {
  --paper: #f2f2f5;
  --white: #ffffff;
  --ink: #1d1d1f;
  --muted: #5f5f69;
  --line: #d3d3db;
  --blue: #2b6cff;
  --display: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  --body: "Public Sans", "Helvetica Neue", Arial, sans-serif;
  --wrap: 1180px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.6;
}

img, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }

a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--blue); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.05; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.75rem, 3.2vw, 2.5rem); }
h3 { font-size: 1.3rem; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; max-width: 62ch; }

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-block: 1.1rem; flex-wrap: wrap; }
.brand { font-family: var(--display); font-weight: 600; font-size: 1.15rem; text-decoration: none; letter-spacing: -0.01em; }
.site-nav { display: flex; gap: 1.5rem; }
.site-nav a { text-decoration: none; color: var(--muted); }
.site-nav a:hover { color: var(--blue); }
.site-nav a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.45em; }

/* Hero */
.hero { padding-block: clamp(2rem, 5vw, 4rem) clamp(3rem, 6vw, 5rem); }
.hero h1 { font-size: clamp(3.4rem, 13.5vw, 11rem); line-height: 0.88; letter-spacing: -0.045em; font-variation-settings: "wdth" 85; margin-bottom: clamp(1.5rem, 4vw, 3rem); }
.hero-grid { display: grid; grid-template-columns: 1.1fr 1fr 0.8fr; gap: clamp(1rem, 2.5vw, 2rem); align-items: end; }
.hero-copy p { font-size: clamp(1.2rem, 2vw, 1.5rem); line-height: 1.35; max-width: 22ch; }
.hero-copy .role { font-size: 1rem; color: var(--muted); margin-top: 1rem; max-width: 30ch; line-height: 1.5; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }
.btn { display: inline-block; padding: 0.7rem 1.15rem; border: 1px solid var(--ink); border-radius: 999px; text-decoration: none; font-weight: 500; line-height: 1.2; }
.btn-solid { background: var(--ink); color: var(--paper); }
.btn-solid:hover { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn:hover { border-color: var(--blue); }
.media-square { aspect-ratio: 1 / 1; width: 100%; object-fit: cover; background: var(--line); }
.media-portrait { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; object-position: 50% 0%; background: var(--line); }

/* Sections */
.section { padding-block: clamp(2.5rem, 6vw, 5rem); border-top: 1px solid var(--line); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: clamp(1.5rem, 3vw, 2.5rem); }
.section-head a { color: var(--muted); }
.section-head a:hover { color: var(--blue); }

/* Skills */
.skills { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(1.25rem, 2.5vw, 2rem); }
.skill canvas { width: 100%; aspect-ratio: 16 / 9; background: var(--paper); border-block: 1px solid var(--ink); }
.skill h3 { margin-top: 1.1rem; }
.skill p { margin-top: 0.5rem; color: var(--muted); font-size: 1rem; }

/* Project list */
.project-list { list-style: none; margin: 0; padding: 0; }
.project-row { display: grid; grid-template-columns: 1.2fr 1.6fr auto; gap: 1rem 2rem; align-items: baseline; padding-block: 1.4rem; border-top: 1px solid var(--line); }
.project-row:last-child { border-bottom: 1px solid var(--line); }
.project-row h3 { font-size: clamp(1.3rem, 2.2vw, 1.7rem); }
.project-row h3 a { text-decoration: none; }
.project-row p { color: var(--muted); font-size: 1rem; }
.project-row .result { font-family: var(--display); font-weight: 600; font-size: 1.05rem; white-space: nowrap; text-align: right; }
.project-row .result small { display: block; font-family: var(--body); font-weight: 400; font-size: 0.85rem; color: var(--muted); }

/* Page intro */
.page-intro { padding-block: clamp(2.5rem, 6vw, 4.5rem); }
.page-intro h1 { font-size: clamp(2.6rem, 8vw, 6rem); line-height: 0.92; letter-spacing: -0.04em; font-variation-settings: "wdth" 85; }
.page-intro .lede { margin-top: 1.25rem; font-size: clamp(1.1rem, 1.8vw, 1.35rem); line-height: 1.45; max-width: 52ch; }
.intro-split { display: grid; grid-template-columns: 1.6fr 1fr; gap: clamp(1.5rem, 4vw, 3rem); align-items: end; }

/* Facts */
.facts { margin: 0; display: grid; grid-template-columns: 11rem 1fr; }
.facts dt, .facts dd { margin: 0; padding-block: 0.9rem; border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd span { display: block; color: var(--muted); font-size: 0.95rem; }
.about-grid { display: grid; grid-template-columns: 0.8fr 1.6fr; gap: clamp(1.5rem, 5vw, 4rem); align-items: start; }

/* Project page */
.prose > * + * { margin-top: 1rem; }
.prose h2 { margin-top: 0; margin-bottom: 0.25rem; font-size: clamp(1.5rem, 2.6vw, 2rem); }
.two-col { display: grid; grid-template-columns: 1fr 1.7fr; gap: clamp(1.5rem, 4vw, 3rem); align-items: start; }
.figure { margin: 0; background: var(--white); border: 1px solid var(--line); padding: clamp(1rem, 2.5vw, 1.75rem); }
.figure figcaption { margin-top: 1rem; color: var(--muted); font-size: 0.95rem; }
.legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1rem; font-size: 0.95rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.5rem; }
.swatch { width: 14px; height: 14px; display: inline-block; }
.swatch-line { width: 22px; height: 0; border-top: 2px dashed var(--ink); display: inline-block; }
.chart text { font-family: var(--body); }
.data-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.data-table th, .data-table td { text-align: left; padding: 0.65rem 0; border-top: 1px solid var(--line); font-weight: 400; vertical-align: top; }
.data-table th { color: var(--muted); width: 45%; }
.data-table td { font-variant-numeric: tabular-nums; }
.back { color: var(--muted); }

/* Contact */
.contact-email { font-family: var(--display); font-weight: 600; font-size: clamp(1.5rem, 5.2vw, 3.6rem); letter-spacing: -0.03em; line-height: 1.1; overflow-wrap: anywhere; text-decoration-thickness: 2px; }

/* Footer */
.site-footer { border-top: 1px solid var(--ink); margin-top: clamp(2rem, 5vw, 4rem); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; padding-block: 1.5rem 2.5rem; color: var(--muted); font-size: 0.95rem; }
.site-footer nav { display: flex; gap: 1.5rem; flex-wrap: wrap; }

@media (max-width: 860px) {
  .hero-grid { grid-template-columns: 1fr 1fr; }
  .hero-copy { grid-column: 1 / -1; }
  .hero-copy p { max-width: 30ch; }
  .skills { grid-template-columns: 1fr; }
  .project-row { grid-template-columns: 1fr; gap: 0.4rem; }
  .project-row .result { text-align: left; }
  .intro-split, .about-grid, .two-col { grid-template-columns: 1fr; }
  .about-grid .media-portrait { max-width: 260px; }
  .intro-split .media-square { max-width: 320px; }
  .facts { grid-template-columns: 1fr; }
  .facts dd { border-top: 0; padding-top: 0; }
  .facts dt { padding-bottom: 0.15rem; }
}

/* Chart grid on project pages */
.chart-grid { display: grid; grid-template-columns: 1fr; gap: clamp(1rem, 2.5vw, 2rem); }
.chart-grid .figure h3 { margin-bottom: 1rem; }
.figure h3 { margin-bottom: 1rem; }
.stack > * + * { margin-top: clamp(1rem, 2.5vw, 2rem); }

/* Simulator */
.sim { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: clamp(1.5rem, 4vw, 3rem); align-items: start; }
.sim-form { display: grid; gap: 1.1rem; }
.field label, .field .label { display: flex; justify-content: space-between; gap: 1rem; font-weight: 500; margin-bottom: 0.35rem; }
.field output { font-variant-numeric: tabular-nums; color: var(--blue); font-weight: 600; }
.field input[type="number"], .field select { width: 100%; font: inherit; color: var(--ink); background: var(--white); border: 1px solid var(--ink); border-radius: 6px; padding: 0.55rem 0.7rem; }
.field input[type="range"] { width: 100%; accent-color: var(--blue); }
.field .hint { color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }
.field .error { color: #b3261e; font-size: 0.9rem; margin-top: 0.3rem; }
.check { display: flex; gap: 0.6rem; align-items: flex-start; }
.check input { width: 1.1rem; height: 1.1rem; margin-top: 0.25rem; accent-color: var(--blue); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.sim-form details { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding-block: 0.8rem; }
.sim-form summary { cursor: pointer; font-weight: 500; }
.sim-form details .sim-form { margin-top: 1rem; }
.sim-form button { font: inherit; cursor: pointer; }
.sim-form button.btn:not(.btn-solid) { background: var(--paper); color: var(--ink); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.tile { padding: 1rem 1rem 1rem 0; }
.tile + .tile { padding-left: 1rem; border-left: 1px solid var(--line); }
.tile b { display: block; font-family: var(--display); font-weight: 600; font-size: clamp(1.4rem, 2.6vw, 2.1rem); letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; line-height: 1.35; }
.tile-main b { color: var(--blue); }
.sim-note { color: var(--muted); font-size: 0.95rem; max-width: 70ch; }
.table-scroll { overflow-x: auto; }
.pct-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.pct-table th, .pct-table td { text-align: right; padding: 0.55rem 0.6rem; border-top: 1px solid var(--line); font-weight: 400; white-space: nowrap; }
.pct-table th:first-child, .pct-table td:first-child { text-align: left; padding-left: 0; }
.pct-table thead th { color: var(--muted); border-top: 0; }

@media (max-width: 860px) {
  .chart-grid, .sim { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile:nth-child(3) { border-left: 0; padding-left: 0; }
  .tile:nth-child(n+3) { border-top: 1px solid var(--line); }
}
.sim > *, .chart-grid > *, .two-col > * { min-width: 0; }
.field label.check { justify-content: flex-start; font-weight: 400; margin-bottom: 0; }

/* Chart filters on project pages */
.filters { position: sticky; top: 0; z-index: 5; background: var(--paper); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.filters .wrap { display: flex; flex-wrap: wrap; gap: 0.75rem 2.5rem; padding-block: 0.8rem; align-items: center; }
.filter-group { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.filter-name { font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--ink); padding: 0.4rem 0.95rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: center; }
.chips label { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.chips input { width: 1.05rem; height: 1.05rem; accent-color: var(--blue); }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer; }
.link-btn:hover { color: var(--blue); }
.section-flush { border-top: 0; }
.chart-empty { color: var(--muted); padding: 2.5rem 0; max-width: 48ch; }
[hidden] { display: none !important; }
@media (max-width: 860px) { .filters { position: static; } }

/* Sudoku */
.sudoku-layout { display: grid; grid-template-columns: auto 1fr; gap: clamp(1.5rem, 5vw, 4rem); align-items: start; }
.sudoku-layout > * { min-width: 0; }
.sudoku { --cell: min(54px, calc((100vw - 2.5rem - 4px) / 9)); display: grid; grid-template-columns: repeat(9, var(--cell)); border: 2px solid var(--ink); width: max-content; background: var(--white); }
.sudoku input { width: var(--cell); height: var(--cell); border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; text-align: center; font-family: var(--display); font-weight: 600; font-size: calc(var(--cell) * 0.5); color: var(--ink); padding: 0; caret-color: var(--blue); }
.sudoku input:nth-child(9n) { border-right: 0; }
.sudoku input:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--ink); }
.sudoku input:nth-child(n+19):nth-child(-n+27), .sudoku input:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ink); }
.sudoku input:nth-child(n+73) { border-bottom: 0; }
.sudoku input:focus { outline: 2px solid var(--blue); outline-offset: -2px; background: #e9f0ff; }
.sudoku input.is-solved { color: var(--blue); font-weight: 400; }
.sudoku input.is-conflict { background: #fde7e5; color: #b3261e; }
.sudoku-msg { min-height: 3.2em; margin-top: 1rem; max-width: 46ch; color: var(--muted); }
.sudoku-msg.is-ok { color: var(--ink); }
.sudoku-msg.is-error { color: #b3261e; }
.sudoku-layout .actions { margin-top: 0.5rem; }
.sudoku-layout button.btn { font: inherit; font-weight: 500; cursor: pointer; }
.sudoku-layout button.btn:not(.btn-solid) { background: var(--paper); color: var(--ink); }
@media (max-width: 860px) { .sudoku-layout { grid-template-columns: 1fr; } }

/* Strategy page extras */
.chips label.is-off { opacity: 0.4; cursor: default; }
.chips .swatch, .pct-table .swatch { width: 12px; height: 12px; display: inline-block; vertical-align: -1px; }
.mix-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; }
.field .mix-grid label { display: block; font-weight: 400; font-size: 0.9rem; margin: 0; }
.mix-grid input { margin-top: 0.2rem; padding: 0.45rem 0.3rem !important; text-align: center; }
.prose strong { font-weight: 600; }

/* Digit recognition demo */
.digit-demo { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.5rem, 5vw, 4rem); align-items: start; }
.digit-demo h3 { margin-bottom: 0.75rem; }
.drop { display: flex; flex-direction: column; gap: 0.3rem; padding: 1.25rem; border: 1.5px dashed var(--ink); background: var(--white); cursor: pointer; }
.drop.is-over, .drop:focus-within { border-color: var(--blue); background: #e9f0ff; }
.drop input { font: inherit; margin-bottom: 0.5rem; max-width: 100%; }
.drop .hint, .digit-demo .error { font-size: 0.9rem; color: var(--muted); }
.digit-demo .error { color: #b3261e; margin-top: 0.4rem; }
.digit-preview { max-width: 180px; max-height: 180px; margin-top: 0.75rem; border: 1px solid var(--line); }
.pad { width: min(280px, 100%); aspect-ratio: 1 / 1; border: 2px solid var(--ink); background: #fff; touch-action: none; cursor: crosshair; }
.digit-demo button.btn { font: inherit; font-weight: 500; cursor: pointer; background: var(--paper); color: var(--ink); }
.samples { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sample { padding: 0; border: 1px solid var(--ink); background: #fff; cursor: pointer; line-height: 0; }
.sample canvas { width: 44px; height: 44px; image-rendering: pixelated; }
.sample:hover { border-color: var(--blue); }
.digit-result { position: sticky; top: 1rem; }
.digit-answer { display: flex; gap: 2.5rem; align-items: flex-end; border-top: 1px solid var(--ink); padding-top: 1rem; }
.digit-label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 0.4rem; }
.digit-answer b { display: block; font-family: var(--display); font-weight: 600; font-size: clamp(5rem, 14vw, 9rem); line-height: 0.85; letter-spacing: -0.04em; color: var(--blue); min-width: 1ch; }
.seen { width: 112px; height: 112px; image-rendering: pixelated; border: 1px solid var(--line); background: #000; }
.digit-result .sim-note { margin: 1rem 0; min-height: 3em; }
.bar-row { display: grid; grid-template-columns: 1.2rem 1fr 3.6rem; gap: 0.6rem; align-items: center; padding: 0.22rem 0; font-variant-numeric: tabular-nums; }
.bar-digit { font-weight: 600; }
.bar-track { height: 14px; background: var(--line); }
.bar-fill { display: block; height: 100%; width: 0; background: var(--muted); transition: width 0.2s ease; }
.bar-row.is-top .bar-fill { background: var(--blue); }
.bar-row.is-top .bar-digit, .bar-row.is-top .bar-pct { color: var(--blue); font-weight: 600; }
.bar-pct { text-align: right; font-size: 0.9rem; }
@media (max-width: 860px) { .digit-demo { grid-template-columns: 1fr; } .digit-result { position: static; } }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }
.digit-demo > *, .digit-demo .stack > * { min-width: 0; }
.drop input { width: 100%; }
