:root {
  color-scheme: light;
  --ink: #211a3e;
  --paper: #ffffff;
  --primary: #7c3aed; /* vivid purple */
  --accent: #f472b6; /* hot pink */
  --lime: #b9f227;
  --sun: #ffd166;
  --good: #16a34a;
  --bad: #e11d48;
  --ink-soft: #2b2450;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 18px;
  --border: 3px solid var(--ink);
  --shadow: 5px 5px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", system-ui, sans-serif;
  line-height: 1.5;
  color: var(--ink);
  background: linear-gradient(155deg, #ffe08a 0%, #ff9aa2 45%, #b8a4ff 100%);
  background-attachment: fixed;
}

main {
  max-width: 660px;
  margin: 0 auto;
  padding: 28px 20px 104px;
}

.view[hidden] {
  display: none;
}

/* ---- Headings ---- */
h1 {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: clamp(34px, 8vw, 52px);
  line-height: 1.05;
  margin: 10px 0 6px;
  text-align: center;
  color: var(--ink);
  text-shadow: 3px 3px 0 var(--accent);
}

h1 .brain {
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
}
h1 .bot {
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite 0.4s;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-6px) rotate(4deg); }
}

h2 {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: clamp(28px, 6vw, 38px);
  line-height: 1.1;
}

.tagline {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  max-width: 44ch;
  margin: 0 auto 8px;
  text-wrap: pretty;
}

.intro {
  text-align: center;
  max-width: 48ch;
  margin: 0 auto 20px;
  font-size: 16px;
  line-height: 1.6;
  font-weight: 500;
  color: #2b2450;
  text-wrap: pretty;
}

.intro a,
.intro-credit a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.intro-credit {
  text-align: center;
  max-width: 48ch;
  margin: 24px auto 20px;
  font-size: 13px;
  line-height: 1.55;
  font-weight: 500;
  color: #2b2450;
}

#view-home {
  padding-top: 6vh;
}

/* ---- Buttons ---- */
button {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  display: block;
  width: 100%;
  padding: 14px 18px;
  margin-top: 14px;
  font-size: 18px;
  border-radius: 14px;
  border: var(--border);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 var(--ink);
  background: #8b46f0;
}

button:active {
  transform: translate(5px, 5px);
  box-shadow: 0 0 0 var(--ink);
}

/* Keyboard focus: a hard grape ring, distinct from the ink border and visible
   on the gradient. Applies to buttons everywhere plus the home browse link. */
button:focus-visible,
.home-link:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

/* `button { display: block }` above overrides the UA `[hidden]` rule, so the
   hidden attribute alone won't hide a button — restore it explicitly. */
button[hidden] {
  display: none;
}

button.secondary {
  background: var(--paper);
  color: var(--ink);
}

button.secondary:hover {
  background: var(--sun);
}

/* ---- Question / result cards ---- */
.question-block {
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 22px;
}

.question-block > p {
  font-size: 16px;
  line-height: 1.45;
}

/* Multi-line stems/choices (grid puzzles, code, step-by-step directions):
   preserve line breaks and align columns with a monospace font instead of
   collapsing everything onto one line. */
.preformatted {
  white-space: pre-wrap;
  font-family: "SFMono-Regular", ui-monospace, "Menlo", "Consolas", monospace;
  font-size: 14px;
  line-height: 1.4;
  overflow-x: auto;
}

.qnum {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary);
  margin-bottom: 8px;
}

.question-block .category {
  display: inline-block;
  background: var(--lime);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* ---- Score / misses display ---- */
#scoreboard {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 18px;
}

#scoreboard span {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 16px;
  padding: 8px 18px;
  border: var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  background: var(--paper);
}

.score-display {
  color: var(--good);
}

.score-misses {
  color: var(--bad);
}

/* ---- Per-question feedback + answer reveal ---- */
#answer-feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border: var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  font-size: 16px;
  background: var(--paper);
}

#answer-feedback.correct {
  background: #dcfce7;
}

#answer-feedback.incorrect {
  background: #ffe4e6;
}

.choice-row.choice-correct {
  background: #dcfce7;
  box-shadow: inset 0 0 0 3px var(--good);
}

.choice-row.choice-wrong {
  background: #ffe4e6;
  box-shadow: inset 0 0 0 3px var(--bad);
}

.choice-row input[type="radio"]:disabled + span {
  opacity: 0.9;
}

/* ---- Answer choices as tappable pills ---- */
.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 11px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fbf5ff;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.12s ease;
}

.choice-row:hover {
  background: #fce7f3;
  transform: translateX(3px);
}

.choice-row:has(input:checked) {
  background: #ede9fe;
  box-shadow: inset 0 0 0 3px var(--primary);
  font-weight: 600;
}

.choice-row input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* ---- Results feedback ---- */
#results-score {
  font-size: clamp(28px, 6vw, 38px);
  text-align: center;
  margin-bottom: 6px;
}

#results-comparison {
  background: #ede9fe;
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  font-weight: 500;
  font-size: 16px;
}

.correct {
  color: var(--good);
  font-weight: 700;
}

.incorrect {
  color: var(--bad);
  font-weight: 700;
}

.muted-answer {
  color: #6b7280;
  font-weight: 500;
}

.attribution {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  text-decoration: none;
}

.attribution:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ---- Submit warning + unanswered highlight ---- */
#quiz-warning {
  margin-top: 16px;
  padding: 14px 16px;
  border: var(--border);
  border-radius: 14px;
  background: var(--sun);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.question-block.unanswered {
  border-color: var(--bad);
  box-shadow: 5px 5px 0 var(--bad);
}

/* ---- Inputs ---- */
input#nickname-input,
textarea#share-text {
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  border: var(--border);
  border-radius: 12px;
  box-sizing: border-box;
}

textarea#share-text {
  height: 90px;
  resize: vertical;
}

#leaderboard-submit,
#share-panel {
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 18px;
}

#share-image-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--primary);
  font-weight: 600;
}

/* ---- Leaderboard ---- */
.leaderboard-list {
  list-style: none;
  padding: 0;
  counter-reset: rank;
}

.leaderboard-list li {
  counter-increment: rank;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 12px 16px 12px 44px;
  margin-bottom: 12px;
  font-weight: 600;
  position: relative;
}

.leaderboard-list li::before {
  content: counter(rank);
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-family: "Fredoka", sans-serif;
}

.leaderboard-list li:nth-child(1)::before { background: var(--sun); color: var(--ink); }
.leaderboard-list li:nth-child(2)::before { background: #cbd5e1; color: var(--ink); }
.leaderboard-list li:nth-child(3)::before { background: #fdba74; color: var(--ink); }

#results-leaderboard {
  margin-top: 18px;
}

#results-leaderboard h3 {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 10px;
}

#results-breakdown-panel {
  margin-top: 18px;
}

#results-breakdown-panel > summary {
  cursor: pointer;
  font-weight: 600;
  font-family: "Fredoka", sans-serif;
  padding: 6px 0;
}

/* ---- Home: link to the question bank ---- */
.home-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  color: var(--primary);
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

/* ---- "Adult SAT" meme banner ---- */
.joke-banner {
  max-width: 52ch;
  margin: 0 auto 18px;
  padding: 12px 16px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink);
  background: var(--sun);
  border: var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  transform: rotate(-1deg);
}

/* ---- Question bank (browse page) ---- */
.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.back-link:hover {
  text-decoration: underline;
}

.bank-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

#bank-search {
  flex: 1 1 220px;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 16px;
  color: var(--ink);
  background: #fff;
  border: var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
#bank-search:focus {
  outline: none;
  box-shadow: 4px 4px 0 var(--primary);
}

/* ---- Category filter chips ---- */
.bank-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: auto;
  margin: 0;
  padding: 7px 12px;
  font-family: "Fredoka", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.12s ease;
}
.cat-chip:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
  background: #fbf5ff;
}
.cat-chip.active {
  background: var(--chip-color, var(--primary));
  box-shadow: 2px 2px 0 var(--ink);
  transform: none;
}
.cat-chip .cat-dot {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  flex-shrink: 0;
}
.cat-chip.active .cat-dot {
  display: none;
}
.cat-chip .cat-count {
  font-family: "Fredoka", sans-serif;
  font-size: 11px;
  padding: 1px 7px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
}
.cat-chip.active .cat-count {
  background: rgba(33, 26, 62, 0.85);
}

.bank-count {
  font-size: 13px;
  font-weight: 600;
  color: #2b2450;
  margin: 0 0 12px;
}

/* ---- Question cards ---- */
.bank-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.qcard {
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.qcard[open],
.qcard:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 var(--ink);
}

.qcard > summary {
  cursor: pointer;
  padding: 14px 16px;
  list-style: none;
}
.qcard > summary::-webkit-details-marker {
  display: none;
}
.qcard > summary::after {
  content: "▸ show choices";
  display: inline-block;
  margin-top: 8px;
  font-family: "Fredoka", sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}
.qcard[open] > summary::after {
  content: "▾ hide choices";
}

.qcard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.cat-badge {
  display: inline-block;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.qcard-num {
  font-family: "Fredoka", sans-serif;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.qcard-q {
  font-size: 16px;
  line-height: 1.45;
  font-weight: 500;
}

.qcard-body {
  padding: 0 16px 14px;
}
.bank-choices {
  margin: 4px 0 12px;
  padding-left: 20px;
}
.bank-choices li {
  margin-bottom: 6px;
  line-height: 1.45;
}
.qcard-meta {
  font-size: 12px;
  color: #6b7280;
  border-top: 2px dashed #e5e7eb;
  padding-top: 10px;
}
.qcard-meta a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.qcard-meta a:hover {
  text-decoration: underline;
}

.bank-empty {
  text-align: center;
  font-weight: 600;
  padding: 24px;
}

/* ---- Sticky footer ---- */
#site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 9px 16px;
  text-align: center;
  font-family: "Fredoka", sans-serif;
  font-weight: 500;
  background: var(--ink);
  color: #fff;
  border-top: 3px solid var(--primary);
}

.footer-line {
  font-size: 14px;
}

.footer-credit {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

#site-footer a {
  color: var(--sun);
  font-weight: 600;
  text-decoration: none;
}

#site-footer a:hover {
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
