:root {
  --bg:            #0a0a0a;
  --surface:       #1a1a1a;
  --surface-alt:   #111;
  --border:        #222;
  --border-strong: #333;
  --text:          #e0e0e0;
  --muted:         #888;
  --muted-dim:     #555;
  --row-border:    #161616;
  --row-hover:     #151515;
  --accent:        #e74c3c;
  --on-accent:     #fff;
  --blue:          #3498db;
  --green:         #66cc66;
  color-scheme: light dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:            #f4f4f5;
    --surface:       #ffffff;
    --surface-alt:   #eaeaec;
    --border:        #e2e2e5;
    --border-strong: #d2d2d6;
    --text:          #1a1a1a;
    --muted:         #6a6a70;
    --muted-dim:     #9a9aa0;
    --row-border:    #ededee;
    --row-hover:     #f0f0f1;
    --accent:        #d63a28;
    --blue:          #2980b9;
    --green:         #2e9e2e;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5 { font-weight: 600; letter-spacing: -0.3px; }
h1 { font-size: 1.6rem; letter-spacing: -0.5px; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }

hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

small { font-size: 0.78rem; color: var(--muted); }

/* ── Header ── */
body > header {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;

  h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.5px;

    a { color: inherit; text-decoration: none; }
    span { color: var(--accent); }
  }

  nav {
    display: flex;
    gap: 16px;

    a {
      color: var(--muted);
      font-size: 0.85rem;
      text-decoration: none;
      &:hover { color: var(--text); text-decoration: none; }
    }
  }
}

/* ── Layout ── */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

hgroup p { color: var(--muted); margin-top: 2px; }

/* ── Cards ── */
.card,
main article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

main article p + p { margin-top: 10px; }
main article h2 { margin-bottom: 8px; }

/* ── Card grid (home, topic list) ── */
main section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 600px) {
  main section { grid-template-columns: repeat(2, 1fr); }
}

main section article {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  transition: border-color 0.15s;
  &:hover { border-color: var(--border-strong); }
}

main section article > :last-child { margin-top: auto; }

/* ── Forms ── */
form { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }

label { color: var(--text); }

select {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 8px 10px;
  outline: none;
  width: 100%;
  max-width: 320px;
  transition: border-color 0.15s, box-shadow 0.15s;

  &:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
  }
}

fieldset { border: none; display: flex; flex-direction: column; gap: 10px; }

legend {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 8px;
}

fieldset label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
}

input[type="radio"] {
  accent-color: var(--accent);
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
  cursor: pointer;
  transform: translateY(2px);
}

/* ── Buttons ── */
button,
input[type="submit"],
a[role="button"],
.btn {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 5px;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  padding: 9px 20px;
  text-decoration: none;
  white-space: nowrap;
  width: auto;
  display: inline-block;
  transition: border-color 0.15s, color 0.15s, background 0.15s;

  &:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, var(--bg));
    text-decoration: none;
  }
  &:disabled { opacity: 0.4; pointer-events: none; }
}

a[role="button"].secondary,
.btn.secondary {
  border-color: var(--border-strong);
  color: var(--text);
  &:hover { border-color: var(--muted-dim); background: var(--row-hover); }
}

/* ── Quiz progress ── */
[aria-label="progress"] { margin: 0; }

/* ── Quiz answer review list ── */
.answers { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }

.answers li {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
}

.answers li.correct {
  border-color: color-mix(in srgb, var(--green) 55%, transparent);
  background: color-mix(in srgb, var(--green) 12%, var(--bg));
  color: var(--text);
}

.answers li.incorrect {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  color: var(--text);
}

/* ── Tables (quiz summary) ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--row-border);
  vertical-align: top;
}

th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

tbody tr:hover { background: var(--row-hover); }

/* ── Topic prose ── */
.prose { display: flex; flex-direction: column; gap: 12px; }
.prose h2, .prose h3 { margin-top: 6px; }
.prose ul, .prose ol { padding-left: 1.4rem; display: flex; flex-direction: column; gap: 4px; }
.prose li { color: var(--text); }
.prose code {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
}

/* ── Responsive (mobile-first: enhance for larger screens) ── */
@media (min-width: 481px) {
  .container { padding: 20px; }
}

/* Touch devices: keep form controls at 16px so iOS Safari doesn't zoom on focus */
@media (pointer: coarse) {
  select, input[type="text"] { font-size: 16px; }
}
