:root {
  --ink: #2b2350;
  --sun: #ffd23f;
  --card: #ffffff;
  --radius: 22px;
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  color: var(--ink);
}

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

html, body { margin: 0; min-height: 100%; }
/* Phones: no text blow-up when turned sideways, no grey flash on tap, and no zoom on a quick double tap. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
a, button, label, input, select, textarea { touch-action: manipulation; }

body {
  min-height: 100vh;
  background: linear-gradient(#7fd4ff 0%, #c9efff 55%, #eafaff 100%);
  overflow-x: hidden;
}

/* ---------- Sky ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud {
  position: absolute;
  width: 160px; height: 50px;
  background: #fff;
  border-radius: 50px;
  opacity: .9;
  animation: drift 70s linear infinite;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 70px; height: 70px; left: 22px; top: -34px; }
.cloud::after { width: 56px; height: 56px; left: 78px; top: -24px; }
.c1 { top: 9%; left: -200px; }
.c2 { top: 24%; left: -200px; animation-duration: 95s; animation-delay: -40s; transform: scale(.7); }
.c3 { top: 5%; left: -200px; animation-duration: 120s; animation-delay: -80s; transform: scale(1.2); }
@keyframes drift { to { left: 110%; } }

/* ---------- Layout ---------- */
#app {
  position: relative;
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}
.screen { animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Title ---------- */
.logo {
  margin: 12px 0 26px;
  text-align: center;
  font-size: clamp(52px, 9vw, 92px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink), 0 4px 0 var(--ink), 0 6px 0 var(--ink), 0 8px 0 var(--ink),
    0 10px 0 #1c1638, 0 18px 22px rgba(43, 35, 80, .35);
  transform: perspective(600px) rotateX(14deg);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
}
.logo .war { color: var(--sun); }
.tagline { text-align: center; font-size: 20px; font-weight: 700; margin: 0 0 26px; }

.setup-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
}
.player-card {
  margin: 0;
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  padding: 14px 20px 20px;
  box-shadow: 0 7px 0 var(--ink);
  min-width: 0;
}
.player-card legend {
  padding: 4px 16px;
  border-radius: 999px;
  color: var(--on-main, #fff);
  background: var(--main);
  font-weight: 900;
  font-size: 18px;
  border: 3px solid var(--ink);
}

.field-label { display: block; font-weight: 800; font-size: 15px; margin: 12px 0 6px; }

.name-input, .answer {
  width: 100%;
  font: inherit;
  font-weight: 800;
  font-size: 22px;
  color: var(--ink);
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  outline: none;
}
.name-input:focus, .answer:focus { box-shadow: 0 0 0 5px var(--sun); }

.colour-msg { margin: 6px 0 0; font-size: 14px; font-weight: 800; color: #6b6690; min-height: 20px; }
.colour-msg.good { color: #2b9a3f; }
.colour-msg.bad { color: #c92a2a; }

.hero-pick { margin-top: 4px; }
.hero-stand { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 10px; }
.kind-name { font-size: 22px; font-weight: 900; }
.hero-preview { width: 104px; height: 113px; animation: bob 1.6s ease-in-out infinite; }
.hero-preview svg, .kinds svg, .hero svg, .hero-inline svg, .mascot svg, .win-mascot svg { width: 100%; height: 100%; display: block; overflow: visible; }
.kinds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.kinds label { cursor: pointer; min-width: 0; }
.kinds input { position: absolute; opacity: 0; pointer-events: none; }
.kinds span {
  display: block;
  aspect-ratio: 1 / 1.08;
  padding: 4px;
  border: 3px solid #d9d5ee;
  border-radius: 14px;
  background: #f6f4ff;
  transition: transform .12s;
}
@media (hover: hover) { .kinds label:hover span { transform: scale(1.08); } }
.kinds input:checked + span { border-color: var(--ink); background: var(--sun); transform: scale(1.08); }
.kinds input:focus-visible + span { box-shadow: 0 0 0 4px var(--ink); }
.name-input.wobble { animation: wobble .4s; }

.vs, .middle {
  font-weight: 900;
  font-size: 34px;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
}

.name-row { display: grid; grid-template-columns: 1fr 96px; gap: 12px; }
.age-input { text-align: center; padding-left: 6px; padding-right: 6px; }
.age-input::-webkit-inner-spin-button, .age-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.age-input { -moz-appearance: textfield; appearance: textfield; }
.name-input::placeholder { color: #b9b5d3; }
.age-hint { text-align: center; font-size: 17px; font-weight: 800; margin: 22px 0 0; }

#setup > .btn { display: block; margin: 18px auto 0; }

.how {
  margin: 30px auto 0;
  padding: 0;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  list-style: none;
  counter-reset: how;
}
.how li {
  counter-increment: how;
  background: rgba(255, 255, 255, .75);
  border-radius: 16px;
  padding: 14px 16px 14px 52px;
  position: relative;
  font-size: 15px;
  line-height: 1.35;
}
.how li::before {
  content: counter(how);
  position: absolute; left: 12px; top: 12px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  border-radius: 50%;
  font-weight: 900;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 900;
  font-size: 18px;
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px 20px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
@media (hover: hover) { .btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); } }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 4px solid #fff; outline-offset: 2px; }
.btn.big { font-size: 24px; padding: 14px 30px; }
.btn.ghost { background-color: #fff; }

/* ---------- Battlefield ---------- */
.field {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 10px;
  padding-top: 70px;
}
.middle { align-self: center; padding-bottom: 20px; }

.side { display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform .25s, opacity .25s; }
.side:not(.active) .nameplate, .side:not(.active) .hp { opacity: .75; }
.side.active { transform: scale(1.04); }

.nameplate {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 18px 6px 10px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  color: var(--on-main);
  background: linear-gradient(rgba(255, 255, 255, .3), rgba(255, 255, 255, 0) 55%, rgba(0, 0, 0, .12)), var(--main);
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 4px 0 var(--ink);
}
.nameplate .mascot { width: 34px; height: 37px; }
.side.active .nameplate { animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }

.hp { display: flex; align-items: center; gap: 8px; width: min(240px, 100%); }
.hp-bar {
  flex: 1;
  height: 20px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(#7be36a, #37b24d);
  transition: width .5s cubic-bezier(.3, 1.4, .5, 1), background .3s;
}
.hp-fill.mid { background: linear-gradient(#ffd96a, #f5a524); }
.hp-fill.low { background: linear-gradient(#ff8f8f, #e03131); }
.hp-text { font-weight: 900; font-size: 16px; white-space: nowrap; min-width: 62px; }

.castle-wrap { position: relative; width: 200px; height: 190px; }
.castle { width: 100%; height: 100%; transform-origin: 50% 100%; transition: transform .8s ease-in, opacity .8s; }
.castle svg { width: 100%; height: 100%; display: block; overflow: visible; }
.castle .crack { display: none; }
.castle[data-damage="1"] .crack.d1,
.castle[data-damage="2"] .crack.d1,
.castle[data-damage="2"] .crack.d2 { display: block; }
.castle[data-damage="3"] { transform: translateY(40px) rotate(-7deg) scaleY(.55); opacity: .55; }
.castle[data-damage="3"] .crack { display: block; }
.castle.shake { animation: shake .5s; }
@keyframes shake {
  10%, 50%, 90% { transform: translateX(-9px) rotate(-2deg); }
  30%, 70% { transform: translateX(9px) rotate(2deg); }
}

.boom {
  position: absolute; left: 50%; top: 40%;
  font-size: 110px; line-height: 1;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
}
.boom.pop { animation: pop .6s ease-out; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  60% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

#shot { position: absolute; left: 0; top: 0; font-size: 46px; line-height: 1; pointer-events: none; z-index: 5; }
#shot-inner { display: block; }

/* ---------- 3D scenery ---------- */
.field { padding-bottom: 44px; }
.side, .middle { position: relative; z-index: 1; }
.scenery { position: absolute; inset: 0; pointer-events: none; }
.hill {
  position: absolute; bottom: 78px;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  background: linear-gradient(#b5ecb0, #86d98c);
}
.hill.h1 { left: -8%; width: 52%; height: 120px; }
.hill.h2 { left: 28%; width: 46%; height: 84px; background: linear-gradient(#cdf3c9, #a2e3a5); }
.hill.h3 { right: -8%; width: 50%; height: 136px; }

/* The ground is a flat striped sheet tipped back, so it looks like it runs into the distance. */
.ground {
  position: absolute; left: -20px; right: -20px; bottom: 0;
  height: 96px;
  overflow: hidden;
  border-radius: 10px 10px 22px 22px;
  background: linear-gradient(#3f9c4c, #63c765 40%, #86de7c);
  box-shadow: 0 10px 0 #2f7d3b, 0 18px 18px rgba(43, 35, 80, .2);
  perspective: 260px;
}
.ground::before {
  content: "";
  position: absolute; left: -60%; right: -60%; bottom: 0;
  height: 340px;
  transform-origin: 50% 100%;
  transform: rotateX(72deg);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .16) 0 44px, transparent 44px 88px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .07) 0 44px, transparent 44px 88px);
}

.castle-wrap::before {
  content: "";
  position: absolute; left: -6%; right: -6%; bottom: -12px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(20, 50, 30, .45), rgba(20, 50, 30, 0));
}
.castle { position: relative; filter: drop-shadow(5px 3px 0 rgba(43, 35, 80, .18)); }

.hero {
  position: absolute; bottom: -30px;
  width: 92px; height: 100px;
  z-index: 2;
  transform-origin: 50% 100%;
  transition: transform .6s, filter .6s;
}
#side-0 .hero { right: -52px; }
#side-1 .hero { left: -52px; }
.side.active .hero { animation: hop .7s ease-in-out infinite; }
.side.lost .hero { transform: rotate(80deg) translateX(18px); filter: grayscale(.7); }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1.04, .96); }
  50% { transform: translateY(-14px) scale(.97, 1.04); }
}
.hero-inline { display: inline-block; width: 40px; height: 43px; vertical-align: -9px; }

#shot-shadow {
  position: absolute; left: 0; top: 0;
  width: 46px; height: 14px;
  border-radius: 50%;
  background: #123;
  pointer-events: none;
  z-index: 1;
}
#shot { filter: drop-shadow(0 6px 4px rgba(43, 35, 80, .35)); }

.sun {
  position: absolute; top: 34px; right: 9%;
  width: 96px; height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffbe0, #ffd23f 55%, #ffab1f);
  box-shadow: 0 0 0 14px rgba(255, 226, 120, .28), 0 0 0 32px rgba(255, 226, 120, .16), 0 0 70px 30px rgba(255, 220, 110, .5);
}
.cloud, .cloud::before, .cloud::after { background: linear-gradient(#fff 55%, #dcefff); }

/* ---------- Turn panel ---------- */
.panel {
  margin-top: 22px;
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 7px 0 var(--ink), 0 22px 30px rgba(43, 35, 80, .22);
  border-top: 14px solid var(--main);
  padding: 22px 26px 26px;
  text-align: center;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.panel h2 { margin: 0 0 6px; font-size: 28px; font-weight: 900; }
.panel p { margin: 0 0 16px; font-size: 18px; font-weight: 700; }
.panel .sub { color: #6b6690; }

.ammo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.ammo .btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; background-color: #f6f4ff; }
@media (hover: hover) { .ammo .btn:hover { background-color: var(--sun); } }
.ammo .icon { font-size: 44px; line-height: 1.1; }
.ammo .name { font-size: 20px; }
.ammo .blurb { font-size: 14px; font-weight: 700; color: #6b6690; }
.ammo .dmg { font-size: 15px; }
.ammo kbd {
  font: inherit; font-size: 12px; font-weight: 900;
  background: var(--ink); color: #fff;
  border-radius: 6px; padding: 1px 7px; margin-top: 4px;
}

.clue-box {
  display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  margin: 4px auto 14px;
  padding: 10px 16px;
  background: #fff7d6;
  border: 3px dashed #e0b400;
  border-radius: 16px;
  font-size: 19px; font-weight: 800;
}
.blanks { font-size: 16px !important; color: #6b6690; margin: 0 0 14px !important; }
.blanks span { font-family: ui-monospace, Menlo, monospace; font-size: 22px; font-weight: 900; color: var(--ink); margin-right: 10px; }
.spell-form { display: flex; gap: 12px; justify-content: center; align-items: stretch; }
.spell-form .answer { max-width: 380px; font-size: 28px; text-align: center; letter-spacing: 2px; }
.blanks span.flash { animation: hintflash .7s; }
@keyframes hintflash { 0%, 60% { color: #e0a000; transform: scale(1.12); } }
.blanks span { display: inline-block; }

.timer { display: flex; align-items: center; gap: 10px; max-width: 420px; width: 100%; margin: 0 auto 12px; font-size: 20px; }
.timer-bar { flex: 1; height: 16px; background: #eeeaf9; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(#8fd3ff, #3b9ef5); transition: width .2s linear; }
.timer-text { font-weight: 900; min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.timer.hurry .timer-fill { background: linear-gradient(#ff8f8f, #e03131); }
.timer.hurry .timer-text { color: #e03131; animation: bob .5s ease-in-out infinite; }

.guess-tiles { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px; margin-top: 14px; }
.guess-tiles:empty { display: none; }
.tile {
  display: grid; place-items: center;
  min-width: 34px; height: 40px; padding: 0 6px;
  border: 3px solid var(--ink); border-radius: 10px;
  font-size: 22px; font-weight: 900;
  box-shadow: 0 3px 0 var(--ink);
  animation: tilepop .3s backwards;
}
.tile.good { background: #8be28a; }
.tile.bad { background: #ff9d9d; text-decoration: line-through; text-decoration-thickness: 2px; }
.tile.gap { background: #fff; border-style: dashed; border-color: #e03131; box-shadow: none; }
@keyframes tilepop { from { transform: scale(.4); opacity: 0; } }

.feedback { margin: 10px 0 0 !important; font-size: 16px !important; color: #6b6690; min-height: 22px; }
.feedback.bad { color: #c92a2a; }
.feedback.hint { color: #9a6b00; }
.answer.wobble { animation: wobble .4s; }
@keyframes wobble { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.flash-word { font-size: 34px; font-weight: 900; letter-spacing: 3px; color: #c2337a; margin: 0 0 10px !important; }

.result-word { font-size: 38px !important; font-weight: 900 !important; letter-spacing: 6px; margin: 6px 0 14px !important; }
.result-word.good { color: #2b9a3f; }
.result-word.bad { color: #e03131; }
.typed { text-decoration: line-through; text-decoration-thickness: 3px; color: #e03131; }
.panel .btn.next { align-self: center; }
.bonus { display: inline-block; background: var(--sun); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 12px; font-size: 15px; }

/* ---------- Win ---------- */
.win-card {
  margin: 40px auto 0;
  max-width: 620px;
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 7px 0 var(--ink);
  padding: 30px 30px 36px;
  text-align: center;
}
.win-mascot { width: 170px; height: 184px; margin: 0 auto; animation: bob 1s ease-in-out infinite; }
.win-card h1 { font-size: 40px; font-weight: 900; margin: 8px 0 10px; }
.win-card p { font-size: 19px; font-weight: 700; margin: 0 0 24px; }
.row { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
#confetti i {
  position: absolute; top: -20px;
  width: 12px; height: 18px;
  border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 720px) {
  .setup-grid { grid-template-columns: 1fr; }
  .vs { text-align: center; }
  .how { grid-template-columns: 1fr; }
  .castle-wrap { width: 140px; height: 133px; }
}
/* Leave room for the QuinnLab link above the title. */
@media (max-width: 900px) { #screen-title .logo { margin-top: 50px; } }

/* ---------- Extra 3D ---------- */
/* The battlefield is a real 3D stage: layers sit at different depths and the
   whole stage tips towards the pointer (see the pointermove handler in game.js). */
#screen-battle { perspective: 1100px; }
.field {
  transform-style: preserve-3d;
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: transform .18s ease-out;
}
.scenery, .side, .castle-wrap { transform-style: preserve-3d; }
.hill { transform: translateZ(-160px) scale(1.12); }
.tree { transform: translateZ(-70px); }
.nameplate, .hp { transform: translateZ(40px); }
.side.active .nameplate { animation: bob3d 1s ease-in-out infinite; }
@keyframes bob3d { 0%, 100% { transform: translateZ(40px); } 50% { transform: translateZ(40px) translateY(-5px); } }
.castle-wrap { transform: translateZ(20px); }
.hero { transform: translateZ(70px); }
.side.active .hero { animation: hop3d .7s ease-in-out infinite; }
.side.lost .hero { transform: translateZ(70px) rotate(80deg) translateX(18px); }
@keyframes hop3d {
  0%, 100% { transform: translateZ(70px) translateY(0) scale(1.04, .96); }
  50% { transform: translateZ(70px) translateY(-14px) scale(.97, 1.04); }
}
.middle { transform: translateZ(100px); }
.castle-wrap { height: 200px; }
.castle-wrap .castle { height: 190px; }

/* Creatures sway from side to side like little models on a turntable. */
.hero svg, .hero-preview svg, .win-mascot svg { animation: turn 3.2s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes turn {
  0%, 100% { transform: perspective(300px) rotateY(-16deg); }
  50% { transform: perspective(300px) rotateY(16deg); }
}

/* Cone trees */
.tree { position: absolute; bottom: 84px; width: 44px; height: 74px; }
.tree::before {
  content: ""; position: absolute; inset: 0 0 12px 0;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: linear-gradient(90deg, #7fe07a, #3fae4c 45%, #1f7a35);
}
.tree::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 10px; height: 14px; margin-left: -5px;
  background: linear-gradient(90deg, #a8733f, #6b4220); border-radius: 0 0 3px 3px;
}
.tree.t1 { left: 1%; }
.tree.t2 { left: 43%; transform: translateZ(-110px) scale(.8); }
.tree.t3 { left: 53%; height: 90px; width: 52px; }
.tree.t4 { right: 1%; height: 86px; width: 50px; }

/* Glossy, chunky controls */
.btn {
  background-image: linear-gradient(rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 48%, rgba(0, 0, 0, .1));
  box-shadow: 0 6px 0 var(--ink), 0 12px 14px rgba(43, 35, 80, .22);
}
@media (hover: hover) { .btn:hover { box-shadow: 0 8px 0 var(--ink), 0 16px 18px rgba(43, 35, 80, .24); } }
.btn:active { box-shadow: 0 1px 0 var(--ink), 0 2px 4px rgba(43, 35, 80, .2); transform: translateY(5px); }
@media (hover: hover) { .ammo .btn:hover { transform: perspective(500px) translateY(-5px) rotateX(10deg); } }
.ammo .icon {
  width: 76px; height: 76px; margin-bottom: 4px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff, #e6e1fb 52%, #aaa1de);
  box-shadow: inset 0 -7px 10px rgba(43, 35, 80, .25), 0 6px 8px rgba(43, 35, 80, .25);
}
.player-card, .panel, .win-card {
  background: linear-gradient(#fff, #f3f0ff);
  box-shadow: 0 10px 0 var(--ink), 0 26px 32px rgba(43, 35, 80, .25);
}
.name-input, .answer { box-shadow: inset 0 4px 0 rgba(43, 35, 80, .1); }
.hp-bar, .timer-bar { box-shadow: inset 0 3px 3px rgba(43, 35, 80, .25); }
.hp-fill, .timer-fill { box-shadow: inset 0 4px 0 rgba(255, 255, 255, .45), inset 0 -3px 0 rgba(0, 0, 0, .15); }
.tile { background-image: linear-gradient(rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 55%); }
.clue-box { box-shadow: 0 4px 0 #e0b400; }
.how li { box-shadow: 0 5px 0 rgba(43, 35, 80, .18); }
.logo { animation: floaty 4s ease-in-out infinite; }
@keyframes floaty {
  0%, 100% { transform: perspective(600px) rotateX(14deg) translateY(0); }
  50% { transform: perspective(600px) rotateX(18deg) translateY(-6px); }
}

/* Lighter / darker slider */
.shade-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; font-weight: 800; color: #6b6690; }
.shade-row input { flex: 1; min-width: 0; accent-color: var(--main); }

/* ---------- True 3D battlefield (scene3d.js) ---------- */
#stage, .spin-hint { display: none; }
.field.is3d {
  display: block;
  height: clamp(340px, 54vh, 540px);
  padding: 0;
  transform: none;
  margin: 0 -20px;
}
.field.is3d #stage { display: block; position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
/* Fade the edges of the 3D view so clouds and the island never end in a hard line. */
.field.is3d #stage {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent), linear-gradient(transparent, #000 6%, #000 94%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent), linear-gradient(transparent, #000 6%, #000 94%, transparent);
  mask-composite: intersect;
}
.field.is3d #stage.dragging { cursor: grabbing; }
.field.is3d .scenery, .field.is3d .castle-wrap, .field.is3d .middle, .field.is3d #shot, .field.is3d #shot-shadow { display: none; }
.field.is3d .side { position: absolute; top: 14px; z-index: 2; pointer-events: none; }
.field.is3d #side-0 { left: 20px; align-items: flex-start; transform-origin: 0 0; }
.field.is3d #side-1 { right: 20px; align-items: flex-end; transform-origin: 100% 0; }
.field.is3d .hp { width: 230px; }
.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-mouse, kbd { display: none !important; }
  .hint-touch { display: inline; }
}
.field.is3d .spin-hint {
  display: block; position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
  margin: 0; padding: 3px 12px;
  font-size: 13px; font-weight: 800; color: #4a4470;
  background: rgba(255, 255, 255, .7); border-radius: 999px;
  pointer-events: none;
}

/* Link back to the QuinnLab home page */
.home-link {
  position: absolute; left: 20px; top: 16px; z-index: 3;
  padding: 6px 14px;
  font-size: 15px; font-weight: 900; color: var(--ink); text-decoration: none;
  background: rgba(255, 255, 255, .85);
  border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
}
@media (hover: hover) { .home-link:hover { background: var(--sun); } }

/* ---------- Fit the screen (no scrolling) ---------- */
/* Battle: the 3D view stretches to fill whatever height the turn panel leaves. */
#app:has(#screen-battle:not([hidden])) { padding: 10px 20px 16px; }
#screen-battle { display: flex; flex-direction: column; height: calc(100dvh - 26px); min-height: 520px; }
#screen-battle .field.is3d { flex: 1 1 0; height: auto; min-height: 170px; }
#screen-battle .panel { flex: 0 0 auto; margin-top: 10px; min-height: min(300px, 45dvh); padding: 14px 22px 18px; }
@media (max-height: 820px) {
  .panel h2 { font-size: 24px; }
  .panel p { margin-bottom: 10px; }
  .ammo .btn { padding: 8px; }
  .ammo .icon { width: 56px; height: 56px; font-size: 32px; }
  .clue-box { margin: 2px auto 8px; padding: 6px 14px; }
  .blanks { margin-bottom: 8px !important; }
  .timer { margin-bottom: 6px; }
  .guess-tiles { margin-top: 10px; }
  .tile { height: 34px; min-width: 30px; font-size: 19px; }
}
/* Title: game.js shrinks this screen with `zoom` until it fits (see fitTitle). */
#app:has(#screen-title:not([hidden])) { padding-top: 16px; padding-bottom: 16px; }
#setup { max-width: 940px; margin: 0 auto; }

/* Wide windows: the 3D world gets the full height and the turn panel sits beside it. */
@media (min-width: 1100px) and (min-aspect-ratio: 3/2), (orientation: landscape) and (max-height: 500px) {
  #app:has(#screen-battle:not([hidden])) { max-width: 1560px; }
  #screen-battle { flex-direction: row; gap: 22px; min-height: 440px; }
  #screen-battle .field.is3d { margin: 0; min-width: 0; }
  #screen-battle .panel { flex: 0 0 clamp(430px, 36vw, 540px); margin: 0 0 10px; min-height: 0; overflow-y: auto; }
  #screen-battle .spell-form { flex-wrap: wrap; }
  #screen-battle .spell-form .answer { flex: 1 0 100%; max-width: none; }
  #screen-battle .spell-form .btn { flex: 1; }
}

/* ---------- Phones ---------- */
/* Small screens: a compact turn panel, so the 3D world keeps a good share of the screen,
   and nameplates that share the width instead of running into each other. */
@media (max-width: 720px), (max-height: 500px) {
  #screen-battle { min-height: 0; }
  #screen-battle .field.is3d { min-height: 150px; }
  #screen-battle .panel { min-height: 0; padding: 10px 14px 14px; border-top-width: 10px; }
  .panel h2 { font-size: 20px; }
  .panel h2 .hero-inline { width: 30px; height: 32px; vertical-align: -7px; }
  .panel p { font-size: 15px; margin-bottom: 8px; }
  .ammo { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .ammo .btn { padding: 8px 4px 10px; border-radius: 14px; }
  .ammo .icon { width: 46px; height: 46px; font-size: 26px; }
  .ammo .name { font-size: 15px; line-height: 1.15; }
  .ammo .blurb { font-size: 12px; line-height: 1.2; }
  .ammo .dmg { font-size: 12px; }
  .ammo .dmg-label { display: none; }
  .timer { font-size: 16px; margin-bottom: 6px; }
  .clue-box { margin: 2px auto 8px; padding: 6px 12px; gap: 8px; font-size: 16px; }
  .clue-box .btn { font-size: 15px; padding: 6px 12px; }
  .flash-word { font-size: 26px; }
  .blanks { font-size: 14px !important; margin-bottom: 8px !important; }
  .blanks span { font-size: 18px; margin-right: 6px; }
  .spell-form { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .spell-form .answer { flex: 1 0 100%; max-width: none; font-size: 24px; padding: 6px 10px; }
  .spell-form .btn { flex: 1; font-size: 16px; padding: 8px 6px; white-space: nowrap; }
  .guess-tiles { margin-top: 8px; gap: 4px; }
  .tile { height: 32px; min-width: 28px; font-size: 18px; }
  .feedback { margin-top: 6px !important; font-size: 14px !important; }
  .result-word { font-size: 28px !important; letter-spacing: 3px; margin: 4px 0 8px !important; }
  .field.is3d .side { top: 8px; }
  .field.is3d #side-0 { left: 12px; }
  .field.is3d #side-1 { right: 12px; }
  .field.is3d .side { max-width: calc(50% - 18px); }
  .nameplate { gap: 6px; padding: 3px 12px 3px 6px; font-size: 16px; max-width: 100%; }
  .nameplate .mascot { flex: none; width: 26px; height: 28px; }
  .nameplate .pname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .field.is3d .hp { width: 100%; gap: 6px; }
  .hp-bar { height: 16px; }
  .hp-text { font-size: 13px; min-width: 0; }
  .field.is3d .spin-hint { font-size: 12px; }
  .win-card { margin-top: 16px; padding: 20px 18px 26px; }
  .win-mascot { width: 120px; height: 130px; }
  .win-card h1 { font-size: 30px; }
  .win-card p { font-size: 16px; }
}

/* A phone held sideways: the world and the turn panel sit side by side (see the wide windows
   rule above), sized for a short screen. */
@media (orientation: landscape) and (max-height: 500px) {
  #app:has(#screen-battle:not([hidden])) { padding: 8px 16px; }
  #screen-battle { height: calc(100dvh - 16px); gap: 12px; }
  #screen-battle .panel { flex-basis: min(48%, 400px); margin: 0; justify-content: flex-start; }
  #screen-battle .panel > :first-child { margin-top: auto; }
  #screen-battle .panel > :last-child { margin-bottom: auto; }
  #screen-battle .panel { padding: 8px 12px 10px; }
  .panel h2 { font-size: 18px; margin-bottom: 4px; }
  .panel h2 .hero-inline { width: 26px; height: 28px; vertical-align: -6px; }
  .ammo .icon { width: 38px; height: 38px; font-size: 22px; }
  .timer { margin-bottom: 4px; }
  .clue-box { margin-bottom: 6px; }
  .blanks { margin-bottom: 6px !important; }
  .spell-form .answer { font-size: 22px; padding: 4px 10px; }
  .spell-form .btn { padding: 6px; }
  .feedback { font-size: 13px !important; min-height: 0; }
}
