:root {
  --ink: #272547;
  --muted: #77758d;
  --purple: #6757e8;
  --purple-dark: #5143c8;
  --purple-soft: #eeeaff;
  --mint: #1ebd95;
  --mint-soft: #dff8f0;
  --orange: #ff9c42;
  --orange-soft: #fff0df;
  --pink: #ff668d;
  --white: #fff;
  --shadow: 0 18px 50px rgba(49, 39, 108, .12);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #f8f7fd; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 15%, rgba(255, 196, 92, .2), transparent 18rem),
    radial-gradient(circle at 92% 18%, rgba(103, 87, 232, .14), transparent 22rem),
    #f8f7fd;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(103, 87, 232, .25); outline-offset: 3px; }
.hidden { display: none !important; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 78px;
  padding: 0 max(24px, calc((100vw - 1160px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(64, 54, 120, .08);
  position: relative;
  z-index: 10;
}

.brand {
  border: 0;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: "Fredoka", sans-serif;
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
}

.brand-mark {
  width: 43px;
  height: 43px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--purple);
  box-shadow: 0 8px 20px rgba(103, 87, 232, .27);
}

.top-actions { display: flex; align-items: center; gap: 10px; }
.xp-count {
  height: 42px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 99px;
  color: #168c70;
  background: var(--mint-soft);
}
.xp-count span { font-size: 11px; font-weight: 900; letter-spacing: .06em; }
.star-count {
  height: 42px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 99px;
  background: #fff6d9;
  color: #bf7b12;
}
.star-count span { color: #ffc23d; font-size: 20px; }
.icon-button, .install-button {
  height: 42px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 800;
}
.icon-button { width: 42px; background: var(--purple-soft); color: var(--purple); font-size: 20px; }
.avatar-button {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: #e8f8ff;
  box-shadow: 0 6px 17px rgba(39,37,71,.12);
  cursor: pointer;
  position: relative;
}
.avatar-button span { font-size: 25px; line-height: 1; }
.avatar-button i {
  position: absolute;
  right: -6px;
  bottom: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 99px;
  color: #fff;
  background: var(--purple);
  font-size: 10px;
  font-style: normal;
  font-weight: 900;
}
.install-button { padding: 0 18px; color: #fff; background: var(--purple); }

main { width: min(1160px, calc(100% - 40px)); margin: 0 auto; flex: 1; }
.screen { display: none; padding: 42px 0 58px; animation: screen-in .35s ease both; }
.screen.active { display: block; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

.hero {
  min-height: 290px;
  padding: 44px 66px;
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  align-items: center;
  overflow: hidden;
  border-radius: 34px;
  background: linear-gradient(125deg, #6254df 0%, #8172f1 60%, #8d81f4 100%);
  color: #fff;
  box-shadow: var(--shadow);
  position: relative;
}
.hero::before, .hero::after {
  content: "";
  position: absolute;
  width: 230px;
  height: 230px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 50%;
}
.hero::before { left: -90px; bottom: -130px; }
.hero::after { right: -80px; top: -100px; }
.eyebrow {
  margin: 0 0 9px;
  color: inherit;
  text-transform: uppercase;
  letter-spacing: .13em;
  font-size: 12px;
  font-weight: 800;
}
.hero h1, .setup-card h1, .result-card h1 {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(36px, 4vw, 53px);
  line-height: 1.03;
}
.hero h1 span { color: #ffdc6c; }
.hero-copy > p:last-child { max-width: 530px; margin: 18px 0 0; color: rgba(255,255,255,.83); font-size: 17px; line-height: 1.6; }
.hero-visual { min-height: 215px; position: relative; display: grid; place-items: center; }
.mascot { width: 154px; position: relative; filter: drop-shadow(0 20px 22px rgba(36, 25, 106, .27)); z-index: 2; }
.mascot-face {
  width: 120px;
  height: 104px;
  margin: 0 auto -23px;
  border-radius: 53% 53% 45% 45%;
  background: #fff4d5;
  position: relative;
  z-index: 3;
}
.mascot-ear { position: absolute; top: -10px; width: 55px; height: 65px; background: #5143c8; border-radius: 70% 30% 55% 45%; z-index: 1; }
.mascot-ear.left { left: 12px; transform: rotate(-22deg); }
.mascot-ear.right { right: 12px; transform: scaleX(-1) rotate(-22deg); }
.eye { position: absolute; top: 44px; width: 12px; height: 17px; background: var(--ink); border-radius: 50%; }
.eye.left { left: 32px; }.eye.right { right: 32px; }
.eye::after { content: ""; position: absolute; width: 4px; height: 4px; left: 2px; top: 2px; background: #fff; border-radius: 50%; }
.mouth { position: absolute; left: 52px; top: 70px; width: 20px; height: 11px; border-bottom: 4px solid var(--pink); border-radius: 50%; }
.mascot-body { width: 154px; height: 100px; display: grid; place-items: center; padding-top: 15px; border-radius: 52% 52% 30% 30%; color: #fff; background: #ff9b43; font: 700 36px "Fredoka"; }
.orbit { position: absolute; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.16); }
.orbit span { display: grid; place-items: center; background: #fff; color: var(--purple); border-radius: 14px; box-shadow: 0 10px 24px rgba(37,28,98,.18); font: 700 21px "Fredoka"; }
.orbit-one { width: 190px; height: 190px; border: 2px dashed rgba(255,255,255,.25); animation: spin 18s linear infinite; }
.orbit-one span { width: 50px; height: 50px; transform: translate(80px, -42px); }
.orbit-two { width: 270px; height: 270px; border: 1px solid rgba(255,255,255,.18); animation: spin 24s linear infinite reverse; }
.orbit-two span { width: 46px; height: 46px; transform: translate(-92px, 80px); }
@keyframes spin { to { transform: rotate(360deg); } }

.section-heading { margin: 42px 4px 22px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.section-heading .eyebrow, .setup-card .eyebrow, .result-card .eyebrow { color: var(--purple); }
.section-heading h2 { margin: 0; font: 700 28px "Fredoka"; }
.section-heading > p { margin: 0; color: var(--muted); }
.grade-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grade-card {
  min-height: 137px;
  padding: 24px;
  border: 2px solid transparent;
  border-radius: 24px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  text-align: left;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 26px rgba(46, 36, 98, .07);
  cursor: pointer;
  transition: .22s ease;
}
.grade-card:hover { transform: translateY(-5px); box-shadow: var(--shadow); }
.grade-icon { grid-row: 1 / 3; width: 58px; height: 58px; display: grid; place-items: center; color: #fff; border-radius: 18px; font: 700 29px "Fredoka"; }
.grade-2 .grade-icon { background: var(--mint); }.grade-2:hover { border-color: var(--mint); }
.grade-3 .grade-icon { background: var(--orange); }.grade-3:hover { border-color: var(--orange); }
.grade-4 .grade-icon { background: var(--pink); }.grade-4:hover { border-color: var(--pink); }
.grade-info { display: flex; flex-direction: column; }
.grade-info strong { font: 700 21px "Fredoka"; }
.grade-info small { color: var(--muted); font-size: 14px; }
.grade-tables { grid-column: 2; color: var(--purple); font-size: 13px; font-weight: 800; }
.progress-card {
  margin-top: 22px;
  padding: 20px 24px;
  border-radius: 22px;
  background: #fff;
  display: grid;
  grid-template-columns: auto 1fr 1.6fr auto;
  align-items: center;
  gap: 16px;
  box-shadow: 0 7px 25px rgba(46,36,98,.06);
}
.progress-icon { width: 46px; height: 46px; display: grid; place-items: center; background: #fff4d7; border-radius: 15px; font-size: 22px; }
.progress-copy { display: flex; flex-direction: column; }
.progress-copy span { color: var(--muted); font-size: 13px; }
.progress-track, .round-progress > div { height: 11px; border-radius: 99px; background: #e9e7f2; overflow: hidden; }
.progress-track span, .round-progress > div span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--purple), #9689fa); transition: width .4s ease; }
.progress-percent { color: var(--purple); }

.back-button { padding: 9px 13px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 800; }
.back-button:hover { background: #fff; color: var(--purple); }
.setup-card, .result-card, .quiz-card {
  width: min(760px, 100%);
  margin: 14px auto 0;
  padding: 44px;
  border-radius: 30px;
  background: #fff;
  box-shadow: var(--shadow);
}
.setup-card h1 { font-size: clamp(30px, 4vw, 42px); }
.setup-card h1 span { color: var(--purple); }
.mode-grid { display: grid; gap: 12px; margin: 31px 0; }
.mode-card {
  width: 100%;
  padding: 15px 18px;
  border: 2px solid #eceaf3;
  border-radius: 18px;
  background: #fff;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 15px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.mode-card.selected { border-color: var(--purple); background: #faf9ff; }
.mode-symbol { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 15px; color: #fff; font: 700 25px "Fredoka"; }
.mode-symbol.multiply { background: var(--orange); }
.mode-symbol.divide { background: var(--mint); }
.mode-symbol.add { background: var(--purple); }
.mode-symbol.subtract { background: var(--pink); }
.mode-symbol.mixed { background: linear-gradient(135deg, var(--purple), var(--pink)); font-size: 13px; letter-spacing: -2px; }
.mode-card span:nth-child(2) { display: flex; flex-direction: column; }
.mode-card strong { font-size: 17px; }.mode-card small { color: var(--muted); }
.mode-card i { width: 24px; height: 24px; display: none; place-items: center; color: #fff; background: var(--purple); border-radius: 50%; font-style: normal; }
.mode-card.selected i { display: grid; }
.round-settings { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 29px 0; }
.round-settings > div:first-child { display: flex; flex-direction: column; }
.round-settings small { color: var(--muted); }
.length-picker { display: flex; padding: 4px; border-radius: 14px; background: #f0eef7; }
.length-picker button { width: 50px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 800; }
.length-picker button.selected { color: #fff; background: var(--purple); box-shadow: 0 5px 12px rgba(103,87,232,.25); }
.primary-button, .secondary-button {
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  padding: 0 24px;
  cursor: pointer;
  font-weight: 800;
  font-size: 17px;
}
.primary-button { width: 100%; color: #fff; background: linear-gradient(135deg, var(--purple), #8273f1); box-shadow: 0 10px 22px rgba(103,87,232,.26); }
.primary-button:hover { background: linear-gradient(135deg, var(--purple-dark), #6f61de); transform: translateY(-1px); }
.primary-button:disabled { background: #d9d6e7; box-shadow: none; cursor: not-allowed; transform: none; }
.primary-button span { margin-left: 10px; }
.secondary-button { background: var(--purple-soft); color: var(--purple); }

.quiz-top { width: min(800px, 100%); margin: 0 auto 15px; display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 24px; }
.round-progress { display: flex; align-items: center; gap: 13px; color: var(--muted); }
.round-progress > div { flex: 1; }
.streak { justify-self: end; padding: 8px 13px; border-radius: 13px; background: #fff0e1; color: #e7771d; }
.quiz-card { margin-top: 0; text-align: center; padding: 35px 44px 40px; }
.quiz-prompt { margin: 0 0 18px; color: var(--muted); font-weight: 700; }
.equation { display: flex; justify-content: center; align-items: center; gap: clamp(14px, 3vw, 29px); font: 700 clamp(44px, 7vw, 68px) "Fredoka"; }
.equation.long { gap: clamp(7px, 2vw, 18px); font-size: clamp(31px, 5vw, 50px); }
.equation.long .answer-box { min-width: 90px; height: 80px; }
.operator { color: var(--orange); }.equals { color: #aaa7b9; }
.answer-box {
  min-width: 105px;
  height: 96px;
  padding: 0 12px;
  display: grid;
  place-items: center;
  color: var(--purple);
  border: 3px solid var(--purple);
  border-radius: 22px;
  background: #faf9ff;
}
.answer-box.correct { border-color: var(--mint); background: var(--mint-soft); color: #139173; animation: pop .35s ease; }
.answer-box.wrong { border-color: var(--pink); background: #fff0f4; color: #dd456c; animation: shake .4s ease; }
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-5px); } }
.feedback { min-height: 26px; margin: 14px 0 5px; font-weight: 800; }
.feedback.correct { color: #159b79; }.feedback.wrong { color: #dc456b; }
.number-pad { width: min(360px, 100%); margin: 14px auto 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.number-pad button {
  height: 53px;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  background: #f1eff7;
  cursor: pointer;
  font: 700 21px "Fredoka";
  transition: .12s;
}
.number-pad button:hover { background: var(--purple-soft); color: var(--purple); transform: translateY(-2px); }
.number-pad button:active { transform: scale(.95); }
.number-pad .hint-key { background: #fff4d8; }.number-pad .delete-key { color: var(--pink); background: #fff0f4; }
.check-button, .next-button { width: min(360px, 100%); }
.visual-hint {
  max-width: 540px;
  margin: 17px auto 4px;
  padding: 15px;
  border-radius: 16px;
  color: #5b4e2d;
  background: #fff7dc;
  font-weight: 700;
  line-height: 1.6;
}
.hint-dots { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; vertical-align: middle; }
.hint-group { display: inline-flex; gap: 3px; padding: 5px; border-radius: 8px; background: rgba(255,255,255,.7); }
.hint-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--orange); }

.result-card { text-align: center; }
.result-burst { height: 126px; position: relative; display: grid; place-items: center; }
.result-burst div { width: 102px; height: 102px; display: grid; place-items: center; border-radius: 50%; background: #fff3c5; font-size: 52px; }
.result-burst > span { position: absolute; color: #ffc33f; font-size: 24px; animation: twinkle 1.3s ease-in-out infinite alternate; }
.result-burst > span:nth-child(1) { left: 27%; top: 20%; }.result-burst > span:nth-child(2) { right: 27%; top: 8%; animation-delay: .3s; }.result-burst > span:nth-child(3) { right: 23%; bottom: 8%; animation-delay: .6s; }
@keyframes twinkle { to { transform: rotate(20deg) scale(1.3); } }
.result-card h1 { font-size: 44px; }
.result-card > p:not(.eyebrow) { color: var(--muted); font-size: 17px; }
.result-score { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 28px 0; }
.result-score div { padding: 18px 8px; border-radius: 17px; background: #f7f5fc; display: flex; flex-direction: column; }
.result-score strong { color: var(--purple); font: 700 25px "Fredoka"; }
.result-score span { color: var(--muted); font-size: 13px; }
.result-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 12px; }

.rewards-hero {
  margin: 14px 0 36px;
  padding: 34px 40px;
  border-radius: 30px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  color: #fff;
  background: linear-gradient(125deg, #6254df, #8273f1);
  box-shadow: var(--shadow);
}
.profile-avatar {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  border: 4px solid rgba(255,255,255,.75);
  border-radius: 34px;
  background: rgba(255,255,255,.18);
  font-size: 61px;
}
.profile-info h1 { margin: 0; font: 700 39px "Fredoka", ui-rounded, system-ui, sans-serif; }
.profile-info h1 span { color: #ffdc6c; }
.profile-info > p:not(.eyebrow) { margin: 4px 0 14px; color: rgba(255,255,255,.8); }
.level-track { width: min(480px, 100%); height: 13px; border-radius: 99px; background: rgba(255,255,255,.2); overflow: hidden; }
.level-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: #ffcf4d; transition: width .45s ease; }
.profile-info small { display: block; margin-top: 6px; color: rgba(255,255,255,.75); }
.wallet {
  min-width: 125px;
  padding: 16px 20px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  text-align: center;
  background: rgba(255,255,255,.15);
}
.wallet span { font-size: 12px; color: rgba(255,255,255,.72); }
.wallet strong { color: #ffdc6c; font: 700 25px "Fredoka", ui-rounded, system-ui, sans-serif; }
.shop-heading { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: end; }
.shop-heading .eyebrow { color: var(--purple); }
.shop-heading h2 { margin: 0; font: 700 28px "Fredoka", ui-rounded, system-ui, sans-serif; }
.shop-heading > p { margin: 0; color: var(--muted); }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.avatar-card {
  min-height: 184px;
  padding: 22px 14px 16px;
  border: 2px solid transparent;
  border-radius: 23px;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 8px 26px rgba(46,36,98,.07);
  cursor: pointer;
  transition: .2s ease;
}
.avatar-card:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--purple); box-shadow: var(--shadow); }
.avatar-card.selected { border-color: var(--mint); background: var(--mint-soft); }
.avatar-card.locked { filter: saturate(.75); }
.avatar-card:disabled { cursor: default; }
.avatar-emoji { font-size: 56px; filter: drop-shadow(0 7px 8px rgba(38,31,83,.12)); }
.avatar-card strong { font-size: 15px; }
.avatar-card small { min-width: 85px; padding: 6px 10px; border-radius: 99px; color: #ad7010; background: #fff2c7; font-weight: 900; }
.avatar-card small.owned { color: #13886d; background: var(--mint-soft); }

footer { min-height: 60px; display: flex; justify-content: center; align-items: center; gap: 12px; color: #9491a5; font-size: 13px; }
footer a { color: var(--purple); font-weight: 800; text-decoration: none; }
footer a:hover { text-decoration: underline; }

.legal-page { background: #f8f7fd; }
.legal-page .brand { text-decoration: none; }
.legal-actions { display: flex; align-items: center; gap: 10px; }
.legal-back {
  padding: 10px 15px;
  border-radius: 12px;
  color: var(--purple);
  background: var(--purple-soft);
  font-weight: 800;
  text-decoration: none;
}
.legal-main {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0;
}
.legal-card {
  padding: clamp(28px, 6vw, 58px);
  border-radius: 30px;
  background: #fff;
  box-shadow: var(--shadow);
}
.legal-card > .eyebrow { color: var(--purple); }
.legal-card h1 {
  margin: 0;
  font: 700 clamp(36px, 6vw, 52px) "Fredoka", ui-rounded, system-ui, sans-serif;
}
.legal-updated { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.legal-card section { padding-top: 25px; margin-top: 25px; border-top: 1px solid #ebe9f3; }
.legal-card h2 { margin: 0 0 10px; color: var(--purple); font: 700 21px "Fredoka", ui-rounded, system-ui, sans-serif; }
.legal-card p { margin: 9px 0 0; color: #55536a; line-height: 1.75; }
.legal-card a { color: var(--purple); font-weight: 800; }

.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 100; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 18px; border-radius: 3px; animation: fall 2.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .7; } }

html[data-theme="dark"] {
  color-scheme: dark;
  background: #12111d;
  --ink: #f4f1ff;
  --muted: #aaa7be;
  --purple: #9689fa;
  --purple-dark: #8274ed;
  --purple-soft: #302b53;
  --mint-soft: #163d35;
  --orange-soft: #49321f;
  --white: #211f35;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 8% 15%, rgba(255, 156, 66, .08), transparent 18rem),
    radial-gradient(circle at 92% 18%, rgba(103, 87, 232, .16), transparent 22rem),
    #12111d;
}

html[data-theme="dark"] .topbar {
  background: rgba(26, 24, 42, .88);
  border-bottom-color: rgba(255,255,255,.07);
}

html[data-theme="dark"] .grade-card,
html[data-theme="dark"] .progress-card,
html[data-theme="dark"] .setup-card,
html[data-theme="dark"] .quiz-card,
html[data-theme="dark"] .result-card,
html[data-theme="dark"] .legal-card {
  background: #211f35;
  box-shadow: var(--shadow);
}

html[data-theme="dark"] .icon-button { background: #302b53; color: #c9c1ff; }
html[data-theme="dark"] .star-count { background: #40351c; color: #ffd36b; }
html[data-theme="dark"] .xp-count { background: #163d35; color: #70e0c4; }
html[data-theme="dark"] .avatar-button { border-color: #4a4660; background: #29263d; }
html[data-theme="dark"] .avatar-button i { border-color: #211f35; }
html[data-theme="dark"] .progress-icon { background: #40351c; }
html[data-theme="dark"] .progress-track,
html[data-theme="dark"] .round-progress > div { background: #373448; }
html[data-theme="dark"] .mode-card { background: #29263d; border-color: #3d3952; }
html[data-theme="dark"] .mode-card.selected { background: #302b53; border-color: var(--purple); }
html[data-theme="dark"] .length-picker { background: #312e43; }
html[data-theme="dark"] .number-pad button { color: var(--ink); background: #302d45; }
html[data-theme="dark"] .number-pad button:hover { background: #3b3564; color: #c9c1ff; }
html[data-theme="dark"] .number-pad .hint-key { background: #40381f; }
html[data-theme="dark"] .number-pad .delete-key { background: #472634; }
html[data-theme="dark"] .answer-box { background: #292642; }
html[data-theme="dark"] .answer-box.correct { background: #163d35; }
html[data-theme="dark"] .answer-box.wrong { background: #472634; }
html[data-theme="dark"] .visual-hint { color: #f0db9d; background: #40381f; }
html[data-theme="dark"] .hint-group { background: rgba(255,255,255,.09); }
html[data-theme="dark"] .streak { background: #49321f; color: #ffb46f; }
html[data-theme="dark"] .result-score div { background: #29263d; }
html[data-theme="dark"] .avatar-card { background: #211f35; }
html[data-theme="dark"] .avatar-card.selected { background: #163d35; }
html[data-theme="dark"] .avatar-card small { background: #40351c; color: #ffd36b; }
html[data-theme="dark"] .avatar-card small.owned { background: #163d35; color: #70e0c4; }
html[data-theme="dark"] .back-button:hover { background: #211f35; }
html[data-theme="dark"] .legal-page { background: #12111d; }
html[data-theme="dark"] .legal-card section { border-top-color: #39364b; }
html[data-theme="dark"] .legal-card p { color: #c4c1d1; }
html[data-theme="dark"] .legal-back { color: #c9c1ff; background: #302b53; }

@media (max-width: 760px) {
  .topbar { padding: 0 18px; height: 68px; }
  .brand { font-size: 18px; }.brand-mark { width: 38px; height: 38px; }
  .install-button { position: fixed; right: 16px; bottom: 16px; z-index: 20; box-shadow: var(--shadow); }
  .xp-count { display: none; }
  main { width: min(100% - 24px, 600px); }
  .screen { padding: 22px 0 40px; }
  .hero { min-height: 390px; padding: 32px 27px; grid-template-columns: 1fr; }
  .hero-copy { z-index: 3; }.hero-copy > p:last-child { font-size: 15px; }
  .hero-visual { min-height: 150px; transform: scale(.75); margin: -4px 0 -35px; }
  .grade-grid { grid-template-columns: 1fr; }
  .grade-card { min-height: 108px; padding: 18px; }
  .section-heading { align-items: start; margin-top: 32px; }.section-heading > p { display: none; }
  .progress-card { grid-template-columns: auto 1fr auto; }.progress-track { grid-column: 1 / -1; grid-row: 2; }
  .setup-card, .quiz-card, .result-card { padding: 30px 20px; border-radius: 24px; }
  .round-settings { align-items: flex-start; flex-direction: column; }
  .length-picker { align-self: stretch; }.length-picker button { flex: 1; }
  .quiz-top { grid-template-columns: auto 1fr auto; gap: 8px; }
  .quiz-top .back-button { font-size: 0; }.quiz-top .back-button::first-letter { font-size: 22px; }
  .equation { gap: 10px; font-size: 42px; }
  .equation.long { gap: 5px; font-size: 27px; }
  .equation.long .answer-box { min-width: 65px; height: 60px; border-radius: 14px; }
  .answer-box { min-width: 75px; height: 72px; border-radius: 17px; }
  .result-actions { grid-template-columns: 1fr; }
  .result-score { grid-template-columns: repeat(2, 1fr); }
  .rewards-hero { padding: 26px 20px; grid-template-columns: auto 1fr; gap: 18px; }
  .profile-avatar { width: 78px; height: 78px; border-radius: 24px; font-size: 43px; }
  .profile-info h1 { font-size: 29px; }
  .wallet { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .shop-heading > p { display: none; }
  .avatar-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .avatar-card { min-height: 165px; padding-inline: 8px; }
  footer { flex-wrap: wrap; padding: 15px; }
  .legal-page .topbar { position: sticky; top: 0; }
  .legal-back { padding: 8px 10px; font-size: 13px; }
  .legal-actions { gap: 6px; }
  .legal-main { padding: 24px 0; }
  .legal-card { border-radius: 22px; }
}

@media (max-width: 520px) {
  .topbar { height: 64px; padding: 0 10px; }
  .brand { flex: 0 0 auto; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 17px; }
  .top-actions { min-width: 0; gap: 5px; }
  .star-count { height: 38px; padding: 0 9px; font-size: 13px; }
  .star-count span { font-size: 17px; }
  .topbar .icon-button { width: 38px; height: 38px; border-radius: 11px; }
  .avatar-button { width: 40px; height: 40px; border-radius: 12px; }
  .avatar-button span { font-size: 22px; }

  main { width: calc(100% - 16px); }
  .screen { padding-top: 16px; }
  .hero { min-height: 368px; padding: 28px 20px; border-radius: 25px; }
  .hero h1 { font-size: clamp(32px, 10vw, 40px); }
  .hero-copy > p:last-child { margin-top: 14px; line-height: 1.5; }
  .hero-visual { transform: scale(.68); margin-top: -12px; }
  .section-heading { margin-inline: 4px; }
  .section-heading h2 { font-size: 25px; }
  .grade-card { padding: 16px; gap: 7px 12px; border-radius: 20px; }
  .grade-icon { width: 52px; height: 52px; border-radius: 16px; }
  .grade-info strong { font-size: 19px; }
  .progress-card { padding: 17px 15px; gap: 11px; }

  .setup-card, .quiz-card, .result-card { padding: 26px 14px; border-radius: 21px; }
  .setup-card h1 { font-size: 29px; }
  .mode-card { padding: 12px; gap: 10px; }
  .mode-symbol { width: 44px; height: 44px; border-radius: 13px; }
  .mode-card strong { font-size: 16px; }
  .mode-card small { font-size: 12px; }
  .round-settings { margin-block: 24px; }

  .quiz-top { grid-template-columns: 38px minmax(0, 1fr) 53px; gap: 6px; }
  .round-progress { min-width: 0; gap: 7px; font-size: 12px; }
  .streak { padding: 7px 8px; font-size: 13px; }
  .equation { width: 100%; gap: 6px; font-size: clamp(31px, 10vw, 39px); }
  .equation .answer-box { min-width: 64px; height: 65px; padding-inline: 6px; border-radius: 15px; }
  .equation.long { gap: 3px; font-size: clamp(22px, 7vw, 27px); }
  .equation.long .answer-box { min-width: 58px; height: 56px; }
  .number-pad { width: min(330px, 100%); }
  .number-pad button { height: 50px; }
  .check-button, .next-button { width: min(330px, 100%); }

  .result-card h1 { font-size: 37px; }
  .result-score { gap: 7px; }
  .result-score div { padding: 15px 5px; }
  .result-score strong { font-size: 21px; }

  .rewards-hero { padding: 22px 14px; gap: 13px; border-radius: 23px; }
  .profile-avatar { width: 70px; height: 70px; font-size: 38px; }
  .profile-info h1 { font-size: 26px; }
  .profile-info > p:not(.eyebrow) { font-size: 13px; }
  .shop-heading h2 { font-size: 24px; }
  .avatar-card strong { font-size: 13px; }

  footer { gap: 7px; font-size: 11px; }
  .legal-main { width: calc(100% - 16px); }
  .legal-page .topbar { padding-inline: 10px; }
}

@media (max-width: 370px) {
  .star-count { padding-inline: 7px; }
  .topbar .icon-button { width: 35px; height: 35px; }
  .avatar-button { width: 37px; height: 37px; }
  .hero { padding-inline: 17px; }
  .equation { font-size: 29px; gap: 4px; }
  .equation.long { font-size: 21px; }
  .avatar-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
