/* Ham Exam Study. Phone first, system fonts, light and dark themes. */

:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17211b;
  --muted: #5b6760;
  --line: #d7ded8;
  --accent: #166534;
  --accent-ink: #ffffff;
  --accent-soft: #dcfce7;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #b45309;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 4px 16px rgba(16, 24, 20, 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1512;
    --surface: #17201b;
    --surface-2: #1f2b24;
    --text: #e6ede8;
    --muted: #9aa8a0;
    --line: #2c3a32;
    --accent: #4ade80;
    --accent-ink: #052e16;
    --accent-soft: #163322;
    --good: #4ade80;
    --good-soft: #143221;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --warn: #fbbf24;
    --focus: #93c5fd;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1512;
  --surface: #17201b;
  --surface-2: #1f2b24;
  --text: #e6ede8;
  --muted: #9aa8a0;
  --line: #2c3a32;
  --accent: #4ade80;
  --accent-ink: #052e16;
  --accent-soft: #163322;
  --good: #4ade80;
  --good-soft: #143221;
  --bad: #f87171;
  --bad-soft: #3a1717;
  --warn: #fbbf24;
  --focus: #93c5fd;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.6rem; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; }

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

.muted { color: var(--muted); }
.small-text { font-size: 0.875rem; }
.good { color: var(--good); }
.wrap { padding: 1rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.brand-mark { border-radius: 7px; flex: none; }

main {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem;
}

.footer {
  padding: 1.5rem 1rem 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
  min-width: 0;
}

.grid { display: grid; gap: 0 1rem; }

.section-title { margin: 1.25rem 0 0.75rem; }

.label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0.35rem 0.75rem; font-size: 0.9rem; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.btn-row.center { justify-content: center; }

.segmented {
  display: inline-flex;
  padding: 3px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.seg {
  min-height: 38px;
  padding: 0.3rem 1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.pill {
  display: inline-block;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.pass { background: var(--good-soft); color: var(--good); }
.pill.fail { background: var(--bad-soft); color: var(--bad); }

.check { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; font-size: 0.9rem; color: var(--muted); }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* ---------- bars ---------- */

.bar {
  display: block;
  height: 8px;
  width: 100%;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* ---------- dashboard ---------- */

.hero { margin: 0.5rem 0 1rem; }
.pool-name { font-size: 1.75rem; margin-bottom: 0.2rem; }

.readiness-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 0.5rem; }
.readiness .big { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.readiness .big.good { color: var(--good); }
.readiness .bar { height: 12px; margin-bottom: 0.6rem; }

.exam-list { list-style: none; margin: 0; padding: 0; }
.exam-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.exam-list li:last-child { border-bottom: 0; }
.exam-list .score { font-weight: 700; font-variant-numeric: tabular-nums; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-extra { font-size: 0.85rem; font-weight: 500; color: var(--muted); }

.actions { display: grid; gap: 0 1rem; }
.action p { font-size: 0.9rem; }
.main-action { border-color: var(--accent); }

.search-input {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0.4rem 0 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.results, .miss-links { list-style: none; margin: 0; padding: 0; }
.result, .miss-links a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.55rem 0.25rem;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.result:hover, .miss-links a:hover { background: var(--surface-2); }
.result-id, .q-id, .topic-code {
  flex: none;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}
.result-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.dot.ok { background: var(--good); }
.dot.miss { background: var(--bad); }

.topic-list { display: grid; gap: 0.6rem; }
.topic {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.topic:hover { border-color: var(--accent); }
.topic:active { transform: translateY(1px); }
.topic-head { display: flex; gap: 0.5rem; align-items: baseline; min-width: 0; }
.topic-title { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.topic-foot { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8rem; flex-wrap: wrap; }

.data { margin-top: 1.25rem; }

/* ---------- question views ---------- */

.view-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.view-title { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.counter, .clock {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--muted);
}
.clock { padding: 0.1rem 0.5rem; border-radius: 8px; background: var(--surface-2); }
.clock.low { color: var(--warn); }

.exam > .bar, .cards > .bar { margin-bottom: 0.75rem; }

.question, .flashcard { margin-bottom: 0.75rem; }
.q-meta { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; font-size: 0.85rem; }
.q-sub { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.q-text { font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }

.figure { margin: 0.5rem 0 0.9rem; text-align: center; }
.figure img {
  display: block;
  max-width: 100%;
  max-height: min(40vh, 340px);
  margin: 0 auto;
  border-radius: 8px;
  background: #ffffff;
  padding: 0.4rem;
}
.figure figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }

.options { display: grid; gap: 0.55rem; margin-top: 0.75rem; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, transform 0.1s;
}
.option:hover { border-color: var(--accent); }
.option:active { transform: translateY(1px); }
.option-key {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 800;
  font-size: 0.9rem;
}
.option-text { flex: 1; min-width: 0; padding-top: 0.1rem; overflow-wrap: anywhere; }

.option[data-state="selected"] { border-color: var(--accent); background: var(--accent-soft); }
.option[data-state="selected"] .option-key { background: var(--accent); color: var(--accent-ink); }
.option[data-state="right"] { border-color: var(--good); background: var(--good-soft); animation: pop 0.25s ease; }
.option[data-state="right"] .option-key { background: var(--good); color: var(--surface); }
.option[data-state="wrong"] { border-color: var(--bad); background: var(--bad-soft); animation: shake 0.3s ease; }
.option[data-state="wrong"] .option-key { background: var(--bad); color: var(--surface); }
.option[data-state="dim"] { opacity: 0.6; }
.option[aria-disabled="true"] { cursor: default; }
.option[aria-disabled="true"]:hover { border-color: var(--line); }
.option[data-state="right"][aria-disabled="true"]:hover { border-color: var(--good); }
.option[data-state="wrong"][aria-disabled="true"]:hover { border-color: var(--bad); }

.answer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.answer-bar .btn { min-width: 7rem; }
.answer-bar[hidden] { display: none; }

.feedback {
  flex: 1 1 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
  animation: fade 0.2s ease;
}
.feedback[hidden] { display: none; }
.feedback.ok { background: var(--good-soft); border-color: var(--good); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.feedback .ref { color: var(--muted); }

.keys-hint { display: none; font-size: 0.8rem; text-align: right; }

/* ---------- flashcards ---------- */

.flashcard { min-height: 14rem; }
.card-answer {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 2px dashed var(--line);
  animation: reveal 0.3s ease;
}
.card-answer[hidden] { display: none; }
.answer-text { font-size: 1.2rem; font-weight: 700; color: var(--good); overflow-wrap: anywhere; }
.flashcard.flipped { border-color: var(--good); }

/* ---------- results ---------- */

.result { text-align: center; }
.result-score { font-size: 3rem; font-weight: 800; line-height: 1.1; margin: 0.25rem 0; font-variant-numeric: tabular-nums; }
.result-verdict { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.06em; }
.result.pass { border-color: var(--good); }
.result.pass .result-verdict { color: var(--good); }
.result.fail { border-color: var(--warn); }
.result.fail .result-verdict { color: var(--warn); }
.card.result { display: block; }

.breakdown { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.breakdown th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.3rem 0; }
.breakdown td { padding: 0.4rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.breakdown td:last-child, .breakdown th:last-child { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 0.75rem; }

.miss-review { list-style: none; margin: 0; padding: 0; }
.miss-q { font-weight: 600; overflow-wrap: anywhere; }
.miss-line { padding: 0.4rem 0.6rem; border-radius: 8px; overflow-wrap: anywhere; }
.miss-line.bad { background: var(--bad-soft); }
.miss-line.ok { background: var(--good-soft); }

.summary h1 { margin-bottom: 0.75rem; }
.summary .bar { margin-bottom: 1rem; }
.summary .btn-row { margin-top: 1rem; }

/* ---------- motion ---------- */

@keyframes pop { 50% { transform: scale(1.015); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } }

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

/* ---------- larger screens ---------- */

@media (min-width: 640px) {
  main { padding: 1.5rem; }
  h1 { font-size: 1.9rem; }
  .pool-name { font-size: 2.1rem; }
  .grid { grid-template-columns: 3fr 2fr; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topic-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keys-hint { display: block; }
  .q-text { font-size: 1.3rem; }
  .card { padding: 1.25rem; }
}

@media (hover: none) {
  .keys-hint { display: none; }
}
