/* The /game adventure: canvas world + puzzle scenes shown as overlays */
body.game { margin: 0; overflow: hidden; background: #0b0806; touch-action: none; }
body.game.in-scene { overflow: auto; touch-action: auto; }
#world { position: fixed; inset: 0; display: block; cursor: pointer; }
body.game .grain { opacity: .1; }

/* puzzle scenes open on top of the world */
body.game #sceneHost .scene.is-active { position: fixed; inset: 0; z-index: 40; overflow-y: auto; overscroll-behavior: contain; }
body.game:not(.in-scene) .trials { opacity: 0; pointer-events: none; }
body.game.in-scene .hud, body.game.in-scene .act-btn, body.game.in-scene .dialog, body.game.in-scene .zone-banner { display: none; }
/* the scenes' own "next" buttons just bring you back to the world */
body.game #sceneHost [data-go] { }

.leave-btn {
  position: fixed; right: 18px; top: 16px; z-index: 75;
  padding: 8px 16px; border: 0; border-radius: 20px;
  font: italic 1rem var(--body); color: var(--parch, #e3d2a8);
  background: rgba(32, 21, 13, .88); box-shadow: inset 0 0 0 1px rgba(176, 141, 87, .6), 0 4px 12px rgba(0, 0, 0, .5);
}
.leave-btn:hover { background: rgba(60, 38, 22, .95); }

.hud { position: fixed; left: 16px; top: 14px; z-index: 20; pointer-events: none; max-width: min(420px, calc(100vw - 32px)); }
.objective {
  margin: 0; padding: 8px 14px 9px 34px; position: relative;
  font: italic 1rem/1.35 var(--body); color: #f1e2bc;
  background: rgba(32, 21, 13, .82); border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(176, 141, 87, .55), 0 4px 12px rgba(0, 0, 0, .5);
}
.objective::before { content: "✦"; position: absolute; left: 12px; top: 8px; color: #ffd96a; text-shadow: 0 0 6px #ffb35a; font-style: normal; }

.zone-banner {
  position: fixed; left: 50%; top: 18%; translate: -50% 0; z-index: 20; margin: 0;
  font: 400 clamp(1.6rem, 4vw, 2.6rem) var(--display); color: #f1e2bc; letter-spacing: .02em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .7), 0 0 24px rgba(255, 180, 90, .45);
  opacity: 0; pointer-events: none; white-space: nowrap;
}
.zone-banner.show { animation: bannerShow 2.6s ease forwards; }
@keyframes bannerShow { 0% { opacity: 0; transform: translateY(8px); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.dialog {
  position: fixed; left: 50%; bottom: 22px; translate: -50% 0; z-index: 30;
  width: min(560px, calc(100vw - 32px)); padding: 14px 20px 16px;
  color: #2b1a0e; font: 1.05rem/1.5 var(--body);
  background: linear-gradient(#efe1bd, #dcc795); border-radius: 4px;
  box-shadow: inset 0 0 18px rgba(90, 55, 20, .45), inset 0 0 0 2px rgba(110, 70, 30, .45), 0 10px 24px rgba(0, 0, 0, .6);
  opacity: 0; transform: translateY(14px); pointer-events: none; transition: opacity .3s, transform .3s;
}
.dialog.show { opacity: 1; transform: none; }
.dialog p { margin: 0; }

.act-btn {
  position: fixed; right: 22px; bottom: 26px; z-index: 25;
  width: 66px; height: 66px; border: 0; border-radius: 50%;
  font-size: 1.8rem; color: #2b1a0e;
  background: radial-gradient(circle at 35% 30%, #f3d58e, #b08d57);
  box-shadow: 0 4px 0 #5b3a1f, 0 0 20px rgba(255, 200, 110, .6);
  animation: actPulse 1.6s ease-in-out infinite;
}
@keyframes actPulse { 50% { transform: scale(1.06); } }
@media (pointer: fine) { .act-btn { display: none; } }

.title-card {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 60%, rgba(60, 38, 22, .75), rgba(8, 6, 4, .96));
  transition: opacity .8s;
}
.title-card.gone { opacity: 0; pointer-events: none; }
.tc-inner { text-align: center; max-width: 520px; }
.title-card h1 {
  margin: 0; font: 400 clamp(2.2rem, 7vw, 3.8rem)/1.05 var(--display); color: #f1e2bc;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .7), 0 0 30px rgba(255, 180, 90, .35);
}
.tc-sub { margin: 10px 0 28px; font: italic 1.15rem var(--body); color: #d8c6a2; }
.tc-help { margin: 26px 0 0; font: .95rem/1.6 var(--body); color: #b9a888; }
.tc-help b { color: #f1e2bc; font-weight: 500; }
.tc-reset { display: block; margin: 16px auto 0; border: 0; background: none; color: #b9a888; font: italic .95rem var(--body); text-decoration: underline; cursor: pointer; }

/* the music box sits above the action button on phones */
@media (pointer: coarse) { body.game .musicbox { bottom: auto; top: 64px; left: 10px; } }
@media (max-width: 760px) { .objective { font-size: .9rem; } }

[hidden] { display: none !important; }

/* =========================================================
   Scenes as overlays on top of the world: no separate rooms,
   just the scroll / book / bridge / gallery / shelf over a dimmed game
   ========================================================= */
body.game #sceneHost .scene.is-active {
  background: radial-gradient(ellipse at 50% 45%, rgba(20, 13, 8, .4), rgba(6, 4, 2, .72)) !important;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: overlayIn .35s ease both;
}
@keyframes overlayIn { from { opacity: 0; } }
body.game #sceneHost .scene::after,
body.game #sceneHost .scene::before { display: none !important; }
body.game #sceneHost :is(.sky, .sea-sky, .sea, .bookcase, .rustic-hang, .moon-clouds, .ambience, .fireflies,
  .mist, .card-frame, .moon-window, .candle, .potions, .moth, .folk-band, .crystal, .shooting-star) { display: none !important; }

/* each puzzle sits on a panel that pops in */
body.game #sceneHost .scene.is-active > :is(.scroll-stage, .book, .keyboard, .cross-wrap, .wall, .reading) { animation: panelIn .45s cubic-bezier(.34, 1.56, .64, 1) both; }
body.game #sceneHost .scene.is-active > .keyboard { animation-delay: .06s; }
@keyframes panelIn { from { opacity: 0; transform: translateY(24px) scale(.96); } }

body.game #sceneHost :is(.cross-wrap, .wall, .reading) {
  padding: 22px clamp(12px, 3vw, 28px) 26px;
  border-radius: 10px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 190, 110, .1), transparent 70%),
    linear-gradient(#24170e, #1a110a);
  box-shadow: inset 0 0 0 2px rgba(176, 141, 87, .55), inset 0 0 0 6px #24170e, inset 0 0 0 7px rgba(176, 141, 87, .25), 0 24px 60px rgba(0, 0, 0, .7);
}
body.game #sceneHost .wall { max-width: 1060px; }
/* the bridge needs some water under it now the sea is gone */
body.game #sceneHost .bridge {
  border-radius: 8px;
  background:
    repeating-linear-gradient(180deg, transparent 0 14px, rgba(140, 170, 200, .08) 14px 16px),
    linear-gradient(#1a2733, #0d151d);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .6);
}
body.game #sceneHost .clue-boards, body.game #sceneHost .cross-actions { width: 100%; }
/* the gallery's wall colour, inside its panel */
body.game #sceneHost .wall {
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='120' viewBox='0 0 80 120'><g fill='none' stroke='%23b08d57' stroke-opacity='.13' stroke-width='1.3'><path d='M40 8 C58 26 58 44 40 60 C22 44 22 26 40 8Z'/><path d='M40 60 C58 76 58 94 40 112 C22 94 22 76 40 60Z'/></g></svg>"),
    #2c3122;
}
body.game #sceneHost .tray-wrap { bottom: 0; }
/* scenes are scrollable panels: keep content clear of the top bar */
body.game #sceneHost .scene.is-active { padding-top: 76px; padding-bottom: 40px; }
body.game #sceneHost .scene-night.is-active { padding-top: max(96px, 12vh); }

/* =========================================================
   Retro game dressing: pixel canvas, scanlines, pixel HUD type,
   boxy RPG dialogue
   ========================================================= */
#world { image-rendering: pixelated; }
body.game::after {
  content: ""; position: fixed; inset: 0; z-index: 15; pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, .16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse 85% 75% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55) 100%);
  mix-blend-mode: multiply;
}
body.game.in-scene::after { opacity: .35; }

.objective, .leave-btn, .sound-btn, .act-btn, .tc-help, .tc-reset, .dialog .who {
  font-family: "Pixelify Sans", monospace !important; font-style: normal !important;
}
.objective {
  border-radius: 0; font-size: .95rem; letter-spacing: .02em;
  background: rgba(24, 16, 10, .92);
  box-shadow: 0 0 0 2px #b08d57, 0 0 0 4px #24170e, 0 6px 0 4px rgba(0, 0, 0, .35);
}
.objective::before { top: 7px; }

.sound-btn {
  position: fixed; right: 16px; top: 14px; z-index: 20;
  padding: 7px 12px; border: 0; border-radius: 0;
  font-size: .9rem; color: #f1e2bc; background: rgba(24, 16, 10, .92);
  box-shadow: 0 0 0 2px #b08d57, 0 0 0 4px #24170e;
}
.sound-btn[aria-pressed="false"] { color: #9c8a6c; }
body.game.in-scene .sound-btn { display: none; }

.leave-btn { border-radius: 0; box-shadow: 0 0 0 2px #b08d57, 0 0 0 4px #24170e; }

/* boxy RPG dialogue with a speaker tab */
.dialog {
  border-radius: 0; padding: 16px 22px 18px;
  background: #ead9b0;
  box-shadow: 0 0 0 3px #2b1a0e, 0 0 0 6px #b08d57, 0 0 0 9px #2b1a0e, 0 14px 0 6px rgba(0, 0, 0, .35);
}
.dialog .who {
  position: absolute; left: 14px; top: -16px; padding: 3px 12px 4px;
  font-size: .9rem; font-weight: 600; color: #f1e2bc; background: #6e2a26;
  box-shadow: 0 0 0 2px #2b1a0e, 0 0 0 4px #b08d57;
}
.dialog p { min-height: 1.5em; }
.dialog.show p::after { content: "▾"; margin-left: 6px; color: #6e2a26; animation: blinkCaret .8s steps(2) infinite; }
@keyframes blinkCaret { 50% { opacity: 0; } }

.act-btn { border-radius: 0; box-shadow: 0 0 0 3px #2b1a0e, 0 0 0 5px #b08d57, 0 6px 0 5px rgba(0, 0, 0, .35); }

/* title card: an old game's start screen */
.title-card h1 { letter-spacing: .01em; }
.title-card .btn-wax { animation: pressStart 1.4s ease-in-out infinite; }
@keyframes pressStart { 50% { filter: brightness(1.15); transform: translateY(-2px); } }
.tc-help { font-size: .9rem; }

@media (pointer: coarse) { .sound-btn { top: auto; bottom: 18px; right: auto; left: 230px; } }
@media (max-width: 760px) { .sound-btn { font-size: .78rem; } }

/* =========================================================
   ATELIER INTERFACE — one look for everything over the world:
   parchment cards in a walnut-and-brass frame, ink headings on
   an oxblood tab, brass-framed buttons. Overrides the retro pass.
   ========================================================= */
body.game {
  --ui-wood: #2b1a0e; --ui-brass: #b08d57; --ui-brass-hi: #d8b67c;
  --ui-paper: #ead9b0; --ui-paper-2: #dcc795; --ui-ink: #2b1a0e; --ui-ink-soft: #5a3e22; --ui-red: #6e2a26;
  --ui-frame: 0 0 0 3px var(--ui-wood), 0 0 0 5px var(--ui-brass), 0 0 0 8px var(--ui-wood);
  --ui-lift: 0 18px 40px rgba(0, 0, 0, .55);
  --ui-paper-bg: radial-gradient(ellipse 90% 60% at 50% 0%, rgba(255, 248, 225, .55), transparent 70%), linear-gradient(var(--ui-paper), var(--ui-paper-2));
}

/* softer retro: no scanlines, just a gentle vignette */
body.game::after { background: radial-gradient(ellipse 90% 80% at 50% 50%, transparent 60%, rgba(0, 0, 0, .45) 100%); mix-blend-mode: normal; }
body.game.in-scene::after { opacity: 0; }
#world { image-rendering: auto; }

/* storybook type everywhere (the pixel font is gone) */
.objective, .leave-btn, .sound-btn, .act-btn, .tc-help, .tc-reset, .dialog .who {
  font-family: "Alegreya", Georgia, serif !important;
}

/* HUD pieces share the frame */
.objective, .sound-btn, .leave-btn {
  border-radius: 2px; color: var(--ui-ink) !important; background: var(--ui-paper-bg) !important;
  box-shadow: var(--ui-frame), 0 8px 18px rgba(0, 0, 0, .45) !important;
}
.objective { font-style: italic !important; font-size: 1rem; padding: 9px 16px 10px 36px; }
.objective::before { color: var(--ui-red); text-shadow: none; top: 9px; }
.sound-btn, .leave-btn { font-style: italic !important; font-size: .95rem; padding: 7px 14px; }
.sound-btn[aria-pressed="false"] { color: #8a7458 !important; }
.leave-btn { top: 18px; right: 20px; }

.dialog { border-radius: 2px; background: var(--ui-paper-bg); box-shadow: var(--ui-frame), var(--ui-lift); }
.dialog .who { font-family: "IM Fell English", Georgia, serif !important; font-weight: 400; font-size: 1rem; background: var(--ui-red); box-shadow: 0 0 0 2px var(--ui-wood), 0 0 0 4px var(--ui-brass); }

.act-btn { border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f3e6c4, var(--ui-paper-2)); color: var(--ui-red); box-shadow: var(--ui-frame), 0 6px 14px rgba(0, 0, 0, .5); }

.zone-banner { font-family: "IM Fell English", Georgia, serif; }

/* title screen: a framed card */
.title-card .tc-inner {
  padding: 40px clamp(22px, 5vw, 48px) 34px; border-radius: 2px;
  background: var(--ui-paper-bg); box-shadow: var(--ui-frame), var(--ui-lift);
}
.title-card h1 { color: var(--ui-ink); text-shadow: 1px 1px 0 rgba(110, 42, 38, .25); }
.tc-sub { color: var(--ui-ink-soft); }
.tc-help { color: var(--ui-ink-soft); }
.tc-help b { color: var(--ui-red); }
.tc-reset { color: var(--ui-ink-soft); }
.title-card .btn-wax { animation: none; }

/* ---------- buttons: one family ---------- */
body.game :is(.btn-wax, .btn-plank) {
  border-radius: 2px; padding: 10px 26px 11px;
  font-family: "IM Fell English", Georgia, serif; font-size: 1.15rem; letter-spacing: .01em;
  transform: none; animation: none;
  box-shadow: var(--ui-frame), 0 7px 0 4px rgba(0, 0, 0, .35);
  transition: filter .2s, transform .2s;
}
body.game .btn-wax { color: #f6e7c8; background: linear-gradient(#843c35, #5e2420); text-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
body.game .btn-plank { color: var(--ui-ink); background: var(--ui-paper-bg); text-shadow: none; }
body.game :is(.btn-wax, .btn-plank):hover { filter: brightness(1.08); transform: translateY(-2px); }
body.game :is(.btn-wax, .btn-plank):active { transform: translateY(1px); }
body.game :is(.btn-wax, .btn-plank)::before, body.game :is(.btn-wax, .btn-plank)::after { display: none !important; }

/* ---------- activity panels ---------- */
body.game #sceneHost :is(.cross-wrap, .wall, .reading) {
  position: relative; margin: 26px auto 0; color: var(--ui-ink);
  padding: 46px clamp(14px, 3vw, 30px) 28px;
  border-radius: 2px; background: var(--ui-paper-bg) !important;
  box-shadow: var(--ui-frame), var(--ui-lift);
}
/* the heading becomes a tab on the top edge, like the dialogue speaker */
body.game #sceneHost :is(.sign, .gallery-head, .cards-head) {
  position: static; transform: none; animation: none; background: none; box-shadow: none; padding: 0; margin: 0 auto;
  color: var(--ui-ink-soft); text-align: center; max-width: 40em;
}
body.game #sceneHost :is(.sign, .gallery-head, .cards-head) p { color: var(--ui-ink-soft); margin: 0 0 4px; }
body.game #sceneHost :is(.cross-wrap, .wall, .reading) .chapter-title {
  position: absolute; left: 50%; top: -22px; translate: -50% 0; white-space: nowrap;
  padding: 6px 22px 8px; font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  color: #f6e7c8; background: var(--ui-red); text-shadow: none;
  box-shadow: 0 0 0 3px var(--ui-wood), 0 0 0 5px var(--ui-brass), 0 0 0 8px var(--ui-wood), 0 6px 12px rgba(0, 0, 0, .4);
}

/* crossword: bridge in an inset "window" onto the water, clues as ruled lists */
body.game #sceneHost .bridge { box-shadow: inset 0 0 0 2px var(--ui-wood), inset 0 0 30px rgba(0, 0, 0, .6); border-radius: 2px; }
body.game #sceneHost .active-clue { background: transparent; color: var(--ui-ink); border: 1px solid rgba(43, 26, 14, .35); border-radius: 2px; backdrop-filter: none; }
body.game #sceneHost .active-clue b { color: var(--ui-red); }
body.game #sceneHost .clue-board { background: transparent !important; box-shadow: none !important; border: 0; border-top: 1px solid rgba(43, 26, 14, .3); border-radius: 0; color: var(--ui-ink); padding: 12px 6px 0; }
body.game #sceneHost .clue-board h3 { color: var(--ui-red); }
body.game #sceneHost .clue-board li.active { background: rgba(110, 42, 38, .12); }

/* gallery: the paintings hang on a green wall set into the card */
body.game #sceneHost .frames {
  padding: 30px 18px 22px; border-radius: 2px;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='120' viewBox='0 0 80 120'><g fill='none' stroke='%23b08d57' stroke-opacity='.14' stroke-width='1.3'><path d='M40 8 C58 26 58 44 40 60 C22 44 22 26 40 8Z'/><path d='M40 60 C58 76 58 94 40 112 C22 94 22 76 40 60Z'/></g></svg>"),
    #2c3122;
  box-shadow: inset 0 0 0 2px var(--ui-wood), inset 0 0 40px rgba(0, 0, 0, .55);
}
body.game #sceneHost .gallery-status, body.game #sceneHost .conn-status, body.game #sceneHost .conn-meta { color: var(--ui-ink-soft); }
body.game #sceneHost .tray { box-shadow: var(--ui-frame), 0 8px 18px rgba(0, 0, 0, .4); border-radius: 2px; }

/* potion shelf: the cabinet sits in the card */
body.game #sceneHost .apothecary { box-shadow: inset 0 0 0 8px #4a2e18, inset 0 0 0 10px var(--ui-wood), inset 0 0 40px rgba(0, 0, 0, .6); }

/* wordle: the book gets the same frame, keys become little parchment tiles */
body.game #sceneHost .book { box-shadow: var(--ui-frame), var(--ui-lift); border-radius: 3px; }
body.game #sceneHost .k { border-radius: 2px; background: var(--ui-paper-bg); color: var(--ui-ink); box-shadow: 0 0 0 2px var(--ui-wood), 0 4px 0 2px var(--ui-brass); }
body.game #sceneHost .k:active, body.game #sceneHost .k.pressed { transform: translateY(3px); box-shadow: 0 0 0 2px var(--ui-wood), 0 1px 0 2px var(--ui-brass); }
body.game #sceneHost .k.k-correct { background: #55603d; color: #f3ead2; }
body.game #sceneHost .k.k-present { background: #c4953e; }
body.game #sceneHost .k.k-absent { background: #6b5d4a; color: #d8ccb2; }

/* scrolls: wooden rods and brass caps to match the frames */
body.game #sceneHost .scroll { filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .6)); }
body.game #sceneHost .unroll-hint { color: #f1e2bc; text-shadow: 0 2px 6px rgba(0, 0, 0, .8); }
body.game #sceneHost .rune-halo { opacity: .07; }

/* progress glyphs: framed, like the HUD */
body.game .trials { border-radius: 2px; background: var(--ui-paper-bg); box-shadow: var(--ui-frame), 0 8px 18px rgba(0, 0, 0, .45); border: 0; }
body.game .trial-glyph { color: rgba(43, 26, 14, .35); }
body.game .trial-glyph.is-current { color: var(--ui-red); }
body.game .trial-glyph.is-done { color: #a87924; filter: none; }

@media (max-width: 760px) {
  body.game #sceneHost :is(.cross-wrap, .wall, .reading) { padding: 40px 8px 18px; }
  body.game #sceneHost :is(.cross-wrap, .wall, .reading) .chapter-title { font-size: 1rem; padding: 5px 12px 6px; }
  .sound-btn { left: auto !important; right: 12px; top: auto; bottom: 96px !important; }
}

/* room for the progress circles above the panel title tabs */
body.game #sceneHost .scene.is-active:not(.scene-night) { padding-top: 112px; }

/* ---------- cutscenes ---------- */
.letterbox::before, .letterbox::after {
  content: ""; position: fixed; left: 0; right: 0; height: 11vh; z-index: 18; background: #050302;
  transition: transform .6s cubic-bezier(.5, 0, .2, 1); pointer-events: none;
}
.letterbox::before { top: 0; transform: translateY(-100%); }
.letterbox::after { bottom: 0; transform: translateY(100%); }
body.cutscene .letterbox::before, body.cutscene .letterbox::after { transform: none; }
body.cutscene :is(.hud, .act-btn, .sound-btn, .musicbox) { opacity: 0; pointer-events: none; transition: opacity .4s; }
.hud, .sound-btn, .musicbox { transition: opacity .4s; }

.unlock-banner {
  position: fixed; left: 50%; top: 22%; z-index: 22; translate: -50% 0;
  display: grid; justify-items: center; gap: 2px;
  padding: 14px 40px 16px; border-radius: 2px; text-align: center;
  background: var(--ui-paper-bg); box-shadow: var(--ui-frame), var(--ui-lift);
  opacity: 0; pointer-events: none;
}
.unlock-banner::before, .unlock-banner::after {
  content: "✦"; position: absolute; top: 50%; translate: 0 -50%; color: #a87924; font-size: 1.1rem;
}
.unlock-banner::before { left: 14px; } .unlock-banner::after { right: 14px; }
.ub-kicker { font: italic .95rem "Alegreya", Georgia, serif; color: var(--ui-red); letter-spacing: .04em; }
.ub-name { font: 400 clamp(1.6rem, 4vw, 2.3rem)/1.1 "IM Fell English", Georgia, serif; color: var(--ui-ink); white-space: nowrap; }
.unlock-banner.show { animation: unlockIn 3.2s ease both; }
@keyframes unlockIn {
  0% { opacity: 0; transform: translateY(14px) scale(.92); }
  12% { opacity: 1; transform: translateY(0) scale(1.03); }
  18% { transform: scale(1); }
  82% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* =========================================================
   Interface motion: everything opens, updates and closes with
   a little intention instead of popping
   ========================================================= */

/* panels rise in, and fold away when closed */
body.game #sceneHost .scene.is-active > :is(.scroll-stage, .book, .keyboard, .cross-wrap, .wall, .reading) {
  animation: panelIn .55s cubic-bezier(.22, 1.3, .36, 1) both;
}
@keyframes panelIn { from { opacity: 0; transform: translateY(34px) scale(.94) rotate(-.6deg); } }
body.game #sceneHost .scene.closing { animation: overlayOut .26s ease forwards !important; }
body.game #sceneHost .scene.closing > * { animation: panelOut .26s ease forwards !important; }
@keyframes overlayOut { to { opacity: 0; } }
@keyframes panelOut { to { opacity: 0; transform: translateY(18px) scale(.96); } }

/* the title tab drops onto its panel a beat after the panel lands */
body.game #sceneHost .scene.is-active :is(.cross-wrap, .wall, .reading) .chapter-title { animation: tabDrop .5s .25s cubic-bezier(.22, 1.4, .36, 1) both; }
@keyframes tabDrop { from { opacity: 0; transform: translateY(-16px) rotate(-3deg); } }

/* objective: a flash of gold and a quill line when it changes */
.objective { overflow: hidden; }
.objective::after {
  content: ""; position: absolute; left: 34px; right: 16px; bottom: 6px; height: 1px;
  background: var(--ui-red); transform: scaleX(0); transform-origin: left;
}
.objective.updated { animation: objNew 1.4s ease both; }
.objective.updated::after { animation: quillLine 1.1s .25s ease forwards; }
@keyframes objNew {
  0% { transform: translateX(-14px); opacity: 0; }
  20% { transform: none; opacity: 1; background: linear-gradient(#f7e7b8, #e8cf8e); }
  100% { background: var(--ui-paper-bg); }
}
@keyframes quillLine { 0% { transform: scaleX(0); opacity: 1; } 70% { transform: scaleX(1); opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }

/* dialogue pops up, and can be tapped to finish or dismiss */
.dialog { transition: opacity .25s, transform .4s cubic-bezier(.22, 1.4, .36, 1); transform: translateY(22px) scale(.97); }
.dialog.show { pointer-events: auto; cursor: pointer; transform: none; }
.dialog .who { transition: transform .4s .08s cubic-bezier(.22, 1.4, .36, 1); transform: translateY(8px); }
.dialog.show .who { transform: none; }

/* room names arrive with flourishes either side */
.zone-banner { display: flex; align-items: center; gap: 16px; }
.zone-banner::before, .zone-banner::after {
  content: ""; width: 70px; height: 1px;
  background: linear-gradient(90deg, transparent, #e2c07e);
}
.zone-banner::after { background: linear-gradient(270deg, transparent, #e2c07e); }
.zone-banner.show::before, .zone-banner.show::after { animation: flourish 2.6s ease both; }
@keyframes flourish { 0% { width: 0; } 25%, 80% { width: 70px; } 100% { width: 0; } }

/* title card: the card lands, then its lines ink in */
.title-card .tc-inner { animation: cardLand .8s cubic-bezier(.22, 1.3, .36, 1) both; }
@keyframes cardLand { from { opacity: 0; transform: translateY(30px) scale(.94); } }
.title-card .tc-inner > * { animation: inkIn .9s var(--ease-ink) both; }
.title-card .tc-inner > :nth-child(1) { animation-delay: .25s; }
.title-card .tc-inner > :nth-child(2) { animation-delay: .45s; }
.title-card .tc-inner > :nth-child(3) { animation-delay: .65s; }
.title-card .tc-inner > :nth-child(n + 4) { animation-delay: .85s; }
.title-card.gone .tc-inner { animation: panelOut .5s ease forwards; }

/* sound and HUD buttons respond to the hand */
.sound-btn, .leave-btn { transition: transform .2s, filter .2s; }
.sound-btn:hover, .leave-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }

@media (prefers-reduced-motion: reduce) {
  .objective.updated, .objective.updated::after, .zone-banner::before, .zone-banner::after,
  .title-card .tc-inner, .title-card .tc-inner > * { animation: none !important; }
}

/* =========================================================
   Loading screen + start screen
   ========================================================= */
.loader {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 55%, #2a1a10, #0b0705 70%);
  transition: opacity .8s ease, visibility 0s .8s;
}
.loader.done { opacity: 0; visibility: hidden; }
.ld-inner { width: min(420px, 100%); display: grid; justify-items: center; text-align: center; }
.ld-glyph { width: 120px; height: 120px; color: #e2c07e; filter: drop-shadow(0 0 12px rgba(255, 200, 110, .5)); animation: spin 14s linear infinite; }
.ld-glyph * { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-dasharray: 400; stroke-dashoffset: 400; animation: ldDraw 2.4s ease-in-out infinite alternate; }
.ld-glyph .thin { stroke-width: .7; }
.ld-glyph :nth-child(2) { animation-delay: .2s; } .ld-glyph :nth-child(3) { animation-delay: .4s; }
.ld-glyph :nth-child(4) { animation-delay: .6s; } .ld-glyph :nth-child(5) { animation-delay: .8s; } .ld-glyph :nth-child(6) { animation-delay: 1s; }
@keyframes ldDraw { to { stroke-dashoffset: 0; } }
.ld-title { margin: 22px 0 18px; font: 400 1.6rem "IM Fell English", Georgia, serif; color: #f1e2bc; letter-spacing: .02em; }
.ld-bar {
  width: 100%; height: 10px; padding: 2px; border-radius: 1px;
  background: #1a100a; box-shadow: 0 0 0 2px #b08d57, 0 0 0 4px #2b1a0e;
}
.ld-bar span {
  display: block; height: 100%; width: 0; transition: width .45s ease;
  background: linear-gradient(90deg, #a87924, #f0c869); box-shadow: 0 0 10px rgba(255, 200, 110, .6);
  position: relative;
}
.ld-bar span::after { content: "✦"; position: absolute; right: -7px; top: 50%; translate: 0 -50%; font-size: 13px; color: #fff3d0; text-shadow: 0 0 8px #ffcf7a; }
.ld-status { margin: 14px 0 0; font: italic .98rem "Alegreya", Georgia, serif; color: #d8c6a2; min-height: 1.4em; }
.ld-tip { margin: 26px 0 0; max-width: 34em; font: .9rem/1.5 "Alegreya", Georgia, serif; color: #9c8a6c; min-height: 3em; opacity: 0; }
.ld-tip.in { animation: tipIn 2.6s ease both; }
@keyframes tipIn { 0% { opacity: 0; transform: translateY(6px); } 15%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* start screen: the library drifts by under a soft dark veil */
.title-card {
  display: grid; grid-template-rows: 1fr auto auto; justify-items: center; align-items: end;
  padding: 6vh 16px 5vh; gap: 26px;
  background:
    radial-gradient(ellipse 60% 50% at 50% 38%, rgba(10, 6, 3, .25), rgba(10, 6, 3, .75) 75%),
    linear-gradient(rgba(8, 5, 3, .55), rgba(8, 5, 3, .2) 40%, rgba(8, 5, 3, .8));
  opacity: 0; pointer-events: none; transition: opacity .9s ease;
}
.title-card.shown { opacity: 1; pointer-events: auto; }
.title-card.gone { opacity: 0 !important; pointer-events: none; transition: opacity .5s ease; }
.title-card .tc-inner { display: none; }

.tc-logo { position: relative; display: grid; justify-items: center; text-align: center; align-self: center; }
.tc-glyph { position: absolute; left: 50%; top: 52%; width: min(520px, 92vw); aspect-ratio: 1; translate: -50% -50%; color: #e2c07e; opacity: .18; z-index: -1; animation: spin 80s linear infinite; }
.tc-glyph .glyph-svg { width: 100%; height: 100%; }
.tc-hat { width: 120px; margin-bottom: -6px; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .5)); animation: hatFloat 4s ease-in-out infinite; }
@keyframes hatFloat { 50% { transform: translateY(-8px) rotate(-3deg); } }
.title-card h1 {
  margin: 0; font: 400 clamp(2.8rem, 9vw, 5.6rem)/.95 "IM Fell English", Georgia, serif; letter-spacing: .01em;
  color: #f4e6c4; text-shadow: 0 3px 0 #2b1a0e, 0 6px 0 rgba(0, 0, 0, .35), 0 0 40px rgba(255, 190, 100, .35);
}
.tc-ribbon {
  position: relative; margin: 18px 0 0; padding: 7px 34px 9px;
  font: italic clamp(1rem, 2.4vw, 1.2rem) "Alegreya", Georgia, serif; color: #f6e7c8;
  background: #6e2a26; box-shadow: 0 0 0 2px #2b1a0e, 0 0 0 4px #b08d57, 0 6px 14px rgba(0, 0, 0, .5);
}
.tc-ribbon::before, .tc-ribbon::after {
  content: ""; position: absolute; top: 8px; width: 22px; height: 100%; background: #4e1c1a; z-index: -1;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 35% 50%);
}
.tc-ribbon::before { left: -18px; } .tc-ribbon::after { right: -18px; transform: scaleX(-1); }

.tc-menu { display: grid; gap: 14px; width: min(280px, 86vw); }
.tc-menu button {
  position: relative; padding: 10px 18px 11px; border: 0; border-radius: 2px; cursor: pointer;
  font: 400 1.25rem "IM Fell English", Georgia, serif; color: var(--ui-ink);
  background: var(--ui-paper-bg); box-shadow: var(--ui-frame), 0 8px 16px rgba(0, 0, 0, .45);
  transition: transform .2s cubic-bezier(.22, 1.4, .36, 1), background .2s, color .2s;
}
.tc-menu button::before, .tc-menu button::after {
  content: "✦"; position: absolute; top: 50%; translate: 0 -50%; color: #f0c869; opacity: 0; transition: opacity .2s, transform .2s;
}
.tc-menu button::before { left: 16px; transform: translateX(8px); } .tc-menu button::after { right: 16px; transform: translateX(-8px); }
.tc-menu button:is(:hover, :focus-visible) { transform: scale(1.04); color: #f6e7c8; background: linear-gradient(#843c35, #5e2420); outline: none; }
.tc-menu button:is(:hover, :focus-visible)::before, .tc-menu button:is(:hover, :focus-visible)::after { opacity: 1; transform: none; }
.title-card.shown .tc-menu button { animation: menuIn .6s cubic-bezier(.22, 1.3, .36, 1) both; }
.title-card.shown .tc-menu button:nth-child(2) { animation-delay: .08s; }
.title-card.shown .tc-menu button:nth-child(3) { animation-delay: .16s; }
.title-card.shown .tc-menu button:nth-child(4) { animation-delay: .24s; }
@keyframes menuIn { from { opacity: 0; transform: translateY(16px); } }
.title-card.shown .tc-logo { animation: cardLand .9s cubic-bezier(.22, 1.3, .36, 1) both; }

.tc-press { margin: 0; font: italic .95rem "Alegreya", Georgia, serif; color: #d8c6a2; letter-spacing: .06em; animation: pressBlink 2s ease-in-out infinite; }
@keyframes pressBlink { 50% { opacity: .35; } }

.tc-howto {
  position: fixed; left: 50%; top: 50%; translate: -50% -50%; z-index: 2;
  width: min(420px, calc(100vw - 32px)); padding: 26px 28px 22px; text-align: left;
  color: var(--ui-ink); background: var(--ui-paper-bg); box-shadow: var(--ui-frame), var(--ui-lift); border-radius: 2px;
}
.tc-howto h2 { margin: 0 0 10px; font: 400 1.5rem "IM Fell English", Georgia, serif; color: var(--ui-red); }
.tc-howto p { margin: 0 0 8px; font: 1rem/1.5 "Alegreya", Georgia, serif; }
.tc-howto button { margin-top: 8px; padding: 7px 20px; border: 0; border-radius: 2px; font: 1.05rem "IM Fell English", Georgia, serif; color: #f6e7c8; background: linear-gradient(#843c35, #5e2420); box-shadow: var(--ui-frame); cursor: pointer; }

/* nothing else peeks out until the library has loaded */
body.game:not(.loaded) :is(.hud, .sound-btn, .musicbox, .act-btn, .dialog) { visibility: hidden; }
body.game:has(.title-card:not(.gone)) :is(.hud, .sound-btn, .act-btn) { opacity: 0; pointer-events: none; }

@media (max-height: 640px) {
  .tc-hat { width: 80px; } .title-card { gap: 14px; } .tc-menu { gap: 10px; } .tc-menu button { font-size: 1.1rem; padding: 7px 14px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .ld-glyph, .ld-glyph *, .tc-glyph, .tc-hat, .tc-press { animation: none !important; stroke-dashoffset: 0; }
}

/* =========================================================
   TRIAL WINDOWS — one layout for every activity:
   crest + title + instructions / the puzzle / status + buttons
   ========================================================= */
body.game #sceneHost .scene.is-active:is(#wordle, #crossword, #gallery, #connections) {
  display: grid !important; place-items: center; padding: 18px !important; overflow: hidden;
}
body.game .tw-hidden { display: none !important; }
body.game.in-scene .trials { display: none; }

.tw {
  position: relative; z-index: 2;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1080px, 100%); height: min(880px, calc(100dvh - 40px));
  color: var(--ui-ink); background: var(--ui-paper-bg); border-radius: 3px;
  box-shadow: 0 0 0 4px var(--ui-wood), 0 0 0 7px var(--ui-brass), 0 0 0 15px #3a2412, 0 0 0 17px var(--ui-brass), 0 0 0 19px var(--ui-wood), 0 30px 80px rgba(0, 0, 0, .7);
  animation: twIn .6s cubic-bezier(.22, 1.25, .36, 1) both;
}
@keyframes twIn { from { opacity: 0; transform: translateY(40px) scale(.94); } }
body.game #sceneHost .scene.closing .tw { animation: panelOut .26s ease forwards; }
.tw::before { /* faint paper grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5; mix-blend-mode: multiply;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='m'><feTurbulence type='fractalNoise' baseFrequency='.02' numOctaves='3' seed='4'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .3  0 0 0 0 .12  0 0 0 .35 -.05'/></filter><rect width='100%' height='100%' filter='url(%23m)'/></svg>");
}
.tw-corner {
  position: absolute; z-index: 3; width: 30px; height: 30px; pointer-events: none;
  background: radial-gradient(circle, #fff3d0 0 2px, #f0c869 2.5px 5px, #8a6524 5.5px 7px, #b08d57 7.5px 10px, #2b1a0e 10.5px 12px, transparent 12.5px);
}
.tw-corner.tl { left: -26px; top: -26px; } .tw-corner.tr { right: -26px; top: -26px; }
.tw-corner.bl { left: -26px; bottom: -26px; } .tw-corner.br { right: -26px; bottom: -26px; }

/* header */
.tw-head {
  position: relative; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 4px 20px;
  padding: 18px 22px 16px;
  background: linear-gradient(rgba(110, 42, 38, .06), transparent);
}
.tw-head::after, .tw-foot::before { /* ink rule with a diamond */
  content: ""; position: absolute; left: 22px; right: 22px; height: 7px;
  background:
    linear-gradient(45deg, transparent 40%, var(--ui-red) 41% 59%, transparent 60%) center / 7px 7px no-repeat,
    linear-gradient(var(--ui-ink), var(--ui-ink)) center / 100% 1px no-repeat;
  opacity: .55;
}
.tw-head::after { bottom: -3px; }
.tw-crest {
  width: 68px; height: 68px; padding: 5px; border-radius: 50%;
  color: var(--ui-red); background: radial-gradient(circle at 40% 35%, #fbf1d8, #e0c896);
  box-shadow: 0 0 0 2px var(--ui-wood), 0 0 0 5px var(--ui-brass), 0 0 0 7px var(--ui-wood), 0 6px 12px rgba(0, 0, 0, .3);
}
.tw-crest .glyph-svg { width: 100%; height: 100%; animation: spin 50s linear infinite; }
.tw-titles { min-width: 0; }
.tw-kicker { margin: 0 0 2px; font: italic .92rem "Alegreya", Georgia, serif; color: var(--ui-red); letter-spacing: .05em; }
body.game .tw-titles .chapter-title {
  position: static !important; translate: none !important; transform: none !important; animation: none !important;
  background: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important;
  font-size: clamp(1.45rem, 3vw, 2.15rem) !important; line-height: 1.05; white-space: normal !important;
  color: var(--ui-ink) !important; text-shadow: none !important; text-align: left;
}
body.game .tw-titles :is(p:not(.tw-kicker), .page-text) {
  margin: 6px 0 0 !important; max-width: 62em; color: var(--ui-ink-soft) !important;
  font: italic .95rem/1.45 "Alegreya", Georgia, serif;
}
body.game .tw-titles .page-text p { display: inline; margin: 0 .3em 0 0; font: inherit; }
.tw-close {
  width: 42px; height: 42px; border: 0; border-radius: 50%; cursor: pointer;
  font: 400 1.7rem/1 "IM Fell English", Georgia, serif; color: var(--ui-ink);
  background: radial-gradient(circle at 35% 30%, #f6e2a8, #b08d57);
  box-shadow: 0 0 0 2px var(--ui-wood), 0 4px 0 2px rgba(0, 0, 0, .3);
  transition: transform .25s cubic-bezier(.22, 1.4, .36, 1);
}
.tw-close:hover, .tw-close:focus-visible { transform: rotate(90deg) scale(1.08); outline: none; }

/* "Solved" stamp lands on the header when the trial is done */
.tw-stamp {
  padding: 4px 14px 5px; font: 400 1.25rem "IM Fell English SC", Georgia, serif; letter-spacing: .08em;
  color: var(--ui-red); border: 3px double var(--ui-red); border-radius: 3px;
  opacity: 0; transform: rotate(-10deg) scale(2.2); pointer-events: none;
}
.tw.solved .tw-stamp { animation: stampIn .5s .15s cubic-bezier(.3, 1.6, .5, 1) forwards; }
@keyframes stampIn { to { opacity: .85; transform: rotate(-10deg) scale(1); } }

/* body: the puzzle, scrolling if it has to */
.tw-body {
  position: relative; min-height: 0; overflow: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 24px clamp(12px, 3vw, 30px);
  scrollbar-width: thin; scrollbar-color: var(--ui-brass) transparent;
}
.tw-body > * { flex: none; }

/* footer: status on the left, buttons on the right */
.tw-foot {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px 18px;
  padding: 16px 22px 18px; background: linear-gradient(transparent, rgba(110, 70, 30, .12));
}
.tw-foot::before { top: -3px; }
body.game .tw-foot :is(.wordle-status, .gallery-status, .conn-status) {
  flex: 1 1 220px; order: 1; margin: 0; min-height: 0; text-align: left;
  font: italic 1rem/1.4 "Alegreya", Georgia, serif; color: var(--ui-ink-soft) !important;
}
body.game .tw-foot :is(.cross-actions, .conn-actions, .after-win) { order: 3; margin: 0; width: auto !important; flex-wrap: nowrap; }
body.game .tw-foot .after-win[hidden] { display: none !important; }
body.game .tw-foot :is(.btn-wax, .btn-plank) { font-size: 1.05rem; padding: 9px 20px 10px; }

/* ---------- Trial I: the word ---------- */
.tw[data-trial="wordle"] .tw-body { justify-content: center; gap: 26px; }
body.game .tw .wordle-board { gap: 8px; }
body.game .tw .w-row { gap: 8px; }
body.game .tw .w-tile {
  width: clamp(48px, 7.2vh, 66px); font-size: clamp(1.6rem, 4vh, 2.3rem);
  background: rgba(255, 250, 235, .55); border: 2px solid rgba(43, 26, 14, .25); border-radius: 3px;
}
body.game .tw .w-tile.filled { border-color: var(--ui-ink); }
body.game .tw .keyboard { width: min(640px, 100%); }
body.game .tw .k { height: clamp(42px, 6.4vh, 54px); }
body.game .tw-foot .legend { order: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; }
body.game .tw-foot .legend p { margin: 0; font-size: .85rem; color: var(--ui-ink-soft); gap: 8px; }
body.game .tw-foot .legend .key-tile { width: 24px; height: 24px; font-size: .85rem; }

/* ---------- Trial II: the bridge ---------- */
body.game .tw .active-clue {
  width: 100%; min-height: 0; padding: 9px 16px; border-radius: 2px; text-align: left;
  background: rgba(110, 42, 38, .08) !important; border: 1px solid rgba(110, 42, 38, .3) !important; color: var(--ui-ink) !important;
  font-size: 1.05rem;
}
body.game .tw .bridge { width: 100%; padding-top: 70px; box-shadow: inset 0 0 0 2px var(--ui-wood), inset 0 0 40px rgba(0, 0, 0, .6), 0 0 0 4px rgba(176, 141, 87, .5); }
body.game .tw .clue-boards { width: 100%; gap: 6px 30px; }
body.game .tw .clue-board { padding-top: 10px; }
body.game .tw-foot .how { order: 1; flex: 1 1 200px; margin: 0; font: italic .95rem "Alegreya", Georgia, serif; color: var(--ui-ink-soft); opacity: 1; }

/* ---------- Trial III: the gallery ---------- */
body.game .tw .frames { width: 100%; margin: 0; }
body.game .tw-foot .tray-wrap { position: static !important; order: 0; flex: 1 1 100%; width: 100%; margin: 0; }
body.game .tw-foot .tray { min-height: 0; padding: 12px 14px; }
body.game .tw-foot .gallery-cat { display: none; }

/* ---------- Trial IV: the potion shelf ---------- */
body.game .tw .apothecary { width: min(760px, 100%); margin: 0 auto; }
body.game .tw-foot .conn-meta { order: 0; margin: 0; color: var(--ui-ink-soft) !important; font: italic 1rem "Alegreya", Georgia, serif; }
body.game .tw-foot .conn-candles { gap: 10px; }

@media (max-width: 760px) {
  body.game #sceneHost .scene.is-active:is(#wordle, #crossword, #gallery, #connections) { padding: 10px !important; }
  .tw { height: calc(100dvh - 22px); box-shadow: 0 0 0 3px var(--ui-wood), 0 0 0 5px var(--ui-brass), 0 0 0 8px var(--ui-wood), 0 20px 50px rgba(0, 0, 0, .7); }
  .tw-corner { display: none; }
  .tw-head { grid-template-columns: auto 1fr auto; padding: 12px 12px 12px; gap: 2px 12px; }
  .tw-crest { width: 44px; height: 44px; padding: 3px; }
  .tw-stamp { position: absolute; right: 60px; top: 10px; font-size: .95rem; }
  body.game .tw-titles :is(p:not(.tw-kicker), .page-text) { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .85rem; }
  .tw-body { padding: 14px 8px; gap: 14px; }
  .tw-foot { padding: 12px 12px 14px; gap: 10px; }
  body.game .tw-foot .legend { display: none; }
  body.game .tw .w-tile { width: clamp(40px, 13vw, 56px); }
}

/* keep the footer clear: the music keeps playing while a window is open */
body.game.in-scene .musicbox { opacity: 0; pointer-events: none; }
