:root { --ink: #2b2b2b; --muted: #6b7680; --line: #e4e9ec; --teal: #13808b; --teal2: #1a97a4; --sun: #f6c218; --bg: #fbfbfa; --card: #f3f5f6; --ok: #16a34a; --no: #dc2626; }
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 18.5px/1.65 -apple-system, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 24px; background: rgba(251,251,250,.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; color: var(--teal); letter-spacing: .5px; }
.brand span { font-weight: 500; color: var(--muted); }
.modes { display: flex; gap: 4px; margin-left: auto; background: #eef1f2; padding: 4px; border-radius: 999px; }
.modes button { border: 0; background: transparent; padding: 6px 16px; border-radius: 999px; font-size: 15px; font-weight: 600; color: var(--muted); }
.modes button.active { background: #fff; color: var(--teal); box-shadow: 0 1px 4px #0001; }
.score { font-size: 14px; color: var(--muted); min-width: 150px; text-align: right; }

main { max-width: 760px; margin: 0 auto; padding: 0 22px 120px; }
.hero { padding: 64px 0 24px; }
.kicker { font-size: 13px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--teal2); }
h1 { font-size: 46px; line-height: 1.1; letter-spacing: -1px; margin: 10px 0 14px; }
h2 { font-size: 30px; line-height: 1.2; letter-spacing: -.5px; margin: 8px 0 14px; }
.meta { color: var(--muted); font-size: 15.5px; }
.toc { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; margin-top: 22px; font-size: 15px; }
.toc a { color: var(--ink); text-decoration: none; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.toc a span { display: inline-block; width: 22px; color: var(--teal); font-weight: 700; }

.beat { padding: 56px 0 8px; }
.beat p { margin: 0 0 16px; }

/* figures break out of the text column, like ciechanow.ski */
.figure { position: relative; width: min(1120px, 96vw); margin: 26px 0 22px 50%; transform: translateX(-50%); background: var(--card); border-radius: 22px; padding: 18px; }
.stage { display: grid; grid-template-columns: 1fr; gap: 14px; }
.stage.with-chart { grid-template-columns: 1fr 340px; }
.scene { position: relative; height: 580px; border-radius: 16px; overflow: hidden; background: radial-gradient(ellipse at 50% 30%, #ffffff 0%, #eef2f4 70%); cursor: grab; }
.scene:active { cursor: grabbing; }
.chart { background: #fff; border-radius: 16px; padding: 14px 14px 6px; align-self: start; }
.chart-title { font-size: 14px; font-weight: 700; fill: var(--ink); }
.chart-label { font-size: 12px; fill: var(--muted); font-weight: 600; }
.chart-legend { font-size: 11px; fill: var(--muted); }
.chart-status { font-size: 13px; font-weight: 700; }
.axis text { fill: var(--muted); font-size: 11px; }
.axis path, .axis line { stroke: #cfd8dc; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.label { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 13px; font-weight: 700; color: #fff; background: #1f2937e6; padding: 4px 10px; border-radius: 8px; transition: opacity .2s; }
.label::after { content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: #1f2937e6; }
.readout { position: absolute; left: 14px; bottom: 12px; font-size: 12.5px; color: var(--muted); background: #fffc; padding: 3px 10px; border-radius: 999px; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 26px; align-items: center; padding: 14px 6px 4px; }
.slider { display: flex; align-items: center; gap: 12px; flex: 1 1 320px; font-size: 15px; font-weight: 600; }
.slider-name { min-width: 92px; }
.slider input { flex: 1; accent-color: var(--teal); height: 26px; }
.slider-val { font-variant-numeric: tabular-nums; color: var(--muted); width: 40px; }
.segmented { display: inline-flex; background: #e3e8ea; border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--teal); box-shadow: 0 1px 4px #0002; }

.stepbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 4px 2px; }
.step { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 12px; font-size: 14px; color: var(--ink); }
.step b { color: var(--teal); margin-right: 7px; }
.step.done { background: #e9f4f5; border-color: #cfe7ea; }
.step.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.step.active b { color: var(--sun); }
.play { border: 0; background: var(--ink); color: #fff; border-radius: 10px; padding: 6px 16px; font-size: 14px; font-weight: 700; }
.play.playing { background: var(--teal); }
.ghost { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 14px; font-size: 14px; color: var(--muted); margin-top: 6px; }
.say { min-height: 30px; padding: 10px 8px 2px; font-size: 16.5px; color: var(--ink); font-style: italic; }
.say.on::before { content: "🔊 "; font-style: normal; }
.caption { font-size: 14.5px; color: var(--muted); padding: 4px 8px 2px; }

.ask { padding: 26px 28px; background: #fff; border: 1px solid var(--line); }
.ask-kicker { font-size: 12px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; color: var(--sun); filter: brightness(.85); }
.ask-q { font-size: 21px; font-weight: 700; line-height: 1.35; margin: 6px 0 14px; }
.ask-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 16px; font-size: 16px; color: var(--ink); transition: transform .1s; }
.opt:hover:not(:disabled) { border-color: var(--teal2); transform: translateY(-1px); }
.opt.right { border-color: var(--ok); background: #f0fdf4; }
.opt.wrong { border-color: var(--no); background: #fef2f2; }
.opt.dim { opacity: .55; }
.reveal { margin-top: 16px; }
.reveal.hidden, .why.hidden { display: none; }
.verdict { font-weight: 800; font-size: 20px; }
.verdict.ok { color: var(--ok); } .verdict.no { color: var(--no); }
.why-wrong { color: var(--muted); }
.reveal .figure { width: 100%; margin: 16px 0 0; transform: none; }
.qbox { padding: 16px 0; border-top: 1px solid var(--line); }
.why { color: var(--muted); font-size: 15.5px; margin: 10px 2px 0; }
.order { padding-left: 22px; } .order li { background: #f6f8f9; border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 6px 0; cursor: pointer; }
.order li.sel { border-color: var(--teal); } .order li.right { border-color: var(--ok); } .order li.wrong { border-color: var(--no); }

/* Check mode: only the questions */
body[data-mode="check"] .beat:not([data-component="predict_reveal"]):not([data-component="quiz"]):not([data-component="drag_order"]) { display: none; }
body[data-mode="check"] .beat p { display: none; }

.watchbar { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 140%); display: flex; gap: 14px; align-items: center; background: #111827; color: #fff; padding: 10px 12px 10px 18px; border-radius: 999px; font-size: 15px; transition: transform .3s; box-shadow: 0 10px 30px #0003; z-index: 30; }
.watchbar.show { transform: translate(-50%, 0); }
.watchbar .dot { width: 9px; height: 9px; border-radius: 99px; background: #ef4444; animation: blink 1.2s infinite; }
.watchbar button { border: 0; background: #ffffff1f; color: #fff; border-radius: 999px; padding: 5px 14px; font-weight: 700; }
@keyframes blink { 50% { opacity: .3; } }

.behind { margin-top: 90px; padding-top: 40px; border-top: 2px solid var(--line); }
.pipeline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; margin: 14px 0; }
.pipeline span { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; color: var(--ink); font-weight: 600; }
.pipeline span.out { background: var(--teal); color: #fff; border-color: var(--teal); }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; font-size: 14px; }
.stats span { background: #eef6f7; color: var(--ink); border-radius: 8px; padding: 4px 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 6px 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.note { font-size: 14.5px; color: var(--muted); margin: 10px 0 8px; }
.json { width: min(1120px, 96vw); margin-left: 50%; transform: translateX(-50%); max-height: 560px; overflow: auto; background: #0f1720; color: #d6e2ea; border-radius: 16px; padding: 18px 20px; font: 12.5px/1.55 "SF Mono", Menlo, monospace; }
.json .k { color: #7dd3fc; } .json .s { color: #fde68a; } .json .n { color: #fca5a5; } .json .b { color: #c4b5fd; }

@media (max-width: 900px) { .stage.with-chart { grid-template-columns: 1fr; } .scene { height: 360px; } .ask-opts { grid-template-columns: 1fr; } h1 { font-size: 36px; } }
.camfeed { position: absolute; right: 14px; bottom: 14px; border: 3px solid #fff; border-radius: 10px; box-shadow: 0 6px 20px #0003; pointer-events: none; display: none; }
.camfeed span { position: absolute; left: 8px; top: 6px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #0008; }
.camfeed span::first-letter { color: #ef4444; }
.hovertip { position: absolute; left: 0; top: 0; display: none; pointer-events: none; background: #111827; color: #fff; font-size: 12.5px; font-weight: 700; padding: 4px 9px; border-radius: 7px; white-space: nowrap; z-index: 3; }
.partcard { position: absolute; left: 14px; top: 14px; width: 330px; max-height: calc(100% - 28px); overflow: auto; background: #ffffffee; backdrop-filter: blur(8px); border-radius: 16px; box-shadow: 0 10px 30px #0002; padding: 16px 18px 14px; font-size: 14.5px; line-height: 1.5; z-index: 4; display: none; }
.partcard.show { display: block; animation: cardin .18s ease-out; }
@keyframes cardin { from { opacity: 0; transform: translateY(6px); } }
.partcard .pc-kicker { font-size: 11px; font-weight: 800; letter-spacing: 1.3px; text-transform: uppercase; color: var(--teal2); }
.partcard h3 { margin: 2px 0 8px; font-size: 20px; letter-spacing: -.3px; }
.partcard .pc-label { font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.partcard p { margin: 2px 0 0; }
.partcard .pc-fact { background: #fff8e1; border-radius: 10px; padding: 8px 10px; margin-top: 10px; }
.partcard .pc-actions { display: flex; gap: 6px; margin-top: 12px; }
.partcard .pc-actions button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 5px 11px; font-size: 13px; font-weight: 700; color: var(--ink); }
.partcard .pc-actions button.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.partcard .pc-close { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 18px; color: var(--muted); }
.clickhint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); font-size: 12.5px; color: var(--muted); background: #fffd; padding: 3px 12px; border-radius: 999px; pointer-events: none; }

/* diagram scene */
.diagram-scene { background: radial-gradient(ellipse at 50% 30%, #ffffff 0%, #f1f4f6 75%) !important; }
.dg { width: 100%; height: 100%; display: block; cursor: grab; }
.dg-label { font: 600 14px -apple-system, Inter, sans-serif; fill: #1f2933; pointer-events: none; }
.dg-icon { font-size: 18px; pointer-events: none; }
.dg-num { font: 700 12px -apple-system, Inter, sans-serif; fill: #13808b; }
.dg-elabel { font: 600 12px -apple-system, Inter, sans-serif; fill: #5b6670; text-anchor: middle; }
.dg-group { font: 800 15px -apple-system, Inter, sans-serif; text-anchor: middle; letter-spacing: .5px; text-transform: uppercase; }
/* code trace */
.codewrap { display: grid; grid-template-columns: 1fr 320px; gap: 14px; }
.code { background: #0f1720; border-radius: 16px; padding: 14px 0; font: 14px/1.7 "SF Mono", Menlo, monospace; color: #d6e2ea; overflow: auto; }
.code .ln { display: flex; padding: 0 16px; transition: background .2s; }
.code .ln span { width: 28px; color: #5b6b78; user-select: none; }
.code .ln.cur { background: #13808b55; box-shadow: inset 3px 0 0 #f6c218; }
.codeside { background: #fff; border-radius: 16px; padding: 14px 16px; }
.vars { width: 100%; border-collapse: collapse; font: 14px "SF Mono", Menlo, monospace; margin: 6px 0 12px; }
.vars td { border-bottom: 1px solid var(--line); padding: 5px 4px; } .vars td:first-child { color: var(--teal); font-weight: 700; }
.vars tr.chg td { background: #fff7d6; transition: background .6s; }
.out { background: #f6f8f9; border-radius: 10px; padding: 8px 10px; min-height: 40px; font-size: 13px; margin: 6px 0 0; white-space: pre-wrap; }
/* image */
.imgwrap { background: #fff; border-radius: 16px; padding: 14px; text-align: center; }
.imgwrap img { max-width: 100%; max-height: 520px; object-fit: contain; }
.imgcap { font-size: 14px; color: var(--muted); margin-top: 8px; }
@media (max-width: 900px) { .codewrap { grid-template-columns: 1fr; } }

/* side panel: book figure and/or chart */
.aside { display: flex; flex-direction: column; gap: 12px; align-self: start; }
.aside .chart { align-self: stretch; }
.bookfig { background: #fff; border-radius: 16px; padding: 12px 14px; }
.bookfig img { width: 100%; max-height: 300px; object-fit: contain; cursor: zoom-in; margin-top: 6px; border-radius: 8px; }
.zoomimg { position: fixed; inset: 0; background: #0f1720dd; z-index: 50; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.zoomimg img { max-width: 92vw; max-height: 92vh; background: #fff; border-radius: 12px; padding: 10px; }
/* scene toolbar and part tags */
.scenetools { position: absolute; right: 14px; top: 12px; display: flex; gap: 6px; z-index: 3; }
.scenetools button { border: 1px solid var(--line); background: #ffffffee; border-radius: 9px; padding: 5px 11px; font-size: 13px; font-weight: 700; color: var(--ink); }
.scenetools button.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.tags .tag { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 11.5px; font-weight: 700; color: #1f2933; background: #ffffffd9; border: 1px solid #d6dde1; padding: 2px 7px; border-radius: 6px; pointer-events: none; }
.clickhint { top: auto; bottom: 12px; }

.bookfig .pc-label, .codeside .pc-label { font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.bookfig .imgcap { font-size: 13px; }
