:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #66736d;
  --line: #d8ded8;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --accent: #116a5c;
  --accent-2: #8a4b16;
  --soft: #eaf3ef;
}

* {
  box-sizing: border-box;
}

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

.auth-banner {
  padding: 10px 18px;
  background: #8b1d1d;
  color: #fff;
  font-weight: 700;
  text-align: center;
}

.shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.75rem;
  line-height: 1.15;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.05rem;
}

h3 {
  margin: 14px 0 6px;
  font-size: 0.92rem;
}

.chapter,
.badges span {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

.source-badge {
  display: inline-block;
  margin-left: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--soft);
  color: var(--accent);
  font-size: 0.74rem;
}

.source-badge.is-real {
  background: #e7f0ff;
  color: #1d4f8f;
}

.source-badge.is-formal {
  background: #e6f4ea;
  color: #14643a;
}

.source-badge.is-disputed {
  background: #fff4cf;
  color: #7a5a00;
}

.source-badge.is-rejected {
  background: #ffe8e8;
  color: #8b1d1d;
}

.source-badge.is-pending {
  background: #eceff1;
  color: var(--muted);
}

.countdown.is-urgent {
  border-color: #8b1d1d;
  background: #ffe8e8;
  color: #8b1d1d;
  animation: pulse-urgent 1s steps(2, start) infinite;
}

@keyframes pulse-urgent {
  50% {
    opacity: 0.55;
  }
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  flex-direction: column;
  gap: 8px;
}

.back-link {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.nav-links a {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.nav-links a.is-active {
  color: var(--accent);
}

.streak-pill {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 800;
}

.streak-pill.is-zero {
  color: var(--muted);
}

.band {
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.core {
  margin-bottom: 0;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  font-size: 1rem;
}

.markdown h2 {
  margin-top: 18px;
  color: var(--accent);
}

.markdown p {
  margin-bottom: 12px;
}

.flashgrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.flashcard {
  position: relative;
  display: block;
  width: 100%;
  min-height: 154px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.card-face {
  display: flex;
  min-height: 154px;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.card-back {
  display: none;
}

.flashcard.is-flipped .card-front {
  display: none;
}

.flashcard.is-flipped .card-back {
  display: flex;
}

.card-kicker,
.anchor-line,
.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

.card-text {
  font-size: 1rem;
}

.anchor-line {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

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

ul,
ol {
  padding-left: 20px;
}

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

.index-list {
  display: grid;
  gap: 10px;
}

.segmented,
.chips {
  display: flex;
  gap: 8px;
}

.segmented {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
  min-width: 0;
  max-width: 100%;
}

.chips {
  flex-wrap: wrap;
}

.segmented button,
.chips button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
}

.segmented button.is-active,
.chips button.is-active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
}

.index-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}

.index-item strong,
.index-item em {
  display: block;
}

.index-item em {
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
}

.anchor-badges {
  grid-column: 1 / -1;
}

.timeline {
  margin-bottom: 0;
}

.timeline li {
  margin-bottom: 6px;
}

code {
  color: var(--accent-2);
}

.loading,
.error {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.error {
  color: #8b1d1d;
}

.rag-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.rag-form {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.rag-form input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}

.rag-form button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 700;
}

.rag-panel.is-disabled {
  opacity: 0.66;
}

.rag-hits {
  padding-left: 20px;
}

.rag-answer {
  margin-bottom: 14px;
  padding: 12px;
  border-left: 3px solid var(--accent);
  background: var(--soft);
}

.citation-link {
  border: 0;
  border-bottom: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}

.rag-hits li {
  margin-bottom: 12px;
}

.rag-hits li.is-active {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.rag-hits p {
  margin: 4px 0;
}

.bank-controls {
  display: grid;
  /* minmax(0,1fr) (not bare 1fr=minmax(auto,1fr)) lets the track shrink below the nowrap
     .segmented content width, so the filter row scrolls internally instead of widening the page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.bank-controls > * {
  min-width: 0;
}

.question-list {
  display: grid;
  gap: 14px;
}

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

.question-item h2 {
  font-size: 1rem;
  line-height: 1.45;
}

.option-list {
  display: grid;
  gap: 8px;
  padding-left: 0;
  list-style: none;
}

.option-list li,
.option-button {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: inherit;
  padding: 10px;
  text-align: left;
}

.option-button {
  cursor: pointer;
  font: inherit;
}

.segmented button:disabled,
.chips button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.option-list li.is-answer,
.option-button.is-selected {
  border-color: var(--accent);
  background: var(--soft);
}

.answer-panel {
  margin-top: 12px;
  padding: 12px;
  border-left: 3px solid var(--accent);
  background: var(--soft);
}

.answer-panel.is-miss {
  border-left-color: var(--accent-2);
}

.ai-hint-wrap {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.ai-hint-button {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 8px 10px;
}

.ai-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.hint-citation {
  border-bottom: 1px dotted var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.question-item.is-wrong {
  border-color: var(--accent-2);
}

.source-line {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.status-list {
  display: grid;
  gap: 12px;
}

.status-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  color: inherit;
  text-decoration: none;
}

.status-row h2 {
  margin: 4px 0;
  font-size: 1rem;
}

.status-row time,
.danger {
  color: var(--accent-2);
  font-size: 0.9rem;
}

.review-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.review-summary span,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 10px 12px;
}

.review-mode-banner a,
.review-action {
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
}

.review-interval {
  display: inline-block;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 700;
  padding: 3px 7px;
}

.mock-settings {
  display: grid;
  gap: 14px;
}

.checkbox-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.checkbox-grid label {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.resume-panel {
  display: grid;
  gap: 8px;
}

.resume-panel button {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 8px 12px;
}

.badges-grid {
  display: grid;
  gap: 12px;
}

.badge-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.badge-card.is-earned {
  border-color: var(--accent);
  background: var(--soft);
}

.badge-card.is-locked {
  opacity: 0.68;
}

.primary-action {
  width: fit-content;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
}

.number-field {
  display: grid;
  gap: 6px;
  max-width: 180px;
}

.number-field input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: inherit;
  font: inherit;
  padding: 10px;
}

.mock-question {
  scroll-margin-top: 16px;
}

.admin-controls {
  display: grid;
  gap: 12px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  font-weight: 700;
}

.status-pill {
  display: inline-block;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  padding: 2px 6px;
  white-space: nowrap;
}

.pager {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.pager button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: inherit;
  cursor: pointer;
  padding: 8px 12px;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.admin-actions {
  display: grid;
  gap: 6px;
  min-width: 150px;
}

.admin-actions button,
.admin-actions select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  padding: 6px 8px;
}

.admin-actions button {
  cursor: pointer;
}

.admin-actions button:disabled,
.admin-actions select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

@media (max-width: 767px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .split {
    display: block;
  }

  .chapter {
    display: inline-block;
    margin-top: 10px;
  }

  .top-actions {
    align-items: flex-start;
    margin-top: 10px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .index-item,
  .rag-form,
  .status-row {
    display: block;
  }

  .rag-form button {
    margin-top: 8px;
    width: 100%;
  }

  .primary-action {
    width: 100%;
  }
}
