:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6a737d;
  --line: #e3e6ea;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --btn: #363636;
  --btn-ink: #ffffff;
  --code-bg: #f6f8fa;
  --kw: #cf222e; --str: #0a3069; --cm: #6e7781; --num: #0550ae; --doc: #57606a;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 18px rgba(0,0,0,0.06);
  --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 16px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-text-size-adjust: 100%; }
a { color: #1c64c8; }
h1, h2, h3, .btn, .kicker, .toc, .demo-title { font-family: "Google Sans", "Noto Sans", system-ui, sans-serif; }
code { font: 0.88em "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--code-bg); padding: 0.08em 0.35em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
img { max-width: 100%; height: auto; display: block; }

/* navigation */
.toc { position: fixed; top: 24px; left: 18px; display: flex; flex-direction: column; gap: 2px; z-index: 5; font-size: 0.86rem; }
.toc a { color: var(--muted); text-decoration: none; padding: 3px 10px; border-left: 2px solid var(--line); }
.toc a:hover { color: var(--ink); }
.toc a.on { color: var(--ink); border-left-color: var(--accent); font-weight: 500; }
@media (max-width: 1320px) { .toc { display: none; } }

/* hero */
.hero { text-align: center; padding: 48px 16px 8px; max-width: 1180px; margin: 0 auto; }
.hero h1 { font-size: clamp(1.7rem, 3.4vw, 2.6rem); line-height: 1.2; margin: 0 auto 14px; max-width: 900px; font-weight: 500; }
.authors { font-size: 1.2rem; margin: 0 0 4px; font-family: "Google Sans", sans-serif; }
.authors a { color: #3273dc; text-decoration: none; }
.venue { color: var(--muted); margin: 0 0 18px; font-family: "Google Sans", sans-serif; font-size: 1.05rem; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 28px; }
.btn { display: inline-flex; align-items: center; gap: 7px; background: var(--btn); color: var(--btn-ink); border: 0; border-radius: 999px; padding: 8px 18px; font-size: 0.98rem; text-decoration: none; cursor: pointer; line-height: 1.3; min-height: 40px; }
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: #111; }
.btn.small { padding: 5px 13px; font-size: 0.88rem; min-height: 32px; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: #c94a06; }
.btn:disabled { opacity: 0.45; cursor: default; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 0.85rem; }
.ghost-btn { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font: 500 0.84rem "Google Sans", sans-serif; cursor: pointer; color: var(--ink); }
.ghost-btn:hover, .ghost-btn.on { border-color: var(--ink); }
.ghost-btn.on { background: var(--ink); color: #fff; }
.chip-btn { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font: 0.85rem "Google Sans", sans-serif; cursor: pointer; color: var(--ink); min-height: 32px; }
.chip-btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.icon-btn { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 0.95rem; }

/* panels (hero demo + playground) */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; }
.demo { padding: 18px; margin: 0 auto 20px; }
.demo-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.demo-title { font-size: 1.25rem; margin: 0 0 4px; font-weight: 500; }
.demo-head p { margin: 0; max-width: 760px; }
.demo-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; }
.viewer-wrap { min-width: 0; }
.viewer { width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: #f4f5f7; touch-action: none; position: relative; }
.viewer.tall { aspect-ratio: 5 / 4; }
.viewer canvas { display: block; }
.wheel-hint { position: absolute; inset: auto 0 12px; margin: 0 auto; width: max-content; max-width: calc(100% - 24px); padding: 6px 12px; border-radius: 8px; background: rgba(20, 22, 26, 0.78); color: #fff; font-size: 0.82rem; text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.2s; }
.wheel-hint.show { opacity: 1; }
.viewer-tools { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 0.86rem; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }
.side { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.views { display: grid; gap: 10px; }
.views.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.view-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg-soft); min-width: 0; }
.view-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 0.84rem; min-width: 0; }
.view-head select { min-width: 0; flex: 1; font: inherit; padding: 3px 4px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.view-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.dot { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; color: #fff; font: 700 0.75rem "Google Sans", sans-serif; align-items: center; justify-content: center; flex: none; }
.view-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.view-imgs figure, .cell-imgs figure, .strips figure { margin: 0; text-align: center; }
.view-imgs canvas { width: 100%; aspect-ratio: 1; image-rendering: pixelated; border-radius: 5px; background: #ddd; display: block; }
figcaption { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }
.view-angles { font-size: 0.8rem; color: var(--muted); margin: 6px 0; display: grid; gap: 2px; }
.view-angles label { display: grid; grid-template-columns: 62px 1fr 34px; align-items: center; gap: 6px; }
.view-angles input { width: 100%; accent-color: var(--accent); }
.view-card .ghost-btn { width: 100%; }
.chart-wrap { width: 100%; min-width: 0; }
.chart-wrap canvas { display: block; }
.status { font-size: 0.86rem; margin: 0; min-height: 2.6em; color: var(--ink); }
.status .err, .err { color: #c92a2a; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; margin: 0; }
.lg { display: inline-block; width: 14px; height: 10px; margin-right: -6px; border-radius: 2px; vertical-align: middle; }
.lg.loss { background: #e8590c; height: 3px; }
.lg.shade { background: rgba(112,72,232,0.18); }
.lg.sub { border-left: 2px dashed rgba(232,89,12,0.8); width: 2px; }
.lg.rays { border-left: 2px dashed rgba(28,126,214,0.7); width: 2px; }

/* prose */
main { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; }
.prose { max-width: 900px; margin: 0 auto; padding: 34px 0 10px; }
.prose h2 { font-size: 1.85rem; margin: 0 0 12px; font-weight: 500; }
.prose h3 { font-size: 1.3rem; margin: 30px 0 8px; font-weight: 500; }
.prose p { margin: 0 0 12px; }
.kicker { color: var(--accent); font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; margin: 0 0 4px !important; }
.math { text-align: center; font-family: "Noto Sans", serif; font-size: 1.04rem; overflow-x: auto; padding: 4px 0; }
.math .eq { color: var(--muted); margin-left: 18px; font-size: 0.9rem; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; align-items: start; margin: 12px 0; }
.paper-fig { margin: 8px 0 14px; }
.paper-fig img { border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.paper-fig.wide { margin: 16px 0; }
.paper-fig figcaption { font-size: 0.84rem; margin-top: 6px; }
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 18px 0 6px; }
.step { display: flex; flex-direction: column; gap: 3px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); background: var(--bg-soft); font-size: 0.88rem; }
.step:hover { border-color: var(--ink); }
.step .n { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font: 700 0.8rem "Google Sans", sans-serif; }
.step b { font-family: "Google Sans", sans-serif; font-size: 1rem; }
.bullets { padding-left: 1.1em; }
.bullets li { margin-bottom: 8px; }

/* figures */
.figure-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 16px 0; background: var(--panel); box-shadow: var(--shadow); }
.fig-head { font-size: 0.88rem; color: var(--muted); margin-bottom: 8px; }
.fig-head b { color: var(--accent); }
.fig-canvas-wrap { width: 100%; min-width: 0; }
.fig-canvas-wrap canvas, .slicing-grid canvas { display: block; touch-action: none; }
.fig-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; font-size: 0.88rem; }
.fig-controls label { display: inline-flex; align-items: center; gap: 6px; }
.fig-controls input[type=range] { accent-color: var(--accent); width: 140px; }
.fig-controls select { font: inherit; padding: 2px 4px; border-radius: 6px; }
.fig-info { font-size: 0.84rem; color: var(--muted); margin: 8px 0 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(0,0,0,0.25); vertical-align: middle; }
.swatch.big { width: 30px; height: 30px; }
.pixel-out { display: inline-flex; align-items: center; gap: 6px; }
.slicing-grid { display: flex; gap: 24px; align-items: flex-start; }
.slice-layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.strips { display: flex; gap: 10px; }
.strips canvas { border-radius: 4px; border: 1px solid var(--line); display: block; }
.targets { display: inline-flex; gap: 4px; }
.swatch-btn { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch-btn.on { box-shadow: 0 0 0 2px var(--ink); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.eq-table, table.data { border-collapse: collapse; font-size: 0.84rem; margin-top: 10px; width: 100%; }
.eq-table th, .eq-table td, table.data th, table.data td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.eq-table th { font-weight: 500; color: var(--muted); }
.eq-table tr.hit td { background: #fff4e6; font-weight: 500; }
.eq-table tr.hidden-row td { color: #adb5bd; }
.chip { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.25); vertical-align: middle; }
table.data caption { text-align: left; font-size: 0.84rem; color: var(--muted); padding-bottom: 4px; }
table.data th { font-weight: 500; background: var(--bg-soft); }
table.data.settings td { white-space: normal; }
table.data.settings td:last-child { white-space: nowrap; }
table.data .live { min-width: 160px; }

/* code */
.code-details { margin: 14px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.code-details summary { cursor: pointer; padding: 9px 14px; background: var(--bg-soft); font: 500 0.92rem "Google Sans", sans-serif; }
.code-file { display: flex; justify-content: space-between; gap: 10px; padding: 6px 14px; font: 0.78rem "JetBrains Mono", monospace; border-top: 1px solid var(--line); background: #fbfbfc; }
pre.code { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg); font: 0.8rem/1.5 "JetBrains Mono", ui-monospace, Menlo, monospace; }
pre.code code { background: none; padding: 0; font-size: inherit; }
.kw { color: var(--kw); } .str { color: var(--str); } .cm { color: var(--cm); font-style: italic; } .num { color: var(--num); } .doc { color: var(--doc); }

/* python cells */
/* code cells: the repository's Python (read-only) next to the same steps in the JavaScript port (editable) */
.pyjs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 12px; margin: 16px 0; overflow: hidden; background: #fff; }
.pyjs-col { display: flex; flex-direction: column; min-width: 0; }
.pyjs-col + .pyjs-col { border-top: 1px solid var(--line); }
.pyjs-head { padding: 8px 12px; font-size: 0.84rem; color: #334; background: var(--bg-soft); border-bottom: 1px solid var(--line); }
.pyjs pre.code { flex: 1; }
.py-badge, .js-badge { display: inline-block; color: #fff; border-radius: 6px; padding: 1px 7px; font: 500 0.74rem "Google Sans", sans-serif; margin-right: 4px; }
.py-badge { background: #3572a5; }
.js-badge { background: #8a6d00; }
.jscell textarea { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; font: 0.8rem/1.5 "JetBrains Mono", ui-monospace, Menlo, monospace; background: #fffdf3; color: var(--ink); resize: vertical; min-height: 60px; tab-size: 2; white-space: pre; overflow-x: auto; overflow-y: hidden; }
.jscell textarea:focus { outline: 2px solid #e2c766; outline-offset: -2px; }
.cell-bar { display: flex; align-items: center; gap: 10px; padding: 7px 12px; flex-wrap: wrap; }
.jscell .out { margin: 0; padding: 0 12px 10px; font: 0.78rem/1.5 "JetBrains Mono", ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word; color: #24292f; }
.jscell .out:empty { display: none; }
.jscell .out.err { color: #b42318; }
.pyjs-img { margin: 0; padding: 0 12px 12px; }
.pyjs-img canvas { width: 128px; height: 128px; image-rendering: pixelated; border-radius: 6px; display: block; }
/* side by side when there is room: the cell grows into the page margins (main is the container) */
main { container-type: inline-size; }
@container (min-width: 1040px) {
  .pyjs:not(.narrow) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-inline: calc((900px - 100cqw) / 2); }
  .pyjs:not(.narrow) .pyjs-col + .pyjs-col { border-top: 0; border-left: 1px solid var(--line); }
}

/* playground */
.playground { max-width: 1180px; margin: 40px auto; padding: 20px; }
.pg-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.pg-head h2 { margin: 0 0 6px; font-size: 1.85rem; font-weight: 500; }
.pg-head p { margin: 0; max-width: 760px; font-size: 0.94rem; }
.pg-head p + p { margin-top: 8px; }
.scenario { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.9rem; max-width: 100%; }
.scenario select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); max-width: 100%; min-width: 0; }
.toggle.speed select { font: inherit; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--line); background: #fff; margin-left: 4px; }
.pg-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 20px; }
.pg-views .views { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pg-views .add { margin-top: 10px; width: 100%; padding: 8px; }
.pg-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.run-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.warn { background: #fff4e6; border: 1px solid #ffd8a8; border-radius: 8px; padding: 8px 10px; font-size: 0.84rem; margin: 10px 0 0; }
.opt-note { margin: 8px 0 0; }
.opts summary { cursor: pointer; font: 500 0.92rem "Google Sans", sans-serif; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 14px; margin-top: 10px; font-size: 0.88rem; }
.opt-grid label { display: flex; align-items: center; gap: 6px; }
.opt-grid input[type=number] { width: 80px; font: inherit; padding: 3px 5px; border-radius: 6px; border: 1px solid var(--line); }
.opt-grid select { font: inherit; padding: 3px; border-radius: 6px; }
.opt-grid input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.is-running [data-r=run] { opacity: 0.6; }

/* citation, footer */
.bib { position: relative; }
.bib pre { background: var(--code-bg); border-radius: 10px; padding: 14px; overflow-x: auto; font: 0.82rem/1.5 "JetBrains Mono", monospace; margin: 0 0 12px; }
.bib .btn { position: absolute; right: 10px; top: 10px; }
.footer { text-align: center; color: var(--muted); font-size: 0.84rem; padding: 26px 16px 40px; border-top: 1px solid var(--line); }

/* responsive */
@media (max-width: 980px) {
  .demo-grid, .pg-grid { grid-template-columns: minmax(0, 1fr); }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  body { font-size: 15px; }
  .hero { padding-top: 30px; }
  .demo, .playground { padding: 12px; border-radius: 12px; }
  .demo-head { flex-direction: column; }
  .views.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .views.compact .view-card { padding: 5px; }
  .views.compact .view-angles, .views.compact .view-label { display: none; }
  .views.compact .ghost-btn { font-size: 0.72rem; padding: 3px 4px; }
  .pg-views .views { grid-template-columns: minmax(0, 1fr); }
  .two { grid-template-columns: minmax(0, 1fr); }
  .slicing-grid { flex-direction: column; gap: 10px; }
  .slice-layout { grid-template-columns: minmax(0, 1fr); }
  .strips { justify-content: center; }
  .strips canvas { transform: rotate(0deg); }
  .prose h2, .pg-head h2 { font-size: 1.5rem; }
  .fig-controls input[type=range] { width: 110px; }
}
.views.compact figcaption { font-size: 0.68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.steps-bar { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.step-btn { font-size: 1.02rem; padding: 10px 20px; min-height: 46px; }
.step-btn .step-n { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,0.22); align-items: center; justify-content: center; font-weight: 700; font-size: 0.86rem; }
.step-btn.primary:not(:disabled) { box-shadow: 0 0 0 0 rgba(232,89,12,0.5); animation: pulse 1.8s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(232,89,12,0.45); } 100% { box-shadow: 0 0 0 12px rgba(232,89,12,0); } }
.toggle input:disabled + * , .toggle:has(input:disabled) { opacity: 0.55; }

/* standalone design tool (app.html) */
.app-bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; max-width: 1180px; margin: 0 auto; padding: 14px 16px 0; }
.app-title { font-family: 'Google Sans', 'Noto Sans', sans-serif; font-weight: 500; font-size: 1.02rem; color: inherit; text-decoration: none; }
.app-title:hover { text-decoration: underline; }
.app-links { display: flex; gap: 16px; font-size: 0.92rem; }
.app-page .playground { margin-top: 16px; }
.app-help { padding-top: 10px; }
.app-help ol { padding-left: 1.3em; }
.app-help li { margin-bottom: 8px; }

/* settings table on phones: two columns, the file name moves under the setting */
@media (max-width: 600px) {
  /* number tables fit the screen: long column headers wrap */
  table.data th { white-space: normal; vertical-align: bottom; }
  table.data th, table.data td { padding: 4px 5px; }
  table.data.num { font-size: 0.78rem; }
  .bib pre { padding-top: 48px; } /* the Copy button sits above the text instead of over it */
  table.data.settings tr:first-child th:last-child { display: none; }
  table.data.settings td:first-child { width: 30%; }
  table.data.settings td:last-child { display: block; border-bottom: 0; padding-top: 0; font-size: 0.78rem; }
  table.data.settings tr { display: grid; grid-template-columns: 30% 70%; border-bottom: 1px solid var(--line); }
  table.data.settings td, table.data.settings th { border-bottom: 0; }
  table.data.settings td:last-child { grid-column: 2; }
}
/* show code exactly as typed: no programming ligatures (<= must not render as ≤) */
html body :is(code, pre, textarea, .code-file, .out), html body .jscell .out { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
/* iOS Safari zooms the page when a form field with text under 16px gets focus: use 16px on touch screens
   (code cells keep their size, so the JavaScript lines up with the Python next to it) */
@media (hover: none) and (pointer: coarse) {
  html body :is(input, select) { font-size: 16px !important; }
  .opt-grid input[type=number] { width: 104px; }
}
/* notice at the top of both pages */
.newbar b { font-weight: 600; user-select: all; }
.newbar { background: #fff8e6; border-bottom: 1px solid #f1dfae; color: #5c4a14; font-size: 0.84rem; line-height: 1.4; text-align: center; padding: 6px 16px; }
