:root {
  color-scheme: light;
  --bg: #f7f8f3;
  --paper: #ffffff;
  --ink: #17201d;
  --muted: #5f6b66;
  --line: #d9ded5;
  --accent: #0f766e;
  --accent-dark: #0b5953;
  --accent-soft: #e0f2ef;
  --warn: #9a5b00;
  --warn-soft: #fff2d2;
  --good: #276749;
  --good-soft: #e4f4ea;
  --bad: #a23b3b;
  --bad-soft: #fde7e7;
  --shadow: 0 12px 34px rgba(16, 24, 20, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button,
textarea,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

button.primary,
.filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover,
.filter.active:hover {
  background: var(--accent-dark);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 243, 0.94);
  padding: 1rem clamp(1rem, 4vw, 3rem);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.35rem);
}

h2 {
  font-size: clamp(1.2rem, 2vw, 1.7rem);
}

h3 {
  font-size: 1.03rem;
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 4rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 0.55rem;
  width: min(100%, 320px);
  min-width: min(100%, 320px);
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 0.55rem 0.7rem;
  text-align: center;
}

.stats strong,
.stats span {
  display: block;
}

.stats strong {
  font-size: 1.12rem;
}

.stats span {
  color: var(--muted);
  font-size: 0.75rem;
}

.intro,
.controls,
.section-nav-wrap,
.section-nav,
.section-header,
.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.intro p,
.notes p,
.feedback p,
.hint p {
  margin: 0.35rem 0 0;
}

.controls {
  position: sticky;
  top: 83px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: space-between;
  margin: 1rem 0;
  padding: 0.75rem;
}

.control-group,
.section-nav,
.q-actions,
.visual-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.section-nav-wrap {
  margin-bottom: 1rem;
  padding: 0.75rem;
}

.section-nav-wrap summary {
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.section-nav-wrap summary::-webkit-details-marker {
  display: none;
}

.section-nav-wrap summary::before {
  content: "+";
  display: inline-block;
  width: 1rem;
  margin-right: 0.35rem;
  color: var(--accent-dark);
}

.section-nav-wrap[open] summary::before {
  content: "-";
}

.section-nav {
  margin-top: 0.75rem;
}

.section-nav a {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf8;
  color: var(--ink);
  padding: 0.45rem 0.65rem;
  text-decoration: none;
}

.section-nav a:hover {
  border-color: var(--accent);
}

.section {
  margin: 1rem 0 1.5rem;
  scroll-margin-top: 160px;
}

.section-header {
  display: flex;
  gap: 1rem;
  align-items: start;
  justify-content: space-between;
  padding: 1rem;
}

.section-range {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.pdf-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.questions {
  display: grid;
  gap: 0.85rem;
  margin-top: 0.85rem;
}

.question-card {
  padding: 1rem;
}

.question-card.cleared {
  opacity: 0.72;
}

.question-card.hidden {
  display: none;
}

.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.55rem;
}

.q-number {
  display: inline-flex;
  min-width: 2.4rem;
  height: 2.4rem;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.flag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.flag-toggle input {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.q-primer {
  border-left: 4px solid var(--accent);
  background: #f3faf7;
  margin-bottom: 0.75rem;
  padding: 0.75rem 0.85rem;
}

.q-primer strong {
  display: block;
  margin-bottom: 0.25rem;
}

.q-primer p {
  margin: 0;
}

.q-primer ul,
.retry-box ul {
  margin: 0.45rem 0 0;
  padding-left: 1.2rem;
}

.q-primer li,
.retry-box li {
  margin-top: 0.25rem;
}

.q-prompt {
  white-space: pre-wrap;
}

.figure-area {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.inline-figure {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  margin: 0;
  overflow: hidden;
}

.inline-figure img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #fff;
}

.inline-figure figcaption {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.55rem 0.7rem;
}

.visual-links {
  margin: 0.7rem 0;
}

.q-actions {
  margin-top: 0.65rem;
}

.answer-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #fbfcf9;
}

.answer-panel.show {
  display: block;
}

.answer-copy strong {
  display: block;
  margin-bottom: 0.2rem;
}

.answer-copy strong + p {
  margin-top: 0;
}

.answer-copy p {
  white-space: pre-wrap;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 800;
}

.tag.correct {
  background: var(--good-soft);
  color: var(--good);
}

.tag.practice {
  background: var(--warn-soft);
  color: var(--warn);
}

.tag.new {
  background: #eef1ea;
  color: var(--muted);
}

.page-dialog {
  width: min(980px, calc(100vw - 1rem));
  max-height: 94vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.page-dialog::backdrop {
  background: rgba(15, 20, 18, 0.52);
}

.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  padding: 0.7rem;
}

.dialog-head button {
  min-width: 42px;
  padding: 0.3rem 0.6rem;
  font-size: 1.45rem;
  line-height: 1;
}

.page-dialog img {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 820px) {
  .topbar,
  .intro {
    display: block;
  }

  .stats {
    margin-top: 0.75rem;
    min-width: 0;
  }

  .controls {
    top: 132px;
  }

  .section-header {
    display: block;
  }

  .section-range {
    display: block;
    margin-top: 0.35rem;
  }
}

@media (max-width: 560px) {
  main {
    width: min(100% - 1rem, 1180px);
  }

  .topbar {
    padding: 0.85rem;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .stats div {
    min-width: 0;
    padding: 0.5rem 0.35rem;
  }

  .controls {
    position: static;
    display: block;
  }

  .control-group,
  .q-actions {
    width: 100%;
    min-width: 0;
  }

  .control-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .control-group + .control-group {
    margin-top: 0.45rem;
  }

  .control-group button {
    min-width: 0;
    width: 100%;
    white-space: normal;
  }

  .q-actions button {
    flex: 1 1 100%;
  }
}
