:root {
  --bg: #e8eef4;
  --ink: #152033;
  --muted: #5c6b7e;
  --navy: #102033;
  --navy-2: #1b3554;
  --card: #ffffff;
  --line: #d5deea;
  --blue: #1a4f86;
  --blue-soft: #e7f0f8;
  --green: #0d7a46;
  --green-soft: #e7f6ee;
  --red: #a3262d;
  --red-soft: #fdecee;
  --amber: #8a5a10;
  --amber-soft: #fbf3e2;
  --shadow: 0 10px 30px rgba(16, 32, 51, 0.06);
  --radius: 16px;
  --max: 760px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

#app { min-height: 100dvh; }
.boot { padding: 48px 20px; color: var(--muted); }

.topbar {
  background: var(--navy);
  color: #f4f7fb;
  padding: calc(10px + env(safe-area-inset-top)) 18px 14px;
  border-top: 4px solid #c0392b;
}
.topbar-inner, .wrap { width: min(var(--max), calc(100% - 28px)); margin: 0 auto; }
.topbar-inner { display: flex; align-items: center; gap: 8px; }
.back {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #f4f7fb;
  font-size: 1.7rem;
  line-height: 1;
  padding: 0;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand b { display: block; font-size: 1.05rem; letter-spacing: 0.01em; }
.brand span { display: block; color: #b7c5d6; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.mark {
  width: 42px; height: 42px; border-radius: 11px;
  border: 2px solid #e6c36a; display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.04em; color: #f0c14a;
}
.top-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.timer.warn { color: #f0c14a; }
.timer.late { color: #ffb4b0; }

.wrap { padding: 22px 0 48px; }
h1 { font-size: 1.85rem; line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; margin: 0 0 8px; }
.lede { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }

.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}
.kicker {
  color: var(--red);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat { background: #f6f8fb; border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.78rem; }

.actions { display: grid; gap: 10px; margin: 16px 0; }
@media (min-width: 700px) {
  .actions.two { grid-template-columns: 1fr 1fr; }
}

.btn {
  border: 1px solid transparent;
  background: var(--blue);
  color: white;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 16px;
  font-weight: 650;
  text-align: center;
}
.btn.secondary { background: white; color: var(--navy); border-color: var(--line); }
.btn.ghost { background: transparent; color: #d5e4f5; border-color: transparent; min-height: 40px; padding: 6px 8px; }
.btn.green { background: var(--green); }
.btn.danger { background: var(--red); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.wide { width: 100%; }

.card-link, .q-row, .choice, .paper {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; color: inherit;
  text-decoration: none;
}
.card-link *, .q-row *, .paper * { text-decoration: none; }
.card-link { margin-bottom: 10px; }
.card-link strong { display: block; margin-bottom: 2px; }
.card-link em, .muted { color: var(--muted); font-style: normal; text-decoration: none; }

.search {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  min-height: 48px;
  padding: 0 14px;
  margin-bottom: 14px;
}

.q-row { margin-bottom: 8px; }
.q-row .prompt { font-weight: 650; line-height: 1.35; }
.answer-line { color: var(--green); margin-top: 6px; line-height: 1.4; font-size: 0.95rem; }
.thumb { height: 54px; width: auto; margin-top: 8px; vertical-align: middle; }

.study-head, .exam-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.pill {
  border-radius: 999px; padding: 4px 10px; font-size: 0.78rem; font-weight: 700;
  background: var(--blue-soft); color: var(--blue);
}
.prompt {
  font-size: 1.28rem; line-height: 1.4; margin: 8px 0 12px; letter-spacing: -0.015em;
}
.figure {
  display: block; margin: 0 auto 16px; max-height: 300px; width: auto;
  background: #f3efe9; border-radius: 12px; border: 1px solid var(--line);
}
.note {
  background: var(--amber-soft); color: #6d4a0d; border-radius: 12px;
  padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px;
}
.choices { display: grid; gap: 8px; }
.choice {
  min-height: 64px;
  display: flex; gap: 12px; align-items: center;
  line-height: 1.4;
}
.choice .letter {
  flex: 0 0 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; font-weight: 750;
  background: #eef3f8; color: var(--navy-2);
}
.choice > span:not(.letter):not(.tag) { flex: 1; min-width: 0; }
.choice.selected { border-color: var(--blue); background: var(--blue-soft); }
.choice.selected .letter { background: var(--blue); color: white; }
.choice.correct { border-color: var(--green); background: var(--green-soft); }
.choice.correct .letter { background: var(--green); color: white; }
.choice.wrong { border-color: var(--red); background: var(--red-soft); }
.choice.wrong .letter { background: var(--red); color: white; }
.choice img { max-height: 132px; width: auto; }
.tag { margin-left: auto; font-size: 0.75rem; font-weight: 750; letter-spacing: 0.04em; text-transform: uppercase; color: var(--green); }

.footer-nav {
  position: sticky; bottom: 0;
  background: rgba(232, 238, 244, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.footer-nav .row { width: min(var(--max), calc(100% - 28px)); margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.rules { margin: 0; padding-left: 18px; }
.rules li { margin: 6px 0; line-height: 1.4; }
.papers { display: grid; gap: 8px; margin-top: 8px; }

.progress-line { height: 8px; background: #d5deea; border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.progress-line i { display: block; height: 100%; background: var(--blue); }

.grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 8px;
}
.cell {
  min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: white;
  font-variant-numeric: tabular-nums; font-weight: 700;
}
.cell.on { background: var(--navy); color: white; border-color: var(--navy); }
.cell.here { outline: 2px solid var(--amber); }
.cell.flag { box-shadow: inset 0 -3px 0 var(--amber); }

.sheet {
  position: fixed; inset: 0; background: rgba(16, 32, 51, 0.45);
  display: grid; align-items: end; z-index: 5;
}
.sheet .panel {
  background: white; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  width: min(var(--max), 100%); margin: 0 auto;
  max-height: 86dvh; overflow: auto;
}

.result-score { text-align: center; padding: 12px 0 4px; }
.result-score b { font-size: 4rem; letter-spacing: -0.04em; display: block; line-height: 1; }
.pass { color: var(--green); }
.fail { color: var(--red); }
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.fine { color: var(--muted); font-size: 0.85rem; line-height: 1.45; }

.filter { display: flex; gap: 8px; margin-bottom: 12px; }
.filter button[aria-pressed="true"] { background: var(--navy); color: white; border-color: var(--navy); }
