:root {
  color-scheme: light dark;
  --ink: #10233f;
  --muted: #506078;
  --paper: #f5f2e9;
  --surface: #fffdf7;
  --line: #b8c0ca;
  --blue: #124f8c;
  --blue-dark: #0b3868;
  --amber: #b65a00;
  --amber-soft: #fff0cf;
  --red: #a02b2b;
  --green: #176b4a;
  --focus: #f2a900;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
}

button, input { font: inherit; }
button { min-height: 3rem; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

:where(button, input):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

::selection { background: #ffd469; color: #172033; }

.skip-link {
  position: fixed;
  z-index: 10;
  inset: 0 auto auto 0;
  padding: 0.75rem 1rem;
  background: var(--ink);
  color: white;
}

.skip-link:not(:focus) {
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.site-header,
.deck-tabs,
main {
  width: min(72rem, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding-block: 2rem 1.25rem;
}

h1, h2, h3, h4, p { margin-block-start: 0; }
h1 { margin-block-end: 0.15rem; font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.15; }
.site-header p { margin: 0; color: var(--muted); }
.file-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }

.quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--blue);
  border-radius: 0.35rem;
  background: transparent;
  color: var(--blue-dark);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.quiet-button:hover { background: #e3edf7; }
.quiet-button.danger { border-color: var(--red); color: var(--red); }
.quiet-button.danger:hover { background: #f9e1df; }

.deck-tabs {
  display: flex;
  gap: 0.25rem;
  border-block-end: 1px solid var(--line);
}

.deck-tab {
  min-height: 3.25rem;
  padding-inline: 1.1rem;
  border: 0;
  border-block-end: 4px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.deck-tab[aria-current="page"] { border-color: var(--blue); color: var(--ink); }
main { padding-block: 1.5rem 4rem; }

.study-status,
.review-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-block-end: 1.25rem;
}

.study-status h2,
.review-intro h2 { margin-block-end: 0.2rem; font-size: 1.25rem; }
.study-status p,
.review-intro p { margin: 0; color: var(--muted); }

.box-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(3.4rem, 1fr));
  gap: 0.35rem;
  min-width: min(28rem, 50%);
  margin: 0;
  padding: 0;
  list-style: none;
}

.box-summary li {
  padding: 0.45rem 0.35rem;
  border-block-start: 4px solid var(--blue);
  background: #e6edf3;
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.box-summary strong { display: block; font-size: 1.05rem; }
.box-summary span { display: block; font-size: 0.76rem; color: var(--muted); }

.question-card {
  max-width: 58rem;
  margin-inline: auto;
  padding: clamp(1.25rem, 4vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  box-shadow: 0 0.8rem 2.5rem rgb(16 35 63 / 10%);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.box-badge,
.review-badge {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #dce9f5;
  color: var(--blue-dark);
  font-weight: 750;
}

.review-badge { background: var(--amber-soft); color: #783900; }
.set-name { margin-block: 1.3rem 0.3rem; color: var(--blue-dark); font-size: 0.88rem; font-weight: 700; }
.question-card h3 { margin-block-end: 1.35rem; max-width: 70ch; font-size: clamp(1.2rem, 3vw, 1.65rem); line-height: 1.35; }

.question-image {
  display: block;
  width: 100%;
  max-height: 34rem;
  margin-block: 1rem 1.5rem;
  border: 1px solid var(--line);
  object-fit: contain;
  background: white;
}

.question-image[hidden] { display: none; }
.choices { display: grid; gap: 0.7rem; margin: 0 0 1.5rem; padding-inline-start: 2rem; }
.choices li { padding: 0.65rem 0.8rem; border: 1px solid var(--line); border-radius: 0.35rem; background: #f7f8f6; }
.choices li.correct { border-color: var(--green); background: #e6f4ec; color: #0b5337; font-weight: 700; }

.primary-button {
  width: 100%;
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--blue-dark);
  border-radius: 0.35rem;
  background: var(--blue);
  color: white;
  font-weight: 750;
}
.primary-button:hover { background: var(--blue-dark); }

.answer-panel {
  margin-block: 1.5rem;
  padding: 1.15rem;
  border: 1px solid #6d9a7f;
  border-radius: 0.35rem;
  background: #edf7f0;
  color: #123d2b;
}
.answer-panel h4 { margin-block-end: 0.45rem; }
.answer-panel p:last-child { margin-block-end: 0; }
.answer-choice { font-weight: 750; }

.grade-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grade-button { padding: 0.85rem; border-radius: 0.35rem; background: transparent; text-align: start; }
.grade-button strong, .grade-button span { display: block; }
.grade-button span { margin-block-start: 0.15rem; font-size: 0.86rem; }
.grade-button.forgot { border: 2px solid var(--red); color: var(--red); }
.grade-button.remembered { border: 2px solid var(--green); color: var(--green); }
.grade-button.forgot:hover { background: #f9e1df; }
.grade-button.remembered:hover { background: #e4f4eb; }

.empty-state { max-width: 42rem; margin: 4rem auto; text-align: center; }
.empty-state p { color: var(--muted); }
.empty-state .primary-button { width: auto; }

.review-intro { align-items: center; }
.review-intro label { margin-inline-start: auto; font-weight: 700; }
.review-intro input { width: 6rem; min-height: 3rem; padding-inline: 0.7rem; border: 1px solid var(--line); border-radius: 0.35rem; background: var(--surface); color: var(--ink); }
.warning-card { border-block-start: 5px solid var(--amber); }
.model-comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-block: 1.5rem; }
.model-comparison section { padding: 1rem; border: 1px solid var(--line); border-radius: 0.35rem; }
.model-comparison section:first-child { background: #eef4fa; }
.model-comparison section:last-child { background: #f4f0fa; }
.model-comparison h4 { margin-block-end: 0.6rem; }
.model-comparison p:last-child { margin-block-end: 0; }
.model-note { color: var(--muted); font-size: 0.88rem; }
.review-navigation { display: flex; justify-content: space-between; gap: 1rem; margin-block-start: 1.5rem; }

.visually-hidden {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ecf3fa;
    --muted: #b7c4d2;
    --paper: #101923;
    --surface: #182532;
    --line: #708195;
    --blue: #72b7f0;
    --blue-dark: #a9d5f7;
    --amber-soft: #4b3512;
    --red: #ff9c9c;
    --green: #8be0b8;
  }
  .quiet-button:hover { background: #263d51; }
  .quiet-button.danger:hover { background: #49292c; }
  .box-summary li { background: #243545; color: var(--ink); }
  .choices li { background: #1f2e3b; }
  .choices li.correct { background: #183d2d; color: #b8f1d2; }
  .answer-panel { background: #18382a; color: #c9f3dd; }
  .grade-button.forgot:hover { background: #49292c; }
  .grade-button.remembered:hover { background: #183d2d; }
  .model-comparison section:first-child { background: #1d3348; }
  .model-comparison section:last-child { background: #302941; }
}

@media (max-width: 48rem) {
  .site-header, .study-status, .review-intro { align-items: stretch; flex-direction: column; gap: 1rem; }
  .file-actions { justify-content: flex-start; }
  .file-actions > * { flex: 1 1 auto; }
  .box-summary { min-width: 0; width: 100%; }
  .review-intro label { margin-inline-start: 0; }
  .model-comparison { grid-template-columns: 1fr; }
}

@media (max-width: 34rem) {
  .site-header, .deck-tabs, main { width: min(100% - 1rem, 72rem); }
  .site-header { padding-block-start: 1rem; }
  .deck-tab { flex: 1; padding-inline: 0.4rem; }
  .question-card { padding: 1rem; }
  .grade-actions { grid-template-columns: 1fr; }
  .box-summary span { font-size: 0.68rem; }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 160ms ease-out, color 160ms ease-out; }
}
