:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1d2b27;
  --muted: #6b7a75;
  --primary: #1f8a70;
  --primary-dark: #17684f;
  --accent: #f5b83d;
  --good: #1f8a70;
  --good-bg: #dff3ec;
  --bad: #d64550;
  --bad-bg: #fbe3e5;
  --line: #e3ddd0;
  --shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14201c;
    --card: #1d2e29;
    --ink: #eef3f0;
    --muted: #93a8a0;
    --primary: #2fb592;
    --primary-dark: #1f8a70;
    --good-bg: #1c3d33;
    --bad-bg: #432229;
    --line: #2c423b;
    --shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

body { min-height: 100vh; min-height: 100dvh; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

button {
  touch-action: manipulation;
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

/* Home */
/* Header stays visible while scrolling (solid background, no blur: cheap on weak GPUs). */
.topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 5; background: var(--bg);
  margin: calc(-16px - env(safe-area-inset-top)) -16px 8px; padding: calc(16px + env(safe-area-inset-top)) 16px 8px; }
.brand { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.brand span { color: var(--primary); }
.chips { display: flex; gap: 8px; }
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 15px;
}
.sub { color: var(--muted); margin: 0 0 18px; }

.topic {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.topic:active { transform: translateY(1px); box-shadow: none; }
.topic .emoji {
  font-size: 34px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--bg);
  flex: none;
}
.topic .info { flex: 1; min-width: 0; }
.topic .name { font-weight: 800; font-size: 19px; }
.topic .desc { color: var(--muted); font-size: 14px; }
.stars { letter-spacing: 2px; font-size: 18px; white-space: nowrap; }
.stars .off { opacity: 0.25; }

.tip {
  margin-top: auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
}

.voicepick { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: -6px 0 16px; font-size: 15px; }
.voicepick select {
  flex: 1; min-width: 0; font: inherit; font-weight: 600; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.voicepick button { background: var(--primary); color: #fff; border-radius: 12px; padding: 8px 12px; }

/* Quiz */
.quizbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; background: var(--bg);
  margin: calc(-16px - env(safe-area-inset-top)) -16px 10px; padding: calc(16px + env(safe-area-inset-top)) 16px 8px; }
.close {
  background: none;
  font-size: 22px;
  color: var(--muted);
  padding: 4px 8px;
}
.progress { flex: 1; height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s; }
.hearts { font-weight: 800; white-space: nowrap; }

.prompt { font-size: 20px; font-weight: 700; margin: 4px 0 16px; }
.sentence { font-size: 22px; font-weight: 700; margin: 4px 0 16px; line-height: 1.5; }
.sentence .blank {
  display: inline-block;
  min-width: 78px;
  border-bottom: 3px solid var(--primary);
  text-align: center;
  color: var(--primary);
}

.players { display: flex; gap: 12px; margin-bottom: 20px; }
.play {
  flex: 1;
  background: var(--primary);
  color: #fff;
  border-radius: 18px;
  padding: 20px 12px;
  font-weight: 800;
  font-size: 19px;
  box-shadow: 0 4px 0 var(--primary-dark);
}
.play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--primary-dark); }
.players .play { padding: 18px 8px; }
.play.slow {
  flex: 0 0 26%;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
  font-size: 16px;
}
.play.slow:active { box-shadow: 0 1px 0 var(--line); }

.opt {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 15px 16px;
  margin-bottom: 10px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.opt:active { transform: translateY(1px); }
.opt.good { border-color: var(--good); background: var(--good-bg); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.opt:disabled { cursor: default; }

.feedback {
  margin-top: auto;
  padding: 16px;
  border-radius: 18px;
  margin-bottom: 4px;
}
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback h3 { margin: 0 0 6px; font-size: 19px; }
.feedback.good h3 { color: var(--good); }
.feedback.bad h3 { color: var(--bad); }
.feedback .en { font-weight: 700; margin: 0 0 12px; }

.primary {
  display: block;
  width: 100%;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 0 var(--primary-dark);
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--primary-dark); }
.ghost {
  display: block;
  width: 100%;
  background: none;
  color: var(--muted);
  font-weight: 700;
  padding: 14px;
  margin-top: 6px;
}

/* Result */
.result { text-align: center; margin: auto 0; }
.result .big { font-size: 64px; line-height: 1.1; }
.result h2 { font-size: 28px; margin: 8px 0 4px; }
.result .stars { font-size: 44px; margin: 8px 0; }
.result p { color: var(--muted); margin: 4px 0; }
.result .stats { display: flex; gap: 10px; justify-content: center; margin: 18px 0 26px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.brand-tagline {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* Memory Match */
.mmmode { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); padding: 5px; border-radius: 16px; margin: 0 0 14px; }
.mmmode button { flex: 1; background: none; border-radius: 12px; padding: 9px 6px; font-weight: 800; color: var(--ink); font-size: 14px; line-height: 1.2; }
.mmmode button small { display: block; font-weight: 600; color: var(--muted); font-size: 11px; }
.mmmode button.on { background: var(--primary); color: #fff; }
.mmmode button.on small { color: #e6f6f1; }

.mmgrid { display: grid; gap: 8px; margin: 8px 0 14px; width: 100%; }
.mmtile { perspective: 700px; border: 0; background: none; padding: 0; aspect-ratio: 1 / 1.05; font: inherit; cursor: pointer; min-width: 0; }
.mmtile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mmtile .in { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.4s; }
.mmtile.up .in, .mmtile.done .in { transform: rotateY(180deg); }
.mmtile .f { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.mmtile .bk { background: var(--primary); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18); }
.mmtile .bk::after { content: "?"; color: rgba(255, 255, 255, 0.6); font-size: 1.6rem; font-weight: 800; }
.mmtile .fr { background: var(--card); border: 2px solid var(--line); color: var(--ink); transform: rotateY(180deg); font-weight: 800; font-size: clamp(0.8rem, 4vw, 1.15rem); padding: 2px; text-align: center; overflow-wrap: anywhere; line-height: 1.1; }
.mmgrid.dense .fr { font-size: clamp(0.65rem, 3.1vw, 0.9rem); }
.mmtile .snd { font-size: 1.6rem; }
.mmtile.done .fr { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.mmtile.done { pointer-events: none; }
.mmsent { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.15em 0.45em; font-size: clamp(1.4rem, 6.5vw, 2rem); line-height: 1.3; font-weight: 800; margin: 14px 0 10px; }
.mmsent span { display: inline-block; opacity: 0; transform: translateY(8px); animation: mmpop 0.35s forwards; }
@keyframes mmpop { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .mmtile .in { transition: none; }
  .mmsent span { animation: none; opacity: 1; transform: none; }
}

/* Misc */
button:disabled { cursor: default; }
.vhint { font-size: 13px; color: var(--muted); margin: -8px 0 14px; }
.vhint:empty { display: none; }

/* Lighter rendering on Android / low-memory phones */
html.lite .progress i { transition: none; }
html.lite .mmtile { perspective: none; }
html.lite .mmtile .in { transform-style: flat; transition: none; transform: none !important; }
html.lite .mmtile .f { backface-visibility: visible; -webkit-backface-visibility: visible; transition: opacity 0.15s; }
html.lite .mmtile .fr { transform: none; opacity: 0; }
html.lite .mmtile.up .fr, html.lite .mmtile.done .fr { opacity: 1; }
html.lite .mmtile.up .bk, html.lite .mmtile.done .bk { opacity: 0; }

/* Arenas + Listen & Do */
.arenalabel { margin: 22px 2px 8px; font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.arenabadge { font-weight: 800; font-size: 14px; color: var(--muted); margin: -6px 0 10px; }
.ldshelf { display: grid; gap: 8px; margin: 6px 0 14px; }
.ldcell { aspect-ratio: 1; min-width: 0; padding: 0; display: grid; place-items: center; font-size: clamp(26px, 9vw, 40px); background: var(--card); border: 2px solid var(--line); border-radius: 14px; }
.ldcell.empty { background: none; border-style: dashed; }
.ldcell.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.ldtray { display: flex; flex-wrap: wrap; gap: 8px; min-height: 76px; padding: 10px; margin-bottom: 14px; border: 1px dashed var(--line); border-radius: 14px; }
.ldtray .ldcell { width: 56px; }
.ldmini { font-size: 26px; margin: 6px 0 0; }
