:root {
  --ink: #1f2933;
  --muted: #64748b;
  --line: #dbe3ef;
  --paper: #fbfcfe;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f4ef;
  --coral: #c2410c;
  --coral-soft: #ffedd5;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 30rem),
    linear-gradient(180deg, #f8fbfc 0%, #edf4f8 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-title {
  font-weight: 800;
  line-height: 1.15;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav button,
.ghost-btn,
.secondary-btn,
.primary-btn,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
}

.nav button.active,
.nav button:hover,
.ghost-btn:hover,
.secondary-btn:hover,
.icon-btn:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--accent-soft);
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 28px;
  align-items: stretch;
  margin-bottom: 28px;
}

.hero-copy {
  padding: 36px 0;
}

.eyebrow {
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 780px;
  margin-top: 12px;
  font-size: clamp(2.1rem, 5vw, 4.7rem);
  line-height: 0.98;
}

.lead {
  max-width: 680px;
  color: #405064;
  font-size: 1.12rem;
  line-height: 1.75;
}

.hero-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.insight-panel,
.exam-card,
.mode-card,
.question-panel,
.result-card,
.auth-panel,
.mini-panel {
  border: 1px solid rgba(219, 227, 239, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.insight-panel {
  padding: 24px;
  display: grid;
  align-content: center;
  gap: 14px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--paper);
}

.stat strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.stat span {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin: 28px 0 14px;
}

.section-head p {
  margin: 8px 0 0;
  color: var(--muted);
}

.section-head.compact {
  margin-top: 0;
}

.exam-grid,
.mode-grid,
.topic-grid,
.summary-grid,
.account-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.topic-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.account-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.analytics-panel {
  display: grid;
  gap: 16px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.recommendation-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: var(--accent-soft);
  padding: 18px;
}

.recommendation-panel p {
  margin: 8px 0 0;
  color: var(--accent-strong);
  line-height: 1.5;
}

.score-trend {
  display: grid;
  grid-template-columns: repeat(8, minmax(32px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 170px;
  margin-top: 12px;
}

.trend-point {
  display: grid;
  gap: 6px;
  align-items: end;
  text-align: center;
}

.trend-bar {
  height: var(--score);
  min-height: 8px;
  border-radius: 8px 8px 2px 2px;
  background: var(--accent);
}

.trend-point strong {
  font-size: 0.88rem;
}

.trend-point span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  align-items: center;
  margin-top: 12px;
}

.metric-row strong,
.metric-row span {
  display: block;
}

.metric-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-row > span {
  color: var(--ink);
  font-weight: 900;
}

.metric-track {
  grid-column: 1 / -1;
  height: 9px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.metric-track div {
  width: var(--value);
  height: 100%;
  background: var(--accent);
}

.time-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 14px;
  margin-top: 12px;
}

.time-stat strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.time-stat span {
  color: var(--muted);
  font-size: 0.9rem;
}

.exam-card,
.mode-card,
.topic-card {
  padding: 18px;
  text-align: left;
}

.exam-card {
  min-height: 178px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.exam-card p,
.mode-card p,
.topic-card p {
  color: var(--muted);
  line-height: 1.55;
}

.topic-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid rgba(219, 227, 239, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.resume-note,
.sync-status,
.muted {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.topic-row {
  margin: -4px 0 18px;
}

.utility-row {
  margin: 0 0 16px;
}

.bookmark-btn.active {
  border-color: rgba(194, 65, 12, 0.4);
  background: var(--coral-soft);
  color: var(--coral);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
}

.source-badge {
  background: var(--coral-soft);
  color: var(--coral);
}

.account-strip {
  margin: 18px 0 30px;
}

.account-page {
  display: grid;
  gap: 22px;
}

.auth-panel {
  width: min(640px, 100%);
  padding: 26px;
}

.auth-panel label {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  color: var(--ink);
  font-weight: 800;
}

.auth-panel input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

.auth-panel input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.search-panel {
  display: flex;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  padding: 16px;
  margin-bottom: 18px;
}

.search-panel label {
  flex: 1;
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.search-panel input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

.search-panel input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.form-error,
.form-message {
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.5;
}

.form-error {
  background: var(--red-soft);
  color: var(--red);
}

.form-message {
  background: var(--green-soft);
  color: var(--green);
}

.mini-panel {
  padding: 18px;
}

.saved-row,
.history-row {
  width: 100%;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  margin-top: 10px;
  padding: 12px;
  text-align: left;
}

.saved-row:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--accent-soft);
}

.saved-row span,
.history-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.quiz-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.quiz-sidebar {
  position: sticky;
  top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  padding: 16px;
}

.topic-focus {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
}

.timer-panel {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 12px;
  margin-top: 14px;
}

.timer-panel span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.timer-panel strong {
  font-size: 2rem;
  line-height: 1;
}

.timer-panel.urgent {
  border-color: rgba(185, 28, 28, 0.34);
  background: var(--red-soft);
  color: var(--red);
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin: 14px 0;
}

.progress-fill {
  height: 100%;
  width: var(--progress);
  background: var(--accent);
}

.question-map {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.question-map button {
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-weight: 800;
}

.question-map button.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.question-map button.answered {
  background: var(--blue-soft);
  color: var(--blue);
}

.question-map button.bookmarked {
  border-color: rgba(194, 65, 12, 0.45);
  box-shadow: inset 0 -3px 0 var(--coral);
}

.question-map-toggle > summary {
  display: none;
}

.question-panel {
  padding: 24px;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 16px;
}

.question-meta-right {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.question-prompt {
  line-height: 1.7;
  font-size: 1.08rem;
}

.source-context {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  overflow: hidden;
}

.source-context > summary {
  cursor: pointer;
  font-weight: 800;
  padding: 12px 14px;
}

.source-context .content-body {
  border-top: 1px solid var(--line);
  max-height: 360px;
  overflow: auto;
  padding: 14px;
}

.source-context .content-body p {
  margin-bottom: 12px;
}

.options {
  display: grid;
  gap: 10px;
  margin: 22px 0;
}

.option {
  width: 100%;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px 14px 10px 10px;
  text-align: left;
}

.option:hover {
  border-color: rgba(15, 118, 110, 0.4);
}

.option-letter {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #edf2f7;
  font-weight: 900;
}

.option.selected {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.option.correct {
  border-color: var(--green);
  background: var(--green-soft);
}

.option.wrong {
  border-color: var(--red);
  background: var(--red-soft);
}

.feedback {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 14px 16px;
  line-height: 1.6;
  border-radius: 0 8px 8px 0;
}

.feedback strong {
  display: block;
  margin-bottom: 4px;
}

.review-rating-panel {
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: var(--paper);
  padding: 14px;
  margin-top: 16px;
}

.review-rating-panel p {
  margin: 6px 0 0;
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.quiz-controls {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
}

.result-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 20px;
  align-items: stretch;
}

.score-ring {
  display: grid;
  place-items: center;
  min-height: 270px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  text-align: center;
}

.score-ring strong {
  display: block;
  font-size: clamp(3.8rem, 10vw, 7rem);
  line-height: 0.95;
}

.result-card {
  padding: 22px;
}

.review-list {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.review-tools {
  margin-top: 22px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.filter-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.filter-btn span {
  color: var(--muted);
}

.filter-btn.active,
.filter-btn:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--accent-soft);
}

.topic-filter-row {
  margin-top: 12px;
}

.topic-link {
  border: 0;
  cursor: pointer;
}

.topic-link:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.search-results {
  margin-top: 0;
}

.finish-review {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.compact-stats {
  grid-template-columns: repeat(2, 1fr);
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}

.review-item.good {
  border-color: rgba(21, 128, 61, 0.38);
}

.review-item.bad {
  border-color: rgba(185, 28, 28, 0.34);
}

.review-item p {
  line-height: 1.58;
}

.markdown-page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.toc {
  position: sticky;
  top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.84);
}

.toc button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 0;
  text-align: left;
  font-weight: 700;
}

.content {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  padding: 28px;
  box-shadow: var(--shadow);
}

.content h1 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
}

.content h2 {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.content h3 {
  margin-top: 22px;
}

.content p,
.content li {
  line-height: 1.7;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 0.92rem;
}

.content th,
.content td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.content th {
  background: #eef6f7;
}

.content a {
  color: var(--blue);
  font-weight: 700;
}

.content-image {
  display: block;
  width: min(220px, 70%);
  height: auto;
  margin: 0 0 22px;
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

@media (min-width: 640px) {
  .content-image {
    float: left;
    width: 220px;
    margin: 0 28px 20px 0;
  }

  /* Stop the intro paragraph's wrap once we reach the next heading,
     so tables and later sections span the full width again. */
  .content-image ~ h2:first-of-type,
  .content-image ~ h3:first-of-type {
    clear: both;
  }
}

@media (max-width: 880px) {
  .topbar,
  .section-head,
  .quiz-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .hero,
  .quiz-layout,
  .result-hero,
  .markdown-page {
    grid-template-columns: 1fr;
  }

  .exam-grid,
  .mode-grid,
  .topic-grid,
  .summary-grid,
  .account-grid,
  .analytics-grid,
  .finish-review {
    grid-template-columns: 1fr;
  }

  .recommendation-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .quiz-sidebar,
  .toc {
    position: static;
  }

  .question-map-toggle > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    list-style: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--ink);
    min-height: 42px;
    padding: 0 14px;
    font-weight: 800;
    margin-top: 14px;
  }

  .question-map-toggle > summary::-webkit-details-marker {
    display: none;
  }

  .question-map-toggle > summary::after {
    content: "Show";
  }

  .question-map-toggle[open] > summary::after {
    content: "Hide";
  }

  .question-map-toggle .question-map {
    margin-top: 10px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  .nav {
    justify-content: stretch;
  }

  .nav button {
    flex: 1 1 auto;
  }

  .search-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .hero-copy {
    padding: 12px 0;
  }

  .question-panel,
  .content {
    padding: 18px;
  }

  .option {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .option-letter {
    width: 32px;
    height: 32px;
  }

  .topic-card {
    align-items: stretch;
    flex-direction: column;
  }

  .rating-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
