:root {
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --border: #E4E4E1;
  --text: #1C1C1E;
  --text-muted: #6B6B6B;

  --accent: #4C6FFF;
  --pass: #3FB950;
  --fail: #F85149;

  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --radius: 4px;
}

[data-theme="dark"] {
  --bg: #16171B;
  --surface: #1E2025;
  --border: #2C2E33;
  --text: #E8E8E6;
  --text-muted: #8A8D93;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* Theme toggle */

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 10;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* Headings / prompt line */

.prompt-line {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.prompt-line::before {
  content: '$ ';
  color: var(--accent);
}

h1 {
  font-family: var(--font-sans);
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

h2 {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: 40px;
  margin-bottom: 12px;
}

p.subtitle {
  color: var(--text-muted);
  margin-top: 0;
  margin-bottom: 32px;
  font-size: 16px;
  line-height: 1.6;
}

/* Directory-listing topic picker */

.topic-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.dir-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease, border-color 0.1s ease;
}

.dir-row:last-child {
  border-bottom: none;
}

.dir-row .dir-prefix {
  color: var(--accent);
}

.dir-row:hover,
.dir-row:focus-visible {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-left-color: var(--accent);
}

/* Recent scores */

.attempt-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attempt-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.attempt-item .topic {
  color: var(--text);
}

.attempt-item .score {
  color: var(--accent);
  font-weight: 600;
}

.empty-state {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-style: normal;
}

/* Buttons (generic) */

.btn {
  display: inline-block;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn:focus-visible,
.dir-row:focus-visible,
.choice-btn:focus-visible,
.exit-btn:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Quiz header / progress bar */

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.progress {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress .bar-filled {
  color: var(--accent);
}

.progress .bar-empty {
  color: var(--border);
}

.exit-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.exit-btn:hover {
  border-color: var(--fail);
  color: var(--fail);
}

/* Question card */

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 16px;
}

.question-text {
  font-family: var(--font-sans);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.6;
  margin-top: 0;
  margin-bottom: 22px;
  color: var(--text);
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-btn {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  cursor: pointer;
  color: var(--text);
}

.choice-btn .choice-letter {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 13px;
  flex-shrink: 0;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-btn.correct {
  border-color: var(--pass);
  color: var(--text);
}

.choice-btn.correct .choice-letter {
  color: var(--pass);
}

.choice-btn.incorrect {
  border-color: var(--fail);
  color: var(--text);
}

.choice-btn.incorrect .choice-letter {
  color: var(--fail);
}

.choice-btn.selected {
  border-color: var(--accent);
}

.choice-btn.selected .choice-letter {
  color: var(--accent);
}

/* Test-runner style feedback */

.test-output {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 14px;
}

@media (prefers-reduced-motion: no-preference) {
  .test-output {
    animation: fade-in 0.15s ease-out;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.test-line {
  font-weight: 700;
  margin-bottom: 6px;
}

.test-line.pass {
  color: var(--pass);
}

.test-line.fail {
  color: var(--fail);
}

.test-comment {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
}

.modal p {
  margin-top: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

.btn.danger {
  background: var(--fail);
  border-color: var(--fail);
}

/* Score summary */

.score-summary {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  margin-bottom: 24px;
}

.score-summary .score-big {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

/* Missed questions */

.missed-question {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.missed-question .label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 14px;
}

.missed-question .your-answer {
  color: var(--fail);
}

.missed-question .correct-answer {
  color: var(--pass);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

@media (min-width: 480px) {
  .actions {
    flex-direction: row;
  }
}

@media (max-width: 480px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }

  .container {
    padding-top: 56px;
  }
}
