:root {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4b6bfb;
  --primary-dark: #4050d3;
  --accent: #ff7eb3;
  --border: rgba(15, 23, 42, 0.08);
  --correct: #1ec28b;
  --incorrect: #f97066;
  --flag: #f1a208;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --card: #111b2f;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #7c8eff;
  --primary-dark: #5b6fe4;
  --border: rgba(148, 163, 184, 0.18);
  --correct: #34d399;
  --incorrect: #fb7185;
  --flag: #facc15;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

img {
  max-width: 100%;
  height: auto;
}

button,
select,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.no-js {
  background: #fee4e2;
  color: #b42318;
  padding: 1rem;
  text-align: center;
}

.app-header {
  padding: clamp(1rem, 3vw, 2rem);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.65rem, 4vw, 2.4rem);
}

.home-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.home-link:focus-visible,
.home-link:hover {
  text-decoration: underline;
}

.eyebrow,
.tag,
.label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: var(--muted);
}

.header-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chip {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  font-weight: 600;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.chip.status {
  background: rgba(75, 107, 251, 0.08);
  border-color: transparent;
  color: var(--primary);
}

.chip.ghost {
  background: rgba(148, 163, 184, 0.15);
  color: inherit;
}

.chip--offline {
  background: rgba(249, 112, 102, 0.15);
  color: var(--incorrect);
}

.chip.active {
  border-color: var(--flag);
  color: var(--flag);
  background: rgba(241, 162, 8, 0.15);
}

.app-shell {
  padding: 0 clamp(1rem, 3vw, 2rem) 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: 1.5rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: 0 25px 80px rgba(15, 23, 42, 0.08);
  border: 1px solid var(--border);
}

.start-card .intro h2 {
  margin-top: 0;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.setting select {
  padding: 0.75rem 0.9rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
}

.setting.switch {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.setting.switch input {
  width: 2.75rem;
  height: 1.4rem;
}

.mode-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 1rem;
  border: 1px dashed var(--border);
}

.mode-toggle label {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-weight: 500;
}

.tips {
  padding-left: 1.2rem;
  color: var(--muted);
}

.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 1rem;
  padding: 0.95rem 1.6rem;
  font-weight: 600;
  box-shadow: 0 15px 30px rgba(75, 107, 251, 0.35);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary:active {
  transform: translateY(1px);
}

.ghost {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 0.95rem;
  padding: 0.85rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.6rem;
}

.stat {
  background: var(--card);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
}

.stat .value {
  margin: 0.2rem 0 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.value.warning {
  color: #fbbf24;
}

.value.danger {
  color: #f97066;
}

.progress {
  margin: 1rem 0;
}

.progress-bar {
  width: 100%;
  height: 0.5rem;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  transition: width 0.3s ease;
}

.question-card {
  margin-top: 1rem;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.question-meta {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.question-text {
  font-size: 1.1rem;
  margin: 0.75rem 0 1.25rem;
}

.question-media {
  margin: 0 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  padding: 0.75rem;
  background: var(--surface);
}

.question-media img {
  width: 100%;
  display: block;
  border-radius: 0.9rem;
  background: #000;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option {
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  padding: 0.9rem;
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  background: var(--surface);
  cursor: pointer;
  transition: border 0.2s ease, transform 0.15s ease;
}

.option:active {
  transform: scale(0.995);
}

.option .letter {
  font-weight: 700;
  color: var(--muted);
}

.option .check {
  font-weight: 700;
  color: var(--muted);
  min-width: 1.5rem;
}

.option.selected {
  border-color: var(--primary);
  background: rgba(75, 107, 251, 0.15);
}

.option.correct {
  border-color: var(--correct);
  background: rgba(30, 194, 139, 0.12);
}

.option.incorrect {
  border-color: var(--incorrect);
  background: rgba(249, 112, 102, 0.12);
}

.feedback {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feedback button {
  align-self: flex-start;
}

.explanation,
.insight {
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(35, 138, 230, 0.08);
  border: 1px solid rgba(35, 138, 230, 0.25);
}

.insight {
  background: rgba(142, 68, 173, 0.1);
  border-color: rgba(142, 68, 173, 0.25);
}

.nav-helpers {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.75rem 0 0.5rem;
  color: var(--muted);
}

#examView {
  padding-bottom: clamp(5rem, 12vh, 7rem);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: calc(100vh - 10rem);
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  position: sticky;
  bottom: 1rem;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  padding: 0.75rem;
  border-radius: 1rem;
  background: var(--card);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.15);
  z-index: 10;
  backdrop-filter: blur(10px);
}

.bottom-nav button {
  width: 100%;
  min-height: 3rem;
}

@media (max-width: 430px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    padding: 1rem;
  }

  .header-controls {
    width: 100%;
    justify-content: space-between;
  }

  .app-header h1,
  .home-link {
    font-size: 1.65rem;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .app-shell {
    padding: 0 1rem 4.5rem;
  }

  .card {
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 10px 35px rgba(15, 23, 42, 0.12);
  }

  .start-card .intro h2 {
    font-size: 1.45rem;
  }

  .start-card .intro p {
    font-size: 0.95rem;
  }

  .tips {
    padding-left: 1rem;
    font-size: 0.9rem;
  }

  .tips li {
    margin-bottom: 0.35rem;
  }

  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .setting select,
  .setting.switch,
  .mode-toggle {
    font-size: 0.95rem;
  }

  .mode-toggle {
    padding: 0.5rem 0.75rem;
  }

  .question-card {
    padding: 1.1rem;
    flex: 1 1 auto;
    overflow: visible;
    max-height: none;
  }

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

  .options {
    gap: 0.55rem;
  }

  .option {
    padding: 0.85rem 0.9rem;
  }

  .nav-helpers {
    flex-direction: column;
    gap: 0.35rem;
    align-items: flex-start;
  }

  #examView {
    padding-bottom: clamp(4.25rem, 11vh, 5.75rem);
    min-height: calc(100vh - 7.5rem);
  }

  .bottom-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    padding: 0.65rem;
  }

  .bottom-nav button {
    min-height: 2.8rem;
    font-size: 0.95rem;
  }
}

.results-card {
  text-align: center;
  margin-top: 1rem;
}

.score-ring {
  width: 180px;
  height: 180px;
  margin: 1.5rem auto;
  border-radius: 50%;
  background: conic-gradient(var(--primary) 0deg, var(--accent) 120deg, rgba(148, 163, 184, 0.2) 120deg 360deg);
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  position: relative;
}

.score-ring span {
  position: absolute;
}

.score-breakdown {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.pass {
  font-weight: 600;
}

.pass--success {
  color: var(--correct);
}

.results-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.review {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.review-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}

.review-card .option {
  cursor: default;
}

.review-card .question-text {
  margin-top: 0.25rem;
}

.review-card .options {
  margin-top: 0.75rem;
}

.review-card .meta {
  font-size: 0.9rem;
  color: var(--muted);
}

#sheet {
  border: none;
  border-radius: 1.5rem 1.5rem 0 0;
  width: min(480px, 90vw);
  max-height: 80vh;
  margin: auto;
  padding: 1.5rem;
  background: var(--card);
  color: inherit;
}

#sheet header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

#sheet .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  gap: 0.5rem;
}

.q-btn {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.65rem 0;
  font-weight: 600;
  background: transparent;
}

.q-btn.current {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.q-btn.answered {
  background: rgba(30, 194, 139, 0.15);
  color: var(--correct);
}

.q-btn.flagged {
  background: rgba(241, 162, 8, 0.18);
  color: var(--flag);
}

::backdrop {
  background: rgba(15, 23, 42, 0.65);
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
    align-items: flex-start;
  }

  #startScreen,
  #examView,
  #resultsCard {
    width: min(880px, 70vw);
    margin-inline: auto;
  }
}
