:root {
  --ink: #2a2620;
  --ink-2: #5d554a;
  --ink-3: #8c8273;
  --paper: #f4ecdb;
  --gold: #c8962f;
  --gold-hi: #e2b955;
  --green: #1c8a5f;
  --red: #c2443d;
  --hud-bg: rgba(28, 21, 15, 0.72);
  --hud-line: rgba(255, 236, 205, 0.14);
  --hud-text: #f6ead6;
  --serif: 'Newsreader', Georgia, serif;
  --display: 'Fraunces', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #120c08; color: var(--hud-text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }
.css3d, .css2d { position: absolute !important; inset: 0; pointer-events: none; }
.css3d * { pointer-events: none; }
.css3d button, .css3d input, .css3d .flap { pointer-events: auto; }

/* ================= the printed page ================= */
.page { color: var(--ink); font-family: var(--serif); font-size: 23px; line-height: 1.42; padding: 58px 64px 50px; position: relative; transition: opacity .35s ease; -webkit-font-smoothing: antialiased; }
.page.fade, .sheet-body.fade { opacity: 0; }
.runhead { display: flex; justify-content: space-between; font: 600 14px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); padding-bottom: 12px; border-bottom: 1.5px solid rgba(60, 45, 25, .18); margin-bottom: 30px; }
.title { font: 800 50px/1.04 var(--display); letter-spacing: -.02em; margin-bottom: 20px; color: #221d16; }
.page p { margin-bottom: 14px; }
.page b { font-weight: 600; color: #1b1712; }
.page i { font-style: italic; }
.formula { margin: 22px 0 18px; padding: 16px 22px 14px; border: 1.5px solid rgba(60, 45, 25, .28); border-radius: 4px; background: rgba(255, 252, 244, .55); display: flex; gap: 24px; align-items: center; }
.formula .f { font: italic 500 31px/1.3 var(--display); white-space: nowrap; color: #1c1813; }
.formula .f i { font-style: italic; }
.formula .f2 { font-size: 24px; }
.formula ul { min-width: 230px; flex: 1; list-style: none; font-size: 17px; line-height: 1.35; color: var(--ink-2); border-left: 1.5px solid rgba(60, 45, 25, .2); padding-left: 18px; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .78em; line-height: 1.15; margin: 0 4px; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 4px 2px; }
.frac > span:last-child { padding-top: 2px; }
.ideas { list-style: none; margin: 6px 0 22px; font-size: 20px; }
.ideas li { position: relative; padding-left: 26px; margin-bottom: 6px; color: var(--ink-2); }
.ideas li::before { content: ''; position: absolute; left: 4px; top: .55em; width: 9px; height: 9px; border: 1.5px solid var(--gold); transform: rotate(45deg); }
.predict { border-top: 1.5px dashed rgba(60, 45, 25, .3); padding-top: 18px; }
.pq { font-size: 21px; margin-bottom: 12px !important; }
.pq span { font: 700 13px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: #fff; background: var(--ink); padding: 5px 8px 4px; border-radius: 3px; margin-right: 10px; vertical-align: 3px; }
.opts { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.opt { font: 500 17px/1.2 var(--sans); padding: 9px 14px; border: 1.5px solid rgba(42, 38, 32, .35); border-radius: 999px; background: rgba(255, 255, 255, .4); transition: background .2s, border-color .2s, transform .15s; }
.opt:hover { border-color: var(--ink); transform: translateY(-1px); }
.opt.right { background: #d8efe2; border-color: var(--green); color: #0f5a3b; }
.opt.right::before { content: '✓ '; }
.opt.wrong { background: #f6dcd8; border-color: var(--red); color: #8a2620; text-decoration: line-through; }
.flapwrap { position: relative; perspective: 900px; min-height: 92px; }
.answer { font-size: 19px; line-height: 1.4; padding: 14px 18px; background: #fffaf0; border-left: 4px solid var(--gold); border-radius: 2px; }
.flap { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 14px 20px; text-align: left;
  background: linear-gradient(180deg, #efe3c8, #e8d9b8); border: 1.5px solid rgba(110, 85, 45, .35); border-radius: 3px; box-shadow: 0 6px 14px rgba(60, 40, 15, .18);
  transform-origin: 50% 0; transition: transform .7s cubic-bezier(.3, 1.3, .5, 1), opacity .5s; }
.flap b { font: 700 22px var(--display); color: #3a2f1f; }
.flap span { font: 15px var(--sans); color: var(--ink-2); }
.flap::after { content: '↑'; position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font: 600 26px var(--sans); color: var(--gold); }
.flap.up { transform: rotateX(-162deg); opacity: 0; pointer-events: none; }
.folio { position: absolute; bottom: 28px; left: 0; right: 0; text-align: center; font: 500 16px var(--display); color: var(--ink-3); }

/* right page: the figure sits on the top 60%; caption & controls below */
.runhead.r { margin-bottom: 0; }
.figure { position: absolute; left: 64px; right: 64px; top: 690px; }
.cap { font-size: 18px !important; line-height: 1.35; color: var(--ink-2); margin-bottom: 6px !important; }
.hint { font: italic 500 21px var(--display); color: #2d271f; margin-bottom: 18px !important; }
.cols { display: grid; grid-template-columns: 1.05fr 1fr; gap: 30px; }
.ctl { display: block; margin-bottom: 14px; }
.cl { display: flex; justify-content: space-between; font: 600 15px var(--sans); color: var(--ink-2); margin-bottom: 7px; letter-spacing: .01em; }
.cl output { font: 700 16px var(--sans); color: var(--ink); font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; cursor: pointer; --p: 50%; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--ink) var(--p), rgba(42, 38, 32, .2) var(--p)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(42, 38, 32, .2); }
input[type=range]::-moz-range-progress { height: 4px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f6d27a, var(--gold) 55%, #8d6418); border: 2px solid #fff8e8; box-shadow: 0 2px 6px rgba(60, 40, 10, .45); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--gold); border: 2px solid #fff8e8; }
input[type=range]:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 4px; }
.ctl-btn { font: 600 15px var(--sans); padding: 9px 16px; border-radius: 999px; border: 1.5px solid var(--ink); background: rgba(255, 255, 255, .45); }
.ctl-btn:hover { background: var(--ink); color: var(--paper); }
.reads { display: grid; grid-template-columns: 1fr auto; row-gap: 9px; column-gap: 14px; align-content: start; padding: 14px 16px; border: 1.5px solid rgba(60, 45, 25, .22); border-radius: 4px; background: rgba(255, 252, 244, .6); }
.reads dt { font: 500 15px/1.3 var(--sans); color: var(--ink-2); }
.reads dd { font: 700 17px/1.3 var(--sans); text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.reads small { display: block; font-size: 13px; }
.up { color: var(--green); } .dn { color: var(--red); }

/* labels that float on the 3D model */
.lbl { display: flex; align-items: center; gap: 6px; font: 600 13px/1 var(--sans); color: #2a2620; white-space: nowrap; pointer-events: none; text-shadow: 0 0 6px rgba(255, 250, 238, .95), 0 0 2px #fffaf0; }
.lbl b { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #2a2620; color: #fff6e4; font-size: 11.5px; text-shadow: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
.tag { font: 500 12px/1.25 var(--sans); color: #2a2620; background: rgba(255, 250, 238, .92); border: 1px solid rgba(60, 45, 25, .25); padding: 5px 9px; border-radius: 6px; text-align: center; white-space: nowrap; box-shadow: 0 4px 14px rgba(40, 25, 10, .25); pointer-events: none; }
.tag.big b { font: 700 16px var(--sans); }
.tag small { color: var(--ink-2); font-size: 11px; }
.tag.axis { background: none; border: 0; box-shadow: none; padding: 0; font: 600 11px var(--sans); color: rgba(42, 38, 32, .75); text-shadow: 0 0 4px rgba(255, 250, 238, .9); }

/* ================= HUD ================= */
.hud { position: fixed; top: 16px; z-index: 20; display: flex; gap: 10px; align-items: flex-start; }
.hud-left { left: 16px; }
.hud-right { right: 16px; }
.brand { font: 800 19px var(--display); color: var(--hud-text); text-decoration: none; padding: 10px 14px; background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); letter-spacing: -.01em; }
.brand span { color: var(--gold-hi); font-style: italic; font-weight: 500; margin-left: 2px; }
.pill { display: flex; align-items: stretch; background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); overflow: hidden; }
.pill-arrow { width: 36px; font-size: 22px; color: var(--hud-text); opacity: .85; }
.pill-arrow:hover:not(:disabled) { background: rgba(255, 255, 255, .08); opacity: 1; }
.pill-arrow:disabled { opacity: .25; cursor: default; }
.pill-body { display: flex; flex-direction: column; text-align: left; padding: 7px 10px; min-width: 210px; max-width: 340px; border-left: 1px solid var(--hud-line); border-right: 1px solid var(--hud-line); }
.pill-body:hover { background: rgba(255, 255, 255, .06); }
.pill-kicker { font: 600 10.5px var(--sans); letter-spacing: .13em; text-transform: uppercase; color: var(--gold-hi); }
.pill-title { font: 600 14.5px/1.25 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc { position: absolute; top: calc(100% + 8px); left: 0; width: min(420px, calc(100vw - 32px)); background: rgba(28, 21, 15, .94); border: 1px solid var(--hud-line); border-radius: 14px; padding: 10px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 20px 50px rgba(0, 0, 0, .5); }
.toc-h { font: 600 11px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--gold-hi); padding: 6px 10px 10px; }
.toc button { display: grid; grid-template-columns: 28px 1fr 18px; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 10px; border-radius: 9px; font-size: 15px; }
.toc button:hover { background: rgba(255, 255, 255, .07); }
.toc button.cur { background: rgba(226, 185, 85, .14); }
.toc .n { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(226, 185, 85, .5); color: var(--gold-hi); font: 600 13px var(--sans); }
.toc .s { color: #6fd3a4; font-weight: 700; }
.tool { width: 40px; height: 40px; display: grid; place-items: center; background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 12px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.tool svg { width: 19px; height: 19px; fill: none; stroke: var(--hud-text); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: rgba(60, 46, 32, .85); }
.tool.on { background: rgba(226, 185, 85, .25); border-color: rgba(226, 185, 85, .5); }
button:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

/* ================= cover title card ================= */
.cover-ui { position: fixed; left: clamp(16px, 6vw, 90px); bottom: clamp(70px, 14vh, 150px); max-width: 430px; z-index: 15; transition: opacity .6s, transform .6s; }
.cover-ui.gone { opacity: 0; transform: translateY(20px); pointer-events: none; }
.cover-eyebrow { font: 600 12px var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--gold-hi); margin-bottom: 10px; }
.cover-ui h1 { font: 800 clamp(40px, 5.4vw, 66px)/1 var(--display); letter-spacing: -.025em; margin-bottom: 14px; text-shadow: 0 4px 30px rgba(0, 0, 0, .6); }
.cover-sub { font: 400 18px/1.5 var(--serif); color: #e5d7c0; margin-bottom: 22px; text-shadow: 0 2px 14px rgba(0, 0, 0, .7); }
.open-btn { font: 700 16px var(--sans); padding: 14px 22px; border-radius: 999px; color: #1b130a; background: linear-gradient(135deg, #f0c96a, #c8962f); box-shadow: 0 10px 30px rgba(200, 150, 47, .35), inset 0 1px 0 rgba(255, 255, 255, .5); transition: transform .2s, box-shadow .2s; }
.open-btn span { display: inline-block; transition: transform .2s; }
.open-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(200, 150, 47, .45); }
.open-btn:hover span { transform: translateX(4px); }
.cover-hint { margin-top: 16px; font: 13px var(--sans); color: rgba(246, 234, 214, .6); }

/* ================= floating bits ================= */
.tip { position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; font: 500 13px/1.35 var(--sans); color: #2a2620; background: #fffaf0; border: 1px solid rgba(60, 45, 25, .2); padding: 7px 10px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); max-width: 280px; }
.toast { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 40; max-width: min(560px, calc(100vw - 32px)); font: 500 14px/1.45 var(--sans); background: rgba(28, 21, 15, .95); border: 1px solid var(--hud-line); padding: 12px 16px; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
.legal { position: fixed; left: 0; right: 0; bottom: 10px; text-align: center; font: 11.5px var(--sans); color: rgba(246, 234, 214, .45); pointer-events: none; z-index: 5; padding: 0 16px; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font: 18px var(--sans); }

/* ================= reading mode / phones: content in a sheet ================= */
.sheet { position: fixed; z-index: 18; right: 16px; top: 72px; bottom: 34px; width: min(460px, 40vw); background: var(--paper); color: var(--ink); border-radius: 16px; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); display: flex; flex-direction: column; overflow: hidden; }
.sheet-tabs { display: flex; gap: 4px; padding: 8px; background: #eadfc8; border-bottom: 1px solid rgba(60, 45, 25, .15); }
.sheet-tabs button { flex: 1; padding: 9px; border-radius: 9px; font: 600 14px var(--sans); color: var(--ink-2); }
.sheet-tabs button[aria-selected=true] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(60, 40, 15, .15); }
.sheet-body { overflow-y: auto; padding: 22px 24px 28px; transition: opacity .3s; -webkit-overflow-scrolling: touch; }
.sheet-body { font-family: var(--serif); font-size: 18px; line-height: 1.5; }
.sheet-body p { margin-bottom: 12px; }
.sheet-body .runhead { margin-bottom: 18px; font-size: 11px; }
.sheet-body .title { font-size: 32px; }
.sheet-body .formula { flex-direction: column; align-items: flex-start; gap: 10px; }
.sheet-body .formula .f { font-size: 24px; white-space: normal; }
.sheet-body .formula ul { border-left: 0; padding-left: 0; font-size: 15px; }
.sheet-body .ideas { font-size: 16.5px; }
.sheet-body .pq { font-size: 17.5px; }
.sheet-body .opt { font-size: 15px; }
.sheet-body .answer { font-size: 16px; }
.sheet-body .flap b { font-size: 18px; }
.sheet-body .flap span { font-size: 13px; }
.sheet-body .folio { display: none; }
.sheet-body .figure { position: static; }
.sheet-body .cols { grid-template-columns: 1fr; gap: 16px; }
.sheet-body .cap { font-size: 15px !important; }
.sheet-body .hint { font-size: 18px; }
body.reading .legal { display: none; }

@media (max-width: 819px), (max-height: 519px) {
  .hud { top: 10px; }
  .hud-left { left: 10px; right: 10px; }
  .hud-right { right: 10px; top: 62px; flex-direction: column; }
  .brand { display: none; }
  .pill { flex: 1; }
  .pill-body { min-width: 0; flex: 1; max-width: none; }
  .tool { width: 38px; height: 38px; }
  #btn-read { display: none; }
  .sheet { left: 0; right: 0; bottom: 0; top: auto; width: auto; height: 52vh; border-radius: 18px 18px 0 0; }
  .cover-ui { left: 16px; right: 16px; bottom: 40px; }
  .cover-sub { font-size: 16px; }
  .toast { bottom: calc(52vh + 12px); }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; } }

/* lamp off: a daylight desk */
body.day { --hud-bg: rgba(40, 32, 24, .7); }
