/* Old-money / Brooks Brothers: EB Garamond, ivory paper, navy & gold, burgundy and forest green. */
:root {
  --bg: #f5f0e4;
  --surface: #fffcf5;
  --text: #16223b;
  --muted: #6d6857;
  --border: #d8ceb6;
  --rule: #b89a62;
  --accent: #13294b;        /* Brooks navy */
  --accent-ink: #fbf7ee;
  --accent-soft: #e7e3d6;
  --gold: #a88549;
  --good: #2c5a43;          /* forest green */
  --good-soft: #e5ece2;
  --bad: #7a1f2b;           /* burgundy */
  --bad-soft: #f2e3e0;
  --warn: #8a5a14;
  --code-bg: #efe9da;
  --radius: 2px;
  --serif: "EB Garamond", Garamond, "Adobe Garamond Pro", "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1628;
    --surface: #132038;
    --text: #efe7d4;
    --muted: #a8a28c;
    --border: #2b3a55;
    --rule: #b3955c;
    --accent: #c9a86a;
    --accent-ink: #0d1628;
    --accent-soft: #1d2c47;
    --gold: #c9a86a;
    --good: #8cbf9f;
    --good-soft: #17302a;
    --bad: #e0959b;
    --bad-soft: #3a1c24;
    --warn: #e0b56a;
    --code-bg: #0f1a2e;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 19px/1.55 var(--serif);
  font-feature-settings: "liga", "kern", "onum";
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }

.smallcaps, .brand, .qtype, .pill, .btn, .chip, .badge, .answer-label, .schema-title, .hint-caps {
  font-variant-caps: all-small-caps;
  letter-spacing: .08em;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px;
  background: #13294b;
  color: #f5efe0;
}
.topbar::after {
  /* repp stripe */
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 6px;
  background: repeating-linear-gradient(135deg, #13294b 0 10px, #b89a62 10px 13px, #7a1f2b 13px 19px, #b89a62 19px 22px);
}
.brand { color: #d9c9a0; text-decoration: none; font-size: 17px; }
.brand:hover { color: #fff; }
.brand-title { font-size: 22px; font-weight: 500; letter-spacing: .04em; }
.timer {
  margin-left: auto;
  font-variant-numeric: lining-nums tabular-nums;
  font-size: 18px; font-weight: 500;
  padding: 2px 14px;
  border: 1px solid #b89a62;
  color: #f5efe0;
}
.timer.low { border-color: #e0959b; color: #f3c1c5; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

main { max-width: 780px; margin: 0 auto; padding: 48px 16px 80px; }
h1 {
  font-size: 44px; font-weight: 400; line-height: 1.1; margin: 0 0 6px;
  text-align: center; letter-spacing: .01em;
}
h1::after {
  content: "❦"; display: block; margin: 10px auto 0; font-size: 20px; color: var(--gold);
}
.lead { color: var(--muted); margin: 10px auto 34px; max-width: 620px; text-align: center; font-style: italic; }
.lead strong { font-style: normal; font-weight: 600; color: var(--text); }
.muted { color: var(--muted); font-size: 16px; }

/* Double-rule frame used on cards */
.framed, .topic-card, .score-card, .review-item, .schema, dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 5px color-mix(in srgb, var(--border) 70%, transparent);
}

/* ---------- Topics ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.topic-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-align: center; padding: 22px 18px 20px;
  border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.topic-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.topic-icon {
  font-size: 15px; color: var(--gold); letter-spacing: .12em;
  font-variant-numeric: lining-nums;
}
.topic-name { font-size: 22px; font-weight: 500; line-height: 1.2; margin-top: 2px; }
.topic-blurb { color: var(--muted); font-size: 16px; font-style: italic; }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.pill { color: var(--gold); font-size: 17px; font-weight: 500; }
#quiz-progress { font-style: italic; }
.progress { height: 2px; background: var(--border); }
#progress-bar { height: 100%; background: var(--gold); transition: width .25s; }
.qtype { margin-top: 30px; font-size: 16px; color: var(--gold); }
.question { font-size: 28px; font-weight: 500; line-height: 1.3; margin: 26px 0 20px; }
.qtype + .question { margin-top: 4px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: flex-start; gap: 14px; text-align: left;
  padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.option:hover { border-color: var(--gold); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.option-letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px; font-weight: 500;
  border: 1px solid var(--rule); color: var(--gold); font-style: italic;
}
.option.selected .option-letter { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.option-text { padding-top: 1px; overflow-wrap: anywhere; }

.nav-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; }
.btn {
  padding: 9px 20px; border-radius: var(--radius); cursor: pointer;
  background: transparent; border: 1px solid var(--accent); color: var(--accent);
  font-size: 18px; font-weight: 500; transition: background .12s, color .12s;
}
.btn:hover:not(:disabled) { background: var(--accent-soft); }
.btn:disabled { opacity: .35; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); color: var(--accent-ink); }
.btn-submit { background: var(--good); border-color: var(--good); color: #fbf7ee; width: 100%; margin-top: 14px; }
.btn-submit:hover:not(:disabled) { background: color-mix(in srgb, var(--good) 85%, #000); }
@media (prefers-color-scheme: dark) { .btn-submit { color: #0d1628; } }

.jump { margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--rule); }
.jump-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.jump-btn {
  aspect-ratio: 1; border-radius: var(--radius); cursor: pointer; font-size: 16px;
  font-variant-numeric: lining-nums;
  background: var(--surface); border: 1px solid var(--border);
}
.jump-btn.written { font-style: italic; border-style: dashed; }
.jump-btn.answered { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); border-style: solid; }
.jump-btn.current { outline: 1px solid var(--gold); outline-offset: 2px; }

dialog { border-radius: var(--radius); color: var(--text); max-width: 420px; padding: 26px 28px; }
dialog::backdrop { background: rgba(13, 22, 40, .55); }
dialog p { margin-top: 0; }

/* ---------- Results ---------- */
.score-card { display: flex; align-items: center; gap: 24px; padding: 26px 28px; border-radius: var(--radius); }
.grade {
  flex: none; width: 86px; height: 86px; border-radius: 50%;
  display: grid; place-items: center; font-size: 46px; font-weight: 500;
  color: var(--good); border: 2px solid currentColor;
  box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 5px currentColor;
}
.grade[data-grade="C"], .grade[data-grade="D"] { color: var(--warn); }
.grade[data-grade="F"] { color: var(--bad); }
.score-line { font-size: 30px; font-weight: 500; font-variant-numeric: lining-nums; }
#score-detail { font-style: italic; }

.filter-row { display: flex; gap: 8px; margin: 26px 0 14px; flex-wrap: wrap; justify-content: center; }
.chip { padding: 4px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 17px; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.review-item { padding: 20px 22px; border-radius: var(--radius); border-left: 3px solid var(--good); }
.review-item.is-wrong { border-left-color: var(--bad); }
.review-head { display: flex; justify-content: space-between; align-items: baseline; }
.review-head .muted { font-style: italic; }
.badge { font-size: 17px; font-weight: 600; color: var(--good); }
.is-wrong .badge { color: var(--bad); }
.review-q { font-size: 21px; font-weight: 500; margin: 4px 0 12px; line-height: 1.35; }
.answer { padding: 12px 14px; border-radius: var(--radius); margin-top: 8px; border: 1px solid transparent; }
.answer.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.answer.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.answer-label { font-weight: 600; font-size: 17px; }
.answer-why { font-size: 17px; margin-top: 6px; }
.answer-why strong { font-weight: 600; font-style: italic; }

/* ---------- Written & code questions ---------- */
.hint { color: var(--muted); font-size: 15px; margin: 6px 0 0; font-style: italic; }
.text-answer {
  width: 100%; padding: 12px 16px; font-size: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.text-answer.long { resize: vertical; min-height: 160px; line-height: 1.5; }
.text-answer:focus, .code-editor:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 20%, transparent); }
.code-editor {
  width: 100%; padding: 14px 16px; resize: vertical; tab-size: 4;
  font: 14px/1.55 var(--mono);
  color: var(--text); background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius);
}
.code-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.code-bar .hint { margin: 0 auto 0 0; }
.btn-small { padding: 4px 14px; font-size: 16px; }
.btn-ghost { border-color: var(--border); color: var(--muted); }
.schema { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.schema-title { font-size: 15px; color: var(--gold); }
.schema pre { margin: 4px 0 0; font: 13px/1.5 var(--mono); white-space: pre-wrap; }

.run-output {
  margin-top: 10px; padding: 10px 14px; border-radius: var(--radius); font-size: 16px;
  background: var(--surface); border: 1px solid var(--border); overflow-x: auto;
}
.run-output.pass { border-color: var(--good); }
.run-output.fail { border-color: var(--bad); }
.run-output > div:not(.run-title):not(.sql-compare):not(.table-wrap) { font: 13px/1.5 var(--mono); white-space: pre-wrap; }
.run-title { font-weight: 600; margin-bottom: 4px; }
.cases { margin: 0; padding-left: 20px; font-size: 15px; }
.case { overflow-wrap: anywhere; }
.case.pass::marker { content: "✓ "; color: var(--good); }
.case.fail::marker { content: "✗ "; color: var(--bad); }
.case code, .answer-text code, code.answer-text { font-family: var(--mono); font-size: 14px; }
.table-wrap { overflow-x: auto; }
.result-table { border-collapse: collapse; font-size: 15px; margin-top: 4px; font-variant-numeric: lining-nums; }
.result-table th, .result-table td { border: 1px solid var(--border); padding: 3px 10px; text-align: left; }
.result-table th { background: var(--code-bg); font-weight: 600; }
.sql-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.answer pre { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-code { font: 13px/1.55 var(--mono); background: var(--code-bg); padding: 10px 12px; border-radius: var(--radius); }
.answer-prose { font: inherit; font-style: italic; }
.ai-tag {
  display: inline-block; margin-left: 8px; padding: 0 8px;
  font-size: 13px; font-variant-caps: all-small-caps; letter-spacing: .08em; font-style: normal;
  border: 1px solid var(--rule); color: var(--gold); vertical-align: 1px;
}
.ref-details { margin-top: 10px; }
.ref-details summary { cursor: pointer; font-size: 16px; color: var(--muted); font-style: italic; }

.grading { text-align: center; min-width: 300px; }
.grading p { margin: 14px 0 0; font-style: italic; }
.spinner {
  width: 34px; height: 34px; margin: 4px auto 0; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--gold); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  body { font-size: 18px; }
  h1 { font-size: 36px; }
  .question { font-size: 23px; }
  .topbar { padding: 12px 16px; gap: 12px; }
  .brand-title { font-size: 19px; }
  .jump-grid { grid-template-columns: repeat(5, 1fr); }
  .sql-compare { grid-template-columns: 1fr; }
  .code-bar { flex-wrap: wrap; }
  .code-bar .hint { flex-basis: 100%; }
  .score-card { gap: 16px; padding: 20px; }
  .grade { width: 70px; height: 70px; font-size: 38px; }
  .score-line { font-size: 24px; }
}
