:root {
  --bg0: #07203d;
  --bg1: #0e3764;
  --bg2: #15508a;
  --panel: rgba(8, 29, 56, 0.84);
  --line: rgba(215, 242, 255, 0.22);
  --text: #f2f9ff;
  --muted: #bfdaef;
  --teal: #70e3d0;
  --gold: #ffd166;
  --pink: #ff8fb0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Nunito", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, rgba(112, 227, 208, 0.2), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(255, 209, 102, 0.15), transparent 30%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 45%, var(--bg2));
}

.bq-page { width: min(1380px, calc(100vw - 24px)); margin: 0 auto; padding: 16px 0 28px; display: grid; gap: 14px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.back-link, .pill-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
  font-weight: 700;
}
.pill-button { cursor: pointer; }
.pill-button.primary { background: linear-gradient(135deg, var(--teal), var(--gold)); color: #0a2134; border-color: transparent; }

.hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.hud-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.hud-card p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.hud-card strong { font-size: 1.3rem; }
.energy-track { margin-top: 8px; background: rgba(255,255,255,0.12); border-radius: 999px; overflow: hidden; height: 11px; }
#energyFill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--gold)); }

.status-text { margin: 0; background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }

.game-shell { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
#gameCanvas {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #d7eef9;
  touch-action: manipulation;
}
.room-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; max-height: calc(100vh - 220px); overflow: auto; }
.room-panel h2 { font-family: "Fredoka", sans-serif; margin: 0 0 4px; }
.panel-copy { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }
.room-list { display: grid; gap: 8px; }
.room-card { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; padding: 10px; }
.room-header { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.room-copy { margin: 5px 0 0; font-size: 0.85rem; color: var(--muted); }
.room-chip { font-size: 0.72rem; border-radius: 999px; padding: 2px 8px; border: 1px solid transparent; white-space: nowrap; }
.room-chip.complete { background: rgba(112,227,208,0.22); border-color: rgba(112,227,208,0.5); }
.room-chip.locked { background: rgba(255,143,176,0.2); border-color: rgba(255,143,176,0.5); }
.room-chip.open { background: rgba(255,209,102,0.2); border-color: rgba(255,209,102,0.5); }
.room-chip.soon { background: rgba(191,218,239,0.2); border-color: rgba(191,218,239,0.5); }

.floating-hint { position: absolute; left: 12px; bottom: 12px; max-width: min(72%, 620px); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(7,25,47,0.84); opacity: 0; transform: translateY(8px); transition: 0.2s; pointer-events: none; }
.floating-hint.visible { opacity: 1; transform: translateY(0); }

.overlay { position: fixed; inset: 0; background: rgba(3,12,24,0.72); display: none; place-items: center; padding: 16px; z-index: 20; }
.overlay.visible { display: grid; }
.modal { width: min(640px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.modal h1, .modal h2 { margin: 0 0 8px; font-family: "Fredoka", sans-serif; }
.modal p { margin: 0 0 10px; }
.modal ul { margin: 0 0 12px 20px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.reward-line { color: var(--gold); font-weight: 700; }

.challenge-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 25; display: grid; place-items: center; padding: 12px; }
.challenge-overlay.visible { pointer-events: auto; }
.challenge-card { width: min(760px, calc(100vw - 24px)); background: #f6fbff; color: #1e3655; border-radius: 16px; padding: 14px; border: 2px solid #c1dff2; display: grid; gap: 10px; }
.challenge-topbar, .challenge-actions, .challenge-scoreboard, .math-answer-row, .dpad-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.challenge-topbar { justify-content: space-between; }
.challenge-title { margin: 0; font-family: "Fredoka", sans-serif; }
.score-line, .challenge-note { margin: 0; color: #4c6685; }
.score-badge { background: #e6f3ff; border: 1px solid #c6def0; border-radius: 10px; padding: 7px 10px; }
.score-badge strong { display: block; font-size: 1.1rem; }
.challenge-feedback { background: #e9f4ff; border: 1px solid #c8e1f4; border-radius: 10px; padding: 8px 10px; }
.challenge-feedback.error { background: #ffe9ef; border-color: #ffc0cf; }
.challenge-action, .primary-button, .secondary-button { border: 0; border-radius: 999px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.challenge-action.primary, .primary-button { background: #4ab8a4; color: #0d2f44; }
.challenge-action.secondary, .secondary-button { background: #d6e8f6; color: #1a3858; }
.typing-word, .math-problem { font: 700 1.9rem "Fredoka", sans-serif; text-align: center; }
.typing-input, .math-input { width: 100%; border-radius: 10px; border: 1px solid #c6def0; padding: 10px; font-size: 1rem; }
.memory-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.memory-card { border-radius: 10px; border: 1px solid #c6def0; background: #e9f4ff; min-height: 58px; font-weight: 700; }
.memory-card.revealed { background: #fff6de; }
.memory-card.matched { background: #ddf7ef; }

.touch-controls { display: none; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.dpad { display: grid; gap: 6px; }
.touch-controls button { border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,0.1); color: var(--text); padding: 8px 12px; font-weight: 700; }
.interact-button { min-width: 110px; }

.toast { position: fixed; right: 14px; bottom: 14px; z-index: 40; background: rgba(7,25,47,0.92); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; max-width: 440px; opacity: 0; transform: translateY(8px); transition: 0.2s; }
.toast.visible { opacity: 1; transform: translateY(0); }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

@media (max-width: 1120px) {
  .game-shell { grid-template-columns: 1fr; }
  .room-panel { max-height: none; }
}
@media (max-width: 760px) {
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .memory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
