:root {
  --board: #16261D;
  --board-light: #1F3327;
  --paper: #F1ECDD;
  --paper-dim: #E4DEC9;
  --ink: #2B2620;
  --ink-soft: #6B6355;
  --chalk-yellow: #E8B94D;
  --brick-red: #C1544A;
  --leaf-green: #6E9B6B;
  --rule: rgba(43, 38, 32, 0.15);
  --serif: Georgia, "Times New Roman", ui-serif, serif;
  --mono: "SF Mono", "Courier New", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--board);
  background-image:
    linear-gradient(var(--board-light) 1px, transparent 1px),
    linear-gradient(90deg, var(--board-light) 1px, transparent 1px);
  background-size: 100% 3em, 3em 100%;
  background-position: 0 4.5em, 0 0;
  color: var(--paper);
  font-family: var(--serif);
  display: flex;
  justify-content: center;
  padding: 24px 16px 60px;
}

.app {
  width: 100%;
  max-width: 640px;
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 22px;
}

.app-header .eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--chalk-yellow);
  opacity: 0.85;
}

.app-header h1 {
  font-size: 1.6rem;
  margin: 6px 0 0;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.app-header h1::before,
.app-header h1::after {
  content: "\2022";
  color: var(--chalk-yellow);
  margin: 0 10px;
  opacity: 0.7;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; }

/* Setup card */
.paper-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  padding: 22px 20px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.35);
}

.field-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 8px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.pill {
  border: 1.5px solid var(--rule);
  background: transparent;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: var(--serif);
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill:hover { border-color: var(--ink-soft); }

.pill.selected {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.setup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px dashed var(--rule);
}

.setup-row:first-of-type { border-top: none; }

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--rule);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.15s ease;
}

.toggle.on { background: var(--leaf-green); }
.toggle.on::after { transform: translateX(18px); }

.start-btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: none;
  border-radius: 6px;
  background: var(--chalk-yellow);
  color: var(--board);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.start-btn:active { transform: scale(0.98); }
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Quiz screen */
.quiz-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--paper-dim);
  margin-bottom: 10px;
  padding: 0 4px;
}

.progress-track {
  height: 5px;
  background: var(--board-light);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-fill {
  height: 100%;
  background: var(--chalk-yellow);
  transition: width 0.25s ease;
}

.topic-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper-dim);
  padding: 3px 9px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.18rem;
  line-height: 1.5;
  margin: 0 0 22px;
}

/* OMR-style bubbles */
.options { display: flex; flex-direction: column; gap: 12px; }

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease;
  position: relative;
  flex-wrap: wrap;
}

.option > span:nth-child(2) { flex: 1; }

.result-tag {
  flex-basis: 100%;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-top: 4px;
  padding-left: 42px;
}

.tag-correct { color: var(--leaf-green); }
.tag-incorrect { color: var(--brick-red); }

.option:hover { border-color: var(--ink-soft); }

.bubble {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  position: relative;
}

.bubble::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--ink);
  transform: scale(0);
  transition: transform 0.18s ease;
}

.option.selected .bubble::after { transform: scale(1); }
.option.selected .bubble { color: var(--paper); }
.option.selected .bubble span { position: relative; z-index: 1; mix-blend-mode: difference; }

.option.correct {
  border-color: var(--leaf-green);
  background: rgba(110, 155, 107, 0.12);
}
.option.correct .bubble { border-color: var(--leaf-green); }
.option.correct .bubble::after { background: var(--leaf-green); transform: scale(1); }

.option.incorrect {
  border-color: var(--brick-red);
  background: rgba(193, 84, 74, 0.1);
}
.option.incorrect .bubble { border-color: var(--brick-red); }
.option.incorrect .bubble::after { background: var(--brick-red); transform: scale(1); }

.option:disabled { cursor: default; }

.explanation {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--paper-dim);
  border-left: 3px solid var(--chalk-yellow);
  border-radius: 4px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
  display: none;
}

.explanation.show { display: block; }

.notes-box {
  margin-top: 16px;
  padding: 12px 14px;
  background: repeating-linear-gradient(
    var(--paper) 0px, var(--paper) 27px,
    var(--rule) 27px, var(--rule) 28px
  );
  border: 1.5px dashed var(--rule);
  border-radius: 4px;
}

.notes-box textarea {
  width: 100%;
  border: none;
  background: transparent;
  resize: vertical;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 28px;
  padding: 0;
  outline: none;
  min-height: 56px;
}

.notes-box textarea::placeholder { color: var(--ink-soft); opacity: 0.7; }

.notes-saved {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--leaf-green);
  text-align: right;
  margin: 4px 0 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.notes-saved.show { opacity: 1; }

.quiz-nav {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-secondary, .btn-primary {
  flex: 1;
  padding: 13px;
  border-radius: 6px;
  border: none;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.98rem;
  cursor: pointer;
}

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--rule);
  color: var(--ink);
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
}

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

/* Results screen */
.score-hero {
  text-align: center;
  padding: 8px 0 20px;
}

.score-number {
  font-family: var(--serif);
  font-size: 3.2rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.score-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 6px;
}

.topic-breakdown { margin-top: 18px; }

.topic-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-top: 1px dashed var(--rule);
  font-size: 0.9rem;
}

.topic-row:first-child { border-top: none; }

.topic-row .bar-track {
  flex: 1;
  height: 6px;
  background: var(--paper-dim);
  border-radius: 999px;
  margin: 0 10px;
  overflow: hidden;
}

.topic-row .bar-fill {
  height: 100%;
  background: var(--leaf-green);
}

.topic-row .pct {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  width: 38px;
  text-align: right;
}

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

/* History screen */
.history-empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 24px 0;
  font-size: 0.95rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-top: 1px dashed var(--rule);
}

.history-item:first-child { border-top: none; }

.history-item .hi-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.history-item .hi-score {
  font-weight: 700;
}

/* Bottom nav */
.bottom-nav {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--paper-dim);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  cursor: pointer;
  opacity: 0.65;
  border-radius: 4px;
}

.nav-btn.active {
  opacity: 1;
  color: var(--chalk-yellow);
}

@media (max-width: 400px) {
  .score-number { font-size: 2.6rem; }
  .question-text { font-size: 1.05rem; }
}