/* Word Knight :: high-fantasy UI, built for iPad thumbs first. */

:root {
  --ink:        #f4ecd8;
  --ink-dim:    #b8ac91;
  --parchment:  #efe0bd;
  --stone-900:  #15121f;
  --stone-800:  #1e1a2e;
  --stone-700:  #2a243d;
  --stone-600:  #3a3252;
  --gold:       #d8b04a;
  --gold-bright:#ffd977;
  --blood:      #b03a3a;
  --heal:       #4fbf6f;
  --mana:       #4a9fe8;
  --violet:     #7a5fbf;

  --r-common:    #9aa0b0;
  --r-uncommon:  #4fbf6f;
  --r-rare:      #4a9fe8;
  --r-epic:      #a86fe8;
  --r-legendary: #f0a83a;

  --font-display: 'Cinzel', 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --font-pixel: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Several components set an explicit `display`, which would otherwise beat the
   UA stylesheet's [hidden] rule and leave "hidden" elements on screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;
  background: var(--stone-900);
  color: var(--ink);
  font-family: var(--font-display);
  /* Kids will hold the iPad and mash buttons — never let it text-select. */
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% 0%, #2e2545 0%, transparent 60%),
    radial-gradient(ellipse 100% 60% at 50% 100%, #1a1630 0%, transparent 55%),
    var(--stone-900);
  display: flex; flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ------------------------------------------------------------ typography */
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.02em; }
h1 { font-size: clamp(28px, 6vw, 52px); }
.subtitle { color: var(--ink-dim); font-size: clamp(13px, 2.4vw, 17px); letter-spacing: 0.08em; }

/* ---------------------------------------------------------------- screens */
/* Screens paint above the scene layer. z-index 1 (not auto) is required — an
   in-flow, non-positioned box paints *below* a positioned z-index:0 sibling. */
.screen { display: none; flex: 1; flex-direction: column; min-height: 0;
  position: relative; z-index: 1; }
.screen.active { display: flex; animation: fade-in 0.28s ease; }

/* ---------------------------------------------------------- scene art
   A real element rather than a pseudo-element on .screen: a negative z-index
   layer paints *before* the body's own background in CSS paint order, so the
   body gradient covered it (it only showed while the fade-in transform was
   briefly creating a stacking context).

   The dark scrim baked in on top is not decoration — the UI is light text on
   dark panels and would be unreadable over a bright daytime village. */
#scene-layer {
  position: fixed; inset: 0; z-index: 0;
  display: none; pointer-events: none;
  background-size: cover; background-position: center 32%;
  image-rendering: pixelated;
}
#scene-layer.on { display: block; }
#scene-layer.camp {
  background-image:
    linear-gradient(180deg, rgba(12,10,22,0.88) 0%, rgba(12,10,22,0.70) 30%,
                            rgba(12,10,22,0.80) 70%, rgba(12,10,22,0.95) 100%),
    url('/scenes/camp.jpg');
}
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* The inline padding is not decoration: a scrolling container clips its
   children's box-shadows at the padding edge, and the hero card glows out to
   ~34px. With only 16px the glow was sliced off in a hard vertical line down
   the left of the card. */
.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 16px 34px; }
@media (max-width: 460px) { .wrap { padding: 16px 20px; } }

/* ----------------------------------------------------------------- panels */
.panel {
  background: linear-gradient(180deg, var(--stone-700), var(--stone-800));
  border: 2px solid var(--stone-600);
  border-radius: 14px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06);
  padding: 18px;
}
.panel.gilt { border-color: var(--gold); box-shadow: 0 6px 0 rgba(0,0,0,0.4), 0 0 26px rgba(216,176,74,0.16); }

/* ---------------------------------------------------------------- buttons */
/* `.btn` is used on <a> as well as <button>; without these the anchor keeps the
   UA link colour and underline. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 14px 22px;
  font-size: 18px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--ink); text-decoration: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #4a4066, #322a4a);
  border: 2px solid #5c5080;
  box-shadow: 0 4px 0 #1a1530;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a1530; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.primary {
  background: linear-gradient(180deg, #e0b855, #b8892c);
  border-color: var(--gold-bright); color: #2b1d05;
  box-shadow: 0 4px 0 #6b4f14;
}
.btn.primary:active { box-shadow: 0 1px 0 #6b4f14; }
.btn.danger { background: linear-gradient(180deg, #c04a4a, #8a2a2a); border-color: #e07070; box-shadow: 0 4px 0 #5a1515; }
.btn.ghost { background: transparent; border-color: var(--stone-600); box-shadow: none; min-height: 44px; }
.btn.small { min-height: 42px; padding: 8px 14px; font-size: 15px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* ------------------------------------------------------------ title screen */
#screen-title .wrap { display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1; text-align: center; gap: 22px; }
.crest { font-size: clamp(56px, 14vw, 110px); line-height: 1; filter: drop-shadow(0 4px 12px rgba(216,176,74,0.4)); }
.title-gold {
  background: linear-gradient(180deg, #fff0c0, var(--gold) 55%, #9c7420);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

.knight-list { display: grid; gap: 12px; width: 100%; max-width: 460px; }
.knight-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; text-align: left;
  border-radius: 12px; background: linear-gradient(180deg, #3a3252, #2a243d);
  border: 2px solid var(--stone-600); box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  transition: transform 0.08s, border-color 0.15s;
}
.knight-card:active { transform: translateY(3px); }
.knight-card .nm { font-size: 20px; font-weight: 700; }
.knight-card .meta { color: var(--ink-dim); font-size: 13px; }
.knight-card .lvl {
  margin-left: auto; font-family: var(--font-pixel); font-size: 12px;
  background: var(--stone-900); border: 1px solid var(--gold); color: var(--gold-bright);
  padding: 5px 9px; border-radius: 999px; white-space: nowrap;
}

input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 13px 14px; font-size: 17px; font-family: inherit;
  color: var(--ink); background: var(--stone-900);
  border: 2px solid var(--stone-600); border-radius: 10px;
  -webkit-user-select: text; user-select: text;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }

/* -------------------------------------------------------------- camp/home */
.camp-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 720px) { .camp-grid { grid-template-columns: 320px 1fr; } }

.avatar-stage {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #241f3a 0%, #171327 100%);
  border-radius: 12px; padding: 12px; border: 2px solid var(--stone-600);
}
/* Trading-card stat strip, sitting under the portrait + level like a CCG. */
.hero-card { border-color: var(--gold); box-shadow: 0 6px 0 rgba(0,0,0,0.4), 0 0 26px rgba(216,176,74,0.14); }

/* Name + selectable title at the top of the character card. */
.card-head { text-align: center; margin-bottom: 10px; }
.card-head .cn { font-size: 22px; font-weight: 700; line-height: 1.15; }
.card-head .ct {
  font-family: var(--font-pixel); font-size: 11.5px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--gold-bright); margin-top: 3px;
}

/* ------------------------------------------ card frames (cosmetics) */
.hero-card.frame-wood {
  border-color: #8a5a2b;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #5c3a18, 0 0 22px rgba(138,90,43,0.35);
}
.hero-card.frame-iron {
  border-color: #9aa0b0;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #6b7080, 0 0 22px rgba(154,160,176,0.3);
}
.hero-card.frame-gold {
  border-color: var(--gold-bright);
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #b8892c, 0 0 34px rgba(255,217,119,0.4);
}
.hero-card.frame-flame {
  border-color: #ff8a3a;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #b03a3a, 0 0 34px rgba(255,138,58,0.5);
  animation: flameGlow 1.6s ease-in-out infinite;
}
@keyframes flameGlow {
  0%,100% { box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #b03a3a, 0 0 26px rgba(255,138,58,0.4); }
  50%     { box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #b03a3a, 0 0 44px rgba(255,209,102,0.65); }
}
.hero-card.frame-rune {
  border-color: #a86fe8;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #7a5fbf, 0 0 34px rgba(168,111,232,0.5);
  animation: runeGlow 2.2s ease-in-out infinite;
}
@keyframes runeGlow {
  0%,100% { box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #7a5fbf, 0 0 26px rgba(168,111,232,0.4); }
  50%     { box-shadow: 0 6px 0 rgba(0,0,0,0.4), inset 0 0 0 3px #7a5fbf, 0 0 46px rgba(192,160,255,0.7); }
}

/* -------------------------------------- card backdrop scenes (cosmetics)

   The default backdrop is a daylight meadow, not the old purple stage: the
   knight sprite is itself purple-outlined, so on a purple field the character
   was nearly unreadable. Hard-edged colour bands (no soft blends) keep it in
   the 16-bit idiom — sky, haze, far hills, dirt, then grass to stand on. */
.avatar-stage.bg-plain {
  background:
    /* sun */
    radial-gradient(circle 16px at 78% 14%, #fff3b0 0 60%, #ffe27a 60% 100%, transparent 100%),
    /* grass tufts, a repeating pixel texture rather than a gradient */
    repeating-linear-gradient(90deg,
      transparent 0 7px, rgba(255,255,255,0.05) 7px 8px),
    linear-gradient(180deg,
      #7fc4e8 0%,   #7fc4e8 20%,
      #9ad4ee 20%,  #9ad4ee 34%,
      #bfe4f2 34%,  #bfe4f2 44%,
      #8d9e78 44%,  #8d9e78 50%,
      #b6a67e 50%,  #b6a67e 57%,
      #9a8a5e 57%,  #9a8a5e 63%,
      #5f9147 63%,  #5f9147 78%,
      #4d7a38 78%,  #4d7a38 100%);
}

/* A card backdrop can also be a real painted image (512×640). Set by JS from
   the cosmetic's `data` when it points at a file. */
.avatar-stage.bg-image {
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
}

.avatar-stage.bg-forest {
  background:
    radial-gradient(ellipse 60% 45% at 18% 78%, #1e4a2a 0%, transparent 70%),
    radial-gradient(ellipse 55% 40% at 82% 74%, #17381f 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 50% 86%, #245a32 0%, transparent 75%),
    linear-gradient(180deg, #0d2416 0%, #123020 55%, #0a1c10 100%);
}
.avatar-stage.bg-castle {
  background:
    repeating-linear-gradient(90deg, transparent 0 26px, rgba(255,255,255,0.05) 26px 28px),
    linear-gradient(180deg, #2c2f3f 0%, #454a5f 60%, #23252f 100%);
}
.avatar-stage.bg-lava {
  background:
    radial-gradient(ellipse 70% 40% at 50% 96%, #ff7a3a 0%, rgba(255,122,58,0.35) 40%, transparent 72%),
    radial-gradient(ellipse 30% 18% at 26% 88%, #ffd166 0%, transparent 70%),
    linear-gradient(180deg, #1c0a08 0%, #3a1410 55%, #58180c 100%);
}
.avatar-stage.bg-starry {
  background:
    radial-gradient(1.5px 1.5px at 18% 22%, #fff 99%, transparent),
    radial-gradient(1.5px 1.5px at 72% 14%, #fff 99%, transparent),
    radial-gradient(2px 2px at 84% 46%, #cfe8ff 99%, transparent),
    radial-gradient(1.5px 1.5px at 38% 38%, #fff 99%, transparent),
    radial-gradient(1.5px 1.5px at 56% 64%, #ffd977 99%, transparent),
    radial-gradient(2px 2px at 12% 58%, #cfe8ff 99%, transparent),
    radial-gradient(1.5px 1.5px at 66% 84%, #fff 99%, transparent),
    linear-gradient(180deg, #0a0a2a 0%, #141040 60%, #060618 100%);
}
.card-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px;
  padding-top: 14px; border-top: 2px solid rgba(216,176,74,0.35);
}
.card-stats .cs {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px; border-radius: 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.42), rgba(0,0,0,0.24));
  border: 2px solid var(--stone-600);
}
.card-stats .k {
  font-family: var(--font-pixel); font-size: 10.5px; letter-spacing: 0.14em;
  color: var(--ink-dim);
}
.card-stats .v { font-size: 25px; font-weight: 700; line-height: 1; }
.card-stats .atk { border-color: #b03a3a; } .card-stats .atk .v { color: #ff8a8a; }
.card-stats .def { border-color: #4a7fb8; } .card-stats .def .v { color: #8fc4ff; }
.card-stats .mag { border-color: #7a5fbf; } .card-stats .mag .v { color: #c0a8ff; }

.stat-row { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0;
  border-bottom: 1px dashed rgba(255,255,255,0.09); font-size: 16px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .v { font-weight: 700; color: var(--gold-bright); }

.purse { display: flex; flex-wrap: wrap; gap: 8px; }
.coin {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-size: 15px; font-weight: 700;
  background: var(--stone-900); border: 1px solid var(--stone-600);
}

/* Progress bars (XP, HP) */
.bar { height: 14px; border-radius: 999px; background: #120f1e;
  border: 2px solid #0a0812; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; border-radius: inherit;
  transition: width 0.45s cubic-bezier(0.22,1,0.36,1); }
.bar.hp > i  { background: linear-gradient(180deg, #6fe08a, #2f9f4f); }
.bar.hp.low > i { background: linear-gradient(180deg, #ff8a6a, #b03a3a); }
.bar.foe > i { background: linear-gradient(180deg, #ff7a7a, #8a2020); }
.bar.xp > i  { background: linear-gradient(180deg, #ffd977, #b8892c); }

/* ---------------------------------------------------------- battle screen */
#screen-battle { position: relative; }
.hud-top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: rgba(10,8,18,0.86);
  border-bottom: 2px solid var(--stone-600);
  position: sticky; top: 0; z-index: 30; backdrop-filter: blur(6px);
}
.session-clock {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-pixel); font-size: 22px; font-weight: 700;
  color: var(--gold-bright); letter-spacing: 0.06em;
}
.session-clock.warn { color: #ff9a5a; }
.session-clock.crit { color: #ff5a5a; animation: pulse 0.9s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
.hud-chip {
  font-family: var(--font-pixel); font-size: 13px; padding: 5px 10px;
  border-radius: 999px; background: var(--stone-800); border: 1px solid var(--stone-600);
}

.arena {
  position: relative; flex: 1; min-height: 240px;
  background-image:
    linear-gradient(180deg, rgba(14,11,26,0.72) 0%, rgba(14,11,26,0.30) 38%,
                            rgba(14,11,26,0.52) 62%, rgba(14,11,26,0.88) 100%),
    url('/scenes/battle.jpg');
  background-size: cover, cover;
  background-position: center 30%, center 62%;
  overflow: hidden;
  image-rendering: pixelated;
}
/* Ground line where the combatants stand. */
.arena::after {
  content: ''; position: absolute; left: 0; right: 0; top: 55%; height: 2px;
  background: rgba(255,255,255,0.10);
}
/* Combatant name plates need to survive a busy backdrop. */
.combatant-bar .nm {
  text-shadow: 0 2px 5px #000, 0 0 12px rgba(0,0,0,0.9);
}
.combatant-bar .bar { box-shadow: 0 2px 8px rgba(0,0,0,0.65); }
#arena-canvas, #boss-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.combatant-bar { position: absolute; z-index: 5; width: min(42%, 240px); }
.combatant-bar .nm { font-size: 14px; font-weight: 700; margin-bottom: 4px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8); }
.combatant-bar.foe { top: 12px; right: 12px; text-align: right; }
.combatant-bar.hero { bottom: 12px; left: 12px; }

/* floating damage / heal numbers */
.floater {
  position: absolute; z-index: 20; pointer-events: none;
  font-family: var(--font-pixel); font-weight: 700; font-size: 26px;
  text-shadow: 0 2px 0 #000, 0 0 12px currentColor;
  animation: floatUp 1.05s cubic-bezier(0.2,0.8,0.3,1) forwards;
}
@keyframes floatUp {
  0%   { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  18%  { transform: translate(-50%, -14px) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -68px) scale(1); opacity: 0; }
}
.floater.dmg  { color: #ff6b6b; }
.floater.heal { color: #6fe08a; }
.floater.crit { color: #ffd166; font-size: 34px; }

.shake { animation: shake 0.34s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-9px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(4px); }
}

/* ------------------------------------------------------------ realm map */
.realm-map { display: grid; gap: 10px; }
.realm-node {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 12px;
  background: linear-gradient(180deg, #3a3252, #2a243d);
  border: 2px solid var(--stone-600); box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  transition: transform .08s, border-color .15s;
}
.realm-node:active { transform: translateY(3px); box-shadow: none; }
.realm-node .seal {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-size: 21px;
  background: rgba(0,0,0,0.35); border: 2px solid var(--rc, var(--stone-600));
}
.realm-node .nm { font-size: 16px; font-weight: 700; }
.realm-node .sub { font-size: 12.5px; color: var(--ink-dim); line-height: 1.35; }
.realm-node.locked { opacity: .62; }
.realm-node.open {
  border-color: var(--rc, var(--gold));
  box-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 22px -6px var(--rc, var(--gold));
}
.realm-node.open .nm { color: var(--gold-bright); }
.realm-node.cleared { border-color: var(--heal); }
.realm-node .badge-done {
  margin-left: auto; font-size: 10px; padding: 4px 9px; border-radius: 999px;
  background: rgba(79,191,111,.2); border: 1px solid var(--heal); color: #9fe8b8;
  font-weight: 700; white-space: nowrap;
}
/* A locked realm shows how far off it is, not just that it is shut. */
.realm-node .gauge { height: 6px; border-radius: 999px; background: #120f1e; margin-top: 6px; }
.realm-node .gauge > i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }

/* --------------------------------------------------- paragraph boss */
.boss-arena { min-height: 190px; }
.boss-zone { max-height: 62dvh; overflow-y: auto; }
.story-so-far {
  font-size: 14px; color: var(--ink-dim); line-height: 1.5; text-align: center;
  margin-bottom: 10px; font-style: italic;
}
.story-so-far:empty { display: none; }
.boss-line {
  font-size: clamp(22px, 5vw, 34px); font-weight: 700; line-height: 1.3;
  text-align: center; margin-bottom: 12px; text-wrap: balance;
}
.boss-verdict {
  text-align: center; font-weight: 700; font-size: 15px; margin-bottom: 10px;
  padding: 9px 12px; border-radius: 10px;
}
.boss-verdict.ok { background: rgba(79,191,111,.16); border: 2px solid var(--heal); color: #9fe8b8; }
.boss-verdict.no { background: rgba(176,58,58,.16); border: 2px solid var(--blood); color: #ffb0b0; }
.boss-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.speaker.orb {
  width: 96px; height: 96px; font-size: 42px;
  background: linear-gradient(180deg, #8a6fd8, #4a2f9f);
  border-color: #c0a8ff; box-shadow: 0 5px 0 #2a1a5a;
}
.speaker.orb:active { box-shadow: 0 1px 0 #2a1a5a; }
.boss-hint { font-size: 13px; color: var(--ink-dim); }

/* The parent's real-world promise, shown at the moment of victory. */
.incentive-card {
  width: 100%; max-width: 420px; padding: 16px 18px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(216,176,74,.22), rgba(216,176,74,.08));
  border: 2px solid var(--gold); text-align: center;
  box-shadow: 0 0 30px -8px var(--gold);
}
.incentive-card .tag {
  font-family: var(--font-pixel); font-size: 10px; letter-spacing: .18em;
  color: var(--gold-bright); margin-bottom: 6px;
}
.incentive-card .txt { font-size: 19px; font-weight: 700; line-height: 1.35; }

/* ------------------------------------------------- daily goal + pin pad */
.daily-goal {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  background: rgba(0,0,0,0.28); border: 2px solid var(--stone-600);
}
.daily-goal .ring { width: 46px; height: 46px; flex: 0 0 auto; }
.daily-goal .lbl { font-size: 14px; font-weight: 700; }
.daily-goal .sub { font-size: 12.5px; color: var(--ink-dim); }
.daily-goal.done { border-color: var(--heal); }
.daily-goal.done .lbl { color: #9fe8b8; }

/* A themed keypad, not the device keyboard: a numeric keyboard on an iPad
   invites a child to poke at autocomplete and lands them outside the app. */
.pinpad-panel { max-width: 360px; }
.pin-dots {
  display: flex; justify-content: center; gap: 12px; margin: 18px 0 6px;
  min-height: 22px;
}
.pin-dots i {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--gold); background: transparent;
  transition: background 0.12s, transform 0.12s;
}
.pin-dots i.on { background: var(--gold-bright); transform: scale(1.15); }
.pin-error {
  min-height: 20px; text-align: center; font-size: 13px; font-weight: 700;
  color: var(--blood);
}
.pinpad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px;
}
.pin-key {
  min-height: 62px; font-size: 26px; font-weight: 700; border-radius: 12px;
  font-family: var(--font-pixel);
  background: linear-gradient(180deg, #4a4066, #322a4a);
  border: 2px solid #5c5080; box-shadow: 0 4px 0 #1a1530;
  transition: transform 0.06s, box-shadow 0.06s;
}
.pin-key:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a1530; }
.pin-key.primary {
  background: linear-gradient(180deg, #5fd08a, #2f8f4f);
  border-color: #9fffc0; box-shadow: 0 4px 0 #1a5a30; color: #06210f;
}
.pin-key.ghost {
  background: linear-gradient(180deg, #4a3a3a, #322424); border-color: #6b5050;
  box-shadow: 0 4px 0 #201212;
}

/* ------------------------------------------------------- reading stages */
.stage-picker { display: grid; gap: 10px; }
@media (min-width: 560px) { .stage-picker { grid-template-columns: 1fr 1fr; } }
.stage-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 13px 15px; border-radius: 12px;
  background: linear-gradient(180deg, #3a3252, #2a243d);
  border: 2px solid var(--stone-600); box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s;
}
.stage-card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.stage-card.on { border-color: var(--gold); box-shadow: 0 4px 0 rgba(0,0,0,0.4), 0 0 20px -4px var(--gold); }
.stage-card .s-num { font-family: var(--font-pixel); font-size: 11px;
  letter-spacing: 0.16em; color: var(--ink-dim); }
.stage-card.on .s-num { color: var(--gold-bright); }
.stage-card .s-name { font-size: 18px; font-weight: 700; }
.stage-card .s-desc { font-size: 12.5px; color: var(--ink-dim); line-height: 1.35; }
.stage-card[disabled] { opacity: 0.4; pointer-events: none; }

/* "hear it again" button — the primary control in Stage 2, so it is big */
.speaker {
  width: 84px; height: 84px; flex: 0 0 auto; border-radius: 50%;
  font-size: 38px; line-height: 1;
  background: linear-gradient(180deg, #4a9fe8, #2a6fb8);
  border: 3px solid #8fd0ff; box-shadow: 0 5px 0 #17457a;
  display: grid; place-items: center;
  transition: transform 0.08s, box-shadow 0.08s;
}
.speaker:active { transform: translateY(4px); box-shadow: 0 1px 0 #17457a; }
.speaker.speaking { animation: speakerPulse 0.7s ease-in-out infinite; }
@keyframes speakerPulse {
  0%,100% { box-shadow: 0 5px 0 #17457a, 0 0 0 0 rgba(143,208,255,0.5); }
  50%     { box-shadow: 0 5px 0 #17457a, 0 0 0 14px rgba(143,208,255,0); }
}
/* Stage 2 hides the word itself but keeps the row height stable. */
.prompt-word.hidden-word { visibility: hidden; }

/* --------------------------------------------- incantation (speak-to-cast) */
/* Arcane Orb — 72px so it clears the 64px iPad touch-target floor. */
.orb-btn {
  width: 72px; height: 72px; flex: 0 0 auto; border-radius: 50%;
  font-size: 32px; line-height: 1;
  background: linear-gradient(180deg, #9a5fe8, #6a2fb8);
  border: 3px solid #d4a8ff; box-shadow: 0 5px 0 #3d1a7a;
  display: grid; place-items: center;
  transition: transform 0.08s, box-shadow 0.08s;
  animation: orbIdle 2.2s ease-in-out infinite;
}
.orb-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #3d1a7a; }
@keyframes orbIdle {
  0%,100% { box-shadow: 0 5px 0 #3d1a7a, 0 0 0 0 rgba(212,168,255,0.45); }
  50%     { box-shadow: 0 5px 0 #3d1a7a, 0 0 0 10px rgba(212,168,255,0); }
}
.orb-btn.listening { animation: orbLive 0.55s ease-in-out infinite; }
@keyframes orbLive {
  0%,100% { box-shadow: 0 5px 0 #3d1a7a, 0 0 0 4px rgba(212,168,255,0.6); transform: scale(1); }
  50%     { box-shadow: 0 5px 0 #3d1a7a, 0 0 0 18px rgba(212,168,255,0);  transform: scale(1.06); }
}

/* What the browser heard, live under the prompt. */
.speech-banner {
  text-align: center; font-size: 16px; font-weight: 600;
  padding: 8px 12px; margin: 0 auto 10px; max-width: 480px;
  border-radius: 10px; border: 1px solid #6a2fb8;
  background: rgba(106,47,184,0.18); color: #d4a8ff;
}
.speech-banner.listening { animation: bannerBlink 1s ease-in-out infinite; }
@keyframes bannerBlink { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
.speech-banner.ok { border-color: #2e8b57; background: rgba(46,139,87,0.2); color: #8fe8b0; }
.speech-banner.no { border-color: #b83a3a; background: rgba(184,58,58,0.18); color: #ff9c9c; }

/* Spoken crits hit harder and look it. */
.floater.spellcrit { color: #d4a8ff; font-size: 38px; text-shadow: 0 2px 0 #000, 0 0 18px #9a5fe8; }

/* Arcane Burst — expanding ring + 8 sparks flying outward over the monster. */
.arcane-burst {
  position: absolute; z-index: 19; pointer-events: none;
  left: 72%; top: 32%; width: 0; height: 0;
}
.arcane-burst::before {
  content: ''; position: absolute; left: 0; top: 0;
  width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 4px solid #d4a8ff; box-shadow: 0 0 22px #9a5fe8, inset 0 0 12px #9a5fe8;
  animation: burstRing 0.9s cubic-bezier(0.2,0.8,0.4,1) forwards;
}
@keyframes burstRing {
  0%   { transform: scale(0.4); opacity: 1; }
  70%  { opacity: 0.9; }
  100% { transform: scale(9); opacity: 0; }
}
.arcane-burst i {
  position: absolute; left: -3px; top: -3px; width: 7px; height: 7px;
  border-radius: 2px; background: #e8ccff; box-shadow: 0 0 10px #9a5fe8;
  animation: burstSpark 0.85s ease-out forwards;
  transform: rotate(var(--ang)) translateX(0);
}
@keyframes burstSpark {
  0%   { transform: rotate(var(--ang)) translateX(6px) scale(1.4); opacity: 1; }
  100% { transform: rotate(var(--ang)) translateX(74px) scale(0.4); opacity: 0; }
}

/* ---------------------------------------------------------- prompt & keys */
.prompt-zone {
  background: rgba(10,8,18,0.92); border-top: 2px solid var(--stone-600);
  padding: 14px 14px calc(14px + var(--safe-bottom));
  position: relative; z-index: 20;
}
.prompt-head { display: flex; align-items: center; justify-content: center;
  gap: 12px; margin-bottom: 12px; }
.prompt-word {
  font-size: clamp(34px, 9vw, 62px); font-weight: 700; letter-spacing: 0.03em;
  text-align: center; line-height: 1.05;
}
.prompt-label { text-align: center; color: var(--ink-dim); font-size: 14px;
  letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 6px; }

/* per-turn timer ring */
.turn-timer { width: 54px; height: 54px; flex: 0 0 auto; position: relative; }
.turn-timer svg { transform: rotate(-90deg); }
.turn-timer .track { stroke: #2a243d; }
.turn-timer .fill  { stroke: var(--gold); transition: stroke-dashoffset 0.2s linear, stroke 0.3s; }
.turn-timer.warn .fill { stroke: #ff9a5a; }
.turn-timer.crit .fill { stroke: #ff5a5a; }
.turn-timer .num {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-pixel); font-size: 17px; font-weight: 700;
}

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px) { .choices.four { grid-template-columns: repeat(4, 1fr); } }
.choice {
  min-height: 74px; padding: 14px 10px;
  font-size: clamp(22px, 5vw, 32px); font-weight: 700;
  border-radius: 14px; border: 3px solid #5c5080;
  background: linear-gradient(180deg, #4a4066, #322a4a);
  box-shadow: 0 5px 0 #1a1530;
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s, border-color 0.2s;
  word-break: break-word;
}
.choice:active { transform: translateY(4px); box-shadow: 0 1px 0 #1a1530; }
.choice.correct {
  background: linear-gradient(180deg, #5fd08a, #2f8f4f);
  border-color: #9fffc0; box-shadow: 0 5px 0 #1a5a30;
  animation: pop 0.35s;
}
.choice.wrong {
  background: linear-gradient(180deg, #d05a5a, #8a2a2a);
  border-color: #ff9a9a; box-shadow: 0 5px 0 #5a1515;
}
.choice.locked { pointer-events: none; }
.choice.dim { opacity: 0.4; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.09); } 100% { transform: scale(1); } }

/* --------------------------------------------------------- bonus round */
.bank { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 60px; }
.tile {
  padding: 13px 18px; font-size: clamp(19px, 4.4vw, 26px); font-weight: 700;
  border-radius: 12px; border: 3px solid #5c5080;
  background: linear-gradient(180deg, #4a4066, #322a4a); box-shadow: 0 4px 0 #1a1530;
  transition: transform 0.1s, opacity 0.15s;
}
.tile:active { transform: translateY(3px); }
.tile.used { opacity: 0.22; pointer-events: none; }
.answer-line {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  min-height: 68px; padding: 12px;
  border: 3px dashed var(--stone-600); border-radius: 14px;
  background: rgba(0,0,0,0.25); margin-bottom: 16px;
}
.answer-line.ok { border-color: var(--heal); border-style: solid; }
.answer-line.no { border-color: var(--blood); border-style: solid; }
.answer-line:empty::before {
  content: 'Tap the words to build the sentence';
  color: var(--ink-dim); font-size: 15px; align-self: center; margin: auto;
}

/* -------------------------------------------------------------- loot box */
.loot-stage { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.crate-wrap { position: relative; width: 190px; height: 190px; display: grid; place-items: center; }
#crate-canvas { width: 160px; height: 160px; }
.crate-wrap.shaking canvas { animation: crateShake 0.42s infinite; }
@keyframes crateShake {
  0%,100% { transform: rotate(0) translateY(0); }
  25% { transform: rotate(-7deg) translateY(-3px); }
  75% { transform: rotate(7deg) translateY(-3px); }
}
.crate-wrap.burst::before {
  content: ''; position: absolute; inset: -40px; border-radius: 50%;
  background: radial-gradient(circle, var(--burst, #ffd977) 0%, transparent 68%);
  animation: burst 0.65s ease-out forwards;
}
@keyframes burst {
  0% { transform: scale(0.2); opacity: 0.95; }
  100% { transform: scale(1.5); opacity: 0; }
}
.spark {
  position: absolute; width: 8px; height: 8px; border-radius: 2px; pointer-events: none;
  animation: sparkFly 0.9s ease-out forwards;
}
@keyframes sparkFly {
  0% { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

.drop-card {
  display: flex; align-items: center; gap: 14px; width: 100%; max-width: 420px;
  padding: 14px 16px; border-radius: 12px; background: var(--stone-800);
  border: 2px solid var(--rc, var(--r-common));
  box-shadow: 0 0 22px -6px var(--rc, transparent);
  animation: dropIn 0.4s cubic-bezier(0.22,1,0.36,1);
}
@keyframes dropIn { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: none; } }
.drop-card .icon { font-size: 34px; width: 44px; text-align: center; }
.drop-card .nm { font-size: 19px; font-weight: 700; }
.drop-card .rar { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--rc); }
.drop-card .stats { font-size: 13px; color: var(--ink-dim); font-family: var(--font-pixel); }

/* ------------------------------------------------------------- inventory */
.slot-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.slot-tab {
  padding: 11px 18px; border-radius: 999px; font-size: 15px; font-weight: 700;
  background: var(--stone-800); border: 2px solid var(--stone-600);
}
.slot-tab.on { background: var(--gold); color: #2b1d05; border-color: var(--gold-bright); }

.gear-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.gear-card {
  padding: 12px; border-radius: 12px; text-align: left;
  background: var(--stone-800); border: 2px solid var(--rc, var(--stone-600));
  position: relative; transition: transform 0.08s;
}
.gear-card:active { transform: translateY(3px); }
.gear-card.locked { opacity: 0.34; filter: grayscale(1); }
.gear-card.equipped { box-shadow: 0 0 0 3px var(--gold-bright), 0 0 22px -4px var(--gold); }
.gear-card .nm { font-size: 15px; font-weight: 700; line-height: 1.25; }
.gear-card .rar { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rc); margin-top: 3px; }
.gear-card .stats { margin-top: 8px; font-family: var(--font-pixel); font-size: 12px; color: var(--ink-dim); }
.gear-card .badge {
  position: absolute; top: 8px; right: 8px; font-size: 10px; padding: 3px 7px;
  border-radius: 999px; background: var(--gold); color: #2b1d05; font-weight: 700;
}

/* ------------------------------------------------------- bazaar village */
.small-note { font-size: 13px; }

/* Customizer cards in the Armoury — same canvas thumbnails as the shop. */
.style-card { border-color: var(--stone-600); text-align: center; }
.style-card .item-art {
  width: 56px; height: 56px; margin: 0 auto 6px; display: block;
  image-rendering: pixelated; background: rgba(0,0,0,0.28); border-radius: 10px;
}
.style-card.owned, .style-card.equipped { border-color: var(--heal); }

/* --------------------------------------------------- the marketplace scene
   Hot-zones are positioned as percentages of the artwork, so they stay glued
   to the painted shopfronts at any width. */
.market-scene {
  position: relative; width: 100%; margin: 0 auto;
  border-radius: 14px; overflow: hidden;
  border: 3px solid var(--stone-600);
  box-shadow: 0 8px 0 rgba(0,0,0,0.4), inset 0 0 60px rgba(0,0,0,0.35);
  line-height: 0;
}
.market-bg { width: 100%; height: auto; display: block; image-rendering: pixelated; }
.market-nodes { position: absolute; inset: 0; }

.market-node {
  position: absolute; padding: 0; border-radius: 10px; line-height: 1;
  background: transparent; border: 2.5px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  transition: background 0.18s, border-color 0.18s, transform 0.08s;
}
/* A permanent, gentle marker: a child must be able to see where to tap
   without hovering, which does not exist on a touch screen.
   It sits at the FOOT of the zone — over the doorway — because the top of
   each zone is the shop's painted sign, and covering the artwork's own
   lettering would be vandalising the thing we are pointing at. */
.market-node .node-pin {
  position: absolute; bottom: 6px;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 17px;
  background: rgba(20,16,32,0.82); border: 2px solid var(--gold);
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
  animation: nodeBob 2.6s ease-in-out infinite;
}
@keyframes nodeBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}
.market-node .node-label {
  position: absolute; bottom: 48px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(12,10,22,0.85); color: var(--gold-bright);
  border: 1px solid rgba(216,176,74,0.5);
  opacity: 0; transition: opacity 0.18s;
}
.market-node:hover, .market-node:focus-visible {
  background: rgba(216,176,74,0.16); border-color: var(--gold-bright); outline: none;
}
.market-node:hover .node-label, .market-node:focus-visible .node-label { opacity: 1; }
.market-node:active { transform: scale(0.97); background: rgba(216,176,74,0.28); }

/* Small screens shrink the scene until the zones are fiddly, so the chip row
   below is the reliable way in — and it names the shops in plain words. */
.market-quick {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; justify-content: center;
}
.market-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 14px; min-height: 46px; border-radius: 999px;
  background: linear-gradient(180deg, #3a3252, #2a243d);
  border: 2px solid var(--stone-600); box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  font-size: 14px; font-weight: 700;
}
.market-chip:active { transform: translateY(3px); box-shadow: none; }
.market-chip .c-icon { font-size: 19px; }

/* Sale banners on the market square */
#market-sales { display: grid; gap: 8px; margin-bottom: 12px; }
.sale-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px; font-size: 14px; font-weight: 700;
  background: linear-gradient(90deg, rgba(224,85,42,0.28), rgba(216,176,74,0.14));
  border: 2px solid #e0552a; color: #ffd6a8;
}
.sale-banner .tag {
  font-family: var(--font-pixel); font-size: 10px; letter-spacing: 0.14em;
  padding: 3px 8px; border-radius: 999px; background: #e0552a; color: #2b1005;
}

/* Discounted prices: show what it was next to what it is. */
.price-row { display: flex; align-items: baseline; gap: 6px; justify-content: center; }
.price-was {
  font-family: var(--font-pixel); font-size: 12px; color: var(--ink-dim);
  text-decoration: line-through;
}
.sale-flag {
  position: absolute; top: 6px; left: 6px; font-size: 9px; font-weight: 700;
  padding: 3px 6px; border-radius: 999px; background: #e0552a; color: #2b1005;
}

.shopfront-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.shopfront-head h3 { font-size: 22px; }

/* -------------------------------------------------------- shop item cards */
.shop-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.shop-item {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 12px 10px 14px; text-align: center;
  border-radius: 12px; background: var(--stone-800);
  border: 2px solid var(--rc, var(--stone-600));
  transition: transform 0.08s;
}
.shop-item:active { transform: translateY(3px); }
.shop-item.owned { border-color: var(--heal); }
.shop-item.cant-afford { opacity: 0.68; }
.shop-item .item-art {
  width: 56px; height: 56px; margin-bottom: 2px;
  image-rendering: pixelated;
  background: rgba(0,0,0,0.28); border-radius: 10px;
}
.shop-item .item-art.small { width: 44px; height: 44px; margin: 0; }
.shop-item .nm { font-size: 14px; font-weight: 700; line-height: 1.25; }
.shop-item .rar {
  font-family: var(--font-pixel); font-size: 10.5px; color: var(--ink-dim);
  line-height: 1.3;
}
.shop-item .stats { font-size: 12px; color: var(--heal); }
.shop-item .price { font-size: 15px; font-weight: 700; font-family: var(--font-pixel); }
.shop-item .price-ok { color: var(--gold-bright); }
.shop-item .price-no { color: var(--blood); }
.shop-item .badge {
  position: absolute; top: 6px; right: 6px; font-size: 9px; padding: 3px 7px;
  border-radius: 999px; background: var(--gold); color: #2b1d05; font-weight: 700;
}

.forge-list { display: grid; gap: 10px; }
.forge-row .item-art {
  width: 44px; height: 44px; flex: 0 0 auto;
  image-rendering: pixelated; background: rgba(0,0,0,0.28); border-radius: 8px;
}

.forge-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; background: var(--stone-800);
  border: 2px solid var(--rc, var(--stone-600));
}
.forge-row .icon { font-size: 28px; width: 36px; text-align: center; }
.forge-row .nm { font-size: 16px; font-weight: 700; }
.forge-row .stats { font-family: var(--font-pixel); font-size: 12px; color: var(--ink-dim); }
.forge-row .badge {
  font-size: 10px; padding: 4px 8px; border-radius: 999px;
  background: var(--gold); color: #2b1d05; font-weight: 700;
}

/* --------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(8,6,14,0.86); backdrop-filter: blur(4px);
}
.overlay.active { display: flex; animation: fade-in 0.25s; }
/* `--modal-max` lets a wide dialog (the item forge) opt out of the default
   560px without fighting this rule's specificity. */
.overlay .panel { width: 100%; max-width: var(--modal-max, 560px); max-height: 88dvh; overflow-y: auto;
  -webkit-overflow-scrolling: touch; }

/* Toasts sit at the bottom, where screens generally have slack. During a
   battle the bottom is the answer buttons, so `.toast.high` lifts it just
   under the HUD instead — it must never cover a tap target. */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 200; padding: 13px 20px; border-radius: 999px; font-weight: 700;
  background: var(--stone-700); border: 2px solid var(--gold);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5); pointer-events: none;
  animation: toastIn 0.3s, toastOut 0.3s 2.2s forwards;
  max-width: 90vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, 20px); } }

.toast.high {
  bottom: auto; top: calc(74px + var(--safe-top));
  animation: toastInHigh 0.3s, toastOutHigh 0.3s 2.2s forwards;
}
@keyframes toastInHigh { from { opacity: 0; transform: translate(-50%, -20px); } }
@keyframes toastOutHigh { to { opacity: 0; transform: translate(-50%, -20px); } }

.muted { color: var(--ink-dim); }
.center { text-align: center; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------- neural voice panel */

.voice-panel { margin-bottom: 18px; display: grid; gap: 12px; }

.voice-status {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 10px; font-size: 14px;
  border: 1px solid var(--edge); background: rgba(0, 0, 0, 0.22);
}
.voice-status .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  background: var(--muted);
}
.voice-status.on { border-color: rgba(96, 200, 120, 0.45); }
.voice-status.on .dot { background: #5fd07a; box-shadow: 0 0 8px #5fd07a; }
.voice-status.off { border-color: rgba(214, 160, 60, 0.45); }
.voice-status.off .dot { background: var(--gold); }

.voice-cache {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 4px 12px; padding: 12px 14px;
  border: 1px solid var(--edge); border-radius: 10px;
  background: rgba(0, 0, 0, 0.16);
}
.voice-cache .k { font-weight: 700; font-size: 14px; }
.voice-cache .sub { grid-column: 1; font-size: 12px; color: var(--muted); }
.voice-cache .btn { grid-column: 2; grid-row: 1 / span 2; }

.voice-tests {
  padding: 12px 14px; border: 1px solid var(--edge);
  border-radius: 10px; background: rgba(0, 0, 0, 0.16);
}
.voice-tests .cfg-group-blurb { margin: 0 0 8px; }
.voice-test-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 9px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.voice-test-row .lbl { font-weight: 600; font-size: 14px; }
/* Voice IDs are opaque 20-char strings — small, dim, and allowed to wrap. */
.voice-test-row .desc {
  font-size: 11px; color: var(--muted); font-family: var(--mono, monospace);
  word-break: break-all;
}
.voice-test-row .btn { flex: 0 0 auto; }

/* The middle state — a key is installed but ElevenLabs refuses it — is the
   one worth shouting about, because everything still "works", just silently. */
.voice-status.bad { border-color: rgba(190, 60, 60, 0.55); background: rgba(120, 30, 30, 0.18); }
.voice-status.bad .dot { background: var(--blood, #c0392b); box-shadow: 0 0 8px rgba(200, 60, 60, 0.7); }
.voice-status.wait .dot { background: var(--muted); animation: voice-pulse 1.1s ease-in-out infinite; }
@keyframes voice-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* Voice pickers: a menu of real voice names beats a 20-character opaque ID. */
.voice-pick select { width: 100%; padding: 10px 8px; font-size: 14px; }
.voice-pick select option:disabled { opacity: 0.45; }
.voice-pick-note {
  margin-top: 5px; font-size: 11px; color: var(--muted); text-transform: capitalize;
}
.voice-pick-warn { margin-top: 5px; font-size: 11px; color: var(--gold); }
/* A resolved voice name is prose, not an identifier, so drop the mono face. */
.voice-test-row .desc.named { font-family: inherit; font-size: 12px; word-break: normal; }

/* Dropdown settings (progression ruleset, etc.) */
.enum-pick select { width: 100%; padding: 10px 8px; font-size: 14px; }
.enum-note {
  margin-top: 6px; font-size: 11px; line-height: 1.45; color: var(--muted);
}

/* ==================================================== Reading Trial */

.trial-call {
  margin: 14px 0; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--gold); background: rgba(120, 90, 20, 0.18);
  text-align: center;
}
.trial-call-title { font-weight: 800; color: var(--gold-bright); margin-bottom: 4px; }
.trial-call-sub { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.trial-scroll { text-align: center; margin: 10px 0 4px; }
.trial-title { font-size: 20px; font-weight: 800; color: var(--gold-bright); }
.trial-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* The card is the whole exercise, so it gets the room. */
.trial-card {
  margin: 18px auto; padding: 38px 20px; max-width: 520px;
  border-radius: 16px; border: 2px solid var(--edge);
  background: rgba(0, 0, 0, 0.3);
  display: flex; align-items: center; justify-content: center;
  min-height: 180px;
  transition: border-color 0.25s, background 0.25s;
}
.trial-card.right { border-color: #5fd07a; background: rgba(40, 110, 60, 0.18); }
.trial-card.wrong { border-color: var(--blood); background: rgba(120, 30, 30, 0.18); }
.trial-word {
  font-size: clamp(44px, 12vw, 84px); font-weight: 800; letter-spacing: 0.02em;
  color: var(--parchment, #f3e7c8); text-align: center; word-break: break-word;
}

.trial-verdict {
  text-align: center; font-size: 15px; font-weight: 700; min-height: 22px;
}
.trial-verdict.good { color: #7fe09a; }
.trial-verdict.bad { color: #ffb0a0; }

.trial-actions { display: grid; justify-items: center; gap: 8px; margin-top: 14px; }
.trial-hint { font-size: 13px; color: var(--muted); }

.trial-pips { display: flex; gap: 6px; justify-content: center; margin-top: 18px; }
.trial-pip {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.trial-pip.hit { background: #5fd07a; }
.trial-pip.miss { background: var(--blood); }
.trial-pip.now { box-shadow: 0 0 0 3px rgba(214, 178, 74, 0.35); background: var(--gold); }

/* --- result --- */
.trial-result-wrap { text-align: center; max-width: 520px; margin: 0 auto; padding: 20px 8px; }
.trial-result-title { font-size: 26px; font-weight: 800; color: var(--gold-bright); }
.trial-stars { font-size: 46px; letter-spacing: 6px; margin: 10px 0; color: #6b6350; }
.trial-stars.s1, .trial-stars.s2, .trial-stars.s3 { color: var(--gold-bright); }
.trial-result-line { font-size: 15px; color: var(--muted); margin-bottom: 16px; }

.trial-scorecard {
  border: 1px solid var(--edge); border-radius: 12px;
  background: rgba(0, 0, 0, 0.2); padding: 6px 14px; text-align: left;
}
.trial-stat {
  display: flex; justify-content: space-between; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-size: 14px;
}
.trial-stat:last-child { border-bottom: 0; }
.trial-stat .k { color: var(--muted); }
.trial-stat .v { font-weight: 700; color: var(--gold-bright); }

.trial-bounty {
  margin-top: 14px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--gold); background: rgba(120, 90, 20, 0.2);
  font-weight: 700;
}
.trial-missed { margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ============================================ new-word orientation */

.teach-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 6px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--gold); background: rgba(120, 90, 20, 0.22);
  width: fit-content; margin-inline: auto;
}
.teach-label { font-size: 11px; letter-spacing: 0.08em; font-weight: 800; color: var(--gold-bright); }
.teach-pips { display: flex; gap: 4px; }
.teach-pips .teach-pip {
  width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.18);
}
.teach-pips .teach-pip.done { background: var(--gold-bright); }
.teach-pips .teach-pip.now { background: var(--gold); box-shadow: 0 0 0 2px rgba(214, 178, 74, 0.35); }

/* A word being introduced is bigger than one being tested — it is the lesson,
   not the question. */
#prompt-word.teaching-word { font-size: clamp(46px, 13vw, 90px); }

/* The clock is held, not stopped, while the orb listens. */
.turn-timer.held { opacity: 0.55; }
.turn-timer.held .fill { stroke: var(--muted); }

/* ==================================================== mastery burst */

.mastery-burst {
  position: absolute; inset: 0; display: grid; place-content: center;
  justify-items: center; gap: 2px; pointer-events: none; z-index: 40;
  animation: mb-in 0.35s ease-out, mb-out 0.45s ease-in 1.75s forwards;
}
.mastery-burst .mb-star { font-size: 54px; animation: mb-pop 0.5s ease-out; }
.mastery-burst .mb-word {
  font-size: clamp(34px, 9vw, 62px); font-weight: 800; color: var(--gold-bright);
  text-shadow: 0 0 24px rgba(214, 178, 74, 0.65);
}
.mastery-burst .mb-label {
  font-size: 13px; letter-spacing: 0.28em; font-weight: 800; color: var(--parchment, #f3e7c8);
}
.mastery-burst .mb-sparks { position: absolute; inset: 0; display: grid; place-content: center; }
.mastery-burst .mb-sparks i {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold-bright);
  transform: rotate(var(--a)) translateY(0);
  animation: mb-spark 0.9s ease-out forwards;
}
@keyframes mb-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: none; } }
@keyframes mb-out { to { opacity: 0; transform: scale(1.08); } }
@keyframes mb-pop { 0% { transform: scale(0.3) rotate(-25deg); } 70% { transform: scale(1.25); } 100% { transform: none; } }
@keyframes mb-spark {
  from { transform: rotate(var(--a)) translateY(0); opacity: 1; }
  to   { transform: rotate(var(--a)) translateY(-120px); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .mastery-burst, .mastery-burst * { animation-duration: 0.01ms !important; }
  .mastery-burst { animation: mb-out 0.3s ease-in 1.8s forwards; }
}

/* ==================================================== the Guild Hall */

#scene-layer.guild {
  background-image:
    linear-gradient(180deg, rgba(12,10,22,0.82) 0%, rgba(12,10,22,0.52) 35%,
                            rgba(12,10,22,0.72) 72%, rgba(12,10,22,0.94) 100%),
    url('/scenes/guild_hall.jpg');
}

/* Knights are scattered across three depth lanes rather than lined up, so the
   hall reads as a room with people in it and not as a list. */
/* The backdrop's stone floor sits low in the frame, so the knights are pushed
   down to stand on it rather than hovering over the quest board. */
.guild-floor {
  position: relative; display: flex; flex-wrap: wrap;
  gap: 6px 10px; justify-content: center; align-items: flex-end;
  min-height: 58vh; margin-top: 8px; padding: 0 0 18px;
}
.guild-knight {
  position: relative; background: none; border: 0; padding: 0 4px;
  display: grid; justify-items: center; gap: 1px; cursor: pointer;
  width: clamp(132px, 30vw, 210px);
  /* Lane pushes them up and shrinks them slightly, faking depth. */
  transform: translateY(calc(var(--lane) * -10px)) scale(calc(1 - var(--lane) * 0.06));
  animation: guild-mill var(--drift, 6s) ease-in-out var(--delay, 0s) infinite;
  transition: filter 0.15s;
}
.guild-knight:hover, .guild-knight:focus-visible { filter: brightness(1.18); outline: none; }
.guild-knight:active { transform: translateY(calc(var(--lane) * -10px)) scale(0.94); }
.guild-knight canvas { width: 100%; image-rendering: pixelated; }
.guild-knight .gk-name {
  font-size: 14px; font-weight: 700; color: var(--parchment, #f3e7c8);
  text-shadow: 0 2px 6px #000; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.guild-knight .gk-lvl { font-size: 11px; color: var(--gold-bright); text-shadow: 0 2px 6px #000; }

/* A slow wander, so the hall is alive without anybody marching. */
@keyframes guild-mill {
  0%, 100% { margin-left: 0; }
  50%      { margin-left: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .guild-knight { animation: none; }
}

.guild-panel { max-width: 420px; }
.guild-hero { margin: 0; }
.guild-gear { margin-top: 12px; display: grid; gap: 6px; text-align: center; }
.guild-gear .gg-line { font-size: 13px; color: var(--muted); }
.guild-gear .gg-gear {
  font-size: 13px; color: var(--gold-bright); line-height: 1.7;
  border-top: 1px solid var(--edge); padding-top: 10px; margin-top: 4px;
}

/* ==================================================== the quest road */

.quest-road { padding: 6px 14px 2px; }
.qr-track {
  position: relative; height: 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.42); border: 1px solid var(--edge);
}
.qr-fill {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width 0.5s ease-out;
}
.qr-knight {
  position: absolute; top: 50%; font-size: 17px; line-height: 1;
  transform: translate(-50%, -55%);
  transition: left 0.5s ease-out;
  filter: drop-shadow(0 2px 3px #000);
}
.qr-goal { position: absolute; right: -4px; top: 50%; transform: translateY(-52%); font-size: 15px; }
.qr-label {
  margin-top: 5px; text-align: center; font-size: 11px;
  letter-spacing: 0.04em; color: var(--muted);
}

/* ------------------------------------------- the Guild Hall speech bubble */

/* Anchored to the knight who opened it rather than floating over the room, so
   it reads as that knight showing off rather than as a dialog. */
.guild-bubble {
  position: absolute; z-index: 20;
  padding: 14px 14px 16px;
  border-radius: 16px; border: 2px solid var(--gold);
  background: linear-gradient(180deg, rgba(30, 24, 46, 0.98), rgba(18, 14, 30, 0.99));
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.66), 0 0 0 1px rgba(0, 0, 0, 0.5);
  transform-origin: var(--ox, 0%) var(--oy, 30%);
  animation: gb-pop 0.26s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.guild-bubble[hidden] { display: none; }
.guild-bubble.from-left  { --ox: 0%;   }
.guild-bubble.from-right { --ox: 100%; }
.guild-bubble.below      { --ox: 50%; --oy: 0%; }

@keyframes gb-pop {
  from { opacity: 0; transform: scale(0.72) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .guild-bubble { animation: none; }
}

/* The tail: a small rotated square poking out toward the knight. */
.gb-tail {
  position: absolute; width: 16px; height: 16px;
  background: rgba(30, 24, 46, 0.98);
  border-left: 2px solid var(--gold); border-bottom: 2px solid var(--gold);
}
.from-left  .gb-tail { left: -9px;  transform: rotate(45deg); }
.from-right .gb-tail { right: -9px; transform: rotate(-135deg); }
.below      .gb-tail { top: -9px; left: 50%; transform: rotate(135deg); }

.gb-x {
  position: absolute; top: 6px; right: 8px; z-index: 2;
  background: none; border: 0; color: var(--muted);
  font-size: 17px; line-height: 1; padding: 4px 6px; cursor: pointer;
}
.gb-x:hover { color: var(--gold-bright); }

/* The knight doing the talking gets lifted out of the crowd. */
.guild-knight.speaking {
  filter: brightness(1.3) drop-shadow(0 0 12px rgba(214, 178, 74, 0.55));
  animation: none;
  z-index: 5;
}

/* ==================================================== the Word Tutor */

.tutor-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(40, 30, 70, 0.86), rgba(8, 6, 16, 0.96));
  animation: fade-in 0.3s ease-out;
  padding: 16px;
}
.tutor-overlay[hidden] { display: none; }

.tutor-stage {
  display: grid; gap: 6px; justify-items: center;
  max-width: 560px; width: 100%;
}
.tutor-sprite { width: 150px; image-rendering: pixelated; filter: drop-shadow(0 8px 18px #000); }

.tutor-scroll {
  width: 100%; display: grid; gap: 12px; justify-items: center;
  padding: 18px 16px 20px; border-radius: 16px;
  border: 2px solid var(--gold);
  background: linear-gradient(180deg, rgba(34, 27, 52, 0.97), rgba(20, 15, 34, 0.99));
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.tutor-says {
  font-size: 15px; text-align: center; color: var(--parchment, #f3e7c8);
  min-height: 22px; font-style: italic;
}

/* The word being spelled out, one glowing letter at a time. */
.tutor-letters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tutor-letter {
  font-size: clamp(34px, 10vw, 58px); font-weight: 800; line-height: 1;
  color: rgba(255, 255, 255, 0.14);
  transition: color 0.18s, text-shadow 0.18s, transform 0.18s;
}
.tutor-letter.shown { color: var(--parchment, #f3e7c8); }
.tutor-letter.lit {
  color: var(--gold-bright);
  text-shadow: 0 0 22px rgba(214, 178, 74, 0.85);
  transform: translateY(-6px) scale(1.14);
}

.tutor-word {
  font-size: clamp(38px, 11vw, 70px); font-weight: 800; letter-spacing: 0.02em;
  color: var(--gold-bright); text-shadow: 0 0 26px rgba(214, 178, 74, 0.6);
}
.tutor-word.flash { animation: tutor-flash 0.4s ease-out; }
@keyframes tutor-flash {
  0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); }
}

.tutor-reps { display: grid; gap: 8px; justify-items: center; }
.tutor-rep-label { font-size: 13px; letter-spacing: 0.06em; color: var(--muted); }
.tutor-pips { display: flex; gap: 7px; }
.tutor-pips .tutor-pip {
  width: 11px; height: 11px; border-radius: 50%; background: rgba(255, 255, 255, 0.16);
}
.tutor-pips .tutor-pip.done { background: var(--gold-bright); box-shadow: 0 0 8px rgba(214,178,74,0.6); }
.tutor-pips .tutor-pip.now { background: var(--gold); box-shadow: 0 0 0 3px rgba(214, 178, 74, 0.3); }
.tutor-hint { font-size: 13px; color: var(--muted); text-align: center; min-height: 18px; }

@media (prefers-reduced-motion: reduce) {
  .tutor-overlay, .tutor-word.flash { animation: none; }
  .tutor-letter { transition: none; }
}

/* ------------------------------------- Sentence Builder, spell-cast feel */

/* Word tiles read as runes being placed into an incantation. */
.bank button, .answer-line span {
  transition: transform 0.12s, box-shadow 0.18s, border-color 0.18s;
}
.bank button:active { transform: scale(0.93); }
.answer-line span {
  border-color: rgba(214, 178, 74, 0.5);
  box-shadow: 0 0 12px rgba(214, 178, 74, 0.18) inset;
  animation: rune-place 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes rune-place {
  from { transform: translateY(-10px) scale(0.8); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.answer-line.ok span {
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(214, 178, 74, 0.55);
  animation: rune-fire 0.6s ease-out;
}
@keyframes rune-fire {
  0% { box-shadow: 0 0 0 rgba(214, 178, 74, 0); }
  40% { box-shadow: 0 0 30px rgba(255, 225, 150, 0.9); }
  100% { box-shadow: 0 0 18px rgba(214, 178, 74, 0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .answer-line span, .answer-line.ok span { animation: none; }
}
