/* Homework — kid-friendly, mobile-first styles */
:root {
  --accent: #ff922b;
  --ink: #2b2d42;
  --muted: #6c7086;
  --card: #ffffff;
  --line: #e7e9f3;
  --good: #2f9e44;
  --good-bg: #d3f9d8;
  --bad: #e03131;
  --bad-bg: #ffe3e3;
  --sky1: #e7f5ff;
  --sky2: #fff4e6;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(43, 45, 66, 0.08), 0 10px 24px rgba(43, 45, 66, 0.08);
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 100%);
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Mali', 'Sarabun', 'Leelawadee UI', 'Thonburi', system-ui, sans-serif;
  color: var(--ink);
  line-height: 1.5;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
mark { background: #ffe066; border-radius: 6px; padding: 0 4px; text-decoration: underline 3px var(--accent); text-underline-offset: 5px; }

#app { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.view { padding-bottom: 32px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(180deg, var(--sky1) 70%, rgba(231, 245, 255, 0));
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.25rem; text-decoration: none; }
.logo-mark {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}
.crumbs { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.95rem; color: var(--muted); min-width: 0; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs .sep { opacity: 0.5; }
.icon-btn {
  border: 0; background: var(--card); width: 44px; height: 44px; border-radius: 14px;
  font-size: 1.3rem; cursor: pointer; box-shadow: var(--shadow);
}
.foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 24px 0 32px; }

@media (max-width: 560px) {
  .logo span:last-child { display: none; }
  .crumbs { font-size: 0.85rem; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 16px; padding: 12px 22px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 1.05rem; text-decoration: none;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18); transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 5px 0 var(--line); }
.btn.small { padding: 8px 14px; font-size: 0.95rem; border-radius: 12px; }
.center { text-align: center; margin-top: 24px; }

/* ---------- hero & heads ---------- */
.hero {
  display: flex; align-items: center; gap: 20px; margin: 12px 0 24px;
  background: var(--card); border-radius: 28px; padding: 24px; box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 6px; font-size: clamp(1.5rem, 4vw, 2.2rem); line-height: 1.25; }
.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; }
.mascot { font-size: 72px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }

.page-head {
  --c: var(--accent);
  display: flex; align-items: center; gap: 16px; margin: 12px 0 20px;
  background: var(--c); color: #fff; border-radius: 26px; padding: 20px 24px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
}
.page-head .emoji { font-size: 52px; background: rgba(255, 255, 255, 0.25); border-radius: 20px; padding: 4px 12px; }
.page-head h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.page-head p { margin: 2px 0 0; opacity: 0.95; }

/* ---------- card grids ---------- */
.grid { display: grid; gap: 16px; }
.grades { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.subjects { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.topics { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.modes { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.card {
  --c: var(--accent);
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border-radius: var(--radius); padding: 20px 16px; text-align: center;
  text-decoration: none; box-shadow: 0 6px 0 color-mix(in srgb, var(--c) 45%, transparent), 0 10px 24px rgba(43, 45, 66, 0.08);
  border: 3px solid transparent; transition: transform 0.12s, border-color 0.12s;
}
.card:hover { transform: translateY(-3px); border-color: var(--c); }
.card:active { transform: translateY(2px); }
.card .emoji { font-size: 48px; line-height: 1.1; }
.card b { font-size: 1.25rem; }
.card small { color: var(--muted); }

.grade-card { background: linear-gradient(160deg, #fff 55%, color-mix(in srgb, var(--c) 18%, #fff)); }
.grade-card b { font-size: 2rem; color: var(--c); }
.subject-card .emoji { font-size: 64px; }

.topic-card { flex-direction: row; text-align: left; gap: 14px; padding: 16px; }
.topic-card .emoji {
  font-size: 34px; min-width: 60px; height: 60px; display: grid; place-items: center;
  border-radius: 18px; background: color-mix(in srgb, var(--c) 14%, #fff);
}
.topic-card .t-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topic-card b { font-size: 1.1rem; }
.topic-card.mix { background: linear-gradient(120deg, #fff0f6, #e7f5ff 50%, #fff9db); }

.stars i { font-style: normal; color: #dee2e6; font-size: 1.1rem; }
.stars i.on { color: #fab005; text-shadow: 0 1px 0 #e67700; }
.best { font-size: 0.9rem; color: var(--muted); background: var(--sky1); border-radius: 10px; padding: 2px 10px; margin-top: 4px; }

.howto h2 { margin: 32px 0 12px; }
.modes-info { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.mini { background: rgba(255, 255, 255, 0.7); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.mini span { font-size: 28px; }
.mini small { color: var(--muted); }

/* ---------- game shell ---------- */
.gamebar { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; flex-wrap: wrap; }
.gb-title { flex: 1; font-size: 1.1rem; min-width: 0; }
.pills { display: flex; gap: 8px; }
.pill { background: var(--card); border-radius: 999px; padding: 6px 14px; font-weight: 700; box-shadow: 0 3px 0 var(--line); white-space: nowrap; }
.pill.hurry { background: var(--bad-bg); color: var(--bad); animation: pulse 0.6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }

.progress { height: 12px; background: rgba(255, 255, 255, 0.8); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s; }
.progress.time div { background: linear-gradient(90deg, #ff6b6b, #ffd43b, #51cf66); transition: width 1s linear; }

.qcard {
  position: relative; background: var(--card); border-radius: 26px; padding: 22px 20px 26px;
  text-align: center; box-shadow: var(--shadow); margin-bottom: 18px;
}
.qcard .q { margin: 0 40px 8px; font-size: 1.25rem; font-weight: 600; }
.qcard .big { font-size: clamp(2.4rem, 9vw, 4rem); font-weight: 700; line-height: 1.3; word-break: break-word; }
.qcard .big.m { font-size: clamp(1.9rem, 6.5vw, 3rem); }
.qcard .big.s { font-size: clamp(1.5rem, 5vw, 2.2rem); }
.qcard .big.xs { font-size: clamp(1.2rem, 4vw, 1.6rem); }
.qcard .sub { margin: 8px 0 0; font-size: 1.6rem; letter-spacing: 2px; }
.qcard.compact { padding: 14px 16px 16px; margin-bottom: 14px; }
.qcard.compact .q { font-size: 1.05rem; }
.qcard.compact .big { font-size: clamp(1.8rem, 7vw, 2.8rem); }
.speak {
  position: absolute; top: 12px; right: 12px; border: 0; background: var(--sky1);
  width: 42px; height: 42px; border-radius: 50%; font-size: 1.2rem; cursor: pointer;
}

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choices.long { grid-template-columns: 1fr; }
.choice {
  position: relative; border: 3px solid var(--line); background: var(--card); border-radius: 20px;
  padding: 16px 12px; font-size: clamp(1.25rem, 4.5vw, 1.7rem); font-weight: 700; cursor: pointer;
  box-shadow: 0 5px 0 var(--line); transition: transform 0.08s, border-color 0.12s; min-height: 72px;
}
.choices.long .choice { font-size: 1.15rem; text-align: left; padding-left: 52px; }
.choice .k {
  position: absolute; top: 8px; left: 10px; font-size: 0.75rem; color: var(--muted); font-weight: 400;
  background: var(--sky1); border-radius: 8px; padding: 0 6px;
}
.choices.long .choice .k { top: 50%; transform: translateY(-50%); left: 14px; font-size: 0.85rem; }
.choice:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .choice:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
}
.choice:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--good); background: var(--good-bg); color: var(--good); box-shadow: 0 5px 0 #8ce99a; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); box-shadow: 0 5px 0 #ffa8a8; animation: shake 0.4s; }

.feedback { min-height: 56px; margin-top: 16px; text-align: center; font-size: 1.3rem; font-weight: 700; border-radius: 18px; padding: 10px; }
.feedback:empty { visibility: hidden; }
.feedback.good { background: var(--good-bg); color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback small { display: block; font-size: 1rem; font-weight: 400; color: var(--ink); margin-top: 4px; }
.feedback .btn { margin-top: 10px; }
.combo { text-align: center; font-size: 1.4rem; font-weight: 700; color: #e8590c; min-height: 40px; margin-top: 10px; }

@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- match ---------- */
.hint { text-align: center; color: var(--muted); margin: 0 0 12px; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.match .col { display: flex; flex-direction: column; gap: 10px; }
.tile {
  border: 3px solid var(--line); background: var(--card); border-radius: 18px; padding: 12px 8px;
  min-height: 68px; font-size: 1.7rem; font-weight: 700; cursor: pointer; box-shadow: 0 4px 0 var(--line);
  word-break: break-word;
}
.tile.m { font-size: 1.2rem; }
.tile.s, .tile.xs { font-size: 0.95rem; }
.tile.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, #fff); transform: scale(1.03); }
.tile.done { border-color: var(--good); background: var(--good-bg); color: var(--good); opacity: 0.55; cursor: default; box-shadow: none; }
.tile.shake { border-color: var(--bad); background: var(--bad-bg); animation: shake 0.4s; }

/* ---------- balloon ---------- */
.sky {
  position: relative; height: min(58vh, 520px); overflow: hidden; border-radius: 26px;
  background: linear-gradient(180deg, #a5d8ff 0%, #d0ebff 60%, #ebfbee 100%); box-shadow: var(--shadow);
}
.balloon {
  position: absolute; left: var(--x); bottom: -150px; width: 22%; max-width: 130px; aspect-ratio: 5 / 6;
  border: 0; padding: 0; cursor: pointer; background: none;
  animation: rise var(--d) linear var(--delay) forwards;
}
.balloon::before {
  content: ''; position: absolute; inset: 0; border-radius: 50% 50% 46% 46%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75) 0 10%, transparent 11%), var(--col);
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.12);
}
.balloon::after {
  content: ''; position: absolute; left: 50%; top: 100%; width: 2px; height: 46px; background: rgba(0, 0, 0, 0.25);
}
.balloon span {
  position: relative; display: grid; place-items: center; height: 100%; padding: 6px;
  color: #fff; font-weight: 700; font-size: clamp(1.1rem, 4.5vw, 1.8rem); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  word-break: break-word; line-height: 1.15;
}
.balloon.m span { font-size: clamp(0.95rem, 3.6vw, 1.35rem); }
.balloon.s span { font-size: clamp(0.8rem, 3vw, 1.05rem); }
.balloon.popped { animation: pop 0.35s forwards !important; pointer-events: none; }
.balloon.popped.bad::before { background: #adb5bd; }
@keyframes rise { from { bottom: -150px; } to { bottom: 105%; } }
@keyframes pop { to { transform: scale(1.6); opacity: 0; } }

/* ---------- result ---------- */
.result { background: var(--card); border-radius: 28px; padding: 32px 20px; text-align: center; box-shadow: var(--shadow); margin-top: 16px; }
.result h1 { margin: 8px 0; }
.result p { font-size: 1.2rem; margin: 6px 0; }
.result-emoji { font-size: 84px; animation: bob 2s ease-in-out infinite; }
.big-stars .stars i { font-size: 3rem; }
.badge { display: inline-block; background: #fff3bf; color: #e67700; border-radius: 999px; padding: 6px 16px; font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 20px; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti span { position: absolute; top: -40px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 560px) {
  .gamebar .pills { margin-left: auto; }
  .gb-title { order: 3; flex-basis: 100%; font-size: 1rem; }
}

@media (max-width: 480px) {
  .hero { flex-direction: column; text-align: center; padding: 20px 16px; }
  .page-head { padding: 16px; }
  .page-head .emoji { font-size: 40px; }
  .choices.three { grid-template-columns: repeat(3, 1fr); }
  .choice { padding: 14px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot, .result-emoji { animation: none; }
  .confetti { display: none; }
}
