:root {
  --ui-bg: rgba(250, 248, 243, 0.84);
  --panel-bg: #faf8f3;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --ui-text: #23211d;
  --ui-muted: #6f6a60;
  --ui-line: rgba(35, 33, 29, 0.12);
  --ui-hover: rgba(35, 33, 29, 0.06);
  --ink-red: #b5432f;
  --accent: #0d7a83;
  --accent-ink: #ffffff;
  --ok: #2f8f5b;
  --warn: #c97a1f;
  --bad: #c4423a;
  --water: #2f7fd1;
  --scene-bg: #e6dfd1;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.14);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ui-bg: rgba(28, 30, 33, 0.82);
  --panel-bg: #17191c;
  --surface: #1f2226;
  --surface-2: #262a2f;
  --ui-text: #ece8df;
  --ui-muted: #a59f93;
  --ui-line: rgba(255, 255, 255, 0.12);
  --ui-hover: rgba(255, 255, 255, 0.07);
  --ink-red: #e3785f;
  --accent: #3cbcbc;
  --accent-ink: #062120;
  --ok: #4fbf82;
  --warn: #e39a45;
  --bad: #e56a60;
  --water: #5aa3ec;
  --scene-bg: #121416;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--scene-bg);
  color: var(--ui-text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

/* ---------- Layout: the book fills the screen ---------- */
#app { position: fixed; inset: 0; overflow: hidden; }
.stage { position: absolute; inset: 0; overflow: hidden; }
/* The 3D canvas sits above the page sheets; it is transparent only where a sheet shows
   through, and lets pointer events pass to them (camera drag listens on the stage). */
#scene { position: relative; z-index: 2; display: block; width: 100%; height: 100%; touch-action: none; outline: none; pointer-events: none; }
/* Layer holding the HTML sheets that sit on the book's pages (CSS3DRenderer) */
.css3d { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* ---------- Scene overlays ---------- */
.home-link {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px; z-index: 3;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--ui-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow); color: var(--ui-text); text-decoration: none; font-size: 13.5px;
}
.home-link svg { color: #2f7fd1; }
.home-link b { color: var(--accent); font-weight: 600; }
/* Quiet link to the lighter 2D version, bottom-left (top-right on phones) */
.alt-link {
  position: absolute; left: 16px; bottom: 22px; z-index: 3;
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; text-decoration: none;
  color: var(--ui-text); background: var(--ui-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  opacity: .75; transition: opacity .2s ease;
}
.alt-link:hover, .alt-link:focus-visible { opacity: 1; }
.hint {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 14px; z-index: 3; margin: 0;
  padding: 7px 12px; border-radius: 999px; font-size: 12.5px; color: var(--ui-muted);
  background: var(--ui-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: opacity .6s ease;
}
.hint.gone { opacity: 0; pointer-events: none; }

.viewbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 2px; max-width: calc(100% - 20px); overflow-x: auto;
  padding: 5px; border-radius: 999px; scrollbar-width: none;
  background: var(--ui-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.viewbar::-webkit-scrollbar { display: none; }
.viewbar button {
  flex: none; border: none; background: transparent; cursor: pointer;
  padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; white-space: nowrap;
}
.viewbar button:hover { background: var(--ui-hover); }
.viewbar button[aria-pressed="true"] { background: var(--ui-text); color: var(--panel-bg); }
.viewbar button.icon { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
.viewbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.viewbar svg .fill { fill: currentColor; stroke: none; }
.viewbar .sep { flex: none; width: 1px; height: 20px; background: var(--ui-line); margin: 0 3px; }
.viewbar.closed button[data-view] { display: none; }
.viewbar.closed .sep { display: none; }

/* Round pad for orbiting the camera: drag the knob, further from the centre = faster */
/* Quiet by default: a faint glassy disc that only firms up on hover, focus or while dragging */
.orbit-pad {
  position: absolute; right: 18px; bottom: 18px; z-index: 3;
  width: 58px; height: 58px; border-radius: 50%;
  display: grid; place-items: center; cursor: grab; touch-action: none; user-select: none;
  background: rgba(255, 255, 255, 0.10); border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: .55; transition: opacity .3s ease, background .3s ease;
}
.orbit-pad:hover, .orbit-pad:focus-visible, .orbit-pad.active { opacity: 1; background: rgba(255, 255, 255, 0.18); }
.orbit-pad.active { cursor: grabbing; }
.orbit-pad svg { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke: rgba(255, 255, 255, 0.75); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.orbit-pad svg .ring { display: none; }
.orbit-knob {
  width: 18px; height: 18px; border-radius: 50%; pointer-events: none;
  background: rgba(255, 255, 255, 0.7); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform .2s ease;
}
.orbit-pad.active .orbit-knob { transition: none; background: rgba(255, 255, 255, 0.9); }
.orbit-pad:focus-visible { outline: 1px solid rgba(255, 255, 255, 0.8); outline-offset: 3px; }

.open-cta {
  position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 8px;
  border: none; border-radius: 999px; padding: 12px 22px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 22px rgba(13, 122, 131, 0.35);
  animation: pulse 2.4s ease-in-out infinite;
}
.open-cta svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
@keyframes pulse { 0%, 100% { box-shadow: 0 6px 22px rgba(13, 122, 131, 0.35); } 50% { box-shadow: 0 6px 22px rgba(13, 122, 131, 0.35), 0 0 0 10px rgba(13, 122, 131, 0.12); } }

.card {
  position: absolute; z-index: 5; width: min(290px, calc(100% - 24px));
  padding: 13px 15px; border-radius: 14px;
  background: var(--ui-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  font-family: "Source Serif 4", Georgia, serif; font-size: 15px; line-height: 1.45;
  animation: card-in .25s ease;
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.card .kicker { margin: 0 0 3px; font: 600 11px Inter, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-red); }
.card strong { display: block; font-family: Fraunces, Georgia, serif; font-size: 17px; margin-bottom: 3px; }
.card p { margin: 0; }

.loading {
  position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--scene-bg); font-family: "Source Serif 4", Georgia, serif; font-size: 17px; color: var(--ui-muted);
  transition: opacity .6s ease;
}
.loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ui-line); border-top-color: var(--ui-text); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fallback {
  position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--scene-bg); text-align: center; padding: 24px; font-size: 16px;
}
.fallback a { color: var(--accent); font-weight: 600; }

/* ---------- Sheets printed on the book's pages ----------
   Sized in "page pixels": 990 px = the page width. The 3D transform scales them down,
   so text is rasterised large and stays sharp when you zoom in. Ink colours stay the same
   by day and night because the page is paper. */
.sheet {
  --ink: #2b2a27; --ink-muted: #77715f; --ink-red: #b5432f; --ink-line: rgba(43, 42, 39, 0.2);
  --teal: #0d7a83; --good: #2f7f55; --warn: #b8741c; --bad: #b5432f; --info: #2f6fb3;
  position: relative; box-sizing: border-box; pointer-events: auto;
  color: var(--ink); font-family: "Source Serif 4", Georgia, serif;
  visibility: hidden; backface-visibility: hidden;
}
.sheet.show { visibility: visible; }
/* Paper, matched to the lit page around it; the gutter shadow falls toward the spine */
.sheet-left { background: linear-gradient(to left, rgba(60, 45, 20, 0.16), rgba(60, 45, 20, 0) 90px), #e8e2d5; }
.sheet-right { background: linear-gradient(to right, rgba(60, 45, 20, 0.16), rgba(60, 45, 20, 0) 90px), #e8e2d5; }
/* Warm lamp light at night: multiply the sheet by the same tint the reading lamp gives the
   3D paper around it (#e8e2d5 lit at night renders about rgb(189,164,137)) */
:root[data-theme="dark"] .sheet { isolation: isolate; }
:root[data-theme="dark"] .sheet::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: rgb(208, 185, 164); mix-blend-mode: multiply;
}
.sheet-left { width: 990px; height: 1320px; padding: 64px 80px 60px; }
.sheet-right { width: 990px; height: 610px; padding: 8px 80px 40px; }
.s-label { margin: 0 0 10px; font: 600 17px Inter, sans-serif; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-red); }
.s-title { margin: 0 0 14px; font: 700 48px/1.1 Fraunces, Georgia, serif; }
.s-body { margin: 0 0 16px; font-size: 21px; line-height: 1.5; }
.s-eq { display: grid; gap: 2px; margin: 0 -18px 14px; padding: 12px 18px; background: rgba(181, 67, 47, 0.06); }
.s-eq .s-label { margin: 0; font-size: 15px; }
.s-eq b { font: italic 500 32px Fraunces, Georgia, serif; }
.s-eq small { font-size: 16px; color: var(--ink-muted); }
.s-watch { margin: 0 0 14px; padding: 0; list-style: none; font-size: 18px; line-height: 1.45; }
.s-watch li::before { content: "— "; color: var(--ink-red); }
.s-rule { border-top: 1.5px solid var(--ink-line); margin: 4px 0 16px; }
.s-page { position: absolute; left: 80px; bottom: 34px; font-size: 18px; color: var(--ink-muted); }
.sheet-right .s-page { left: auto; right: 80px; bottom: 12px; }

.sheet .cases { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 16px; }
.sheet .cases button {
  min-height: 58px; padding: 8px 8px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid rgba(43, 42, 39, 0.28); background: rgba(255, 255, 255, 0.35);
  color: var(--ink); font: 600 16px/1.2 Inter, sans-serif; text-align: center;
}
.sheet .cases button small { display: none; }
.sheet .cases button:hover { border-color: var(--teal); }
.sheet .cases button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #f7f3ea; }

.sheet .slider { margin-bottom: 10px; }
.sheet .slider-top { display: flex; justify-content: space-between; align-items: baseline; font: 500 18px Inter, sans-serif; }
.sheet .slider-top output { font-weight: 700; font-variant-numeric: tabular-nums; }
.sheet .slider-top output small { font-weight: 400; color: var(--ink-muted); }
.sheet .slider input { width: 100%; height: 30px; margin: 0; accent-color: var(--teal); cursor: pointer; }
.sheet .slider .scale { display: flex; justify-content: space-between; margin-top: -4px; font: 14px Inter, sans-serif; color: var(--ink-muted); }

.sheet .run-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.sheet .btn {
  padding: 10px 20px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  border: 1.5px solid rgba(43, 42, 39, 0.28); background: rgba(255, 255, 255, 0.35);
  color: var(--ink); font: 600 17px Inter, sans-serif;
}
.sheet .btn:hover { border-color: var(--teal); }
.sheet .btn.primary { min-width: 104px; background: var(--teal); border-color: var(--teal); color: #fff; }
.sheet .btn.ghost { background: transparent; }
.sheet .year { margin-left: auto; font: 17px Inter, sans-serif; color: var(--ink-muted); }
.sheet .year strong { color: var(--ink); font-size: 22px; font-variant-numeric: tabular-nums; }

.sheet .verdict { margin: 0 0 14px; padding: 12px 18px; border-left: 6px solid var(--good); background: rgba(43, 42, 39, 0.045); }
.sheet .verdict b { font: 700 16px Inter, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--good); }
.sheet .verdict p { margin: 4px 0 0; font-size: 20px; line-height: 1.4; }
.sheet .verdict.warn { border-left-color: var(--warn); } .sheet .verdict.warn b { color: var(--warn); }
.sheet .verdict.bad { border-left-color: var(--bad); } .sheet .verdict.bad b { color: var(--bad); }
.sheet .verdict.info { border-left-color: var(--info); } .sheet .verdict.info b { color: var(--info); }
.sheet .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 16px; margin: 0 0 12px; }
.sheet .stats dt { font: 15px Inter, sans-serif; color: var(--ink-muted); }
.sheet .stats dd { margin: 0; font: 700 22px Fraunces, Georgia, serif; font-variant-numeric: tabular-nums; }
.sheet .stats .good { color: var(--good); } .sheet .stats .warn { color: var(--warn); } .sheet .stats .bad { color: var(--bad); }
.sheet #chart { display: block; width: 830px; height: 150px; }
.sheet .legend { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; font: 15px Inter, sans-serif; color: var(--ink-muted); }
.sheet .legend .sw { display: inline-block; width: 26px; height: 4px; border-radius: 2px; }
.sheet .legend .sw.storage { background: var(--info); }
.sheet .legend .sw.depth { background: #c97a1f; margin-left: 14px; }
.sheet .s-note { margin: 8px 0 0; font-size: 16px; font-style: italic; color: var(--ink-muted); }
.sheet .s-fig { margin: 6px 0 0; font-size: 16px; font-style: italic; color: var(--ink); }
.s-short { display: none; }

/* Phones show one page at a time at roughly a third of its real size, so the printed
   sheets switch to big type and keep only what is needed to run the model. */
@media (max-width: 640px) {
  .sheet-left { padding: 56px 70px; }
  .sheet .s-label { font-size: 26px; margin-bottom: 14px; }
  .sheet .s-title { font-size: 64px; margin-bottom: 6px; }
  .s-short { display: block; margin: 0 0 22px; font-size: 32px; font-style: italic; color: var(--ink-muted); }
  .s-body, .s-eq, .s-watch, .s-rule, .sheet .slider .scale, .s-page { display: none; }
  .sheet .cases { grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
  .sheet .cases button { min-height: 92px; font-size: 27px; border-width: 2px; }
  .sheet .slider { margin-bottom: 16px; }
  .sheet .slider-top { font-size: 30px; }
  .sheet .slider input { height: 58px; }
  .sheet .run-row { gap: 14px; }
  .sheet .btn { padding: 16px 28px; font-size: 28px; border-width: 2px; }
  .sheet .btn.primary { min-width: 150px; }
  .sheet .year { font-size: 28px; } .sheet .year strong { font-size: 38px; }

  .sheet-right { padding: 6px 70px 30px; }
  .sheet .verdict { padding: 14px 22px; border-left-width: 8px; }
  .sheet .verdict b { font-size: 26px; }
  .sheet .verdict p { font-size: 30px; }
  .sheet .stats { grid-template-columns: repeat(2, 1fr); gap: 10px 24px; }
  .sheet .stats div:nth-child(n + 5) { display: none; }
  .sheet .stats dt { font-size: 24px; }
  .sheet .stats dd { font-size: 36px; }
  .sheet .legend { font-size: 24px; }
  .sheet .s-note, .sheet .s-fig { display: none; }
}

@media (max-width: 640px) {
  .home-link span { display: none; }
  .hint { display: none; }
  .viewbar { bottom: 10px; }
  .alt-link { left: auto; right: 14px; bottom: auto; top: max(16px, env(safe-area-inset-top)); }
  .orbit-pad { width: 50px; height: 50px; right: 12px; bottom: 64px; }
  .viewbar button { padding: 6px 10px; font-size: 12.5px; }
  .open-cta { bottom: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .open-cta { animation: none; }
}

/* ---------- Demo mode (?demo): scripted tour for sales videos ---------- */
body.demo .alt-link, body.demo .hint, body.demo .orbit-pad, body.demo .viewbar { display: none !important; }
.demo-caption {
  position: absolute; left: 50%; bottom: 22px; z-index: 6; transform: translate(-50%, 8px);
  display: grid; gap: 4px; text-align: center; max-width: min(760px, calc(100% - 40px));
  padding: 14px 26px; border-radius: 18px; color: #fff;
  background: rgba(20, 16, 13, 0.72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  opacity: 0; transition: opacity .35s ease, transform .35s ease; pointer-events: none;
}
.demo-caption.show { opacity: 1; transform: translate(-50%, 0); }
.demo-caption strong { font: 700 clamp(20px, 2.6vw, 30px)/1.2 Fraunces, Georgia, serif; }
.demo-caption span { font: clamp(13px, 1.4vw, 16px) Inter, sans-serif; color: rgba(255, 255, 255, 0.82); }
.demo-cursor {
  position: absolute; left: -11px; top: -11px; z-index: 7; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.92); border: 2px solid rgba(20, 16, 13, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); pointer-events: none;
  opacity: 0; transition: transform .6s cubic-bezier(.3, .7, .2, 1), opacity .3s ease;
}
.demo-cursor.show { opacity: 1; }
.demo-cursor::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 2px solid #fff; opacity: 0;
}
.demo-cursor.tap::after { animation: demo-tap .5s ease-out; }
@keyframes demo-tap { from { opacity: .9; transform: scale(.4); } to { opacity: 0; transform: scale(1.6); } }
.demo-end {
  position: absolute; inset: 0; z-index: 8; display: grid; place-content: center; gap: 10px; text-align: center;
  background: radial-gradient(circle at 50% 45%, rgba(31, 90, 104, 0.94), rgba(18, 14, 11, 0.97));
  color: #fff; opacity: 0; transition: opacity .7s ease; pointer-events: none;
}
.demo-end.show { opacity: 1; }
.demo-end .kicker { color: #d6b46a; }
.demo-end h2 { margin: 0; font: 700 clamp(40px, 6vw, 72px)/1.05 Fraunces, Georgia, serif; color: #f6e3a4; }
.demo-end p { margin: 0; font: clamp(16px, 2vw, 22px) "Source Serif 4", Georgia, serif; color: rgba(255, 255, 255, 0.88); }
.demo-end b { margin-top: 14px; font: 600 clamp(14px, 1.6vw, 18px) Inter, sans-serif; letter-spacing: .12em; color: #d6b46a; }
.demo-panel {
  position: absolute; right: 16px; top: 64px; z-index: 9; display: grid; gap: 8px; width: 280px;
  padding: 16px; border-radius: 16px; background: var(--ui-bg); box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.demo-panel .kicker { margin: 0; font: 600 11px Inter, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-red); }
.demo-panel .btn {
  border: 1px solid var(--ui-line); background: var(--surface); border-radius: 999px; cursor: pointer;
  padding: 9px 14px; font: 600 13.5px Inter, sans-serif; color: var(--ui-text);
}
.demo-panel .btn.primary { background: #c4423a; border-color: #c4423a; color: #fff; }
.demo-panel small { font-size: 12px; line-height: 1.45; color: var(--ui-muted); }
.demo-msg { margin: 0; font-size: 13px; line-height: 1.45; }
