:root {
  --ink: #0b2540;
  --sea: #0b74a8;
  --sea-light: #e6f4fb;
  --card: #ffffff;
  --accent: #ffb703;
  --good: #2a9d5c;
  --bad: #d64545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--sea-light), #ffffff 60%);
  color: var(--ink);
  min-height: 100vh;
}

header {
  position: relative;
  text-align: center;
  padding: 1.25rem 3.5rem 0.25rem;
}
header h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 0; }

#sound-btn {
  position: absolute;
  top: 1rem;
  right: 0.75rem;
  width: 46px;
  height: 46px;
  font-size: 1.3rem;
  line-height: 1;
  border: 2px solid var(--sea);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
#sound-btn[aria-pressed="false"] { opacity: 0.55; }

main { max-width: 1000px; margin: 0 auto; padding: 1rem; }

/* ---------- Setup ---------- */

#quiz-setup { text-align: center; }

fieldset { border: none; margin: 0 0 1.25rem; padding: 0; }
legend {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  color: #33506b;
}

.opt-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.opt-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.6rem 1.2rem;
  border: 3px solid var(--sea);
  border-radius: 14px;
  background: #fff;
  color: var(--sea);
  cursor: pointer;
}
.opt-btn small { font-weight: 500; font-size: 0.75rem; opacity: 0.85; }
.opt-btn.active { background: var(--sea); color: #fff; }

.reel-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 6.5rem;
  padding: 0.6rem 1rem;
  border: 3px dashed var(--sea);
  border-radius: 14px;
  font-weight: 700;
  color: var(--sea);
  background: #fff;
}

/* Generic category picture behind the label, for players who cannot read
   the label yet. Sized generously, kept faint so the word still wins for
   players who can. */
.opt-btn, .reel-slot {
  position: relative;
  overflow: hidden;
  justify-content: center;
  min-height: 4.4rem;
  min-width: 8rem;
}

.opt-bg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 96%;
  height: 96%;
  opacity: 0.4;
  pointer-events: none;
}

.opt-btn.active .opt-bg { opacity: 0.5; }

.opt-label { position: relative; z-index: 1; }

#swap-reels {
  font-size: 1.3rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--ink);
  cursor: pointer;
}

#quiz-start, #quiz-again {
  font-size: 1.15rem;
  font-weight: 800;
  padding: 0.7rem 2.4rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--ink);
  cursor: pointer;
}

#best-score {
  margin-top: 1rem;
  font-size: 0.98rem;
  color: #6a8199;
}

/* ---------- Play ---------- */

#play-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
}

#quiz-progress {
  text-align: center;
  font-weight: 700;
  color: #33506b;
  margin: 0;
}

#restart-btn {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.35rem 0.9rem;
  border: 2px solid var(--sea);
  border-radius: 999px;
  background: #fff;
  color: var(--sea);
  cursor: pointer;
}

#hint-btn {
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0.35rem 1rem;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--ink);
  cursor: pointer;
}
#hint-btn[hidden] { display: none; }

/* A reel currently showing help, so it doesn't read as a normal guess. */
.guess-reel.hinted { border-color: var(--accent); }

/* The prompt's own arrows pick which item to attempt. They grey out once
   a guess is committed — see updatePromptNav(). */
.prompt-reel .scroll-window { cursor: pointer; }
.prompt-reel.locked .scroll-btn { opacity: 0.25; }

/* 264px is the measured floor for a legible reel: two 42px arrows plus
   gaps and padding (~124px) around a ~140px image window. Below that the
   silhouettes stop being tellable apart, so reels wrap instead of
   shrinking — three across on a tablet in landscape, two in portrait. */
#reels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(264px, 1fr));
  gap: 1rem;
  align-items: start;
}
@media (max-width: 560px) {
  #reels { grid-template-columns: 1fr; }
}

.reel {
  position: relative;   /* anchors the ✓ / ✗ verdict mark */
  background: var(--card);
  border-radius: 16px;
  padding: 0.9rem;
  text-align: center;
  box-shadow: 0 4px 14px rgba(11,37,64,0.12);
  border: 4px solid transparent;
}
.reel h3 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6a8199;
}

.prompt-reel { border-color: var(--accent); }

/* Below three columns the prompt spans the full width instead of
   leaving a hole in the grid, so the two guess reels stay side by side
   on a tablet in portrait. */
@media (max-width: 900px) {
  .prompt-reel { grid-column: 1 / -1; }
}

/* The prompt has to stay on screen while the player works the other
   reels — on a phone the reels stack, so without this the thing being
   asked about scrolls away exactly when it's needed. */
@media (max-width: 760px) {
  .prompt-reel {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
  }
  .prompt-reel h3 { margin: 0; white-space: nowrap; }
  .prompt-reel .scroller { flex: 1; gap: 0.25rem; }
  .prompt-reel .scroll-window { min-height: 64px; flex: 1; }
  .prompt-reel .face-img { max-height: 60px; }
  .prompt-reel .scroll-btn { width: 36px; height: 36px; flex: 0 0 36px; font-size: 1rem; }
  .reel { padding: 0.6rem; }
  .scroll-window { min-height: 104px; }
}

/* Subtitle pill for the spoken line. */
/* Anchored to the bottom: the top is taken by the title, and on a phone
   by the sticky prompt. */
#toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translate(-50%, 12px);
  z-index: 60;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 6px 20px rgba(11, 37, 64, 0.3);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: 92vw;
  text-align: center;
}
#toast[hidden] { display: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Verdict marks on a reel — shown whether or not sound is on. */
.mark {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  animation: mark-pop 1.1s ease-out forwards;
}
.mark-hit { color: var(--good); }
.mark-miss { color: var(--bad); }

@keyframes mark-pop {
  0%   { opacity: 0; transform: scale(0.5); }
  18%  { opacity: 1; transform: scale(1.15); }
  32%  { transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

.pip {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin: 0 3px;
  border-radius: 50%;
  background: var(--good);
  vertical-align: middle;
}
.pip.spent { background: #d9e2ea; }
.guess-reel.solved { border-color: var(--good); }
.guess-reel.failed { border-color: var(--bad); }

.scroller {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.scroll-btn {
  font-size: 1.2rem;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  border: none;
  background: var(--sea-light);
  color: var(--ink);
  cursor: pointer;
}
.scroll-btn:disabled { opacity: 0.4; cursor: default; }

.scroll-window {
  flex: 1;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  overflow: hidden;
}

.face-img { width: 100%; max-height: 110px; }
.face-name { font-size: clamp(1.05rem, 3vw, 1.4rem); font-weight: 800; }
.face-caption { font-size: 0.95rem; font-weight: 700; color: var(--sea); }

.tries { margin: 0.5rem 0; font-size: 0.88rem; color: #6a8199; min-height: 1.1rem; }

.pick-btn {
  font-size: 1rem;
  font-weight: 700;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 999px;
  background: var(--sea);
  color: #fff;
  cursor: pointer;
}
.pick-btn:disabled { opacity: 0.45; cursor: default; }

#quiz-feedback {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  min-height: 1.75rem;
  margin-top: 1rem;
}

#quiz-result { text-align: center; padding: 2rem 0; }
#quiz-score { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
#quiz-best-note { color: var(--good); font-weight: 700; margin-bottom: 1.25rem; }

.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
