:root {
  color-scheme: light dark;
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-strong: #edf7f2;
  --ink: #15211f;
  --muted: #60706b;
  --line: #d8e3df;
  --accent: #0f8a70;
  --accent-strong: #075c4c;
  --accent-soft: #dff5ec;
  --warm: #f06d4f;
  --sidebar: #17332e;
  --hero: #17332e;
  --hero-2: #285348;
  --right: #157347;
  --wrong: #b42318;
  font-family: Inter, Arial, Helvetica, sans-serif;
}

[data-theme="dark"] {
  --bg: #101513;
  --surface: #17211d;
  --surface-strong: #203029;
  --ink: #eef8f2;
  --muted: #a6b9b0;
  --line: #30453e;
  --accent: #41d6ad;
  --accent-strong: #a6f4d3;
  --accent-soft: #1f4037;
  --warm: #ff8a6b;
  --sidebar: #0f1d1a;
  --hero: #10221d;
  --hero-2: #1c3d34;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #101513;
    --surface: #17211d;
    --surface-strong: #203029;
    --ink: #eef8f2;
    --muted: #a6b9b0;
    --line: #30453e;
    --accent: #41d6ad;
    --accent-strong: #a6f4d3;
    --accent-soft: #1f4037;
    --warm: #ff8a6b;
    --sidebar: #0f1d1a;
    --hero: #10221d;
    --hero-2: #1c3d34;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select,
input,
textarea {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

button {
  cursor: pointer;
  font-weight: 700;
}

textarea {
  min-height: 280px;
  padding: 12px;
  font-family: Consolas, Monaco, monospace;
  line-height: 1.45;
  resize: vertical;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 56px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  display: block;
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
}

.top-nav,
.hero-actions,
.pill-row,
.toolbar,
.question-admin-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.theme-toggle,
.secondary-action,
.top-nav a {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 11px 14px;
  font-weight: 700;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 800;
}

.landing-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 80px;
}

.hero-panel {
  min-height: 68vh;
  border-radius: 8px;
  padding: clamp(26px, 5vw, 58px);
  color: #edf4ff;
  background: #07110f;
  border: 1px solid rgba(139, 175, 165, 0.18);
  box-shadow: 0 24px 80px rgba(5, 16, 13, 0.28);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  align-items: center;
  gap: clamp(28px, 5vw, 64px);
  overflow: hidden;
  position: relative;
}

.hero-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(65, 214, 173, 0.12), transparent 42%),
    radial-gradient(circle at 78% 18%, rgba(65, 214, 173, 0.16), transparent 28%);
  pointer-events: none;
}

.hero-copy,
.hero-preview {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-panel .eyebrow {
  color: #41d6ad;
}

h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(38px, 6vw, 76px);
  line-height: 1.02;
}

.lede {
  max-width: 720px;
  margin: 0;
  color: #b9cbc4;
  font-size: 20px;
  line-height: 1.6;
}

.hero-copy {
  display: grid;
  gap: 22px;
}

.hero-panel .secondary-action {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.16);
  color: #edf4ff;
}

.pill-row span {
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
}

.hero-preview {
  display: grid;
  gap: 18px;
  border: 1px solid rgba(139, 175, 165, 0.2);
  border-radius: 8px;
  background: rgba(13, 28, 24, 0.88);
  padding: 22px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
}

.preview-top,
.preview-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.preview-top span,
.preview-score span {
  color: #9bb4ac;
  font-weight: 800;
}

.preview-top strong {
  color: #41d6ad;
}

.preview-bars {
  display: grid;
  gap: 12px;
}

.preview-bars span {
  display: block;
  height: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.preview-bars span:nth-child(1) {
  width: 88%;
}

.preview-bars span:nth-child(2) {
  width: 68%;
}

.preview-bars span:nth-child(3) {
  width: 78%;
}

.preview-question {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(139, 175, 165, 0.18);
  border-radius: 8px;
  padding: 16px;
}

.preview-question p {
  margin: 0 0 4px;
  color: #edf4ff;
  font-weight: 800;
}

.preview-question div {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #cbdad5;
}

.preview-question div span {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(65, 214, 173, 0.7);
  border-radius: 50%;
}

.preview-score div {
  flex: 1;
  border: 1px solid rgba(139, 175, 165, 0.18);
  border-radius: 8px;
  padding: 14px;
}

.preview-score strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.preview-logo {
  width: 86px;
  height: 86px;
  justify-self: center;
  filter: drop-shadow(0 18px 34px rgba(65, 214, 173, 0.2));
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.landing-features article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
}

.landing-features span {
  color: var(--accent-strong);
  font-weight: 900;
}

.landing-features h2 {
  margin: 12px 0 8px;
}

.landing-features p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.auth-shell {
  width: min(520px, calc(100% - 32px));
  margin: 36px auto 80px;
}

.auth-card,
.auth-panel,
.status,
.results,
.question,
.topic-panel,
.scoreboard,
.dashboard-header {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.auth-card,
.auth-panel,
.dashboard-header {
  padding: 24px;
}

.auth-card h1 {
  font-size: clamp(34px, 6vw, 56px);
}

.auth-card p,
.auth-panel p,
.dashboard-header p {
  color: var(--muted);
  line-height: 1.55;
}

.auth-form,
.inline-form,
.admin-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.inline-form label,
.admin-form label,
.topic-panel label {
  font-weight: 800;
}

.mfa-panel {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 20px;
}

.mfa-panel[hidden],
.auth-grid[hidden],
.account-panel[hidden] {
  display: none;
}

.mfa-qr {
  display: block;
  width: min(220px, 100%);
  margin: 12px 0;
  border: 1px solid var(--line);
  background: #ffffff;
}

.mfa-qr[hidden] {
  display: none;
}

.mfa-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.mfa-secret {
  overflow-wrap: anywhere;
  font-family: Consolas, Monaco, monospace;
}

.dashboard-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  transition: grid-template-columns 180ms ease;
}

.dashboard-page.sidebar-collapsed {
  grid-template-columns: 92px 1fr;
}

.app-sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  color: #edf4ff;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 24px;
  position: sticky;
  top: 0;
}

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

.sidebar-collapse {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #edf4ff;
  font-size: 22px;
  line-height: 1;
}

.sidebar-collapsed .app-sidebar {
  padding: 22px 14px;
  justify-items: center;
}

.sidebar-collapsed .sidebar-label,
.sidebar-collapsed .theme-toggle,
.sidebar-collapsed .secondary-action {
  display: none;
}

.sidebar-collapsed .sidebar-top,
.sidebar-collapsed .brand,
.sidebar-collapsed .side-link {
  justify-content: center;
}

.sidebar-collapsed .sidebar-top {
  display: grid;
  justify-items: center;
}

.sidebar-collapsed .brand {
  width: 64px;
}

.sidebar-collapsed .side-nav {
  width: 64px;
}

.sidebar-collapsed .side-link {
  width: 64px;
  min-height: 64px;
  padding: 0;
}

.sidebar-collapsed .sidebar-collapse {
  width: 44px;
}

.app-sidebar .theme-toggle,
.app-sidebar .secondary-action {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #edf4ff;
}

.side-nav {
  display: grid;
  gap: 10px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #edf4ff;
  border-color: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 12px;
  font-weight: 800;
}

.side-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font-size: 13px;
  font-weight: 900;
}

.side-link.is-active {
  background: #edf8f2;
  border-color: #edf8f2;
  color: #17332e;
}

.app-main {
  width: min(1180px, 100%);
  padding: 28px clamp(16px, 4vw, 44px);
}

.dashboard-header {
  margin-bottom: 18px;
  background:
    linear-gradient(135deg, rgba(15, 138, 112, 0.14), rgba(240, 109, 79, 0.08)),
    var(--surface);
}

.dashboard-header h1 {
  font-size: clamp(30px, 5vw, 52px);
}

.dashboard-view {
  display: none;
}

.dashboard-view.is-active {
  display: block;
}

.toolbar {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 18px;
}

.session-builder {
  display: grid;
  gap: 16px;
  margin-bottom: 20px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.setup-row {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(220px, 1fr);
  align-items: center;
  gap: 14px;
}

.setup-row label,
.search-label {
  font-weight: 800;
}

.topic-picker-head,
.exam-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topic-picker-head h2 {
  margin: 0 0 4px;
}

.topic-picker-head p,
.topic-count {
  margin: 0;
  color: var(--muted);
}

.topic-actions,
.exam-actions {
  flex-wrap: wrap;
}

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

.exam-actions {
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.exam-actions button:first-child,
.exam-actions button:nth-child(2) {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.status {
  display: none;
  margin-bottom: 18px;
  padding: 16px;
  color: var(--muted);
}

.status.is-visible {
  display: block;
}

.topic-panel,
.scoreboard,
.results {
  display: none;
  margin-bottom: 18px;
  padding: 18px;
}

.topic-panel.is-visible,
.scoreboard.is-visible,
.results.is-visible {
  display: block;
}

.session-builder .topic-panel {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.topic-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  margin-top: 10px;
  overflow: hidden;
}

.topic-group:first-child {
  margin-top: 0;
}

.topic-group-title {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 14px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

.topic-group-title small,
.topic-option small {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.topic-options {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.topic-option,
.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.topic-option {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.topic-option span {
  display: grid;
  gap: 2px;
}

.topic-option input,
.choice input {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

.quiz {
  display: grid;
  gap: 14px;
}

.question {
  padding: 20px;
  box-shadow: 0 10px 28px rgba(21, 33, 31, 0.05);
}

.question h2 {
  margin: 0 0 10px;
  font-size: 21px;
}

.question-source {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-weight: 800;
}

.stem {
  margin: 0 0 16px;
  line-height: 1.6;
}

.choice {
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.mark-button {
  margin-top: 6px;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.progress-empty {
  padding: 10px;
}

.progress-head {
  margin-bottom: 18px;
}

.progress-head h2 {
  margin: 4px 0 8px;
  font-size: clamp(28px, 5vw, 44px);
}

.progress-head p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.score-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.score-card,
.question-admin-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
}

.score-card {
  display: grid;
  gap: 8px;
  min-height: 120px;
}

.score-card strong {
  display: block;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

.score-card span {
  color: var(--muted);
  font-weight: 800;
}

.score-card small,
.explanation,
.question-admin-item p {
  color: var(--muted);
}

.progress-filters {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(220px, 1.4fr);
  gap: 14px;
  margin-bottom: 18px;
}

.score-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.score-table {
  width: 100%;
  border-collapse: collapse;
}

.score-table th,
.score-table td {
  border-top: 1px solid var(--line);
  padding: 14px;
  text-align: left;
  vertical-align: middle;
}

.score-table thead th {
  border-top: 0;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 14px;
}

.score-table td:first-child {
  min-width: 260px;
}

.score-table td:first-child strong,
.score-table td:first-child span {
  display: block;
}

.score-table td:first-child span {
  color: var(--muted);
  font-size: 14px;
  margin-top: 3px;
}

.score-table small {
  display: inline-block;
  min-width: 38px;
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.progress-meter {
  display: inline-block;
  width: min(160px, 70%);
  height: 8px;
  margin-right: 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--line) 78%, transparent);
  overflow: hidden;
}

.progress-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.progress-meter[data-tone="okay"] span {
  background: #f2b84b;
}

.progress-meter[data-tone="weak"] span {
  background: #e85d4f;
}

.trend-up {
  color: var(--accent-strong);
  font-weight: 900;
}

.trend-flat {
  color: var(--warm);
  font-weight: 900;
}

.correct {
  color: var(--right);
  font-weight: 800;
}

.incorrect {
  color: var(--wrong);
  font-weight: 800;
}

.admin-actions {
  margin: 0;
}

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

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

.question-admin-item h3,
.question-admin-item p {
  margin: 0;
}

.question-editor[hidden] {
  display: none;
}

.account-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-auth-panel {
  margin-bottom: 18px;
}

.compact-auth-panel:has(#adminLoggedOut[hidden]) {
  display: none;
}

@media (max-width: 860px) {
  .dashboard-page,
  .dashboard-page.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    min-height: auto;
    position: static;
    gap: 14px;
  }

  .sidebar-collapsed .app-sidebar {
    padding: 16px;
  }

  .sidebar-collapsed .sidebar-label {
    display: inline;
  }

  .sidebar-collapsed .theme-toggle,
  .sidebar-collapsed .secondary-action {
    display: block;
  }

  .sidebar-collapse {
    width: 44px;
  }

  .site-header,
  .app-main {
    padding: 16px;
  }

  .side-nav {
    grid-template-columns: 1fr;
  }

  .hero-panel,
  .landing-features {
    grid-template-columns: 1fr;
  }

  .hero-panel {
    min-height: auto;
  }

  .hero-preview {
    width: 100%;
  }

  .setup-row,
  .topic-picker-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topic-actions,
  .exam-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .score-summary {
    grid-template-columns: 1fr;
  }

  .progress-filters {
    grid-template-columns: 1fr;
  }

  select,
  input,
  textarea,
  button,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .sidebar-collapse {
    width: 44px;
  }
}
