:root {
  --bg: #fdf8ee;
  --ink: #1f2933;
  --muted: #6b7280;
  --card: #ffffff;
  --line: #e9e1cf;
  --accent: #c2410c;
  --good: #15803d;
  --good-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --chip: #f3ead7;
  --shadow: 0 2px 0 rgba(31,41,51,.06), 0 10px 30px rgba(31,41,51,.08);
  --radius: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c; --ink: #f1f1ee; --muted: #a1a1aa; --card: #23252b; --line: #34363d;
    --good: #4ade80; --good-bg: #14321f; --bad: #f87171; --bad-bg: #3a1a1a; --chip: #2d2f36;
    --shadow: 0 2px 0 rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
#app {
  max-width: 760px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}
h1, h2, h3, .display { font-family: "Fredoka", "Nunito", sans-serif; letter-spacing: .2px; }
h1 { font-size: 2.1rem; margin: 6px 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.back {
  border: 0; background: var(--chip); border-radius: 999px; padding: 8px 14px; font-weight: 800;
}
.topbar .title { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 1.15rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.chip {
  border: 2px solid transparent; background: var(--chip); border-radius: 999px;
  padding: 8px 14px; font-weight: 800; font-size: .95rem;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--card); }

/* ---------- deck tiles ---------- */
.decks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.deck {
  text-align: left; border: 0; background: var(--card); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); border-top: 8px solid var(--deck, var(--accent));
  display: flex; flex-direction: column; gap: 6px; min-height: 170px;
}
.deck .emoji { font-size: 2rem; line-height: 1; }
.deck h3 { margin: 4px 0 0; font-size: 1.3rem; }
.deck .meta { color: var(--muted); font-size: .9rem; font-weight: 700; }
.deck p { margin: 2px 0 0; font-size: .95rem; color: var(--muted); }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: auto; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- setup ---------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 12px; font-size: 1.15rem; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  border: 0; border-radius: 18px; padding: 18px 14px; text-align: left;
  background: var(--chip); display: flex; flex-direction: column; gap: 4px;
}
.mode b { font-family: "Fredoka", sans-serif; font-size: 1.25rem; font-weight: 600; }
.mode span { color: var(--muted); font-size: .9rem; }
.mode .big { font-size: 1.8rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; font-weight: 700; padding: 6px 0; }

/* ---------- flip card ---------- */
.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 800; color: var(--muted); font-size: .95rem; }
.progress .bar { flex: 1; margin: 0; }
.scene { perspective: 1400px; margin-bottom: 16px; touch-action: pan-y; }
.flip {
  position: relative; width: 100%; min-height: min(56dvh, 420px); border: 0; padding: 0; background: none;
  transform-style: preserve-3d; transition: transform .45s cubic-bezier(.3,.7,.3,1);
  display: block;
}
.flip.flipped { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 24px 44px; text-align: center; border: 3px solid var(--line);
}
.face.back { transform: rotateY(180deg); border-color: var(--deck, var(--accent)); }
.face .tag {
  position: absolute; top: 14px; left: 16px; font-size: .8rem; font-weight: 800; color: var(--muted);
  background: var(--chip); padding: 4px 10px; border-radius: 99px;
}
.face .text { font-family: "Fredoka", sans-serif; font-weight: 500; font-size: clamp(1.4rem, 4.6vw, 2.2rem); line-height: 1.3; }
.face.back .text { font-weight: 600; color: var(--deck, var(--accent)); }
.face .hint { margin-top: 14px; color: var(--muted); font-size: 1rem; }
.face .tap { position: absolute; bottom: 14px; color: var(--muted); font-size: .85rem; font-weight: 700; }
.drag-good { box-shadow: 0 0 0 4px var(--good) inset; }
.drag-bad { box-shadow: 0 0 0 4px var(--bad) inset; }

.answer-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-btn {
  border: 0; border-radius: 18px; padding: 18px 10px; font-weight: 800; font-size: 1.1rem;
  font-family: "Fredoka", sans-serif;
}
.big-btn.good { background: var(--good-bg); color: var(--good); }
.big-btn.bad { background: var(--bad-bg); color: var(--bad); }
.big-btn.primary { background: var(--ink); color: var(--bg); }
.big-btn.plain { background: var(--chip); }
.big-btn:disabled { opacity: .45; }
.helper { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 10px; }

/* ---------- quiz ---------- */
.qcard { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 26px 22px; margin-bottom: 14px; border: 3px solid var(--line); position: relative; }
.qcard .tag { display: inline-block; font-size: .8rem; font-weight: 800; color: var(--muted); background: var(--chip); padding: 4px 10px; border-radius: 99px; margin-bottom: 12px; }
.qcard .text { font-family: "Fredoka", sans-serif; font-weight: 500; font-size: clamp(1.3rem, 4.2vw, 1.9rem); line-height: 1.3; }
.choices { display: grid; gap: 10px; }
.choice {
  border: 3px solid var(--line); background: var(--card); border-radius: 16px; padding: 16px;
  text-align: left; font-weight: 700; font-size: 1.05rem; line-height: 1.35;
}
.choice.right { border-color: var(--good); background: var(--good-bg); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice:disabled { cursor: default; color: var(--ink); }
.feedback { font-family: "Fredoka", sans-serif; font-size: 1.3rem; text-align: center; margin: 14px 0 10px; min-height: 1.6em; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

/* ---------- results ---------- */
.results { text-align: center; padding: 26px 18px; }
.results .score { font-family: "Fredoka", sans-serif; font-size: 4rem; font-weight: 700; line-height: 1; margin: 10px 0; }
.results .stack { display: grid; gap: 10px; margin-top: 18px; }
.missed { text-align: left; margin-top: 18px; }
.missed li { margin-bottom: 8px; }
.missed b { display: block; }
.missed span { color: var(--muted); }

@media (max-width: 420px) {
  body { font-size: 17px; }
  .modes { grid-template-columns: 1fr; }
}
@media print { .topbar, .answer-btns { display: none; } }
