:root {
  --bg: #0a0a0a;
  --gold: #D4A017;
  --red: #8B0000;
  --cream: #F5F0E8;
  --card: #141414;
  --card-border: #2a2a2a;
  --muted: #8a8275;
  --correct: #2d8a3e;
  --wrong: #a83232;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--cream);
  font-family: 'DM Sans', system-ui, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .serif {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ---------- Featured strip ---------- */
.featured-strip {
  margin: 24px 0 8px;
  padding: 18px 20px;
  background: linear-gradient(180deg, rgba(212, 160, 23, 0.06), rgba(20, 20, 20, 0.4));
  border: 1px solid var(--card-border);
  border-radius: 12px;
}
.featured-eyebrow {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 12px;
}
.featured-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.featured-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  color: var(--cream);
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.featured-chip:hover {
  border-color: var(--gold);
  background: #181818;
  transform: translateY(-1px);
}
.featured-chip-mode {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  flex-shrink: 0;
}
.featured-chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
@media (max-width: 540px) {
  .featured-chip-label { max-width: 200px; }
}

/* ---------- Landing ---------- */
.hero {
  text-align: center;
  padding: 56px 16px 40px;
  border-bottom: 1px solid var(--card-border);
}
.hero-eyebrow {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}
.hero-title {
  font-size: clamp(40px, 7vw, 72px);
  line-height: 1.05;
  margin: 0 0 16px;
  color: var(--cream);
}
.hero-title .accent { color: var(--gold); }
.hero-tagline {
  color: var(--muted);
  max-width: 620px;
  margin: 0 auto;
  font-size: 17px;
  line-height: 1.55;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 48px;
}
@media (max-width: 720px) {
  .mode-grid { grid-template-columns: 1fr; }
}

.mode-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 36px 28px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
  width: 100%;
}
.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
  background: #181818;
}
.mode-card .badge {
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}
.mode-card h2 {
  font-size: 28px;
  margin: 0;
}
.mode-card p {
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}
.mode-card .cta {
  margin-top: 12px;
  color: var(--gold);
  font-weight: 600;
}

/* ---------- Shared mode shell ---------- */
.mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 24px;
  border-bottom: 1px solid var(--card-border);
}
.back-btn {
  color: var(--cream);
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: transparent;
  transition: border-color .15s, color .15s;
}
.back-btn:hover { border-color: var(--gold); color: var(--gold); }
.mode-title {
  font-size: 22px;
  margin: 0;
}

/* ---------- Trivia ---------- */
.score-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 24px;
  padding: 14px 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
}
.score-bar .score-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.score-bar .score-value {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  color: var(--gold);
}

.question-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 28px;
  margin-top: 20px;
}
.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  color: var(--gold);
  font-weight: 600;
}
.tag.era { color: var(--cream); }

.question-text {
  font-size: 22px;
  font-family: 'Playfair Display', serif;
  line-height: 1.35;
  margin: 0 0 24px;
}

.answers {
  display: grid;
  gap: 12px;
}
.answer-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #1a1a1a;
  border: 1px solid var(--card-border);
  color: var(--cream);
  padding: 16px 18px;
  border-radius: 10px;
  font-size: 16px;
  text-align: left;
  transition: border-color .15s, background .15s, transform .1s;
}
.answer-btn:not(:disabled):hover {
  border-color: var(--gold);
  background: #202020;
}
.answer-btn:not(:disabled):active { transform: scale(.995); }
.answer-btn .letter {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #0a0a0a;
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--gold);
  flex-shrink: 0;
}
.answer-btn:disabled { cursor: default; opacity: .85; }
.answer-btn.correct {
  background: rgba(45, 138, 62, 0.18);
  border-color: var(--correct);
}
.answer-btn.correct .letter { background: var(--correct); color: white; border-color: var(--correct); }
.answer-btn.wrong {
  background: rgba(168, 50, 50, 0.18);
  border-color: var(--wrong);
}
.answer-btn.wrong .letter { background: var(--wrong); color: white; border-color: var(--wrong); }
.answer-btn.dim { opacity: 0.4; }

.explanation {
  margin-top: 20px;
  padding: 18px 20px;
  background: #161616;
  border-left: 4px solid var(--gold);
  border-radius: 6px;
  color: var(--cream);
  line-height: 1.55;
  font-size: 15px;
}
.explanation strong { color: var(--gold); display: block; margin-bottom: 6px; font-family: 'Playfair Display', serif; }

.next-btn {
  margin-top: 24px;
  background: var(--gold);
  color: #0a0a0a;
  padding: 14px 22px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  transition: background .15s, transform .1s;
}
.next-btn:hover { background: #e5b22a; }
.next-btn:active { transform: scale(.98); }

.loading {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-style: italic;
}
.error-box {
  margin-top: 20px;
  padding: 16px 18px;
  background: rgba(139,0,0,.15);
  border: 1px solid var(--red);
  border-radius: 8px;
  color: #f0d0d0;
}

.hero.compact { padding: 32px 16px 20px; }
.hero.compact .hero-title { font-size: clamp(32px, 5vw, 56px); margin-bottom: 10px; }
.hero.compact .hero-tagline { font-size: 15px; }

.tab-row {
  display: flex;
  gap: 8px;
  padding: 16px 0 4px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 4px;
}
.tab {
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 15px;
  border: 1px solid transparent;
  border-bottom: none;
}
.tab:hover { color: var(--cream); }
.tab.active {
  color: var(--gold);
  background: var(--card);
  border-color: var(--card-border);
}

/* ---------- Flashcards & controls ---------- */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
}
.cat-label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.cat-select {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--cream);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: normal;
  text-transform: none;
}
.cat-select:focus { outline: none; border-color: var(--gold); }

.flash-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 28px;
  margin-top: 20px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 720px) {
  .flash-card {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 24px 20px;
  }
}

.flash-media {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #0a0a0a;
  border: 1px solid var(--card-border);
}
@media (max-width: 720px) {
  .flash-media {
    max-width: 220px;
    margin: 0 auto;
  }
}

.flash-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.flash-media-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(160deg, #1c1c1c 0%, #0e0e0e 100%);
  border-color: rgba(212, 160, 23, 0.35);
  color: var(--gold);
  text-align: center;
  padding: 16px;
}
.flash-media-initial {
  font-family: 'Playfair Display', serif;
  font-size: 84px;
  line-height: 1;
  color: var(--gold);
  font-weight: 700;
}
.flash-media-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.flash-text {
  min-width: 0;
}

.flash-title {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  line-height: 1.2;
  margin: 0 0 18px;
  color: var(--cream);
}
.flash-body {
  color: var(--cream);
  font-size: 17px;
  line-height: 1.6;
  margin: 0 0 8px;
}

/* ---------- Persistent stats & mastery ---------- */
.stats-panel {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 560px) {
  .stats-summary { grid-template-columns: 1fr; }
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
}
.stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  color: var(--gold);
}

.mastery {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 18px 18px 16px;
}
.mastery-title {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
  margin-bottom: 14px;
}
.mastery-empty {
  color: var(--muted);
  font-style: italic;
  margin: 0 0 14px;
  font-size: 14px;
}
.mastery-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.mastery-row { display: flex; flex-direction: column; gap: 6px; }
.mastery-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
}
.mastery-cat { color: var(--cream); font-weight: 500; }
.mastery-pct { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mastery-bar {
  height: 6px;
  background: #1a1a1a;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--card-border);
}
.mastery-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #e5b22a);
  border-radius: 999px;
  transition: width .3s ease;
}
.reset-btn {
  align-self: flex-start;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--card-border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: border-color .15s, color .15s;
}
.reset-btn:hover { border-color: var(--red); color: #f0d0d0; }

/* ---------- Legacy chat (unused) ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 16px;
}
.chip {
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--cream);
  font-size: 13px;
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--gold); color: var(--gold); }

.chat-thread {
  margin-top: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 20px;
  height: min(60vh, 520px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-empty {
  color: var(--muted);
  text-align: center;
  margin: auto;
  font-style: italic;
  max-width: 360px;
  line-height: 1.5;
}
.msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--gold);
  color: #0a0a0a;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.msg.assistant {
  align-self: flex-start;
  background: #1a1a1a;
  border: 1px solid var(--card-border);
  color: var(--cream);
  border-bottom-left-radius: 4px;
}
.msg.assistant.thinking { color: var(--muted); font-style: italic; }

.chat-input-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.chat-input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--cream);
  padding: 14px 16px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.chat-input:focus { border-color: var(--gold); }
.send-btn {
  background: var(--gold);
  color: #0a0a0a;
  padding: 0 22px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
}
.send-btn:disabled { opacity: .5; cursor: not-allowed; }
