:root {
  color-scheme: dark;
  --panel: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.18);
  --text: #f7fbff;
  --muted: rgba(247, 251, 255, 0.72);
  --primary: #6ee7f0;
  --primary-2: #8b7cff;
  --gold: #f7c948;
  --ok: #42e9a3;
  --bad: #ff6b7e;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --radius: 8px;
}

[data-theme="light"] {
  color-scheme: light;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(30, 41, 59, 0.16);
  --text: #172033;
  --muted: rgba(23, 32, 51, 0.72);
  --primary: #116bd8;
  --primary-2: #5b5ff0;
  --gold: #b77900;
  --ok: #087a57;
  --bad: #bf2844;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
html { min-width: 320px; }
body {
  margin: 0;
  background: #070b1d url("/assets/mathfun-bg.png") center / cover fixed no-repeat;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(5, 8, 24, 0.44), rgba(5, 8, 24, 0.58)),
    radial-gradient(ellipse at 50% 42%, rgba(6, 10, 30, 0.08), rgba(6, 10, 30, 0.6) 72%);
  pointer-events: none;
}
[data-theme="light"] body::before {
  background:
    linear-gradient(180deg, rgba(244, 248, 255, 0.76), rgba(233, 240, 252, 0.86)),
    radial-gradient(ellipse at 50% 42%, rgba(255, 255, 255, 0.28), rgba(214, 226, 248, 0.64) 72%);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 24px;
}
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 64px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(110, 231, 240, .22);
}
.brand h1 {
  color: var(--text);
  margin: 0;
  font-size: 2.05rem;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 10px 28px rgba(0, 0, 0, .34);
}
.brand p { margin: 5px 0 0; color: var(--muted); font-weight: 700; }
[data-theme="light"] .brand h1 {
  color: #071329;
  text-shadow: 0 2px 18px rgba(255, 255, 255, .86);
}
[data-theme="light"] .brand p {
  color: rgba(7, 19, 41, .76);
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.lang-switch { display: flex; gap: 6px; }
.lang-switch .icon-btn { min-width: 46px; padding-inline: 10px; }

.icon-btn, .pill, .primary-btn, .choice, .key, .link-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  min-height: 42px;
  padding: 10px 13px;
  font-weight: 800;
  letter-spacing: 0;
  backdrop-filter: blur(14px) saturate(1.14);
  transition: transform .14s ease, border-color .14s ease, background .14s ease, box-shadow .14s ease;
}
.top-actions .icon-btn,
.top-actions .primary-btn {
  min-width: 0;
  white-space: nowrap;
}
.icon-btn:hover, .pill:hover, .primary-btn:hover, .choice:hover, .key:hover, .link-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(110, 231, 240, .52);
}
.icon-btn[aria-pressed="true"], .pill.active, .choice.correct, .key.enter, .primary-btn {
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  border-color: rgba(255,255,255,.44);
  color: #06111f;
  box-shadow: 0 18px 42px rgba(86, 130, 255, .24);
}
.choice.wrong { border-color: rgba(255, 107, 126, .75); background: rgba(255, 107, 126, .18); }
.choice.correct { color: #06111f; }
.primary-btn.big { min-height: 52px; padding-inline: 22px; font-size: 1.05rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
  margin-top: 18px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(1.2);
}
.stage { padding: clamp(16px, 3vw, 26px); min-width: 0; }
.side { display: grid; gap: 16px; }
.side .panel { padding: 16px; }

.mode-grid, .settings-grid { display: grid; gap: 10px; min-width: 0; }
.mode-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.settings-grid { align-items: stretch; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 12px; }
.field { display: grid; gap: 7px; min-width: 0; }
.settings-grid .field {
  background: rgba(255,255,255,.075);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: var(--radius);
  padding: 12px;
}
[data-theme="light"] .settings-grid .field {
  background: rgba(255,255,255,.62);
  border-color: rgba(30, 41, 59, .14);
}
.label { color: var(--muted); font-size: .78rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.settings-grid .label {
  color: var(--text);
}
.segment { display: flex; gap: 6px; flex-wrap: wrap; }
.segment .pill { flex: 1 1 auto; padding-inline: 10px; white-space: nowrap; }
.settings-grid .segment .pill:not(.active) {
  background: rgba(255,255,255,.07);
}
[data-theme="light"] .settings-grid .segment .pill:not(.active) {
  background: rgba(255,255,255,.7);
}

.hero-card { margin-top: 16px; min-height: 385px; display: grid; gap: 16px; min-width: 0; }
.score-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stat {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.1);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 0;
}
.stat span { display: block; color: var(--muted); font-size: .72rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.stat strong { display: block; font-size: 1.45rem; line-height: 1.1; overflow-wrap: anywhere; }
.timer-track, .bar-track { height: 8px; border-radius: 999px; background: rgba(255,255,255,.14); overflow: hidden; }
.timer-track > span, .bar-track > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--primary), var(--primary-2));
  transition: width .2s ease;
}
.problem-wrap { display: grid; place-items: center; gap: 14px; text-align: center; min-height: 160px; }
.problem {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(8px, 2vw, 16px);
  font-size: 5.6rem;
  line-height: 1;
  font-weight: 950;
  letter-spacing: 0;
  text-shadow: 0 12px 36px rgba(0,0,0,.3);
}
.problem .slot { min-width: 1.25em; color: var(--gold); border-bottom: 5px solid currentColor; }
.coach-line { color: var(--muted); font-weight: 750; min-height: 1.5em; }
.answer-zone { display: grid; gap: 12px; justify-items: center; }
.answer-input {
  width: min(100%, 280px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.92);
  color: #0f172a;
  min-height: 60px;
  text-align: center;
  font-size: 2rem;
  font-weight: 950;
  padding: 8px 14px;
  outline: none;
}
.answer-input:focus { box-shadow: 0 0 0 4px rgba(110, 231, 240, .22); border-color: rgba(110, 231, 240, .65); }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(100%, 520px); }
.choice {
  align-items: center;
  display: grid;
  font-size: 1.35rem;
  gap: 14px;
  grid-template-columns: 34px minmax(0, 1fr);
  justify-items: center;
  min-height: 62px;
  padding-inline: 12px 18px;
}
.choice-index {
  align-items: center;
  background: rgba(255,255,255,.14);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: inline-flex;
  font-size: .92rem;
  height: 34px;
  justify-content: center;
  line-height: 1;
  width: 34px;
}
.choice-value {
  font-size: 1.45rem;
  font-weight: 950;
  justify-self: center;
  min-width: 0;
  overflow-wrap: anywhere;
}
.choice.correct .choice-index {
  background: rgba(6, 17, 31, .12);
  color: #06111f;
}
.keypad { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; width: min(100%, 560px); }
.key { min-height: 48px; padding: 0; font-size: 1.15rem; }
.key.enter { grid-column: span 2; }
.feedback { min-height: 36px; font-weight: 900; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.side h2 { margin: 0 0 12px; font-size: 1rem; letter-spacing: 0; }
.achievement-list, .history-list, .review-list { display: grid; gap: 8px; }
.badge-row, .history-item, .review-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.09);
  padding: 10px;
}
.badge-row { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: center; }
.badge-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(247,201,72,.16);
  color: var(--gold);
  font-weight: 950;
}
.badge-row.locked { opacity: .48; }
.badge-row strong, .history-item strong, .review-item strong { display: block; }
.badge-row span, .history-item span, .review-item span { color: var(--muted); font-size: .86rem; font-weight: 700; }
.skill-row { display: grid; gap: 9px; }
.skill-line { display: grid; gap: 5px; }
.skill-label { display: flex; justify-content: space-between; color: var(--muted); font-size: .84rem; font-weight: 800; }
.empty { color: var(--muted); font-weight: 750; }

.toast {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  z-index: 20;
  border: 1px solid rgba(247, 201, 72, .45);
  border-radius: var(--radius);
  background: rgba(7, 11, 29, .88);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  font-weight: 900;
  backdrop-filter: blur(14px);
}
.hidden { display: none !important; }

.site-foot {
  align-items: center;
  color: rgba(247, 251, 255, .66);
  display: flex;
  font-size: .78rem;
  font-weight: 800;
  gap: 10px;
  justify-content: flex-end;
  margin: 12px 2px 0;
  position: relative;
  z-index: 1;
}
[data-theme="light"] .site-foot {
  color: rgba(7, 19, 41, .58);
}
.foot-link {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.foot-link:hover { color: var(--primary); }

.cookie-pop {
  align-items: center;
  background: rgba(7, 11, 29, .9);
  backdrop-filter: blur(18px) saturate(1.15);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: var(--radius);
  bottom: 16px;
  box-shadow: var(--shadow);
  color: #f7fbff;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  left: 50%;
  padding: 16px;
  position: fixed;
  transform: translateX(-50%);
  width: min(940px, calc(100% - 28px));
  z-index: 30;
}
.cookie-pop h2 {
  font-size: 1rem;
  letter-spacing: 0;
  margin: 0 0 5px;
}
.cookie-pop p {
  color: rgba(247, 251, 255, .72);
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.45;
  margin: 0;
}
.cookie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.85rem; }
  .mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .problem { font-size: 4.4rem; }
  .side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side .panel:first-child,
  .side .panel:last-child { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  body { background-attachment: scroll; }
  .shell { width: min(100% - 18px, 1180px); padding-top: 10px; }
  .topbar { grid-template-columns: 1fr; }
  .top-actions { justify-content: stretch; }
  .top-actions > * { flex: 1; }
  .lang-switch { flex: 1 1 100%; }
  .lang-switch .icon-btn { flex: 1; }
  .top-actions .icon-btn,
  .top-actions .primary-btn {
    font-size: .9rem;
    padding-inline: 9px;
  }
  .brand p { display: none; }
  .brand h1 { font-size: 1.6rem; }
  .stage { padding: 14px; }
  .side { grid-template-columns: 1fr; gap: 12px; }
  .score-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:last-child { grid-column: span 2; }
  .mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-grid .pill span { display: none; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid .field:last-child { grid-column: 1 / -1; }
  .field { gap: 5px; }
  .settings-grid .field { padding: 10px; }
  .label { font-size: .7rem; }
  .segment .pill { min-height: 38px; padding: 8px 9px; }
  .hero-card { min-height: 0; }
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice {
    gap: 10px;
    grid-template-columns: 30px minmax(0, 1fr);
    min-height: 56px;
    padding-inline: 9px 12px;
  }
  .choice-index {
    font-size: .82rem;
    height: 30px;
    width: 30px;
  }
  .choice-value { font-size: 1.28rem; }
  .keypad { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .key.enter { grid-column: span 3; }
  .problem { font-size: 3.5rem; }
  .problem-wrap { min-height: 130px; }
  .cookie-pop {
    grid-template-columns: 1fr;
    gap: 10px;
    max-height: min(72vh, 420px);
    overflow: auto;
  }
  .cookie-pop h2 { margin-bottom: 3px; }
  .cookie-pop p {
    font-size: .84rem;
    line-height: 1.32;
  }
  .cookie-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .site-foot { justify-content: center; }
}
@media (max-width: 440px) {
  .shell { width: min(100% - 12px, 1180px); }
  .brand { gap: 9px; }
  .logo { height: 38px; width: 38px; }
  .brand h1 { font-size: 1.36rem; }
  .top-actions { gap: 6px; }
  .top-actions > .icon-btn,
  .top-actions > .primary-btn {
    flex: 1 1 calc(50% - 6px);
  }
  .top-actions .icon-btn,
  .top-actions .primary-btn {
    min-height: 38px;
    padding: 8px 7px;
  }
  .mode-grid,
  .settings-grid,
  .hero-card { gap: 10px; }
  .settings-grid .field { padding: 9px; }
  .pill { padding: 9px 10px; }
  .score-row { gap: 7px; }
  .stat { padding: 9px; }
  .stat span { font-size: .66rem; }
  .stat strong { font-size: 1.15rem; }
  .problem { font-size: 2.8rem; gap: 8px; }
  .answer-input {
    min-height: 54px;
    font-size: 1.7rem;
    width: min(100%, 240px);
  }
  .key { min-height: 44px; }
  .cookie-pop {
    bottom: 8px;
    padding: 12px;
    width: calc(100% - 16px);
  }
}
@media (max-width: 360px) {
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .field:last-child { grid-column: auto; }
  .choice-grid { grid-template-columns: 1fr; }
  .top-actions .icon-btn,
  .top-actions .primary-btn { font-size: .82rem; }
  .problem { font-size: 2.45rem; }
}
