* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  background: #0a0e1a; color: #eef2ff;
  -webkit-user-select: none; user-select: none;
  touch-action: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#scene { display: block; width: 100vw; height: 100vh; }

.hidden { display: none !important; }

/* ---- HUD ---- */
#hud {
  position: fixed; inset: 0; pointer-events: none;
}
#progress {
  position: absolute; top: 18px; left: 58px;
  background: rgba(12,18,38,.6); border: 1px solid rgba(120,160,255,.35);
  padding: 10px 16px; border-radius: 999px;
  font-size: 18px; font-weight: bold; letter-spacing: .5px;
  backdrop-filter: blur(6px);
}
#objective {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(12,18,38,.6); border: 1px solid rgba(120,160,255,.35);
  padding: 9px 18px; border-radius: 999px; font-size: 16px; font-weight: bold;
  backdrop-filter: blur(6px); white-space: nowrap;
}
#hearts {
  position: absolute; top: 18px; right: 18px;
  font-size: 26px; letter-spacing: 2px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.6));
  transition: transform .12s;
}
#hearts.hurt { animation: heartHit .4s; }
@keyframes heartHit { 0%,100%{transform:scale(1)} 30%{transform:scale(1.35)} 60%{transform:scale(.9)} }
#hint-bubble {
  position: absolute; left: 50%; bottom: 12%;
  transform: translateX(-50%);
  background: rgba(12,18,38,.78); border: 1px solid rgba(120,160,255,.45);
  padding: 12px 22px; border-radius: 14px;
  font-size: 19px; font-weight: bold;
  box-shadow: 0 0 30px rgba(90,140,255,.4);
  animation: bob 1.4s ease-in-out infinite;
}
@keyframes bob { 0%,100%{ transform: translateX(-50%) translateY(0);} 50%{ transform: translateX(-50%) translateY(-7px);} }

/* ---- Topbar (pause/mute) + legend (shared across modes) ---- */
.topbar { position: absolute; top: 16px; right: 70px; display: flex; gap: 8px; pointer-events: auto; }
.iconbtn {
  width: 42px; height: 42px; flex: none; border-radius: 12px; font-size: 20px; padding: 0;
  background: rgba(35,48,86,.85); border: 1px solid rgba(120,160,255,.4); color: #eaf0ff;
}
.iconbtn:active { transform: scale(.92); }
.iconbtn.selbtn { width: auto; min-width: 42px; padding: 0 9px; display: inline-flex; flex-direction: column; line-height: 1.05; }
.iconbtn.selbtn small { font-size: 9px; opacity: .85; }
.iconbtn.on { background: linear-gradient(135deg,#2fb86a,#49d6a0); border-color: #bfffd9; color: #06210f; }
#sel-box { position: absolute; border: 2px solid #49ff9a; background: rgba(73,255,154,.12); border-radius: 3px; display: none; pointer-events: none; z-index: 6; }
.legend {
  position: absolute; bottom: 10px; left: 14px;
  background: rgba(12,18,38,.55); border: 1px solid rgba(120,160,255,.2);
  padding: 5px 14px; border-radius: 999px; font-size: 12px; color: #aebbe0; white-space: nowrap;
}
.legend b { color: #bfe0ff; }
@media (pointer: coarse) { .legend { display: none; } }

/* ---- Controls graphic (keycap diagram) ---- */
#ctrl-guide {
  position: absolute; left: 14px; bottom: 12px;
  background: rgba(12,18,38,.62); border: 1px solid rgba(120,160,255,.28);
  border-radius: 14px; padding: 12px 14px; display: flex; gap: 14px; align-items: center;
  backdrop-filter: blur(6px);
}
.cg-wasd { display: grid; grid-template-columns: repeat(3, 26px); grid-auto-rows: 26px; gap: 4px; justify-items: center; }
.cg-wasd .k-w { grid-area: 1 / 2; } .cg-wasd .k-a { grid-area: 2 / 1; } .cg-wasd .k-s { grid-area: 2 / 2; } .cg-wasd .k-d { grid-area: 2 / 3; }
.cg-move { grid-area: 3 / 1 / 4 / 4; text-align: center; font-size: 11px; color: #8fb3ff; text-transform: uppercase; letter-spacing: 1px; }
.cg-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 14px; font-size: 12px; color: #c2cdec; }
.cg-rows span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.kc {
  display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 6px;
  background: linear-gradient(#39456e, #222a44);
  border: 1px solid rgba(150,180,255,.45); border-bottom-width: 3px; border-radius: 6px;
  font: bold 12px 'Trebuchet MS', sans-serif; color: #eef2ff; box-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.kc.wide { min-width: 46px; }
@media (pointer: coarse) { #ctrl-guide { display: none; } }

/* ---- Resources ---- */
#resources {
  position: absolute; top: 54px; left: 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.res { display: flex; align-items: center; gap: 7px; background: rgba(12,18,38,.55); padding: 4px 9px; border-radius: 999px; border: 1px solid rgba(120,160,255,.25); }
.res .ri { font-size: 16px; }
.res.ammo { font-weight: bold; font-size: 16px; min-width: 64px; }
.res.ammo.low { color: #ff9e9e; animation: heartHit .5s; }
.res .bar { width: 90px; height: 9px; background: rgba(0,0,0,.45); border-radius: 5px; overflow: hidden; }
.res .bar i { display: block; height: 100%; width: 100%; border-radius: 5px; background: linear-gradient(90deg,#7CFFB2,#49d6ff); transition: width .25s; }
.res.low .bar i { background: linear-gradient(90deg,#ff6b6b,#ffae3a); }

/* ---- Dock menu ---- */
.dock-sub { color: #aebbe0; margin: 4px 0 18px; font-size: 15px; }
.dock-options { display: flex; flex-direction: column; gap: 10px; }
.dock-opt {
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
  background: #1a2342; border: 1px solid rgba(120,160,255,.3); border-radius: 14px; font-size: 18px;
}
.dock-opt span { font-size: 12px; color: #8fb3ff; text-transform: uppercase; letter-spacing: 1px; }
.dock-opt:hover { background: #233056; }

/* ---- Party bar (switch character) ---- */
#party {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: auto; z-index: 7;
}
.party-chip {
  position: relative; width: 50px; height: 50px; padding: 0; flex: none;
  border-radius: 50%; background: rgba(20,28,54,.7); border: 2px solid rgba(120,160,255,.3);
  overflow: visible; opacity: .7; transition: transform .1s, opacity .15s;
}
.party-chip img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.party-chip b {
  position: absolute; bottom: -3px; right: -3px; font-size: 10px; background: #222a44;
  border-radius: 50%; width: 16px; height: 16px; line-height: 16px; color: #cdd8f5; border: 1px solid rgba(255,255,255,.2);
}
.party-chip.active { opacity: 1; border-color: #ffd24a; box-shadow: 0 0 16px rgba(255,210,74,.6); transform: translateY(-6px) scale(1.12); }

/* ---- Touch controls ---- */
#joystick {
  position: fixed; z-index: 8; width: 130px; height: 130px; margin: -65px 0 0 -65px;
  border-radius: 50%; border: 2px solid rgba(150,180,255,.4);
  background: radial-gradient(circle, rgba(40,60,120,.25), rgba(20,30,60,.12));
  pointer-events: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px;
  transform: translate(-50%,-50%); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #8fb3ff, #4f6fd0);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
#touch-buttons {
  position: fixed; right: 18px; bottom: 26px; z-index: 8;
  display: flex; align-items: flex-end; gap: 14px;
}
.tbtn {
  width: 74px; height: 74px; flex: none; border-radius: 50%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; background: rgba(35,48,86,.85);
  border: 2px solid rgba(120,160,255,.45); color: #eaf0ff;
  box-shadow: 0 4px 16px rgba(0,0,0,.4); -webkit-user-select: none; user-select: none;
}
.tbtn small { font-size: 11px; margin-top: 3px; font-weight: bold; opacity: .85; }
.tbtn:active { transform: scale(.92); filter: brightness(1.2); }
.tbtn.purify { width: 88px; height: 88px; font-size: 32px; background: linear-gradient(135deg,#4f7bff,#7a5cff); border-color:#fff; animation: bob 1.4s ease-in-out infinite; }
.tbtn.fire { width: 92px; height: 92px; font-size: 34px; background: linear-gradient(135deg,#ff7a3a,#e2424f); border-color:#ffd0b0; }
.tbtn.dock { background: linear-gradient(135deg,#4f7bff,#49d6ff); border-color:#fff; animation: bob 1.4s ease-in-out infinite; }

/* lift the touch buttons above the party bar on phones */
@media (pointer: coarse) { #touch-buttons { bottom: 78px; } #party { bottom: 12px; } }

/* ---- Overlays ---- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,14,30,.55), rgba(5,7,16,.85));
  backdrop-filter: blur(3px);
  padding: 20px;
}
.card {
  width: min(560px, 94vw);
  background: linear-gradient(160deg, #131a32, #0d1224);
  border: 1px solid rgba(120,160,255,.35);
  border-radius: 22px;
  padding: 30px 32px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.6), 0 0 60px rgba(60,110,255,.15) inset;
}

.card-title { font-size: 15px; letter-spacing: 2px; text-transform: uppercase; color: #8fb3ff; opacity:.8; margin-bottom: 14px; }
.definition { font-size: 26px; font-weight: bold; line-height: 1.25; margin-bottom: 10px; }
.sentence { font-size: 17px; color: #aebbe0; font-style: italic; margin-bottom: 22px; }

#answer {
  width: 100%; font-size: 26px; text-align: center;
  padding: 14px 16px; border-radius: 14px;
  border: 2px solid rgba(120,160,255,.4);
  background: #070b18; color: #eef2ff; letter-spacing: 3px;
  outline: none;
}
#answer:focus { border-color: #5a8cff; box-shadow: 0 0 0 4px rgba(90,140,255,.2); }
#answer.shake { animation: shake .35s; border-color: #ff6b6b; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)} 40%{transform:translateX(9px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)} }

/* Tap-to-answer choices (no typing) */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 4px; }
.choice {
  font-size: 22px; font-weight: bold; padding: 16px 12px; border-radius: 14px;
  background: #1d2747; border: 2px solid rgba(120,160,255,.35); color: #eef2ff;
}
.choice:hover { background: #27345c; }
.choice.right { background: linear-gradient(135deg,#2fb86a,#49d6a0); border-color:#bfffd9; color:#06210f; }
.choice.wrong { background: #5a2030; border-color:#ff8a8a; opacity: .6; }

.feedback { min-height: 24px; margin: 12px 0 4px; font-weight: bold; font-size: 17px; }
.feedback.good { color: #7CFFB2; }
.feedback.bad { color: #ff9e9e; }

.card-buttons { display: flex; gap: 12px; margin-top: 16px; }
button {
  font-family: inherit; cursor: pointer; border: none;
  border-radius: 12px; padding: 14px 18px; font-size: 17px; font-weight: bold;
  background: #233056; color: #dfe7ff; transition: transform .08s, filter .15s;
  flex: 1;
}
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(2px); }
button.primary { background: linear-gradient(135deg, #4f7bff, #7a5cff); color: white; }
button.big { font-size: 21px; padding: 18px; margin-top: 8px; }
button.link { background: none; color: #8aa0d0; font-weight: normal; font-size: 14px; margin-top: 14px; flex: none; text-decoration: underline; }

/* ---- Start screen ---- */
.start-card h1 {
  font-size: 40px; letter-spacing: 3px; line-height: 1;
  background: linear-gradient(120deg, #7Cc0ff, #a98cff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.start-card h1 span { display: block; font-size: 22px; letter-spacing: 8px; color: #6f86c0; -webkit-text-fill-color: #6f86c0; margin-top: 4px; }
.tagline { color: #aebbe0; margin: 16px 0 24px; font-size: 17px; }
.grade-pick { margin-bottom: 22px; }
.grade-label { font-size: 14px; color: #8fb3ff; letter-spacing: 1px; margin-bottom: 10px; text-transform: uppercase; }
.grade-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.grade-buttons button { flex: none; width: 54px; padding: 12px 0; background:#1a2342; }
.grade-buttons button.sel { background: linear-gradient(135deg,#4f7bff,#7a5cff); color:#fff; box-shadow:0 0 18px rgba(90,140,255,.5); }
.crew-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.crew-btn {
  flex: none; width: 72px; padding: 8px 6px 6px; background: #1a2342; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.crew-btn img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(120,160,255,.3); background:#0a0e1a; }
.crew-btn span { font-size: 12px; color: #aebbe0; }
.crew-btn.sel { background: linear-gradient(135deg,#4f7bff,#7a5cff); box-shadow: 0 0 18px rgba(90,140,255,.5); }
.crew-btn.sel img { border-color: #fff; }
.crew-btn.sel span { color: #fff; font-weight: bold; }
.controls-note { margin-top: 22px; font-size: 13px; color: #7585ad; line-height: 1.7; }

.win-burst { font-size: 64px; animation: pop .6s ease; }
@keyframes pop { 0%{transform:scale(.2);opacity:0} 60%{transform:scale(1.2)} 100%{transform:scale(1)} }
#win h2 { font-size: 32px; margin: 8px 0 10px; color:#9fd9ff; }
#win p { color:#aebbe0; margin-bottom: 22px; }

/* ---- Phone fit ---- */
@media (max-height: 560px), (max-width: 420px) {
  .card { padding: 20px 22px; border-radius: 18px; }
  .start-card h1 { font-size: 32px; }
  .start-card h1 span { font-size: 17px; letter-spacing: 5px; }
  .tagline { margin: 10px 0 16px; font-size: 15px; }
  .grade-pick { margin-bottom: 14px; }
  .crew-btn { width: 62px; } .crew-btn img { width: 44px; height: 44px; }
  .definition { font-size: 22px; } .sentence { font-size: 15px; margin-bottom: 14px; }
  #answer { font-size: 22px; padding: 11px; }
  .controls-note { display: none; }
  #progress { font-size: 15px; padding: 8px 13px; }
  #hearts { font-size: 22px; }
  /* never clip a tall start/win card on a small or short screen — let it scroll */
  .overlay { align-items: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 26px; }
  .card { max-height: 94vh; overflow-y: auto; }
  .card-buttons { flex-wrap: wrap; }
}

/* round-11 touch bar (contract ⑬): kid-tappable text links (skip/cancel/leave) + icon buttons get real ≥44px targets */
.card .link, button.link, a.link { display: inline-block; padding: 12px 18px; min-height: 44px; min-width: 44px; box-sizing: border-box; font-size: 15px; }
.iconbtn { min-width: 44px; min-height: 44px; font-size: 20px; }
