:root {
  --text: #2d2a55;
  --soft: #7d7aa6;
  --accent: #6c5ce7;
  --accent-deep: #5143c4;
  --gold: #ffbe1a;
  --silver: #b4b9d6;
  --go: #2fb350;
  --shade: rgba(64, 54, 130, 0.16);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Arial Rounded MT Bold",
    system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

/* The page never scrolls or zooms, so a tap is always a tap. */
body {
  color: var(--text);
  background: linear-gradient(160deg, #ffe9b0 0%, #c8f0d6 50%, #bfe3ff 100%);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

img { -webkit-user-drag: none; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.star {
  width: 1em;
  height: 1em;
  flex: none;
  fill: #dcd9ee;
  stroke: #dcd9ee;
  stroke-width: 2;
  stroke-linejoin: round;
}
.star.on { fill: var(--gold); stroke: var(--gold); }

/* ---------- layout ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
  grid-template:
    "bar" auto
    "stage" minmax(0, 1fr)
    "picker" auto
    / minmax(0, 1fr);
}

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  margin: 0 auto 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 24px;
  font-weight: 800;
  white-space: nowrap;
}
.brand img { width: 36px; height: 36px; }

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 0 var(--shade);
  font-size: 18px;
  font-weight: 800;
}
.pill .star { font-size: 20px; }

.seg {
  display: flex;
  min-width: 0;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
}
.seg button {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: transparent;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}
.seg img { width: 28px; height: 28px; }
.seg .arrow { font-size: 13px; opacity: 0.7; }
.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 0 var(--accent-deep);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 0 var(--shade);
  font-size: 20px;
}
.icon-btn[aria-pressed="false"] { opacity: 0.6; }

.brand a { display: flex; align-items: center; gap: inherit; color: inherit; text-decoration: none; }
.brand a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* The way to the other game: its picture, and its name when there is room. */
.hop {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 0 var(--shade);
  color: inherit;
  font-size: 17px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.hop:active { transform: translateY(2px); box-shadow: none; }
.hop:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.hop img { width: 30px; height: 30px; }
.hop-icon { width: 30px; font-size: 22px; line-height: 1; text-align: center; }
.hop .lbl { display: none; }
@media (min-width: 1000px) {
  .hop { padding: 0 16px 0 8px; }
  .hop .lbl { display: inline; }
}

/* ---------- a question ---------- */

.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  container: stage / size;
}

/* Upright, the prompt sits above the four answers. A word needs less room
   than a picture, so the share each gets depends on which is the prompt. */
.sheet {
  --prompt: 0.42fr;
  --choices: 1fr;
  position: absolute;
  inset: 0;
  display: grid;
  gap: 10px;
  grid-template:
    "trail" auto
    "prompt" minmax(0, var(--prompt))
    "choices" minmax(0, var(--choices))
    / minmax(0, 1fr);
  transition: opacity 0.25s;
}
.sheet[data-mode="word"] { --prompt: 0.9fr; }
.sheet.resting { opacity: 0.3; pointer-events: none; }

/* One pip for each question in the round. */
.trail {
  grid-area: trail;
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.trail li {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  font-size: 19px;
}
.trail .star { fill: none; stroke: none; }
.trail .now { background: #fff; box-shadow: inset 0 0 0 3px var(--accent); }
.trail .gold,
.trail .silver { background: none; font-size: 26px; }
.trail .gold .star { fill: var(--gold); stroke: var(--gold); animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.trail .silver .star { fill: var(--silver); stroke: var(--silver); animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }

/* The prompt: tap it to hear its word. */
.prompt {
  grid-area: prompt;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 8px 12px 8px 18px;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 4px 0 var(--shade);
}
.prompt:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--shade); }

.prompt-body {
  position: relative;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
}
.prompt-body > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  animation: arrive 0.3s ease-out backwards;
}
.pic, .thumb { object-fit: contain; pointer-events: none; }

.hear {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 var(--accent-deep);
}
.hear svg { width: 24px; height: 24px; }
.hear.nudge { animation: nudge 0.7s ease; }
.muted .hear { display: none; }

/* A tapped word hops along its letters; a tapped picture wobbles. */
.sing .ltr { animation: hop 0.45s ease calc(var(--i) * 70ms); }
.sing .pic { animation: wobble 0.6s ease; }

.choices {
  grid-area: choices;
  display: grid;
  grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.card {
  --tint: #e4f2ff;
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 4px solid #fff;
  border-radius: 24px;
  background: var(--tint);
  box-shadow: 0 4px 0 var(--shade);
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.25s, background-color 0.2s, border-color 0.2s;
  animation: arrive 0.36s cubic-bezier(0.2, 1.3, 0.4, 1) calc(var(--n) * 55ms) backwards;
}
.card:nth-child(2) { --tint: #fff0dc; }
.card:nth-child(3) { --tint: #e3f6e6; }
.card:nth-child(4) { --tint: #efe9ff; }
.card:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--shade); }

.card > * { position: absolute; transition: transform 0.3s cubic-bezier(0.2, 1.3, 0.4, 1), opacity 0.25s; }

/* A picture to pick, with its word waiting underneath until the card is tried. */
.card .pic { inset: 5%; width: 90%; height: 90%; }
.card .caption { left: 8%; bottom: 4%; width: 84%; height: 27%; opacity: 0; }
.card.shown .pic { transform: translateY(-12%) scale(0.76); }
.card.shown .caption { opacity: 1; }

/* A word to pick, with its picture waiting beside it. */
.card .label { left: 9%; top: 12%; width: 82%; height: 76%; }
.card .thumb { left: 4%; top: 12%; width: 30%; height: 76%; opacity: 0; transform: scale(0.4); }
.card.shown .label { transform: translateX(18%) scale(0.68); }
.card.shown .thumb { opacity: 1; transform: none; }

.card.wrong {
  --tint: #eceef5;
  border-color: #f6f7fb;
  box-shadow: 0 2px 0 var(--shade);
  color: var(--soft);
  cursor: default;
  transform: none;
  animation: shake 0.4s ease;
}
.card.wrong .pic { filter: grayscale(1); opacity: 0.5; }
.card.wrong .thumb { opacity: 0.8; }

.card.right {
  --tint: #dcf6e1;
  z-index: 1;
  border-color: var(--go);
  transform: none;
  animation: pop 0.55s ease;
}
.card.right::after {
  content: "✓";
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--go);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) 0.1s both;
}
.choices.done .card { cursor: default; }
.choices.done .card:not(.right) { opacity: 0.4; transform: none; }

/* Between questions the old one slips away before the next arrives. */
.sheet.leaving .choices,
.sheet.leaving .prompt-body {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.15s, transform 0.15s;
}

/* Sideways, the prompt sits beside the answers. */
@container stage (min-aspect-ratio: 5/4) {
  .sheet {
    --prompt: 0.8fr;
    --choices: 1.2fr;
    column-gap: 14px;
    grid-template:
      "trail trail" auto
      "prompt choices" minmax(0, 1fr)
      / minmax(0, var(--prompt)) minmax(0, var(--choices));
  }
  .sheet[data-mode="word"] { --prompt: 1fr; --choices: 1fr; }
  .prompt {
    align-self: center;
    aspect-ratio: 5 / 4;
    max-height: 100%;
    grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
    justify-items: center;
    gap: 8px;
    padding: 16px 24px;
  }
  .prompt-body { justify-self: stretch; }
  .sheet[data-mode="word"] .prompt { aspect-ratio: 1; }
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(12px) scale(0.92); }
}
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-7px) rotate(-1.5deg); }
  40% { transform: translateX(6px) rotate(1.5deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes pop {
  0%, 100% { transform: none; }
  30% { transform: scale(1.08) rotate(-2deg); }
  60% { transform: scale(0.97) rotate(1.5deg); }
}
@keyframes hop {
  0%, 100% { transform: none; }
  40% { transform: translateY(-14px); color: var(--accent); }
}
@keyframes wobble {
  0%, 100% { transform: none; }
  25% { transform: rotate(-5deg) scale(1.05); }
  60% { transform: rotate(4deg) scale(1.05); }
}
@keyframes nudge {
  0%, 100% { transform: none; }
  20% { transform: scale(1.25) rotate(-12deg); }
  45% { transform: scale(1.25) rotate(10deg); }
  70% { transform: scale(1.1) rotate(-5deg); }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 0 var(--shade);
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shade); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-deep); }
.btn.primary:active { box-shadow: 0 1px 0 var(--accent-deep); }

/* ---------- the level picker ---------- */

.picker {
  grid-area: picker;
  display: grid;
  gap: 6px;
  grid-auto-flow: column;
  grid-auto-columns: minmax(52px, 1fr);
  padding: 2px 2px 4px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.picker::-webkit-scrollbar { display: none; }

.tile {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 62px;
  padding: 4px 0 5px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 2px 0 var(--shade);
  font-weight: 800;
  scroll-snap-align: center;
}
.tile-no { position: absolute; top: 3px; left: 7px; color: var(--soft); font-size: 12px; }
.tile-pic { width: 36px; height: 36px; pointer-events: none; }
.tile-stars { display: flex; gap: 1px; font-size: 11px; }
.tile[aria-current="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 0 var(--accent-deep);
}
.tile[aria-current="true"] .tile-no { color: #fff; }
.tile[aria-current="true"] .star:not(.on) { fill: #9a8df0; stroke: #9a8df0; }

/* ---------- the reward card ---------- */

.cheer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 12px;
}
.cheer[hidden] { display: none; }

.cheer-card {
  width: min(330px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 16px 20px 20px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 16px 40px rgba(64, 54, 130, 0.3);
  text-align: center;
  animation: card-pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.cheer-pic { height: 104px; font-size: 76px; line-height: 104px; }
.cheer-pic img { height: 100%; animation: wobble 1.2s ease 0.3s 2; }
.cheer-stars { display: flex; justify-content: center; gap: 6px; font-size: 56px; }
.cheer-stars .star.on { animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.cheer-stars .star.on:nth-child(1) { animation-delay: 0.2s; }
.cheer-stars .star.on:nth-child(2) { animation-delay: 0.45s; }
.cheer-stars .star.on:nth-child(3) { animation-delay: 0.7s; }
.cheer-card h2 { margin: 6px 0 2px; font-size: 28px; font-weight: 800; }
.cheer-meter { margin: 0 0 14px; color: var(--soft); font-size: 15px; font-weight: 700; }
.cheer-actions { display: flex; justify-content: center; gap: 10px; }
.cheer-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 10px; background: #f0eefc; box-shadow: 0 3px 0 #d9d4f5; }
.cheer-actions .btn.primary { background: var(--accent); box-shadow: 0 3px 0 var(--accent-deep); }

@keyframes card-pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes star-pop {
  from { transform: scale(0) rotate(-40deg); }
  to { transform: scale(1) rotate(0); }
}

#fx {
  position: fixed;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- other screen shapes ---------- */

/* Roomy screens: bigger level tiles. */
@media (min-width: 720px) and (min-height: 600px) {
  .tile { min-height: 78px; }
  .tile-no { font-size: 14px; }
  .tile-pic { width: 46px; height: 46px; }
  .tile-stars { font-size: 14px; }
  .trail li { width: 32px; height: 32px; font-size: 23px; }
  .trail .gold, .trail .silver { font-size: 32px; }
  .hear { width: 54px; height: 54px; }
  .hear svg { width: 30px; height: 30px; }
}

/* An upright phone has height to spare, so every level is on show, in two rows. */
@media (max-width: 520px) and (min-height: 700px) {
  .picker {
    grid-auto-flow: row;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
  }
  .tile { grid-auto-flow: column; gap: 3px; min-height: 46px; padding: 4px 0; }
  .tile-no { position: static; }
  .tile-pic { width: 30px; height: 30px; }
  .tile-stars { font-size: 10px; }
}

/* A phone on its side has very little height, so the levels go down the side. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    column-gap: 10px;
    grid-template:
      "bar bar" auto
      "stage picker" minmax(0, 1fr)
      / minmax(0, 1fr) auto;
  }
  .picker {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, 54px);
    grid-auto-rows: minmax(0, 1fr);
    padding: 0 2px 2px;
    overflow: hidden;
  }
  .tile { min-height: 0; }
}

/* Without room for the name, the tabs stretch to fill the top bar. */
@media (max-width: 660px) {
  .brand { display: none; }
  .seg { flex: 1; }
  .seg button { padding: 0 6px; }
  .pill { padding: 0 10px; }
}

/* Narrow phones: the top bar also holds the star count, sound and the other
   game, so it tightens up, and the narrowest drop the star count. */
@media (max-width: 420px) {
  .bar { gap: 6px; }
  .pill { gap: 4px; padding: 0 8px; font-size: 16px; }
  .seg button { gap: 3px; padding: 0 4px; font-size: 16px; }
  .seg img { width: 24px; height: 24px; }
  .seg .arrow { font-size: 11px; }
}

/* The very smallest screens: no star count. */
@media (max-width: 350px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .trail { gap: 4px; }
  .trail li { width: 22px; height: 22px; font-size: 16px; }
  .trail .gold, .trail .silver { font-size: 22px; }
}
@media (max-width: 360px) {
  .pill { display: none; }
}

/* Short screens (a phone on its side): shrink the chrome, keep the pictures big. */
@media (max-height: 480px) {
  .app { gap: 6px; padding-top: 6px; }
  .sheet { gap: 6px; }
  .brand { font-size: 20px; }
  .brand img { width: 30px; height: 30px; }
  .pill, .icon-btn, .hop { min-height: 38px; height: 38px; }
  .icon-btn { width: 38px; }
  .hop { min-width: 38px; }
  .hop img { width: 26px; height: 26px; }
  .seg button { min-height: 32px; }
  .seg img { width: 24px; height: 24px; }
  .trail li { width: 20px; height: 20px; font-size: 15px; }
  .trail .gold, .trail .silver { font-size: 20px; }
  .choices { gap: 6px; }
  .card { border-width: 3px; border-radius: 18px; }
  .prompt { border-radius: 20px; }
  .tile-pic { width: 30px; height: 30px; }
  .btn { min-height: 40px; }
  .cheer-card { padding: 10px 16px 14px; }
  .cheer-pic { height: 56px; font-size: 40px; line-height: 56px; }
  .cheer-stars { font-size: 36px; }
  .cheer-card h2 { font-size: 20px; }
  .cheer-meter { margin-bottom: 8px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card.wrong, .card.right, .card.right::after, .prompt-body > *, .hear.nudge,
  .sing .ltr, .sing .pic, .trail .star, .cheer-card, .cheer-pic img, .cheer-stars .star.on { animation: none; }
  .card > * { transition: none; }
}
