/* ВПР Тренажёр — Светлый дизайн */
:root {
  --bg: #F5F0EB;
  --surface: #FFFBF7;
  --text: #2D3142;
  --text-muted: #7A7974;
  --border: #EDEBE8;
  --accent: #5B8DEF;
  --accent-dark: #7C5CE7;
  --green: #66BB6A;
  --green-dark: #43A047;
  --green-bg: #E8F5E9;
  --green-border: #A5D6A7;
  --blue: #42A5F5;
  --blue-bg: #E3F2FD;
  --blue-border: #90CAF9;
  --orange: #FFA726;
  --orange-bg: #FFF3E0;
  --orange-border: #FFCC80;
  --purple: #AB47BC;
  --purple-bg: #F3E5F5;
  --purple-border: #CE93D8;
  --red: #E53935;
  --red-bg: #FFEBEE;
  --red-border: #EF9A9A;
  --yellow: #FFD93D;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-xl: 40px;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== SCREENS ===== */
.screen {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

/* ===== HOME ===== */
.home-header {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  padding: 36px 20px 40px;
  border-radius: 0 0 32px 32px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.home-header::before {
  content: '';
  position: absolute;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  top: -30px; right: -40px;
}
.home-header::after {
  content: '';
  position: absolute;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  top: 50px; left: -20px;
}
.home-title {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  position: relative;
  z-index: 2;
  text-shadow: 0 2px 8px rgba(0,0,0,.12);
  letter-spacing: -.02em;
}
.home-title::after {
  content: '4 класс — готовься играючи';
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.8);
  margin-top: 4px;
  text-shadow: none;
  letter-spacing: 0;
}

.home-body {
  padding: 20px 18px 0;
  flex: 1;
}

.home-greeting {
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 18px;
}
.home-greeting strong { color: var(--text); font-weight: 700; }

/* Subject grid */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.subject-card {
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  font-size: inherit;
}
.subject-card:active { transform: scale(.96); }

.subject-card.env  { background: linear-gradient(145deg, #E8F5E9, #C8E6C9); border-color: var(--green-border); }
.subject-card.math { background: linear-gradient(145deg, #E3F2FD, #BBDEFB); border-color: var(--blue-border); }
.subject-card.rus  { background: linear-gradient(145deg, #FFF3E0, #FFE0B2); border-color: var(--orange-border); }
.subject-card.lit  { background: linear-gradient(145deg, #F3E5F5, #E1BEE7); border-color: var(--purple-border); }

.subject-card-icon {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.subject-card.env  .subject-card-icon { background: var(--green);  }
.subject-card.math .subject-card-icon { background: var(--blue);   }
.subject-card.rus  .subject-card-icon { background: var(--orange); }
.subject-card.lit  .subject-card-icon { background: var(--purple); }

.subject-card-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  line-height: 1.25;
}

/* Today progress */
.today-progress { margin-bottom: 16px; }
.today-progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.today-progress-header span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.today-bar {
  height: 8px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.today-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 6px;
  transition: width .5s ease;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  flex: 1;
  background: #F0ECE6;
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}
.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Random button */
.btn-random {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(91,141,239,.28);
  transition: transform .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-random:active { transform: scale(.97); }

/* Bottom nav */
.bottom-nav {
  display: flex;
  justify-content: space-around;
  padding: 10px 0 env(safe-area-inset-bottom, 16px);
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 4px 12px;
}
.nav-icon { font-size: 20px; }
.nav-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.nav-btn.active .nav-label { color: var(--accent); }

/* ===== QUIZ ===== */
.quiz-header {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  padding: 16px 18px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.quiz-exit {
  background: none; border: none;
  color: rgba(255,255,255,.9);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.quiz-subject-badge {
  background: rgba(255,255,255,.2);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.quiz-meta {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  padding: 0 18px 20px;
  border-radius: 0 0 24px 24px;
}
.quiz-topic-label {
  display: block;
  font-size: 13px;
  color: rgba(255,255,255,.85);
  font-weight: 600;
  margin-bottom: 10px;
}
.quiz-progress-segments {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
}
.progress-segment {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,.25);
  transition: background .3s ease;
}
.progress-segment.done { background: #fff; }
.progress-segment.current { background: var(--yellow); box-shadow: 0 0 6px rgba(255,217,61,.5); }
.quiz-progress-text {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,.8);
}

.quiz-body {
  padding: 14px 18px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.question-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,.05);
  border-left: 4px solid var(--green);
  margin-bottom: 16px;
}
.question-topic-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--green);
  margin-bottom: 6px;
}
.question-text {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
}

/* Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #F8F5F1;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: all .12s ease;
  font-family: inherit;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.option-btn:active:not(:disabled) { transform: scale(.98); }
.option-btn:disabled { cursor: default; }

.option-btn.correct {
  border-color: var(--green-dark) !important;
  background: var(--green-bg) !important;
}
.option-btn.wrong {
  border-color: var(--red) !important;
  background: var(--red-bg) !important;
}

.option-letter {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  color: var(--text-muted);
  background: var(--border);
  flex-shrink: 0;
  transition: all .12s ease;
}
.option-btn.correct .option-letter { background: var(--green-dark); color: #fff; }
.option-btn.wrong   .option-letter { background: var(--red); color: #fff; }

.option-text {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  text-align: left;
  flex: 1;
}

/* Feedback */
.quiz-feedback {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  margin-top: 12px;
}
.feedback-correct {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: #2E7D32;
}
.feedback-wrong {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: #C62828;
}

/* Next button */
.btn-next {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
  box-shadow: 0 6px 16px rgba(67,160,71,.22);
  -webkit-tap-highlight-color: transparent;
}
.btn-next:active { transform: scale(.97); }

/* ===== RESULT ===== */
.result-header {
  background: linear-gradient(135deg, #FFB74D, #FF9800);
  padding: 28px 20px 36px;
  border-radius: 0 0 28px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.result-header::before {
  content: '';
  position: absolute;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  top: -30px; left: -30px;
}
.result-trophy { font-size: 48px; }
.result-title {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  margin-top: 4px;
  text-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.result-subtitle {
  font-size: 13px;
  color: rgba(255,255,255,.85);
  margin-top: 2px;
}

.result-body {
  padding: 16px 18px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Streak badge */
.streak-badge {
  background: #FFF8E1;
  border: 1px solid #FFE082;
  border-radius: 12px;
  padding: 8px 14px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #F57F17;
  margin-bottom: 14px;
}

/* Score circle */
.result-score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 0 16px;
}
.score-circle-wrap {
  position: relative;
  width: 110px; height: 110px;
}
.score-circle {
  width: 110px; height: 110px;
  transform: rotate(-90deg);
}
.score-circle-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}
.score-circle-fill {
  fill: none;
  stroke: var(--green);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 0 251.3;
  transition: stroke-dasharray .8s ease;
}
.score-circle-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.score-big { font-size: 28px; font-weight: 900; color: var(--text); }
.score-pct { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.result-stats-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

/* Topics breakdown */
.topics-section { margin: 8px 0 12px; }
.topics-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.topics-list { display: flex; flex-direction: column; gap: 6px; }
.topic-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #F8F5F1;
  border-radius: 14px;
}
.topic-icon-correct,
.topic-icon-wrong {
  width: 26px; height: 26px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.topic-icon-correct { background: var(--green-bg); color: var(--green-dark); }
.topic-icon-wrong   { background: var(--red-bg); color: var(--red); }
.topic-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); }
.status-correct {
  font-size: 11px; font-weight: 700;
  background: var(--green-bg); color: #2E7D32;
  border-radius: 8px; padding: 2px 8px;
}
.status-wrong {
  font-size: 11px; font-weight: 700;
  background: var(--red-bg); color: #C62828;
  border-radius: 8px; padding: 2px 8px;
}

/* Result tip */
.result-tip {
  background: linear-gradient(135deg, #EDE7F6, #E8EAF6);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #5B4A9E;
  line-height: 1.4;
  margin-bottom: 14px;
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(91,141,239,.25);
  margin-bottom: 8px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { transform: scale(.97); }

.btn-ghost {
  width: 100%;
  padding: 13px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ===== PROGRESS ===== */
.progress-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.progress-header h2 {
  font-size: 18px;
  font-weight: 800;
  margin-top: 8px;
}
.back-btn {
  background: none; border: none;
  font-family: inherit;
  font-size: 14px; font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.progress-body {
  padding: 18px;
  flex: 1;
}
.progress-body pre {
  font-family: inherit;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .screen { min-height: 100dvh; }
  .home-header { padding: 28px 16px 32px; }
  .home-body { padding: 16px 14px 0; }
  .quiz-body { padding: 12px 14px 20px; }
  .result-body { padding: 14px 14px 20px; }
}

/* ============================================================
   DARK THEME — append to styles.css
   Activated by adding class "dark" to <html>
   ============================================================ */

/* ---------- CSS variable overrides ---------- */
html.dark {
  --bg:         #1A1A2E;
  --surface:    #222240;
  --text:       #E8E6E3;
  --text-muted: #9B9A97;
  --border:     #3A3A52;
  --accent:     #6B9EFF;
}

/* ---------- Body / page background ---------- */
html.dark body {
  background: var(--bg);
  color: var(--text);
}

/* ---------- Subject cards ---------- */
html.dark .subject-card.env {
  background: linear-gradient(135deg, #1C3A2A 0%, #1A3028 100%);
}
html.dark .subject-card.math {
  background: linear-gradient(135deg, #1A2E4A 0%, #18294A 100%);
}
html.dark .subject-card.rus {
  background: linear-gradient(135deg, #3A1A2E 0%, #301826 100%);
}
html.dark .subject-card.lit {
  background: linear-gradient(135deg, #3A2E18 0%, #2E2616 100%);
}

/* ---------- Home header gradient ---------- */
html.dark .home-header {
  background: linear-gradient(135deg, #1E1E3A 0%, #16163A 100%);
  border-bottom: 1px solid var(--border);
}

/* ---------- Quiz header gradient ---------- */
html.dark .quiz-header {
  background: linear-gradient(135deg, #1E1E3A 0%, #16163A 100%);
  border-bottom: 1px solid var(--border);
}

/* ---------- Result header gradient ---------- */
html.dark .result-header {
  background: linear-gradient(135deg, #1A2E1E 0%, #152616 100%);
  border-bottom: 1px solid var(--border);
}

/* ---------- Stat cards ---------- */
html.dark .stat-card {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

/* ---------- Option buttons ---------- */
html.dark .option-btn {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
html.dark .option-btn:hover,
html.dark .option-btn:focus {
  background: #2A2A50;
  border-color: var(--accent);
}
html.dark .option-btn.correct {
  background: #1A3A22;
  border-color: #4CAF7A;
  color: #7DEBA0;
}
html.dark .option-btn.wrong {
  background: #3A1A1A;
  border-color: #CF6679;
  color: #F09AA8;
}

/* ---------- Question card ---------- */
html.dark .question-card {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

/* ---------- Topic rows ---------- */
html.dark .topic-row {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
html.dark .topic-row:hover {
  background: #2A2A50;
}

/* ---------- Today / progress bar track ---------- */
html.dark .today-bar,
html.dark .progress-track {
  background: var(--border);
}

/* ---------- Bottom navigation ---------- */
html.dark .bottom-nav {
  background: var(--surface);
  border-top: 1px solid var(--border);
}
html.dark .nav-btn {
  color: var(--text-muted);
}
html.dark .nav-btn.active {
  color: var(--accent);
}

/* ---------- Text colour helpers ---------- */
html.dark h1,
html.dark h2,
html.dark h3,
html.dark h4 {
  color: var(--text);
}
html.dark p,
html.dark span,
html.dark label {
  color: var(--text);
}
html.dark .text-muted,
html.dark .setting-desc,
html.dark .topic-meta {
  color: var(--text-muted);
}

/* ---------- Generic surfaces ---------- */
html.dark .screen,
html.dark .card {
  background: var(--surface);
}
html.dark .back-btn {
  color: var(--accent);
  background: transparent;
}

/* ============================================================
   SETTINGS SCREEN STYLES
   ============================================================ */

.settings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.settings-body {
  padding: 16px 20px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child {
  border-bottom: none;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.setting-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.setting-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- iOS-style toggle switch ---------- */
.theme-toggle {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.toggle-track {
  display: inline-flex;
  align-items: center;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #CDCDD4;
  padding: 2px;
  transition: background 0.25s ease;
  position: relative;
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.25s ease;
  transform: translateX(0);
}

/* Active (dark mode ON) state */
html.dark .toggle-track {
  background: var(--accent);
}
html.dark .toggle-thumb {
  transform: translateX(20px);
}

/* Also support explicit aria-pressed on the button */
.theme-toggle[aria-pressed="true"] .toggle-track {
  background: var(--accent);
}
.theme-toggle[aria-pressed="true"] .toggle-thumb {
  transform: translateX(20px);
}
