:root {
  color-scheme: light;
  --ink: #1f1717;
  --muted: #6f6262;
  --line: #ead8d8;
  --paper: #fff8f8;
  --panel: #ffffff;
  --input-bg: #fffdfd;
  --soft: #fff0f0;
  --soft-strong: #ffdede;
  --accent: #b4232a;
  --accent-dark: #86181d;
  --coral: #b4232a;
  --amber: #b57b12;
  --link: #8d1f2a;
  --good: #287c4b;
  --good-soft: #e8f7ee;
  --bad-soft: #fff0f0;
  --notice-bg: #fff7ed;
  --notice-border: #f0cfaa;
  --notice-text: #5f3513;
  --overlay: rgba(37, 18, 18, 0.42);
  --toast-bg: #2a1517;
  --shadow: 0 18px 40px rgba(57, 18, 18, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f7eeee;
  --muted: #b9adad;
  --line: #3b3232;
  --paper: #111111;
  --panel: #1b1b1b;
  --input-bg: #242424;
  --soft: #2b2020;
  --soft-strong: #3a2527;
  --accent: #f0525b;
  --accent-dark: #ff7a81;
  --coral: #ff6a72;
  --amber: #e0b15d;
  --link: #ff8a90;
  --good: #70d08d;
  --good-soft: #153420;
  --bad-soft: #351d20;
  --notice-bg: #211b14;
  --notice-border: #5b4430;
  --notice-text: #f3d8b9;
  --overlay: rgba(0, 0, 0, 0.66);
  --toast-bg: #2b2b2b;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
textarea,
input,
select {
  font: inherit;
  font-size: 16px;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 44px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.topbar h1,
.topbar p,
.section-heading h2,
.section-heading p {
  margin: 0;
}

.topbar h1 {
  font-size: 2rem;
  letter-spacing: 0;
}

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

.topbar-actions,
.app-nav,
.input-actions,
.nav-row,
.result-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.app-nav {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.nav-tab {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.nav-tab.active {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(57, 18, 18, 0.12);
}

:root[data-theme="dark"] .nav-tab.active {
  color: var(--accent);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 1.1rem;
  font-weight: 900;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--soft-strong);
}

.theme-button {
  font-size: 1.2rem;
}

main {
  min-width: 0;
}

.app-page {
  width: 100%;
}

.page-wrap,
.quiz-page {
  padding: 24px 44px 48px;
}

.page-wrap {
  max-width: 1180px;
  margin: 0 auto;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px 44px 48px;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 16px;
}

.panel,
.question-panel,
.results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.section-heading {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
}

.section-heading h2 {
  font-size: 1.08rem;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.primary-button,
.ghost-button,
.choice-button,
.nav-dot {
  border-radius: 7px;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.primary-button,
.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 750;
}

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

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

.ghost-button {
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost-button:hover,
.ghost-button:focus-visible {
  background: var(--soft-strong);
}

.compact {
  min-height: 32px;
}

.full {
  width: 100%;
}

details {
  margin-top: 14px;
}

summary {
  color: var(--link);
  cursor: pointer;
  font-weight: 750;
}

.prompt-preview {
  overflow: auto;
  max-height: 260px;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
  color: var(--ink);
  line-height: 1.45;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--input-bg);
  color: var(--ink);
  line-height: 1.45;
}

.text-input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--input-bg);
  color: var(--ink);
}

.small-textarea {
  min-height: 82px;
}

textarea:focus,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(180, 35, 42, 0.24);
  outline-offset: 2px;
}

.status {
  min-height: 1.2em;
  color: var(--muted);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

.builder-form,
.choice-editor {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.workspace {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 16px;
}

.notice {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--notice-border);
  border-radius: 8px;
  background: var(--notice-bg);
  color: var(--notice-text);
  padding: 14px 16px;
  line-height: 1.5;
}

.notice-close {
  flex: 0 0 auto;
  width: 32px;
  min-width: 32px;
  height: 32px;
  background: color-mix(in srgb, var(--notice-bg) 72%, var(--panel));
  color: var(--notice-text);
}

.bottom-notice {
  padding: 0 44px 16px;
}

.bottom-notice .notice {
  max-width: 1180px;
  margin: 0 auto;
}

.library-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.library-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}

.library-header h2 {
  margin: 4px 0 0;
}

.library-filters {
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
}

.library-filters .field-label {
  margin-top: 0;
}

.tag-filter-row,
.library-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-filter {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 850;
}

.tag-filter.active {
  border-color: var(--accent);
  background: var(--soft-strong);
  color: var(--accent-dark);
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.library-item {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--input-bg);
  min-height: 210px;
}

.library-item-main {
  display: grid;
  align-content: start;
  gap: 8px;
}

.library-item h3 {
  margin: 0;
  font-size: 1rem;
}

.library-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.library-owner {
  font-size: 0.88rem;
  font-weight: 800;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty-state {
  min-height: 64vh;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.empty-copy {
  max-width: 620px;
  padding: 36px;
}

.empty-copy h2 {
  font-size: 2.45rem;
  line-height: 1.05;
  letter-spacing: 0;
  margin: 8px 0 16px;
}

.empty-copy p {
  color: var(--muted);
  line-height: 1.55;
}

.start-panel {
  min-height: 64vh;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.start-copy {
  width: min(680px, 100%);
  padding: 36px;
}

.start-copy h2 {
  font-size: 2.25rem;
  line-height: 1.08;
  letter-spacing: 0;
  margin: 8px 0 14px;
}

.start-copy p {
  color: var(--muted);
  line-height: 1.55;
}

.start-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}

.start-stats span {
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 0.86rem;
  font-weight: 850;
}

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

.quiz-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.quiz-header,
.results-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
}

.quiz-header {
  display: block;
}

.quiz-header h2,
.results-header h2 {
  margin: 4px 0 0;
  font-size: 2rem;
}

.quiz-tools {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
}

.quiz-details {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quiz-details .eyebrow {
  min-width: 0;
  overflow-wrap: anywhere;
}

.score-pill,
.score-big {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--accent-dark);
  border-radius: 8px;
  font-weight: 850;
  white-space: nowrap;
}

.score-pill {
  padding: 10px 12px;
}

.quiz-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.fullscreen-exit {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
}

.score-big {
  padding: 14px 18px;
  font-size: 1.5rem;
}

.progress-wrap {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft-strong);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  transition: width 180ms ease;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
}

.nav-dot {
  min-height: 36px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 800;
}

.nav-dot.current {
  border-color: var(--accent);
  background: var(--soft-strong);
}

.nav-dot.answered {
  background: var(--good-soft);
  border-color: var(--good);
}

.nav-dot.flagged {
  border-color: var(--amber);
  color: #775000;
}

.nav-dot.missed {
  border-color: var(--coral);
  background: var(--bad-soft);
}

.question-panel {
  padding: 28px;
}

.question-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 750;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.tag {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.objective {
  margin: 0 0 12px;
  color: var(--link);
  font-weight: 750;
}

.vignette {
  margin: 0 0 18px;
  padding: 14px;
  border-left: 4px solid var(--link);
  background: var(--soft);
  line-height: 1.55;
}

#questionStem {
  margin: 0 0 18px;
  font-size: 1.42rem;
  line-height: 1.32;
}

.choices {
  display: grid;
  gap: 10px;
}

.choice-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 56px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  line-height: 1.42;
}

.choice-button:hover,
.choice-button:focus-visible {
  border-color: var(--accent);
  background: var(--soft);
}

.choice-button.selected {
  border-color: var(--accent);
  background: var(--soft-strong);
}

.choice-button.locked:not(.selected) {
  cursor: not-allowed;
  opacity: 0.72;
}

.choice-button.locked:not(.selected):hover,
.choice-button.locked:not(.selected):focus-visible {
  border-color: var(--line);
  background: var(--panel);
}

.choice-button.correct {
  border-color: var(--good);
  background: var(--good-soft);
}

.choice-button.incorrect {
  border-color: var(--coral);
  background: var(--bad-soft);
}

.choice-letter {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--soft);
  font-weight: 900;
  color: var(--accent-dark);
}

.explanation {
  margin-top: 18px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--input-bg);
}

.motivation {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--good-soft);
  color: var(--ink);
  font-weight: 800;
  line-height: 1.45;
}

.motivation.wrong {
  border-color: var(--coral);
  background: var(--bad-soft);
  color: var(--ink);
}

.explanation h4 {
  margin: 0 0 8px;
}

.explanation p {
  line-height: 1.55;
}

.explanation ul {
  padding-left: 20px;
}

.nav-row {
  justify-content: flex-end;
}

.results {
  padding: 28px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--input-bg);
}

.stat b {
  display: block;
  font-size: 1.35rem;
  margin-bottom: 3px;
}

.review-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
}

.review-item.missed {
  border-color: var(--coral);
}

.review-item h3 {
  margin: 0 0 10px;
  font-size: 1.02rem;
}

.review-item p {
  line-height: 1.55;
}

.review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.answer-line {
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--overlay);
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 22px;
  box-shadow: var(--shadow);
}

.terms-card {
  width: min(720px, 100%);
}

.terms-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding-left: 22px;
  color: var(--ink);
  line-height: 1.5;
}

.terms-check {
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.modal-card h2 {
  margin: 0 0 8px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  padding: 0 44px 30px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.site-footer p {
  margin: 0;
}

body.fullscreen-quiz {
  min-height: 100vh;
  overflow-x: hidden;
}

body.fullscreen-quiz .topbar,
body.fullscreen-quiz .quiz-header,
body.fullscreen-quiz .quiz-tools,
body.fullscreen-quiz .results {
  display: none;
}

body.fullscreen-quiz .quiz-page {
  min-height: 100vh;
  padding: 28px;
  align-items: center;
}

body.fullscreen-quiz .quiz-shell {
  width: min(100%, 940px);
  margin: 0 auto;
}

body.fullscreen-quiz .question-panel {
  min-height: min(720px, calc(100vh - 128px));
  display: grid;
  align-content: center;
}

body.fullscreen-quiz #questionStem {
  font-size: 1.8rem;
}

body.fullscreen-quiz .nav-row {
  justify-content: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .results-header,
  .library-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .layout,
  .page-wrap,
  .quiz-page {
    padding-left: 22px;
    padding-right: 22px;
  }

  .bottom-notice,
  .site-footer {
    padding-left: 22px;
    padding-right: 22px;
  }

  .topbar h1 {
    font-size: 1.75rem;
  }

  .empty-copy h2,
  .start-copy h2 {
    font-size: 2rem;
  }

  .quiz-header h2 {
    font-size: 1.75rem;
  }

  #questionStem {
    font-size: 1.28rem;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .workspace {
    order: 1;
  }
}

@media (max-width: 520px) {
  .topbar,
  .layout,
  .page-wrap,
  .quiz-page {
    padding-left: 14px;
    padding-right: 14px;
  }

  .layout,
  .page-wrap,
  .quiz-page {
    padding-top: 16px;
    padding-bottom: 32px;
  }

  .bottom-notice,
  .site-footer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .empty-copy,
  .start-copy {
    padding: 22px;
  }

  .empty-copy h2,
  .start-copy h2 {
    font-size: 1.65rem;
    line-height: 1.12;
  }

  .quiz-header h2 {
    font-size: 1.5rem;
    line-height: 1.14;
  }

  .question-panel,
  .results {
    padding: 18px;
  }

  #questionStem {
    font-size: 1.18rem;
  }

  .quiz-details {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .input-actions,
  .nav-row,
  .result-actions,
  .modal-actions,
  .library-actions,
  .start-actions,
  .quiz-header-actions {
    flex-direction: column;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .app-nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .question-grid {
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  }

  .choice-button {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .split-row {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 12px;
  }
}
