/* The Red Cantor's Book — a candlelit vaulted cellar, old books, paper slips.
   Colours that depend on the chosen cellar arrive as custom properties from
   themes.js. */

:root {
  --wall-base: #5f2d1d;
  --wall-size: 120px 80px;
  --niche-in: #140c09;
  --niche-rim: #8d4c34;
  --keystone: #b3a184;
  --shelf: #4a2e1c;
  --wood-base: #5c3a26;
  --wood-rim: #3b2316;
  --wood-light: #8a5d3b;
  --light: #ffb257;
  --bg-a: #1d130f;
  --bg-b: #0b0706;
  --text: #f4e8d0;
  --text-dim: rgba(244, 232, 208, 0.62);
  --gold: #dcb75e;
  --wine: #94272a;
  --wine-deep: #5a1214;
  --ink: #2b211a;
  --ink-soft: #6e5f4f;
  --paper: #f7f0e2;
  --paper-2: #ece2ce;
  --line: rgba(60, 45, 30, 0.14);
  --radius: 18px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--text);
  background: radial-gradient(130% 90% at 50% 0%, #2c1b13, var(--bg-a) 48%, var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------- background */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.22;
  will-change: transform;
}
.bg .b1 { width: 60vmax; height: 60vmax; left: -25vmax; top: -30vmax; background: var(--light); animation: drift 50s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -25vmax; bottom: -22vmax; background: var(--wine); animation: drift 64s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 36vmax; height: 36vmax; left: 35vw; bottom: -26vmax; background: var(--light); opacity: 0.12; animation: drift 76s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 21px; letter-spacing: 0.01em; color: #f7e6c4; text-shadow: 0 1px 10px rgba(255, 170, 80, 0.25); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-size: 11px; color: var(--text-dim); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { display: flex; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: rgba(255, 235, 210, 0.1); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg, .nav-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 4px 16px 6px;
}
.stat {
  background: rgba(255, 236, 210, 0.06);
  border: 1px solid rgba(255, 236, 210, 0.1);
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.stat span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.stat b { font-family: var(--serif); font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; color: #f7e6c4; }

.stage {
  flex: 1;
  min-height: 0;
  container: stage / size;
  padding: 6px 12px;
}

.actions {
  display: flex;
  gap: 8px;
  padding: 6px 12px 14px;
}
.app[data-mode="wall"] [data-mode="zoom"],
.app[data-mode="zoom"] [data-mode="wall"] { display: none; }

.btn {
  appearance: none;
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(255, 235, 210, 0.16);
  background: rgba(255, 235, 210, 0.08);
  color: var(--text);
  font: 500 15px var(--sans);
  padding: 11px 10px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }
.btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn:hover { background: rgba(255, 235, 210, 0.14); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.38; cursor: default; transform: none; }
.btn.primary, .btn.pull {
  background: linear-gradient(180deg, #b23a34, var(--wine-deep));
  color: #fff3dc;
  border-color: #3e0c0d;
  box-shadow: 0 4px 14px -4px rgba(120, 20, 20, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}
.btn.primary:hover, .btn.pull:hover { filter: brightness(1.08); }
.app[data-mode="zoom"] #btn-hint { background: rgba(255, 235, 210, 0.08); border-color: rgba(255, 235, 210, 0.16); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; color: var(--ink-soft); border-color: transparent; font-size: 13.5px; margin: 18px auto 0; display: flex; }

/* --------------------------------------------------------------- scene */
.scene {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}
@container stage (min-aspect-ratio: 6 / 5) {
  .scene { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1.7fr) minmax(250px, 1fr); }
  .table { max-height: none !important; }
}

/* ---------------------------------------------------------------- wall */
.wall {
  position: relative;
  min-height: 0;
  border-radius: 50% 50% 14px 14px / 18% 18% 14px 14px;
  background: var(--wall-img) center top / var(--wall-size) repeat, var(--wall-base);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 40px 60px -20px rgba(0, 0, 0, 0.8),
    inset 0 -30px 40px -20px rgba(0, 0, 0, 0.55),
    0 20px 40px -18px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  container: wall / size;
}
.wall::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(75% 60% at 50% 100%, color-mix(in oklab, var(--light) 20%, transparent), transparent 70%),
    radial-gradient(120% 100% at 50% 60%, transparent 40%, rgba(0, 0, 0, 0.6) 100%);
}
.wall::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 3;
  box-shadow: inset 0 0 0 9px rgba(0, 0, 0, 0.28), inset 0 0 0 10px rgba(255, 240, 220, 0.05);
}

.niches {
  position: absolute;
  inset: 12% 4% 3%;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), var(--nw, 140px));
  grid-auto-rows: calc(var(--nw, 140px) / 0.92);
  place-content: center;
}

/* --------------------------------------------------------------- niche */
.niche {
  --rim: var(--niche-rim);
  position: relative;
  width: var(--nw, 140px);
  height: calc(var(--nw, 140px) / 0.92);
  container-type: size;
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.niche:focus-visible { outline: none; }
.niche:focus-visible .arch { outline: 2px solid #ffd27a; outline-offset: 4cqw; }
@media (hover: hover) {
  .niche:not(.big):hover { --rim: color-mix(in oklab, var(--niche-rim) 70%, #fff1d2); }
}

.arch {
  position: absolute;
  left: 11%;
  right: 11%;
  top: 15%;
  bottom: 7%;
  border-radius: 50% 50% 3% 3% / 34% 34% 3% 3%;
  background:
    radial-gradient(85% 55% at 50% 104%, color-mix(in oklab, var(--light) 17%, transparent), transparent 75%),
    linear-gradient(180deg, #000 0%, var(--niche-in) 34%, color-mix(in oklab, var(--niche-in) 82%, #4d2e1d) 100%);
  box-shadow:
    inset 0 4cqh 4.5cqh -1.5cqh rgba(0, 0, 0, 0.92),
    inset 2.6cqw 0 3cqw -1cqw rgba(0, 0, 0, 0.75),
    inset -2.6cqw 0 3cqw -1cqw rgba(0, 0, 0, 0.75),
    0 0 0 2.8cqw var(--rim),
    0 0 0 3.4cqw rgba(0, 0, 0, 0.4),
    0 1.5cqh 2.5cqh 3cqw rgba(0, 0, 0, 0.35);
  transition: box-shadow 0.25s;
}
.niche[data-decor="candle"][data-side="l"] .arch { background-image: radial-gradient(45% 40% at 18% 72%, color-mix(in oklab, var(--light) 34%, transparent), transparent 80%), radial-gradient(85% 55% at 50% 104%, color-mix(in oklab, var(--light) 17%, transparent), transparent 75%), linear-gradient(180deg, #000 0%, var(--niche-in) 34%, color-mix(in oklab, var(--niche-in) 82%, #4d2e1d) 100%); }
.niche[data-decor="candle"][data-side="r"] .arch { background-image: radial-gradient(45% 40% at 82% 72%, color-mix(in oklab, var(--light) 34%, transparent), transparent 80%), radial-gradient(85% 55% at 50% 104%, color-mix(in oklab, var(--light) 17%, transparent), transparent 75%), linear-gradient(180deg, #000 0%, var(--niche-in) 34%, color-mix(in oklab, var(--niche-in) 82%, #4d2e1d) 100%); }

.keystone {
  position: absolute;
  left: 50%;
  top: 5%;
  width: 19%;
  height: 12%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  padding-bottom: 1.2cqh;
  background: linear-gradient(180deg, color-mix(in oklab, var(--keystone) 88%, #fff), var(--keystone) 45%, color-mix(in oklab, var(--keystone) 68%, #000));
  clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
  color: rgba(48, 30, 16, 0.9);
  font: 700 5.4cqw/1 var(--serif);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  z-index: 2;
  pointer-events: none;
}

.spines {
  position: absolute;
  left: 5%;
  right: 5%;
  top: 16%;
  bottom: 7%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: max(1px, 0.35cqw);
}
.spines.side-l .decor { order: -1; margin-right: 1.8cqw; }
.spines.side-r .decor { order: 1; margin-left: 1.8cqw; }
.shelf {
  position: absolute;
  left: -2%;
  right: -2%;
  bottom: 0;
  height: 7%;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(180deg, color-mix(in oklab, var(--shelf) 75%, #fff) 0, var(--shelf) 24%, color-mix(in oklab, var(--shelf) 62%, #000));
  box-shadow: 0 -0.6cqh 1.4cqh rgba(0, 0, 0, 0.45), 0 0.5cqh 1cqh rgba(0, 0, 0, 0.6);
}

.decor {
  flex: 0 0 auto;
  width: calc(var(--u, 8cqw) * 1.75);
  max-height: 50%;
  aspect-ratio: 24 / 40;
  height: auto;
  filter: drop-shadow(0.5cqw 0.4cqh 0.6cqw rgba(0, 0, 0, 0.65));
}

/* ---------------------------------------------------------------- books */
.book {
  --c: #92261f;
  --cc: var(--c);
  --gild: var(--gold);
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: var(--u, 8cqw);
  height: var(--bh, 70%);
  padding: 0;
  margin: 0;
  border: 0;
  appearance: none;
  color: inherit;
  cursor: inherit;
  border-radius: 0.7cqw 0.7cqw 0.25cqw 0.25cqw;
  background-color: var(--cc);
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, 0.55) 0, rgba(255, 255, 255, 0.17) 16%, rgba(255, 255, 255, 0.05) 38%, rgba(0, 0, 0, 0.12) 70%, rgba(0, 0, 0, 0.6) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 5%, transparent 95%, rgba(0, 0, 0, 0.4));
  box-shadow: 0.3cqw 0 0.6cqw rgba(0, 0, 0, 0.55);
  transition: transform 0.28s var(--ease), box-shadow 0.25s;
}
.book.thick { width: calc(var(--u, 8cqw) * 1.45); }
.book.h0 { --bh: 56%; }
.book.h1 { --bh: 70%; }
.book.h2 { --bh: 85%; }
.c-red { --c: #94261f; }
.c-green { --c: #2c5c3c; }
.c-blue { --c: #2b4e80; }
.c-brown { --c: #6e4829; }
.c-black { --c: #322e33; }
.c-ochre { --c: #b98b2e; --gild: #fff2c2; }
.book.t1 { --cc: color-mix(in oklab, var(--c) 88%, #fff); }
.book.t2 { --cc: color-mix(in oklab, var(--c) 86%, #000); }

.band {
  position: absolute;
  left: 7%;
  right: 7%;
  height: 3.4%;
  border-top: max(1px, 0.45cqw) solid var(--gild);
  border-bottom: max(1px, 0.45cqw) solid var(--gild);
  filter: drop-shadow(0 0 0.25cqw rgba(0, 0, 0, 0.75));
}
.band.hi { top: 7%; }
.band.lo { bottom: 7%; }
.emb {
  position: absolute;
  left: 50%;
  top: 30%;
  width: 72%;
  height: auto;
  aspect-ratio: 1;
  transform: translateX(-50%);
  fill: var(--gild);
  filter: drop-shadow(0 0.25cqw 0.15cqw rgba(0, 0, 0, 0.7));
}

.book::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(6, 4, 3, 0);
  transition: background 0.3s;
  pointer-events: none;
}
.book.x::after { background: rgba(6, 4, 3, 0.66); }
.book.wrong::after { background: rgba(6, 4, 3, 0.74); }
.mark { position: absolute; left: 50%; top: 58%; width: 0; height: 0; z-index: 1; pointer-events: none; }
.book.x .mark::before,
.book.x .mark::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--u, 8cqw) * 1.25);
  height: max(1.5px, 0.7cqw);
  border-radius: 1px;
  background: rgba(238, 230, 212, 0.82);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%) rotate(62deg);
}
.book.x .mark::after { transform: translate(-50%, -50%) rotate(-62deg); }
.book.wrong .mark {
  width: calc(var(--u, 8cqw) * 0.8);
  height: calc(var(--u, 8cqw) * 0.8);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e25a4c, #9d241c 55%, #5c0f0c);
  box-shadow: 0 0.3cqw 0.6cqw rgba(0, 0, 0, 0.65), inset 0 0 0 0.45cqw rgba(0, 0, 0, 0.2);
}

.book.sel {
  z-index: 3;
  transform: translateY(-4%);
  box-shadow: 0 0 0 max(1.5px, 0.55cqw) #ffd27a, 0 0 3cqw 0.6cqw color-mix(in oklab, var(--light) 70%, transparent);
}
.book.flash { z-index: 3; animation: flash 0.7s ease-in-out 3; }
@keyframes flash {
  50% { transform: translateY(-4%); box-shadow: 0 0 0 max(1.5px, 0.6cqw) #ffe3a0, 0 0 4cqw 1cqw color-mix(in oklab, var(--light) 80%, transparent); }
}
.book.hit { animation: hit 0.7s ease-out; }
@keyframes hit { 0% { filter: brightness(2.4) saturate(0.6); } 100% { filter: none; } }
.book.pull-wrong { z-index: 3; animation: pull-wrong 0.85s var(--ease); }
@keyframes pull-wrong {
  0% { transform: none; }
  30% { transform: translateY(-16%) scale(1.06); }
  55% { transform: translateY(-16%) scale(1.06) rotate(-2.5deg); }
  100% { transform: none; }
}
.book.found, .book.pull-right { z-index: 4; }
.book.found {
  transform: translateY(-6%);
  box-shadow: 0 0 0 max(1.5px, 0.55cqw) #ffe1a0, 0 0 4cqw 1cqw color-mix(in oklab, var(--light) 80%, transparent);
}
.book.pull-right { animation: pull-right 1.1s var(--ease) forwards; }
@keyframes pull-right {
  0% { transform: none; }
  45% { transform: translateY(-24%) scale(1.12); box-shadow: 0 0 0 0.6cqw #ffe1a0, 0 0 6cqw 2cqw color-mix(in oklab, var(--light) 85%, transparent); }
  100% { transform: translateY(-18%) scale(1.12); box-shadow: 0 0 0 0.6cqw #ffe1a0, 0 0 7cqw 2.5cqw color-mix(in oklab, var(--light) 85%, transparent); }
}

/* ------------------------------------------------------------- close-up */
.zoom {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: radial-gradient(90% 75% at 50% 60%, rgba(18, 11, 7, 0.4), rgba(8, 5, 3, 0.86));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.22s;
}
.zoom-stage {
  position: absolute;
  inset: 7% 44px 62px;
  display: grid;
  place-items: center;
  container-type: size;
  touch-action: pan-y;
}
.zoom-stage .niche.big {
  width: min(100cqw, 100cqh * 0.92);
  height: auto;
  aspect-ratio: 0.92;
  cursor: default;
  animation: zoom-in 0.28s var(--ease);
}
.niche.big .book { cursor: pointer; }
.niche.big .book:focus-visible { outline: 2px solid #ffd27a; outline-offset: 2px; }
@keyframes zoom-in { from { transform: scale(0.86); opacity: 0; } }
.nav-btn {
  position: absolute;
  top: 50%;
  width: 40px;
  height: 56px;
  margin-top: -28px;
  appearance: none;
  border: 1px solid rgba(255, 235, 210, 0.14);
  background: rgba(20, 12, 8, 0.55);
  color: var(--text);
  border-radius: 14px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.nav-btn:hover { background: rgba(60, 36, 24, 0.7); }
.nav-btn:active { transform: scale(0.94); }
.nav-btn.prev { left: 4px; }
.nav-btn.next { right: 4px; }
.inspect-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  min-height: 46px;
  padding: 4px 12px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
}
.inspect-text .main { font: 600 15px var(--serif); color: #f7e6c4; }
.inspect-text .sub { font-size: 12.5px; color: var(--text-dim); }

.dark {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(circle 28cqmin at var(--lx, 50%) var(--ly, 75%), rgba(5, 3, 2, 0) 30%, rgba(5, 3, 2, 0.55) 62%, rgba(5, 3, 2, 0.97) 100%);
}
#dark-zoom { inset: 7% 44px 62px; z-index: 1; }

/* --------------------------------------------------------------- table */
.table {
  position: relative;
  min-height: 0;
  max-height: 41cqh;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px 12px;
  border-radius: 14px;
  background: var(--wood-img) center / 600px 400px, var(--wood-base);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    inset 0 -20px 30px -10px rgba(0, 0, 0, 0.45),
    0 3px 0 var(--wood-rim),
    0 16px 30px -12px rgba(0, 0, 0, 0.85);
}
.table::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(90% 120% at 100% 0%, color-mix(in oklab, var(--light) 26%, transparent), transparent 60%), linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, 0.25));
}
.table-title {
  position: relative;
  margin: 0 0 6px;
  padding-right: 64px;
  font: 600 11px var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 240, 215, 0.72);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.slips {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 2px 2px 4px;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 7px;
  scrollbar-width: thin;
}
.slip {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 7px;
  text-align: left;
  cursor: pointer;
  border: 0;
  padding: 7px 10px 7px 9px;
  border-radius: 2px 3px 2px 4px;
  background: linear-gradient(180deg, #f8efda, #ebdcbc);
  color: #3a291b;
  font: italic 15px/1.32 var(--serif);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 3px 6px -2px rgba(0, 0, 0, 0.6);
  transform: rotate(var(--rot, 0deg));
  transition: opacity 0.25s, box-shadow 0.25s, transform 0.2s;
}
.slip:active { transform: rotate(var(--rot, 0deg)) scale(0.985); }
.slip .num { flex: 0 0 auto; font: 700 13px var(--serif); color: var(--wine); font-style: normal; min-width: 1.3em; }
.slip.ticked { opacity: 0.55; }
.slip.ticked .txt { text-decoration: line-through; text-decoration-color: rgba(148, 39, 42, 0.75); text-decoration-thickness: 1.5px; }
.slip.lit { box-shadow: 0 0 0 2px #ffd27a, 0 0 18px rgba(255, 200, 100, 0.75); opacity: 1; }
.slip:focus-visible { outline: 2px solid #ffd27a; outline-offset: 2px; }

.props {
  position: absolute;
  top: -14px;
  right: 10px;
  width: 54px;
  height: 46px;
  pointer-events: none;
  z-index: 2;
}
.glass { position: absolute; left: 0; bottom: 0; width: 25px; height: 38px; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5)); }
.candle {
  position: absolute;
  right: 4px;
  bottom: 2px;
  width: 11px;
  height: 26px;
  border-radius: 2px 2px 1px 1px;
  background: linear-gradient(90deg, #cdbd96, #f8f0dc 40%, #e3d4b2 70%, #b9a67b);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
}
.candle::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  bottom: -4px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 35%, #a7abb0, #5e6267);
  z-index: -1;
}
.flame {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 9px;
  height: 17px;
  margin-left: -4.5px;
  border-radius: 50% 50% 45% 45% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 76%, #fffbe6 0 22%, #ffd75e 42%, #ff8d2c 68%, rgba(255, 120, 30, 0) 72%);
  transform-origin: 50% 100%;
  animation: flicker 2.8s ease-in-out infinite;
}
.flame::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 55%;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  background: radial-gradient(color-mix(in oklab, var(--light) 42%, transparent), transparent 65%);
  animation: halo 2.8s ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-1deg); }
  22% { transform: scale(1.06, 0.95) rotate(1.8deg); }
  46% { transform: scale(0.95, 1.07) rotate(-2deg); }
  71% { transform: scale(1.03, 0.98) rotate(1deg); }
}
@keyframes halo { 50% { opacity: 0.72; transform: scale(0.94); } }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 5, 3, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  color-scheme: light;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
  -webkit-user-select: text;
  user-select: text;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 22px;
  flex: 0 0 auto;
}
.sheet .icon-btn, .dialog .icon-btn { color: var(--ink); }
.sheet .icon-btn:hover { background: rgba(60, 45, 30, 0.08); }
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 24px;
    max-height: 80dvh;
    animation: pop 0.28s var(--ease);
  }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 410px);
  max-height: 94dvh;
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  color-scheme: light;
  border-radius: 24px;
  padding: 24px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
  animation: popc 0.3s var(--ease);
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.dialog .btn { color: var(--ink); background: rgba(255, 255, 255, 0.6); border-color: rgba(60, 45, 30, 0.16); box-shadow: 0 1px 2px rgba(60, 45, 30, 0.1); }
.dialog .btn:hover { background: #fff; }
.dialog .btn.primary { color: #fff3dc; background: linear-gradient(180deg, #b23a34, var(--wine-deep)); border-color: #3e0c0d; }

/* New cellar */
.levels { display: grid; gap: 8px; margin: 16px 0 8px; }
.level {
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  text-align: left;
  padding: 10px 14px 10px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.level:hover { background: #fff; }
.level:active { transform: scale(0.985); }
.level[aria-current="true"] { border-color: var(--wine); box-shadow: 0 0 0 3px rgba(148, 39, 42, 0.14); }
.level b { font: 600 16.5px var(--serif); }
.level small { grid-column: 2; color: var(--ink-soft); font-size: 12.5px; line-height: 1.3; }
.level.done small { color: #2f7a4c; font-weight: 600; }
.badge {
  grid-row: span 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 21px 21px 6px 6px;
  background: linear-gradient(180deg, #7b3a26, #4c2216);
  color: #f6dfb6;
  font: 700 14px var(--serif);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.level[data-level="daily"] .badge { background: linear-gradient(180deg, #b23a34, var(--wine-deep)); }
.lost { font-size: 13px !important; margin: 4px 0 14px !important; }

/* Result */
.result .glow {
  position: absolute;
  inset: -30% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--light) 50%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.7;
}
.result h2 { position: relative; font-size: 30px; animation: shimmer 2.4s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--light) 80%, white); } }
.tome {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 88%;
  margin: 0 auto 14px;
  aspect-ratio: 2 / 1.2;
  filter: drop-shadow(0 12px 14px rgba(60, 30, 10, 0.35));
  animation: tome-in 0.8s var(--ease);
}
@keyframes tome-in { from { transform: perspective(600px) rotateX(35deg) scale(0.8); opacity: 0; } }
.tome::before {
  content: "";
  position: absolute;
  inset: -6px -8px -8px;
  border-radius: 10px;
  background: linear-gradient(180deg, #a3302a, #5e1515);
  z-index: -1;
  box-shadow: inset 0 0 0 2px rgba(220, 180, 90, 0.5);
}
.page {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  background: linear-gradient(90deg, #ede0c0, #f9f1de 35%, #f2e6cb);
}
.page.left { border-radius: 6px 0 0 6px; box-shadow: inset -12px 0 14px -10px rgba(90, 60, 20, 0.55); }
.page.right { border-radius: 0 6px 6px 0; background: linear-gradient(90deg, #f2e6cb, #f9f1de 65%, #ede0c0); box-shadow: inset 12px 0 14px -10px rgba(90, 60, 20, 0.55); }
.initial {
  font: 700 46px/1 var(--serif);
  color: #a3271f;
  padding: 2px 10px 4px;
  border: 2px solid #c9a24a;
  border-radius: 4px;
  background: radial-gradient(circle, rgba(220, 180, 90, 0.35), transparent 70%);
  text-shadow: 0 0 1px #6e1a17;
}
.tome-title { font: italic 11px var(--serif); color: #6b4a2a; margin-top: 6px; }
.staff { width: 70%; height: 13px; margin-top: 6px; background: repeating-linear-gradient(180deg, rgba(150, 40, 30, 0.55) 0 1px, transparent 1px 3px); }
.page.right p { font: italic 12.5px/1.45 var(--serif); color: #4a3320; margin: 0; text-align: left; }
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; min-width: 0; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.result-stats b, .summary b { font-family: var(--serif); font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; }
.score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.score b { font-family: var(--serif); font-size: 44px; font-weight: 600; line-height: 1.05; color: var(--wine); }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.time, th.wrong, th.hints, th.score, td.time, td.wrong, td.hints, td.score { text-align: right; }
td.score { font-family: var(--serif); font-weight: 600; font-size: 15px; }
tr[data-level="daily"] td.level { color: var(--wine); font-weight: 600; }
@media (max-width: 420px) { th.hints, td.hints { display: none; } td { padding: 7px 3px; } }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--wine); background: #fff; box-shadow: 0 0 0 3px rgba(148, 39, 42, 0.14); }
.opts.lang .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 13px 13px 4px 4px;
  background: radial-gradient(60% 55% at 50% 100%, var(--sw2) 98%, transparent 100%), var(--sw);
  box-shadow: inset 0 0 0 2px var(--sw3), inset 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 22px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: #cfc6b8; position: relative; transition: background 0.25s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--wine); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--wine); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: rgba(250, 238, 214, 0.96);
  color: #2b1d12;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(90vw, 440px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- small screens */
@media (max-height: 680px) {
  .top { padding-top: 6px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .stat b { font-size: 16px; }
  .stat { padding: 3px 6px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 9px 8px; }
  .slip { font-size: 14px; padding: 5px 9px 5px 8px; }
}
@media (max-width: 560px) {
  .btn { flex-direction: column; gap: 3px; padding: 8px 4px 7px; font-size: 12.5px; }
  .btn svg { width: 21px; height: 21px; }
  .brand b { font-size: 18px; }
  .brand img { width: 36px; height: 36px; }
}
@media (max-width: 420px) {
  .top { padding-left: 12px; padding-right: 8px; }
  .brand { gap: 8px; }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 16.5px; letter-spacing: 0; }
  .icon-btn { width: 38px; height: 38px; }
  .inspect-text .main { font-size: 14px; }
  .inspect-text .sub { font-size: 12px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 25px; }
  .stage { padding: 10px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob, .flame, .flame::after { animation: none; }
  .book, .sheet, .dialog, .backdrop, .zoom, .zoom-stage .niche.big, .tome { animation: none !important; transition-duration: 0.01s; }
}

/* The symbol sprite must stay rendered (not display:none), or its gradients vanish. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
