:root {
  color-scheme: dark;
  --bg: #07090c;
  --surface: #15181d;
  --surface-2: #20242b;
  --surface-3: #2a2f38;
  --text: #f6f7f9;
  --muted: #969ca7;
  --line: rgba(255, 255, 255, .075);
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, .15);
  --accent-text: #051526;
  --good: #43d39e;
  --good-soft: rgba(67, 211, 158, .16);
  --bad: #ff7379;
  --bad-soft: rgba(255, 115, 121, .16);
  --warning: #ffbd4a;
  --shadow: 0 18px 48px rgba(0, 0, 0, .28);
  --radius: 22px;
  --nav-height: 78px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg); }
body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font: inherit; }
button { color: inherit; }
button, a { -webkit-user-select: none; user-select: none; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 58%, transparent);
  outline-offset: 2px;
}
.app-shell { min-height: 100vh; }
.page {
  width: min(100%, 620px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(var(--nav-height) + 28px + env(safe-area-inset-bottom));
  animation: page-in .28s cubic-bezier(.2, .75, .3, 1);
}
.page.no-nav { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
.loading-screen { display: grid; place-items: center; align-content: center; gap: 14px; min-height: 100vh; color: var(--muted); }
.loading-mark { width: 34px; height: 34px; border: 4px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(26px, 7vw, 34px); line-height: 1.05; letter-spacing: -.04em; }
h2 { font-size: 22px; line-height: 1.15; letter-spacing: -.025em; }
h3 { font-size: 17px; line-height: 1.2; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.screen-reader { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.icon { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.icon.flame { fill: currentColor; stroke: none; }

.header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.header-copy { min-width: 0; }
.header-copy h1, .header-copy h2 { margin-top: 5px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.icon-button, .back-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}
.back-button { margin-right: 2px; }
.icon-button:active, .back-button:active { transform: scale(.92); background: var(--surface-2); }
.streak-pill { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 8px 12px; border-radius: 15px; background: var(--surface); }
.streak-pill .icon { width: 20px; color: #ff8548; }
.streak-pill span { display: grid; line-height: 1; }
.streak-pill small { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .12em; }
.streak-pill strong { margin-top: 4px; font-size: 18px; }

.segment { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 18px; padding: 4px; border-radius: 15px; background: var(--surface-2); }
.segment button { min-height: 40px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; transition: background .16s ease, transform .16s ease; }
.segment button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 3px 13px rgba(0,0,0,.15); }
.segment button:active { transform: scale(.97); }

.hero-card {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 19px;
  border: 0;
  border-radius: 24px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 88%, #fff 12%), var(--accent));
  color: var(--accent-text);
  text-align: left;
  box-shadow: 0 18px 40px color-mix(in srgb, var(--accent) 23%, transparent);
  cursor: pointer;
  transition: transform .17s cubic-bezier(.2,.8,.3,1.2), filter .17s ease;
}
.hero-card:active { transform: scale(.975); filter: brightness(1.05); }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero-card small, .hero-card span { color: inherit; opacity: .82; }
.hero-card strong { font-size: 20px; letter-spacing: -.02em; }
.hero-meter { height: 7px; overflow: hidden; border-radius: 99px; background: color-mix(in srgb, var(--accent-text) 20%, transparent); }
.hero-meter i { display: block; width: var(--progress, 0%); height: 100%; border-radius: inherit; background: var(--accent-text); transition: width .4s ease; }

.section { margin-top: 25px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.section-title small { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .1em; }
.row-list, .card-list, .theory-list { display: grid; gap: 9px; }
.action-row, .task-row, .theory-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px;
  border: 1px solid transparent;
  border-radius: 17px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.action-row:active, .task-row:active, .theory-row:active { transform: scale(.98); background: var(--surface-2); }
.row-icon, .task-number {
  display: grid;
  place-items: center;
  width: 41px;
  height: 41px;
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 850;
}
.row-copy, .task-copy { display: grid; gap: 4px; min-width: 0; }
.row-copy strong, .task-copy strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.row-copy small, .task-copy small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.row-end { color: var(--muted); }
.task-score { min-width: 42px; color: var(--muted); font-size: 11px; text-align: right; }
.task-score.good { color: var(--good); }

.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.feature-card {
  display: grid;
  align-content: space-between;
  gap: 14px;
  min-height: 116px;
  padding: 15px;
  border: 0;
  border-radius: 19px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}
.feature-card:active { transform: scale(.965); background: var(--surface-2); }
.feature-card > .icon { color: var(--accent); }
.feature-card span { display: grid; gap: 4px; }
.feature-card small { color: var(--muted); font-size: 11px; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 620px);
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.bottom-nav button { display: grid; justify-items: center; align-content: center; gap: 4px; min-width: 0; border: 0; border-radius: 14px; background: transparent; color: var(--muted); font-size: 10px; cursor: pointer; }
.bottom-nav button[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.bottom-nav button:active { transform: scale(.94); }
.bottom-nav .icon { width: 20px; height: 20px; }

.page-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.page-heading .heading-copy { min-width: 0; }
.page-heading h1 { font-size: 25px; }
.page-heading p { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.block-title { margin: 22px 0 10px; color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }

.info-card, .stat-card, .empty-card, .source-card, .profile-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.info-card { display: grid; gap: 12px; line-height: 1.5; }
.info-card p, .source-card p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.points-badge, .status-badge { display: inline-flex; align-items: center; width: max-content; min-height: 27px; padding: 5px 9px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 850; }
.status-badge.updated { background: var(--good-soft); color: var(--good); }
.tip-list { display: grid; gap: 8px; padding: 0; margin: 0; list-style: none; }
.tip-list li { position: relative; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.tip-list li::before { position: absolute; left: 1px; content: "•"; color: var(--accent); }

.primary-button, .secondary-button, .danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 0;
  border-radius: 16px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.primary-button { background: var(--accent); color: var(--accent-text); }
.secondary-button { background: var(--surface-2); color: var(--text); }
.danger-button { background: var(--bad-soft); color: var(--bad); }
.primary-button:active, .secondary-button:active, .danger-button:active { transform: scale(.975); filter: brightness(1.05); }
.button-stack { display: grid; gap: 9px; margin-top: 18px; }

.question-page { display: flex; flex-direction: column; }
.session-header { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; margin-bottom: 17px; }
.session-meta { min-width: 0; }
.session-meta strong { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.session-meta small { color: var(--muted); font-size: 10px; }
.session-count { min-width: 47px; color: var(--muted); font-size: 12px; text-align: right; }
.session-progress { grid-column: 1 / -1; height: 5px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.session-progress i { display: block; width: var(--progress, 0%); height: 100%; background: var(--accent); transition: width .25s ease; }
.timer { color: var(--warning); font-variant-numeric: tabular-nums; }

.question-card { display: grid; gap: 14px; padding: 19px; border-radius: 23px; background: var(--surface); animation: card-in .25s ease-out; }
.question-task { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.question-task span { color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.question-card h2 { font-size: 19px; line-height: 1.35; }
.source-text { padding: 14px; border-radius: 15px; background: var(--surface-2); color: color-mix(in srgb, var(--text) 90%, var(--muted)); font-size: 14px; line-height: 1.55; white-space: pre-line; }
.instruction { color: var(--muted); font-size: 12px; line-height: 1.5; }

.answer-area { display: grid; gap: 9px; margin-top: 13px; }
.choice-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.choice-button:active { transform: scale(.98); }
.choice-button.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice-button.correct { border-color: var(--good); background: var(--good-soft); }
.choice-button.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice-index { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 850; }
.choice-button.selected .choice-index { background: var(--accent); color: var(--accent-text); }
.choice-copy { font-size: 14px; line-height: 1.42; white-space: pre-line; }

.stress-choice { grid-template-columns: 1fr; min-height: 66px; font-size: 21px; text-align: center; }
.stress-choice .choice-copy { font-size: 21px; text-align: center; }
.text-answer { width: 100%; min-height: 56px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); font-size: 16px; font-weight: 750; }
.text-answer::placeholder { color: var(--muted); }
.text-answer.correct { border-color: var(--good); background: var(--good-soft); }
.text-answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.match-list { display: grid; gap: 10px; }
.match-row { display: grid; gap: 8px; padding: 12px; border-radius: 16px; background: var(--surface); }
.match-row label { font-size: 13px; line-height: 1.4; }
.match-row select { width: 100%; min-height: 45px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--text); }
.match-options { display: grid; gap: 7px; margin-top: 10px; padding: 14px; border-radius: 16px; background: var(--surface); }
.match-options p { color: var(--muted); font-size: 12px; line-height: 1.45; }

.answer-feedback { display: none; gap: 7px; margin-top: 12px; padding: 14px; border-radius: 16px; animation: feedback-in .22s ease-out; }
.answer-feedback.show { display: grid; }
.answer-feedback.good { background: var(--good-soft); color: var(--good); }
.answer-feedback.bad { background: var(--bad-soft); color: var(--bad); }
.answer-feedback strong { font-size: 15px; }
.answer-feedback p { color: var(--text); font-size: 12px; line-height: 1.5; }
.session-actions { display: grid; gap: 9px; margin-top: 13px; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.stat-card { display: grid; gap: 7px; min-height: 105px; }
.stat-card small { color: var(--muted); font-size: 11px; }
.stat-card strong { font-size: 27px; letter-spacing: -.04em; }
.stat-card .icon { color: var(--accent); }
.accuracy-bar { height: 7px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.accuracy-bar i { display: block; height: 100%; width: var(--progress, 0%); background: var(--good); }

.result-hero { display: grid; justify-items: center; gap: 11px; padding: 26px 18px; border-radius: 25px; background: var(--surface); text-align: center; }
.result-ring { display: grid; place-items: center; width: 112px; height: 112px; border-radius: 50%; background: conic-gradient(var(--good) var(--score), var(--surface-2) 0); }
.result-ring::after { display: grid; place-items: center; width: 88px; height: 88px; border-radius: 50%; background: var(--surface); content: attr(data-value); font-size: 24px; font-weight: 850; }
.result-hero p { color: var(--muted); font-size: 13px; line-height: 1.5; }

.empty-card { display: grid; justify-items: center; gap: 10px; padding: 30px 19px; color: var(--muted); text-align: center; }
.empty-card .icon { width: 34px; height: 34px; color: var(--accent); }
.empty-card strong { color: var(--text); }
.empty-card p { max-width: 330px; font-size: 13px; line-height: 1.5; }
.profile-card { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px; }
.avatar { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 850; }
.profile-card p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.source-card { display: grid; gap: 11px; }
.source-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--accent); text-align: left; cursor: pointer; }
.source-link:first-of-type { margin-top: 2px; }

.settings-list { display: grid; gap: 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-button { display: grid; justify-items: center; gap: 7px; min-height: 72px; padding: 9px; border: 1px solid transparent; border-radius: 15px; background: var(--surface); color: var(--muted); font-size: 11px; cursor: pointer; }
.theme-button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }
.theme-swatch { width: 36px; height: 24px; border: 4px solid #15181d; border-radius: 9px; background: #07090c; box-shadow: inset 0 -7px #58a6ff; }
.theme-button[data-theme="light"] .theme-swatch { border-color: #fff; background: #f0f3f8; box-shadow: inset 0 -7px #2879dd; }
.theme-button[data-theme="violet"] .theme-swatch { border-color: #211a34; background: #130f20; box-shadow: inset 0 -7px #a98afa; }

.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(var(--nav-height) + 17px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 36px); padding: 11px 15px; border-radius: 13px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; align-items: end; padding: 18px; background: rgba(0,0,0,.56); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); animation: fade-in .18s ease; }
.modal { width: min(100%, 500px); margin: 0 auto calc(env(safe-area-inset-bottom)); padding: 20px; border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); animation: modal-in .23s ease-out; }
.modal p { margin-top: 9px; color: var(--muted); font-size: 13px; line-height: 1.5; }

body.theme-light {
  color-scheme: light;
  --bg: #f1f4f8;
  --surface: #ffffff;
  --surface-2: #e7ecf3;
  --surface-3: #d9e0ea;
  --text: #151922;
  --muted: #687284;
  --line: rgba(15, 31, 51, .09);
  --accent: #2879dd;
  --accent-soft: rgba(40, 121, 221, .12);
  --accent-text: #ffffff;
  --shadow: 0 18px 48px rgba(31, 55, 85, .16);
}
body.theme-violet {
  --bg: #100d19;
  --surface: #211a31;
  --surface-2: #302642;
  --surface-3: #3a2e51;
  --text: #fbf9ff;
  --muted: #aaa0ba;
  --line: rgba(255, 255, 255, .08);
  --accent: #a98afa;
  --accent-soft: rgba(169, 138, 250, .16);
  --accent-text: #140d25;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes page-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes card-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes feedback-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

@media (min-width: 620px) {
  .page { padding-inline: 24px; }
  .bottom-nav { border-inline: 1px solid var(--line); border-radius: 22px 22px 0 0; }
}
@media (max-width: 340px) {
  .page { padding-inline: 13px; }
  .feature-grid, .stats-grid { grid-template-columns: 1fr; }
  .theme-grid { grid-template-columns: 1fr; }
  .theme-button { grid-template-columns: auto 1fr; align-items: center; justify-items: start; min-height: 55px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
