/* Layout: a dual-screen handheld in the video's teal. The top screen is the painted story canvas, the bottom screen
   is the paper puzzle sheet. Stacked on phones, side by side on wide landscape screens. One look, not theme-switched. */
:root {
  --room: #142120;          /* the table the handheld lies on */
  --room-glow: #20302e;
  --shell: #2f6560;         /* the handheld's slab (the video's teal) */
  --shell-hi: #3f7b75;
  --shell-lo: #224c48;
  --bezel: #182220;
  --paper: #f8efd8;         /* puzzle sheet */
  --card: #fbf5e6;
  --tile: #efd9ab;
  --ink: #3b2a1e;
  --ink-soft: #6b5240;
  --sepia: #a07a4f;
  --clay: #d97757;          /* Claude */
  --clay-deep: #b9573a;
  --plum: #6d4a5e;          /* Hilde */
  --plum-deep: #4f3343;
  --red: #b8322e;           /* Q.E.D. ink */
  --blue: #2f5d8a;          /* ONCE MORE! ink */
  --gold: #e3b54a;
  --gold-deep: #a87a22;
  --memo: #2f6f7a;
  --on-shell: #e9f2ef;
  --f-display: "Fraunces", Georgia, "Times New Roman", serif;
  --f-body: "EB Garamond", Garamond, Georgia, serif;
  --f-hand: "Caveat", "Segoe Print", "Comic Sans MS", cursive;
  --f-pixel: "DotGothic16", "Courier New", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--room-glow), var(--room) 70%);
  background-color: var(--room);
  color: var(--on-shell);
  font: 400 17px/1.45 var(--f-body);
  padding-inline: 16px;
  padding-block: 18px 28px;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.foot { margin: 0; max-width: 40rem; text-align: center; font-size: .9rem; color: #9fb5b0; }
.foot a { color: #cfe3de; text-underline-offset: 3px; }

/* ---- the handheld ------------------------------------------------------------------------------------------------ */
.device {
  width: 100%; max-width: 640px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px;
  padding: 12px 12px 16px;
  background: linear-gradient(180deg, var(--shell-hi), var(--shell) 18%, var(--shell) 80%, var(--shell-lo));
  border-radius: 22px;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 -2px 0 rgba(0,0,0,.25) inset, 0 18px 40px rgba(0,0,0,.45);
}
.device-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-inline: 4px; }
.brand { font-family: var(--f-pixel); font-size: .8rem; letter-spacing: .14em; color: var(--on-shell); opacity: .85; }
.brand b { color: var(--gold); font-weight: 400; }
.mute {
  font-family: var(--f-pixel); font-size: .74rem; letter-spacing: .08em;
  background: var(--shell-lo); border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.mute[aria-pressed="true"] { opacity: .7; }
.mute:focus-visible, .btn:focus-visible, .tile:focus-visible, .opt:focus-visible, .spot:focus-visible, .book-row:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.screen { position: relative; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 5px var(--bezel), 0 0 0 6px rgba(255,255,255,.08); }
.hinge { display: flex; justify-content: center; gap: 40%; height: 8px; }
.hinge span { width: 18%; height: 6px; border-radius: 3px; background: var(--shell-lo); box-shadow: 0 1px 0 rgba(255,255,255,.12); }

/* ---- top screen -------------------------------------------------------------------------------------------------- */
.top-screen { aspect-ratio: 16 / 9; background: #2a2320; container-type: inline-size; cursor: pointer; }
.top-screen canvas { display: block; width: 100%; height: 100%; }
.dlg {
  position: absolute; left: 2.2%; right: 2.2%; bottom: 3%;
  background: rgba(251, 243, 223, .96); color: var(--ink);
  border: 2px solid #4a2c1c; border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(251,243,223,.6) inset, 0 0 0 4px rgba(160,122,79,.55) inset, 0 4px 10px rgba(0,0,0,.25);
  padding: 1.05em 1.1em .65em;
  font-family: var(--f-body); font-weight: 500;
  font-size: max(14px, 3.15cqw); line-height: 1.28;
}
.dlg-tab {
  position: absolute; left: 1.2em; top: 0; transform: translateY(-58%);
  font-family: var(--f-display); font-weight: 700; font-size: .78em; line-height: 1;
  color: var(--card); background: var(--plum); border: 2px solid #4a2c1c; border-radius: 5px; padding: .3em .7em .35em;
}
.dlg[data-who="claude"] .dlg-tab { background: var(--clay); }
.dlg-text { margin: 0; text-wrap: pretty; }
.dlg-text .ghost { color: transparent; }
.dlg-more { position: absolute; right: .7em; bottom: .35em; width: 0; height: 0; border-left: .32em solid transparent; border-right: .32em solid transparent; border-top: .42em solid var(--plum-deep); opacity: 0; }
.dlg[data-who="claude"] .dlg-more { border-top-color: var(--clay-deep); }
.dlg.done .dlg-more { opacity: 1; animation: bob .7s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(3px); } }
.coin-pop {
  position: absolute; left: 50%; top: 10%; transform: translateX(-50%);
  font-family: var(--f-pixel); font-size: max(13px, 2.4cqw); color: #3b2a1e; background: var(--gold); border: 2px solid var(--gold-deep);
  border-radius: 999px; padding: .2em .8em; animation: pop 1.6s ease-out forwards; pointer-events: none;
}
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 8px); } 15% { opacity: 1; transform: translate(-50%, 0); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -10px); } }

/* ---- bottom screen ----------------------------------------------------------------------------------------------- */
.bottom-screen {
  background: var(--paper); color: var(--ink);
  background-image: radial-gradient(rgba(160,122,79,.10) 1px, transparent 1.2px);
  background-size: 9px 9px;
  min-height: 300px; display: flex; flex-direction: column;
  container-type: inline-size;
}
.view { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 8px; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; padding: 8px 16px 16px; }
.actions:empty { display: none; }
.actions .spacer { flex: 1; }

.btn {
  font-family: var(--f-display); font-weight: 700; font-size: 1.02rem; line-height: 1;
  border: 2px solid #4a2c1c; border-radius: 8px; padding: .62em 1.05em; cursor: pointer;
  background: var(--card); color: var(--ink); box-shadow: 0 3px 0 #4a2c1c;
  transition: transform .06s ease, box-shadow .06s ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #4a2c1c; }
.btn.primary { background: var(--clay); color: #fff8ef; }
.btn.plum { background: var(--plum); color: #fff8ef; }
.btn.quiet { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; font-family: var(--f-body); font-weight: 600; padding-inline: .4em; }
.btn[disabled] { opacity: .45; cursor: default; transform: none; box-shadow: 0 3px 0 #4a2c1c; }
.btn.big { font-size: 1.3rem; padding: .75em 1.6em; }

.label { font-family: var(--f-pixel); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
h1, h2, h3 { font-family: var(--f-display); margin: 0; line-height: 1.1; text-wrap: balance; color: var(--ink); }
p { margin: 0; }

/* start */
.start { align-items: center; text-align: center; justify-content: center; gap: 14px; padding-block: 22px; }
.start h1 { font-size: clamp(1.7rem, 7cqw, 2.4rem); font-weight: 800; }
.start h1 b { color: var(--clay); }
.start .kanji { font-family: "Dela Gothic One", var(--f-display); font-size: 1rem; letter-spacing: .2em; color: var(--plum); }
.start .small { font-size: .95rem; color: var(--ink-soft); max-width: 26rem; }

/* status strip: coins and sparks */
.status { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-pixel); font-size: .82rem; letter-spacing: .05em; color: var(--ink); background: var(--card); border: 1px solid var(--tile); border-radius: 999px; padding: 2px 10px 2px 4px; }
.coin { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fbe7a6, var(--gold) 55%, var(--gold-deep)); border: 1px solid var(--gold-deep); flex: none; }
.spark { color: var(--gold-deep); font-family: var(--f-display); font-weight: 800; }

/* the book */
.book h2 { font-size: 1.45rem; }
.book-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.book-row {
  width: 100%; display: grid; grid-template-columns: 4.6rem minmax(0, 1fr) auto; align-items: center; gap: 10px;
  text-align: left; cursor: pointer; background: var(--card); border: 1.5px solid #c9ad7d; border-radius: 7px; padding: 8px 10px;
}
.book-row:hover:not([disabled]) { border-color: #4a2c1c; }
.book-row[disabled] { cursor: default; opacity: .55; }
.book-no { font-family: var(--f-display); font-weight: 800; font-size: .95rem; color: var(--card); background: var(--clay); border-radius: 4px; padding: 4px 6px; text-align: center; font-variant-numeric: tabular-nums; }
.book-row.inf .book-no { background: var(--plum); }
.book-title { font-family: var(--f-display); font-weight: 650; font-size: 1.05rem; min-width: 0; }
.book-meta { font-size: .92rem; color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini-stamp { display: inline-block; font-family: var(--f-display); font-weight: 900; font-size: .78rem; color: var(--red); border: 2px solid var(--red); border-radius: 4px; padding: 0 .3em; transform: rotate(-8deg); margin-left: 6px; }
.lock { font-family: var(--f-pixel); font-size: .74rem; color: var(--ink-soft); }

/* the puzzle sheet */
.sheet { position: relative; display: flex; flex-direction: column; gap: 10px; }
.sheet-head { display: grid; grid-template-columns: auto minmax(0, 1fr); border: 2px solid #4a2c1c; border-radius: 4px; background: var(--card); overflow: hidden; }
.sheet-no { background: var(--clay); color: var(--card); padding: 6px 10px; display: flex; flex-direction: column; justify-content: center; }
.sheet-no small { font-family: var(--f-display); font-weight: 700; font-size: .62rem; letter-spacing: .16em; }
.sheet-no b { font-family: var(--f-display); font-weight: 800; font-size: 1.35rem; line-height: 1; font-variant-numeric: tabular-nums; }
.sheet-title { padding: 6px 12px; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; }
.sheet-title h2 { font-size: clamp(1.1rem, 4.6cqw, 1.45rem); font-style: italic; font-weight: 700; }
.sheet-title .val { font-size: .95rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.statement { font-size: 1.08rem; line-height: 1.42; }
.illus { position: relative; width: 100%; aspect-ratio: 1200 / 640; max-width: 100%; }
.illus canvas { display: block; width: 100%; height: 100%; }
.stamp-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts.col { flex-direction: column; }
.opt {
  font-family: var(--f-body); font-weight: 600; font-size: 1.05rem; text-align: left; line-height: 1.3;
  background: var(--card); color: var(--ink); border: 2px solid #c9ad7d; border-radius: 8px; padding: .5em .85em; cursor: pointer;
}
.opt[aria-pressed="true"] { border-color: var(--clay-deep); background: #fde3d2; box-shadow: 0 0 0 2px var(--clay) inset; }
.opt[disabled] { cursor: default; }
.opt.big { font-family: var(--f-display); font-weight: 800; font-size: 2rem; padding: .3em .9em; font-variant-numeric: tabular-nums; }
.opt .key { font-family: var(--f-display); font-weight: 800; color: var(--clay-deep); margin-right: .35em; }

.tiles { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; }
.tile {
  aspect-ratio: 4 / 5; display: grid; place-items: center; cursor: pointer;
  font-family: var(--f-display); font-weight: 800; font-size: clamp(1rem, 5.4cqw, 1.9rem);
  background: var(--tile); color: var(--ink); border: 2px solid #4a2c1c; border-radius: 6px; box-shadow: 0 3px 0 #a98a57;
}
.tile[aria-pressed="true"] { background: var(--card); box-shadow: 0 0 0 3px var(--red) inset, 0 3px 0 #a98a57; color: var(--red); }

.numrow { display: flex; align-items: center; gap: 8px; }
.numrow input {
  width: 6.2rem; font-family: var(--f-display); font-weight: 800; font-size: 1.8rem; text-align: center; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--card); border: 2px solid #4a2c1c; border-radius: 8px; padding: .12em .2em;
}
.numrow .step { width: 2.6rem; height: 2.6rem; padding: 0; font-size: 1.4rem; }

.spot {
  position: absolute; transform: translate(-50%, -50%); width: 2.3rem; height: 2.3rem; border-radius: 50%;
  font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; cursor: pointer;
  background: rgba(251,245,230,.92); color: var(--clay-deep); border: 2px solid var(--clay-deep); box-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.spot[aria-pressed="true"] { background: var(--clay); color: #fff8ef; }

.hints { display: flex; flex-direction: column; gap: 6px; }
.hint-card { font-family: var(--f-hand); font-size: 1.32rem; line-height: 1.15; color: var(--memo); background: #fffbe9; border-left: 4px solid var(--memo); border-radius: 4px; padding: 6px 10px; }
.hint-card b { font-family: var(--f-pixel); font-weight: 400; font-size: .72rem; letter-spacing: .1em; color: var(--ink-soft); display: block; margin-bottom: 2px; }
.feedback { font-family: var(--f-hand); font-size: 1.35rem; color: var(--blue); min-height: 1.2em; }
.feedback.good { color: var(--red); }

/* trunk and ending */
.trunk .illus { cursor: pointer; }
.ending { text-align: center; align-items: center; gap: 12px; padding-block: 18px; }
.ending .score { font-family: var(--f-display); font-weight: 800; font-size: 2.6rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.ending .score small { font-size: 1rem; color: var(--ink-soft); font-weight: 600; }
.ending .credits { font-size: .98rem; color: var(--ink-soft); max-width: 28rem; }
.ending a { color: var(--memo); text-underline-offset: 3px; }
.confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; font-size: .98rem; }

/* wide landscape screens: the two screens side by side */
@media (min-width: 640px) and (min-aspect-ratio: 4/3) {
  .device { max-width: 1180px; grid-template-columns: minmax(0, 1.35fr) 14px minmax(0, 1fr); grid-template-rows: auto 1fr; align-items: start; }
  .device-bar { grid-column: 1 / -1; }
  .hinge { flex-direction: column; justify-content: center; align-self: stretch; gap: 40%; height: auto; width: 14px; }
  .hinge span { width: 6px; height: 18%; margin: 0 auto; }
  .bottom-screen { min-height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .dlg.done .dlg-more { animation: none; }
  .coin-pop { animation-duration: .01s; animation-fill-mode: forwards; opacity: 1; }
}
@container (max-width: 380px) { .actions .btn { font-size: .95rem; padding: .55em .8em; } }

/* the handheld's controls: only on wide screens, where the left half has room under the top screen. A presses the
   main button of the moment (Next, Submit, Next puzzle), B the quiet one (Skip, Book). */
.left { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
/* the story screen stays in view while the sheet scrolls under it (the dialogue lives there) */
.left { position: sticky; top: 0; z-index: 3; background: var(--shell); margin-top: -6px; padding-top: 6px; padding-bottom: 6px; }
@media (min-width: 640px) and (min-aspect-ratio: 4/3) { .left { top: 8px; margin-top: 0; padding-block: 0; background: none; } }
@container (max-width: 420px) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: 19rem; margin-inline: auto; } }
.pad { display: none; }
@media (min-width: 640px) and (min-aspect-ratio: 4/3) and (min-height: 640px) {
  .pad { display: grid; grid-template-columns: auto 1fr auto; align-items: center; padding: 6px 28px 4px; }
  .dpad { position: relative; width: 112px; height: 112px; }
  .dpad::before, .dpad::after { content: ""; position: absolute; background: var(--bezel); border-radius: 6px; box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.08) inset; }
  .dpad::before { left: 36px; top: 0; width: 40px; height: 112px; }
  .dpad::after { left: 0; top: 36px; width: 112px; height: 40px; }
  .dpad span { position: absolute; left: 46px; top: 46px; width: 20px; height: 20px; border-radius: 50%; background: #233230; z-index: 1; }
  .pills { display: flex; justify-content: center; gap: 22px; }
  .pills span { font-family: var(--f-pixel); font-size: .66rem; letter-spacing: .14em; color: var(--on-shell); opacity: .6; padding-top: 22px; position: relative; }
  .pills span::before { content: ""; position: absolute; left: 50%; top: 0; width: 46px; height: 12px; transform: translateX(-50%); border-radius: 6px; background: var(--bezel); }
  .ab { display: flex; gap: 22px; align-items: center; }
  .ab button { width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer; font-family: var(--f-display); font-weight: 800; font-size: 1.3rem; color: rgba(255,255,255,.88);
    box-shadow: 0 4px 0 rgba(0,0,0,.4), 0 2px 0 rgba(255,255,255,.25) inset; }
  .ab button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.4), 0 2px 0 rgba(255,255,255,.25) inset; }
  .a-btn { background: var(--clay); margin-top: -26px; }
  .b-btn { background: var(--plum); margin-top: 26px; }
}
