:root {
  --bg: #F5FAFB;
  --card: #FFFFFF;
  --ink: #0E2430;
  --ink-soft: #5E7783;
  --azure: #0090A8;
  --azure-dark: #036C88;
  --sun: #FEC50C;
  --sun-ink: #6B4E00;
  --line: #DCEBEE;
  --green: #1E9E5A; --green-bg: #E4F7ED;
  --red: #E0453B; --red-bg: #FDEAE8;
  --purple: #7C5CBF; --purple-bg: #EFE8FB;
}
[data-theme="dark"] {
  --bg: #061B22;
  --card: #0C2A34;
  --ink: #E8F5F7;
  --ink-soft: #93B4BC;
  --azure: #1BB6CF;
  --azure-dark: #1BB6CF;
  --sun: #FFD84D;
  --sun-ink: #3A2C00;
  --line: #123B47;
  --green: #57D690; --green-bg: #0E3323;
  --red: #F08076; --red-bg: #3A1712;
  --purple: #A98DE0; --purple-bg: #241A3D;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', 'Inter', -apple-system, sans-serif;
  transition: background .2s, color .2s;
  overflow-x: hidden;
  width: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

.screen { display: none; padding: 20px 18px 24px; min-width: 0; }
.screen.active { display: block; flex: 1 0 auto; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; min-height: 32px; }
.brand { font-weight: 800; font-size: 16px; }
.brand span { color: var(--azure); font-weight: 600; }

.icon-btn {
  border: none; background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.quiz-counter { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

/* ---- switches / rows ---- */
.kid-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px;
  box-shadow: 0 1px 6px rgba(6,60,70,.05);
}
.kid-row .label { font-size: 14px; font-weight: 600; }
.kid-row .sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: .2s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--azure); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.kid-note { font-size: 12px; color: var(--ink-soft); margin: -6px 0 16px; padding: 0 2px; display: none; }
.kid-note.show { display: block; }

/* ---- hero ---- */
.hero { margin-bottom: 18px; }
.hero h1 { font-size: 21px; margin: 0 0 4px; font-weight: 800; }
.hero p { font-size: 13.5px; color: var(--ink-soft); margin: 0; line-height: 1.5; }

/* ---- mode cards ---- */
.mode-card {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border-radius: 16px; padding: 16px; margin-bottom: 12px; cursor: pointer;
  box-shadow: 0 1px 8px rgba(6,60,70,.06); border: 1.5px solid transparent;
  width: 100%; text-align: left; font-family: inherit; color: var(--ink);
}
.mode-card:active { border-color: var(--azure); }
.mode-card.hidden { display: none; }
.mode-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; font-size: 19px;
}
.mode-title { font-size: 14.5px; font-weight: 700; margin: 0 0 2px; }
.mode-sub { font-size: 12px; color: var(--ink-soft); margin: 0; line-height: 1.4; }

/* ---- quiz ---- */
.head-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.ring-wrap { position: relative; width: 52px; height: 52px; flex-shrink: 0; }
svg.ring { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--sun); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 145; stroke-dashoffset: 145; transition: stroke-dashoffset .3s; }
.ring-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 11px; }
.cat-chip { display: inline-block; background: var(--azure); color: #fff; font-weight: 700; font-size: 11px; padding: 5px 10px; border-radius: 999px; }
.pts { font-size: 11.5px; color: var(--ink-soft); font-weight: 600; }

.q-card { background: var(--card); border-radius: 18px; padding: 20px 18px; box-shadow: 0 1px 10px rgba(6,60,70,.06); }
.q-text { font-size: 16px; font-weight: 700; line-height: 1.45; margin: 0 0 16px; }

.options { display: grid; gap: 8px; }
.opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--bg); border: 1.5px solid transparent; border-radius: 12px;
  padding: 11px 12px; cursor: pointer; font-family: inherit; color: var(--ink); }
.opt-badge { width: 22px; height: 22px; border-radius: 50%; background: var(--card);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 11px; color: var(--azure); flex-shrink: 0; }
.opt-text { font-size: 13.5px; font-weight: 600; }
.opt.correct { border-color: var(--green); background: var(--green-bg); }
.opt.correct .opt-badge { background: var(--green); color: #fff; }
.opt.wrong { border-color: var(--red); background: var(--red-bg); }
.opt.wrong .opt-badge { background: var(--red); color: #fff; }
.opt:disabled { cursor: default; }

.comment { display: none; margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  background: var(--bg); font-size: 12.5px; line-height: 1.55; border-left: 4px solid var(--sun); }
.comment.show { display: block; }

.next-btn {
  display: none; margin-top: 16px; width: 100%; padding: 13px;
  background: var(--azure); color: #fff; border: none; border-radius: 12px;
  font-weight: 700; font-size: 13.5px; cursor: pointer;
}
.next-btn.show { display: block; }

/* ---- result ---- */
.score-card { background: var(--card); border-radius: 18px; padding: 24px 18px; text-align: center; margin-bottom: 16px; box-shadow: 0 1px 10px rgba(6,60,70,.06); }
.score-num { font-size: 40px; font-weight: 800; color: var(--azure); }
.score-num span { font-size: 20px; color: var(--ink-soft); font-weight: 600; }
.score-total { font-size: 15px; color: var(--ink-soft); margin-bottom: 10px; }
.verdict { display: inline-block; background: var(--green-bg); color: var(--green); font-size: 12.5px; font-weight: 700; padding: 5px 14px; border-radius: 999px; }

.breakdown { background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 8px rgba(6,60,70,.05); }
.bd-title { font-size: 12px; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; margin: 0 0 12px; }
.bd-row { margin-bottom: 10px; }
.bd-label { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.bd-track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bd-fill { height: 100%; background: var(--azure); }

.redo-btn { width: 100%; padding: 14px; background: var(--azure); color: #fff; border: none; border-radius: 14px; font-weight: 700; font-size: 14px; cursor: pointer; margin-bottom: 10px; }
.errors-btn {
  width: 100%; padding: 14px; background: var(--purple-bg); color: var(--purple); border: none;
  border-radius: 14px; font-weight: 700; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.version-note { text-align: center; font-size: 11.5px; color: var(--ink-soft); margin-top: 22px; }

/* ---- bottom nav ---- */
.bottom-nav {
  position: sticky; bottom: 0; left: auto; transform: none;
  width: 100%; height: 68px; flex: 0 0 auto;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-around; padding-bottom: 4px;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer; color: var(--ink-soft); font-family: inherit;
  padding: 4px 14px;
}
.nav-item.active { color: var(--azure); }
.nav-item i { font-size: 19px; }
.nav-item span { font-size: 10px; font-weight: 600; }

.loading-hint { text-align: center; color: var(--ink-soft); font-size: 13px; padding: 30px 0; }
.error-hint { text-align: center; color: var(--red); font-size: 13px; padding: 30px 0; }

/* ---- language switch ---- */
.lang-switch { display: flex; gap: 6px; width: 100%; }
.lang-opt {
  flex: 1; padding: 9px 6px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink-soft); font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.lang-opt.active { border-color: var(--azure); background: var(--azure); color: #fff; }

/* ---- мини-переключатель языка в шапке каждого экрана ---- */
.topbar { min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.lang-mini { display: flex; background: var(--bg); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.lang-mini .lang-opt {
  flex: none; width: auto; border: none; border-radius: 0; padding: 6px 10px;
  font-size: 10.5px; font-weight: 700; background: transparent; color: var(--ink-soft);
}
.lang-mini .lang-opt.active { background: var(--azure); color: #fff; }

/* ---- progress: xp / streak chips ---- */
.xp-chip, .streak-chip {
  display: inline-flex; align-items: center; gap: 5px; background: var(--card);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 700;
  box-shadow: 0 1px 6px rgba(6,60,70,.06); color: var(--sun-ink);
}
.xp-chip[hidden], .streak-chip[hidden] { display: none; }
.xp-chip i { color: var(--sun); }
.streak-chip { color: #B4470E; }
[data-theme="dark"] .streak-chip { color: #FFB27A; }
.streak-chip i { color: #FF6A2B; }
.quiz-chips { display: flex; gap: 8px; margin: -6px 0 14px; }

/* ---- badges ---- */
.badges-card {
  background: var(--card); border-radius: 16px; padding: 14px 16px; margin-top: 4px;
  box-shadow: 0 1px 8px rgba(6,60,70,.05);
}
.badges-title { font-size: 12px; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; margin: 0 0 12px; }
.badges-row { display: flex; justify-content: space-between; gap: 6px; }
.badge-item { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 1; min-width: 0; position: relative; }
.badge-item::after {
  content: attr(data-tooltip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-6px);
  background: var(--ink); color: var(--bg); font-size: 11px; font-weight: 600; line-height: 1.4;
  padding: 7px 10px; border-radius: 9px; white-space: normal; width: max-content; max-width: 150px; text-align: center;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .15s ease, transform .15s ease;
  z-index: 10; box-shadow: 0 6px 16px rgba(0,0,0,.18);
}
.badge-item::before {
  content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(2px);
  border: 5px solid transparent; border-top-color: var(--ink);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .15s ease; z-index: 10;
}
.badge-item:hover::after, .badge-item:hover::before { opacity: 1; visibility: visible; }
.badge-item:hover::after { transform: translateX(-50%) translateY(-10px); }
.badge-disc {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 15px; background: var(--bg); color: var(--line); border: 2px solid var(--line);
}
.badge-disc.tier-bronze { background: linear-gradient(150deg, #EFC49B, #A65C2E); color: #3B1A06; border-color: #A65C2E; }
.badge-disc.tier-silver { background: linear-gradient(150deg, #F1F5F9, #94A3B8); color: #1E293B; border-color: #94A3B8; }
.badge-disc.tier-gold { background: linear-gradient(150deg, #FDE68A, #F59E0B); color: #2A1A02; border-color: #F59E0B; }
.badge-label { font-size: 9.5px; color: var(--ink-soft); text-align: center; line-height: 1.25; }

/* ---- badge promotion overlay ---- */
.promo-overlay {
  position: fixed; inset: 0; background: rgba(6,20,26,.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.promo-overlay[hidden] { display: none; }
.promo-card {
  background: var(--card); border-radius: 20px; padding: 28px 24px; text-align: center;
  max-width: 300px; width: 100%;
}
.promo-disc {
  width: 76px; height: 76px; border-radius: 50%; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  background: linear-gradient(150deg, #FDE68A, #F59E0B); color: #2A1A02;
}
.promo-disc.tier-bronze { background: linear-gradient(150deg, #EFC49B, #A65C2E); color: #3B1A06; }
.promo-disc.tier-silver { background: linear-gradient(150deg, #F1F5F9, #94A3B8); color: #1E293B; }
.promo-tier { font-size: 17px; font-weight: 800; margin: 0 0 2px; }
.promo-cat { font-size: 13px; color: var(--ink-soft); margin: 0 0 18px; }

/* =========================================================================
   Адаптивность: телефон (база, до 639px) → планшет (640–1023px) → десктоп (1024px+)
   ========================================================================= */

/* ---- планшет: шире колонка, больше воздуха, варианты в 2 колонки ---- */
@media (min-width: 640px) {
  .app { max-width: 640px; }
  .screen { padding: 28px 40px 32px; }
  .hero h1 { font-size: 23px; }
  .options { grid-template-columns: 1fr 1fr; }
  .badges-row { justify-content: center; gap: 22px; }
  .badge-item { flex: 0 0 auto; width: 76px; }
}

/* ---- десктоп: боковая навигация слева, широкая центрированная колонка справа ---- */
@media (min-width: 1024px) {
  body { display: flex; justify-content: center; padding: 32px 24px; }
  .app {
    max-width: 1040px; width: 100%; min-height: auto;
    flex-direction: row; align-items: flex-start; gap: 32px;
  }
  .bottom-nav {
    position: sticky; top: 32px; left: auto; transform: none; order: -1;
    width: 96px; max-width: 96px; height: auto; flex-direction: column;
    border-top: none; border-radius: 22px; padding: 24px 0; gap: 20px;
    box-shadow: 0 4px 24px rgba(6,60,70,.08); flex-shrink: 0;
  }
  .nav-item { padding: 10px 6px; }
  .nav-item i { font-size: 21px; }
  .screen { flex: 1; min-width: 0; max-width: 680px; margin: 0 auto; padding: 8px 0 40px; }
  .screen.active { display: block; }
  .options { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 25px; }
  .q-text { font-size: 18px; }
  .badges-row { justify-content: flex-start; gap: 28px; }
}
