/* ---------- Theme tokens ---------- */
:root {
  --bg: #f4f5fb;
  --bg-glow-1: rgb(99 91 255 / 14%);
  --bg-glow-2: rgb(236 72 153 / 9%);
  --surface: #ffffff;
  --surface-2: #f0f1f8;
  --surface-3: #e5e7f2;
  --text: #171a2b;
  --muted: #555b72;
  --border: #e1e3ee;
  --border-strong: #c9cce0;
  --primary: #5145e5;
  --primary-2: #8b3fd9;
  --primary-hover: #4136c9;
  --primary-soft: #eceafe;
  --on-primary: #ffffff;
  --gradient: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  --focus: #5145e5;
  --correct: #0b6b3a;
  --correct-strong: #16a34a;
  --correct-bg: #e4f7ec;
  --wrong: #b4231a;
  --wrong-strong: #dc2626;
  --wrong-bg: #fdeceb;
  --warn: #8a5300;
  --warn-bg: #fff4de;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow-sm: 0 1px 2px rgb(23 26 43 / 6%);
  --shadow: 0 1px 2px rgb(23 26 43 / 4%), 0 8px 24px -6px rgb(23 26 43 / 10%);
  --shadow-primary: 0 6px 18px -6px rgb(81 69 229 / 55%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d16;
    --bg-glow-1: rgb(110 100 255 / 18%);
    --bg-glow-2: rgb(236 72 153 / 9%);
    --surface: #151826;
    --surface-2: #1d2133;
    --surface-3: #272c42;
    --text: #eceef7;
    --muted: #a3a9c2;
    --border: #262a3d;
    --border-strong: #3a4060;
    --primary: #8f87ff;
    --primary-2: #c084fc;
    --primary-hover: #a9a3ff;
    --primary-soft: #23244a;
    --on-primary: #0b0d16;
    --focus: #a9a3ff;
    --correct: #6ee7a0;
    --correct-strong: #34d399;
    --correct-bg: #0f2e20;
    --wrong: #ff9a90;
    --wrong-strong: #f87171;
    --wrong-bg: #36161a;
    --warn: #ffc56b;
    --warn-bg: #33260f;
    --shadow-sm: none;
    --shadow: 0 10px 30px -12px rgb(0 0 0 / 60%);
    --shadow-primary: 0 6px 20px -6px rgb(143 135 255 / 45%);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 30rem at 15% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(50rem 28rem at 100% 0%, var(--bg-glow-2), transparent 60%);
  background-repeat: no-repeat;
  font: 400 1.0625rem/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.015em; }

.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }

main.wrap { padding-bottom: 56px; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 10;
  background: var(--primary); color: var(--on-primary);
  padding: 8px 14px; border-radius: 10px; text-decoration: none;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

kbd {
  font: inherit; font-size: 0.8em; font-weight: 600;
  padding: 1px 7px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 6px; background: var(--surface); color: var(--text);
}

/* ---------- Header ---------- */
.app-header { padding: 22px 0 4px; }
.header-inner { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 13px;
  background: var(--gradient); color: #fff;
  box-shadow: var(--shadow-primary);
}
.brand { font-size: 1.3rem; font-weight: 800; }
.tagline { margin: 0; font-size: 0.9rem; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 18px;
}
.card-title { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 750; margin-bottom: 16px; }
.step {
  display: inline-grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: 9px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 0.9rem; font-weight: 800;
}
.section-title { font-size: 1.15rem; font-weight: 750; margin: 32px 0 12px; }

.banner {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--gradient) border-box;
}
.banner p { margin: 0 0 12px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 10px 20px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 650; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  transition: background-color .15s, border-color .15s, transform .12s, box-shadow .15s, filter .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--gradient); color: var(--on-primary); box-shadow: var(--shadow-primary); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.primary:disabled { box-shadow: none; }
.btn.secondary { background: var(--surface); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--wrong); border-color: var(--border); margin-top: 14px; font-size: 0.95rem; min-height: 44px; }
.btn.danger:hover { background: var(--wrong-bg); border-color: transparent; }
.btn.link {
  background: none; color: var(--primary); min-height: 44px; padding: 8px 2px;
  font-weight: 600; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px;
}
.btn.block { width: 100%; }

/* ---------- Import ---------- */
.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 150px; padding: 22px; text-align: center;
  border: 2px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer;
  transition: border-color .15s, background-color .15s, transform .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.dragging { transform: scale(1.01); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.dz-icon { color: var(--primary); margin-bottom: 6px; transition: transform .2s; }
.dropzone:hover .dz-icon, .dropzone.dragging .dz-icon { transform: translateY(-3px); }
.dz-title { font-weight: 750; color: var(--text); }
.dz-hint { color: var(--muted); font-size: 0.95rem; }
.file-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.status:empty { display: none; }
.status {
  margin-top: 14px; padding: 12px 14px 12px 16px; border-radius: 12px;
  border: 1px solid var(--border); border-left-width: 4px;
}
.status.ok { background: var(--correct-bg); color: var(--correct); border-color: var(--correct-strong); border-width: 0 0 0 4px; }
.status.warn { background: var(--warn-bg); color: var(--warn); border-color: currentColor; border-width: 0 0 0 4px; }
.status.error { background: var(--wrong-bg); color: var(--wrong); border-color: var(--wrong-strong); border-width: 0 0 0 4px; }
.status p { margin: 0; font-weight: 650; }
.status details { margin-top: 6px; color: var(--text); }
.status summary { cursor: pointer; min-height: 32px; display: list-item; font-weight: 600; }
.status ul { margin: 6px 0 0; padding-left: 20px; font-size: 0.95rem; }

#bank-info { margin: 10px 0 0; font-size: 0.95rem; }
#bank-info:empty { display: none; }

/* ---------- Settings form ---------- */
fieldset { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; font-size: 0.95rem; }

.choices { display: grid; gap: 10px; }
.choices.inline { grid-template-columns: 1fr 1fr; }

.choice {
  display: flex; align-items: flex-start; gap: 12px;
  min-height: 52px; padding: 13px 15px;
  background: var(--surface);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.choice:hover { border-color: var(--border-strong); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgb(81 69 229 / 10%); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice input { margin: 4px 0 0; width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.choice input:focus-visible { outline: none; }
.choice span { display: flex; flex-direction: column; }
.choice small { color: var(--muted); font-size: 0.9rem; }

.check { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.field { margin: 12px 0 20px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; }
.field small { font-weight: 400; color: var(--muted); }
input[type="number"] {
  width: 100%; max-width: 200px; min-height: 50px; padding: 8px 14px;
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s, background-color .15s;
}
input[type="number"]:hover { border-color: var(--border-strong); }
input[type="number"]:focus-visible { border-color: var(--focus); background: var(--surface); outline-offset: 1px; }

#start-btn { margin-top: 4px; font-size: 1.05rem; min-height: 54px; }
#start-hint { margin: 10px 0 0; text-align: center; }
#start-hint:empty { display: none; }

/* ---------- Progress & history ---------- */
#stats { margin: 0 0 14px; }
.history { list-style: none; padding: 0; margin: 14px 0 0; }
.history li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border); font-size: 0.95rem;
}
.history .when { color: var(--muted); font-size: 0.88rem; }
.history .pct {
  font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums;
  padding: 3px 10px; border-radius: 999px; background: var(--surface-2);
}

/* ---------- Quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.counter { font-weight: 750; font-variant-numeric: tabular-nums; }
.badge {
  font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary);
}
.timer {
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 750;
  padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
}
.timer::before { content: "⏱ "; }
.timer.low { background: var(--wrong-bg); color: var(--wrong); border-color: transparent; animation: pulse 1s ease-in-out infinite; }

.progress { height: 10px; margin-top: 12px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress-bar {
  height: 100%; width: 0; border-radius: inherit;
  background: var(--gradient);
  transition: width .35s cubic-bezier(.2, .8, .2, 1);
}

.question-card { padding: 24px 20px; }
.question { font-size: 1.25rem; font-weight: 700; white-space: pre-line; overflow-wrap: anywhere; line-height: 1.4; }
.question:focus { outline: none; }
.question:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 6px; }

.options { display: grid; gap: 12px; margin-top: 20px; }

.option {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 60px; padding: 12px 14px; text-align: left;
  font: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer; overflow-wrap: anywhere;
  transition: border-color .15s, background-color .15s, transform .12s, box-shadow .15s;
}
.option:hover:not([aria-disabled="true"]) { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.option:active:not([aria-disabled="true"]) { transform: translateY(0) scale(.995); }
.option .key {
  flex: none; display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface-2); color: var(--muted);
  font-weight: 800; font-size: 0.95rem;
  transition: background-color .15s, color .15s;
}
.option:hover:not([aria-disabled="true"]) .key { background: var(--primary-soft); color: var(--primary); }
.option .text { flex: 1; }
.option[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.option[aria-pressed="true"] .key, .option[aria-pressed="true"]:hover .key { background: var(--gradient); color: var(--on-primary); }
.option[aria-disabled="true"] { cursor: default; }
.option[aria-disabled="true"]:not(.correct):not(.wrong) { opacity: .72; }
.option.correct { border-color: var(--correct-strong); background: var(--correct-bg); animation: pop .35s ease-out; }
.option.correct .key { background: var(--correct-strong); color: #fff; }
.option.wrong { border-color: var(--wrong-strong); background: var(--wrong-bg); animation: shake .4s ease-in-out; }
.option.wrong .key { background: var(--wrong-strong); color: #fff; }
.option .mark { font-weight: 750; font-size: 0.88rem; padding-left: 8px; white-space: nowrap; }
.option.correct .mark { color: var(--correct); }
.option.wrong .mark { color: var(--wrong); }

.feedback {
  margin: 16px 0 0; padding: 12px 14px; border-radius: 12px;
  font-weight: 650; animation: fade-up .25s ease-out;
}
.feedback:empty { display: none; }
.feedback.ok { color: var(--correct); background: var(--correct-bg); }
.feedback.bad { color: var(--wrong); background: var(--wrong-bg); }

.quiz-nav { display: flex; gap: 10px; margin-top: 18px; align-items: center; }
.quiz-nav .spacer { flex: 1; }
#next-btn { min-width: 130px; }

.kbd-hint { text-align: center; margin-top: 20px; }
@media (hover: none) and (pointer: coarse) { .kbd-hint { display: none; } }

/* ---------- Results ---------- */
.score-card { text-align: center; padding-top: 28px; }
.score-card h2 { font-size: 1.3rem; }
.score-card h2:focus { outline: none; }

.ring {
  --p: 0;
  --ring-color: var(--primary);
  position: relative; display: grid; place-items: center;
  width: 160px; height: 160px; margin: 18px auto 6px; border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--p) * 1%), var(--surface-3) 0);
  animation: ring-in .6s ease-out;
}
.ring::before {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: var(--surface);
}
.ring[data-tier="high"] { --ring-color: var(--correct-strong); }
.ring[data-tier="mid"] { --ring-color: var(--primary); }
.ring[data-tier="low"] { --ring-color: var(--wrong-strong); }
.score {
  position: relative; margin: 0;
  font-size: 2.6rem; font-weight: 850; letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.score-detail { margin: 8px 0 22px; color: var(--muted); }
.actions { display: grid; gap: 10px; }

.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.review li {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 5px solid var(--correct-strong); border-radius: var(--radius-sm);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.review li.is-wrong { border-left-color: var(--wrong-strong); background: var(--wrong-bg); border-color: transparent; border-left-color: var(--wrong-strong); }
.review .rq { font-weight: 700; margin: 0 0 8px; white-space: pre-line; overflow-wrap: anywhere; }
.review .ra { margin: 2px 0; font-size: 0.97rem; overflow-wrap: anywhere; }
.review .label { font-weight: 700; }
.review .yours.bad { color: var(--wrong); }
.review .yours.good, .review .right { color: var(--correct); }
.review .tag {
  display: inline-block; margin-bottom: 4px;
  font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
}

/* ---------- Animations ---------- */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.025); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(2px); }
}
@keyframes fade-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .65; } }
@keyframes ring-in { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }

#screen-start:not([hidden]), #screen-quiz:not([hidden]), #screen-results:not([hidden]) { animation: fade-up .3s ease-out; }

@media (min-width: 560px) {
  .actions { grid-template-columns: 1fr 1fr 1fr; }
  .card { padding: 26px; }
  .question-card { padding: 30px 28px; }
  .question { font-size: 1.35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
