/* ============================================================
   Super Trivia Kids — NES-flavoured UI.
   Chunky borders, flat colours, no gradients or rounded corners
   so the DOM matches the pixel canvas.
   ============================================================ */

:root {
  --bg:        #160f28;
  --bg-2:      #241a45;
  --panel:     #2d1b5c;
  --panel-2:   #3a2570;
  --line:      #6650a9;
  --text:      #f8f4ff;
  --muted:     #b7abda;
  --gold:      #f6c453;
  --green:     #62e5a0;
  --red:       #e43b44;
  --blue:      #5cc8ff;
  --purple:    #8f7dff;
  --pixel-font: 'Press Start 2P', 'Courier New', ui-monospace, monospace;
  --body-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font);
  /* Faint scanline wash, the way an old TV looked. */
  background-image: repeating-linear-gradient(
    180deg, rgba(255,255,255,0.02) 0px, rgba(255,255,255,0.02) 1px,
    transparent 1px, transparent 3px);
}

body { padding-bottom: env(safe-area-inset-bottom); }

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 12px 24px;
}

/* ---------- screens ---------- */
.screen { display: none; }
.screen.active { display: block; animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-title {
  font-family: var(--pixel-font);
  font-size: 15px;
  line-height: 1.6;
  margin: 8px 0 6px;
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}
.screen-sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* ---------- title screen ---------- */
.title-art { text-align: center; margin-top: 10px; }
.logo {
  font-family: var(--pixel-font);
  font-size: 26px;
  line-height: 1.5;
  margin: 12px 0 6px;
  color: var(--gold);
  text-shadow: 4px 4px 0 #000;
  letter-spacing: 1px;
}
.logo span { display: block; color: var(--blue); }
.tagline { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.title-canvas {
  display: block;
  width: 100%;
  max-width: 640px;
  margin: 6px auto 4px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.menu { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 10px auto 0; }
.hint-line { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--pixel-font);
  font-size: 11px;
  line-height: 1.7;
  padding: 14px 16px;
  color: var(--text);
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  cursor: pointer;
  transition: transform .06s ease, background .12s ease;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #120a29; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #2b1c00; border-color: #fff0b8; }
.btn-primary:hover:not(:disabled) { background: #ffd97a; }
.btn-ghost { background: transparent; }
.btn-danger { border-color: #7a2b31; color: #ff9f9f; }
.btn.small { font-size: 9px; padding: 10px 12px; }

.nav-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.nav-row .btn { flex: 1; min-width: 130px; }

/* ---------- pickers ---------- */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.pick {
  font-family: var(--pixel-font);
  font-size: 10px;
  line-height: 1.7;
  padding: 18px 10px;
  text-align: center;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  color: var(--text);
  cursor: pointer;
}
.pick .icon { display: block; font-size: 24px; margin-bottom: 8px; }
.pick.selected {
  background: var(--gold);
  color: #2b1c00;
  border-color: #fff0b8;
}
.pick.selected .check { display: block; }
.check { display: none; font-size: 9px; margin-top: 6px; }

/* ---------- hero picker ---------- */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.hero-card {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  padding: 10px 6px 12px;
  text-align: center;
  cursor: pointer;
}
.hero-card.selected { background: var(--panel-2); border-color: var(--gold); }
.hero-card canvas {
  width: 64px; height: 64px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block; margin: 0 auto 8px;
}
.hero-card h4 {
  font-family: var(--pixel-font);
  font-size: 10px; margin: 0 0 6px; color: var(--gold);
}
.hero-card p { margin: 0; font-size: 11px; color: var(--muted); }

/* ---------- world map ---------- */
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.map-node {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
}
.map-node.locked { opacity: .45; cursor: not-allowed; }
.map-node.cleared { border-color: var(--green); }
.map-node .lvl {
  font-family: var(--pixel-font); font-size: 13px; color: var(--gold); display: block; margin-bottom: 8px;
}
.map-node .nm { font-size: 12px; color: var(--text); display: block; margin-bottom: 6px; }
.map-node .skills {
  display: block; font-size: 10px; color: var(--muted);
  line-height: 1.5; margin-bottom: 8px; min-height: 30px;
}
.map-node .st { font-size: 15px; letter-spacing: 2px; }

.stat-row {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px;
}
.stat {
  flex: 1; min-width: 100px;
  background: var(--bg-2); border: 2px solid var(--line);
  padding: 10px; text-align: center;
}
.stat b { display: block; font-family: var(--pixel-font); font-size: 13px; color: var(--gold); margin-bottom: 6px; }
.stat span { font-size: 11px; color: var(--muted); }

/* ---------- play screen ---------- */
.stage-wrap {
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  background: #000;
  line-height: 0;
}
#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.quiz {
  margin-top: 12px;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  padding: 14px;
}
.quiz-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tag {
  font-family: var(--pixel-font); font-size: 9px;
  background: var(--purple); color: #17102c;
  padding: 6px 8px;
}
.tag.ghost { background: transparent; color: var(--muted); border: 2px solid var(--line); }
.speak-btn {
  margin-left: auto;
  font-size: 18px; line-height: 1;
  background: var(--blue); color: #06263a;
  border: 3px solid #a9e6ff;
  padding: 6px 10px; cursor: pointer;
  box-shadow: 0 3px 0 #120a29;
}
.speak-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #120a29; }

.question {
  font-size: 19px;
  line-height: 1.5;
  margin: 0 0 14px;
  min-height: 52px;
  font-weight: 700;
}

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer {
  font-family: var(--body-font);
  font-size: 17px;
  font-weight: 700;
  padding: 18px 12px;
  min-height: 60px;
  color: var(--text);
  background: var(--bg-2);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 #120a29;
  cursor: pointer;
  word-break: break-word;
}
.answer:hover:not(:disabled) { background: var(--panel-2); }
.answer:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #120a29; }
.answer:disabled { cursor: default; }
.answer.right { background: var(--green); color: #05301c; border-color: #b6ffd9; }
.answer.wrong { background: var(--red); color: #360507; border-color: #ffb3b3; }

.feedback {
  margin: 12px 0 0;
  min-height: 22px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}
.feedback.good { color: var(--green); }
.feedback.bad { color: #ff9f9f; }

.play-controls { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.play-controls .btn { flex: 1; min-width: 96px; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(9,5,20,.86);
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
  z-index: 40;
}
.overlay.active { display: flex; }
.modal {
  width: 100%; max-width: 460px;
  background: var(--panel);
  border: 4px solid var(--gold);
  box-shadow: 0 8px 0 #120a29;
  padding: 20px;
  text-align: center;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 {
  font-family: var(--pixel-font);
  font-size: 15px; line-height: 1.6;
  color: var(--gold); margin: 0 0 12px;
  text-shadow: 2px 2px 0 #000;
}
.modal p { color: var(--muted); font-size: 14px; margin: 0 0 14px; line-height: 1.5; }
.modal .reward-row { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.modal .reward {
  flex: 1; min-width: 84px;
  background: var(--bg-2); border: 2px solid var(--line); padding: 10px;
}
.modal .reward b { display: block; font-family: var(--pixel-font); font-size: 14px; color: var(--gold); margin-bottom: 6px; }
.modal .reward span { font-size: 11px; color: var(--muted); }
.modal .modal-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.modal .modal-btns .btn { flex: 1; min-width: 120px; }
.modal .review { text-align: left; margin: 12px 0; }
.modal .review li { font-size: 13px; color: var(--muted); margin-bottom: 8px; line-height: 1.45; }
.modal .review b { color: var(--green); }
.modal .review i { color: var(--muted); font-style: normal; font-size: 11px; }

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .logo { font-size: 18px; }
  .screen-title { font-size: 12px; }
  .question { font-size: 17px; }
  .answer { font-size: 15px; min-height: 56px; padding: 14px 8px; }
  .pick-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .hero-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .map-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  .btn, .answer { transition: none; }
}
