/* ===== Tokens ===== */
:root {
  --paper: #f4f1ea;
  --paper-2: #ebe6db;
  --ink: #14171a;
  --muted: #5d6165;
  --line: #d6d0c3;
  --accent: #d9431f;
  --accent-ink: #ffffff;
  --card: #fbf9f4;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101214; --paper-2: #171a1d; --ink: #ece9e1; --muted: #9a9ea2;
    --line: #2b2f33; --accent: #ff6a43; --accent-ink: #101214; --card: #15181b;
  }
}
:root[data-theme="dark"] {
  --paper: #101214; --paper-2: #171a1d; --ink: #ece9e1; --muted: #9a9ea2;
  --line: #2b2f33; --accent: #ff6a43; --accent-ink: #101214; --card: #15181b;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 17px/1.6 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
img, svg, canvas { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 .5em; }
h1 { font-size: clamp(2.4rem, 6vw, 4.6rem); }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 1em; max-width: 68ch; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }
.label { font: 500 .72rem/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.accent { color: var(--accent); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ===== Header ===== */
.site-header { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.brand { font: 500 1.05rem var(--serif); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.nav { display: flex; align-items: center; gap: clamp(10px, 2.2vw, 26px); flex-wrap: wrap; }
.nav a { font: 500 .8rem var(--mono); letter-spacing: .06em; text-transform: uppercase; text-decoration: none; padding: 6px 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { border-bottom-color: var(--accent); }
.nav a:hover { color: var(--accent); }
.icon-btn { background: none; border: 1px solid var(--line); color: var(--ink); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 640px) { .site-header .wrap { padding-top: 8px; padding-bottom: 8px; } .brand span.long { display: none; } }

/* ===== Hero ===== */
.hero { position: relative; min-height: min(86vh, 760px); border-bottom: 1px solid var(--line); overflow: hidden; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: manipulation; }
.hero-text { position: relative; z-index: 2; pointer-events: none; padding-top: clamp(48px, 12vh, 120px); padding-bottom: 140px; }
.hero-text a, .hero-text .btn { pointer-events: auto; }
.hero h1 { max-width: 15ch; margin-bottom: .35em; }
.hero h1 em { font-style: italic; color: var(--accent); }
.hero .lede { font-size: clamp(1.05rem, 1.6vw, 1.3rem); max-width: 52ch; color: color-mix(in srgb, var(--ink) 82%, var(--paper)); }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.hero-hud { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 80%, transparent); backdrop-filter: blur(6px); }
.hero-hud .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.hud-item b { font: 500 1.05rem var(--mono); color: var(--ink); margin-left: 6px; }

.btn { display: inline-block; font: 500 .85rem var(--mono); letter-spacing: .06em; text-transform: uppercase; text-decoration: none; padding: 12px 20px; border: 1.5px solid var(--ink); border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.small { padding: 8px 14px; font-size: .75rem; }

/* ===== Sections ===== */
.section { padding: clamp(48px, 8vw, 96px) 0; border-bottom: 1px solid var(--line); }
.section-head { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 32px; }
.page-head { padding: clamp(40px, 8vw, 88px) 0 24px; border-bottom: 1px solid var(--line); }
.page-head p { font-size: 1.15rem; color: var(--muted); }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.card:hover { border-color: var(--ink); }
.tag { display: inline-block; font: 500 .68rem var(--mono); letter-spacing: .08em; text-transform: uppercase; padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.tag.hot { border-color: var(--accent); color: var(--accent); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.two { display: grid; gap: 40px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .two { grid-template-columns: 5fr 7fr; } }

/* ===== Lists (CV-style) ===== */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; gap: 4px 24px; grid-template-columns: 1fr; padding: 18px 0; border-top: 1px solid var(--line); }
@media (min-width: 720px) { .row { grid-template-columns: 180px 1fr; } }
.row .when { font: 500 .8rem var(--mono); color: var(--muted); padding-top: 4px; }
.row h3 { margin: 0 0 2px; font-size: 1.12rem; font-family: var(--sans); font-weight: 600; letter-spacing: 0; }
.row .org { color: var(--muted); margin: 0 0 6px; font-size: .95rem; }
.row ul { margin: 6px 0 0; padding-left: 1.1em; }
.row li { margin-bottom: 5px; max-width: 70ch; }
.skills dt { font: 500 .72rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-top: 14px; }
.skills dd { margin: 4px 0 0; }

/* ===== Stats strip ===== */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.strip div { padding: 18px 20px; border-right: 1px solid var(--line); }
.strip div:last-child { border-right: 0; }
.strip b { display: block; font: 500 1.4rem var(--serif); }
@media (max-width: 640px) { .strip div { border-right: 0; border-bottom: 1px solid var(--line); } .strip div:last-child { border-bottom: 0; } }

/* ===== Lab ===== */
.lab-panel { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: clamp(18px, 3vw, 32px); }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font: 500 .72rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.field input, .field textarea { font: inherit; padding: 10px 12px; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 4px; width: 100%; }
.field textarea { min-height: 110px; resize: vertical; }
.code-big { font: 500 clamp(2.4rem, 8vw, 4.4rem)/1 var(--mono); letter-spacing: .12em; color: var(--accent); }
.bars { display: grid; gap: 12px; margin: 20px 0; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 220px) 1fr 56px; gap: 12px; align-items: center; }
.bar-track { height: 28px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); width: 0; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar-num { font: 500 .95rem var(--mono); text-align: right; }
.choice { display: block; width: 100%; text-align: left; font: inherit; padding: 16px 18px; margin-bottom: 10px; background: var(--paper); color: var(--ink); border: 1.5px solid var(--ink); border-radius: 6px; cursor: pointer; }
.choice:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.choice[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice:disabled { cursor: default; opacity: .75; }
.notice { border-left: 3px solid var(--accent); padding: 8px 14px; background: var(--paper-2); font-size: .92rem; color: var(--muted); margin: 0 0 20px; }
.split { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ===== Footer ===== */
.site-footer { padding: 40px 0 56px; color: var(--muted); font-size: .9rem; }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.site-footer a { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bar-fill { transition: none; }
}
@media print {
  .site-header, .site-footer, .hero-hud, .icon-btn { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
}

/* ===== Lab activities ===== */
.qgrid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.qcol { border: 1px solid var(--line); border-radius: 6px; padding: 14px; background: var(--paper); }
.qcol h3 { margin: 0 0 4px; font-size: 1.05rem; }
.dots { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; margin: 12px 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.dot.housed { background: var(--accent); border-color: var(--accent); }
.wall { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; margin: 18px 0; font-family: var(--serif); }
.entry small { font: 500 .7rem var(--mono); color: var(--accent); }
.entry .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0 2px; }
.entry .x:hover { color: var(--accent); }

/* ===== Paper pages: widgets ===== */
.ctrls { display: grid; gap: 14px 28px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 20px; }
.ctrl label { display: flex; justify-content: space-between; gap: 8px; font: 500 .72rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ctrl output { color: var(--ink); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font: 500 .8rem var(--mono); cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
.readout { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; max-width: 70ch; }
.readout b { font-family: var(--mono); font-weight: 500; }
.rowbars { display: grid; gap: 8px; margin: 12px 0; }
.rowbar { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 12px; align-items: center; font: 500 .8rem var(--mono); }
.rowbar .t { height: 14px; background: var(--paper-2); border-radius: 2px; overflow: hidden; }
.rowbar .t i { display: block; height: 100%; }
.rowbar .t i.q { background: var(--ink); } .rowbar .t i.w { background: var(--accent); }
.steps { counter-reset: s; }
.steps div b::before { counter-increment: s; content: counter(s) ". "; color: var(--accent); }
svg.chart text { font: 500 11px var(--mono); fill: var(--muted); }
svg.chart .ax { stroke: var(--line); } svg.chart .zero { stroke: var(--ink); }
svg.chart .ci { stroke: var(--ink); stroke-width: 1.5; } svg.chart .pt { fill: var(--accent); }
svg.chart .truth { stroke: var(--ink); stroke-dasharray: 3 4; fill: none; stroke-width: 1.5; }
