/* ── Christianity & Islam study app ─────────────────────────────────────── */

:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #fbf9f4;
  --ink: #23201b;
  --ink-soft: #5d574d;
  --line: #e3ddd1;
  --accent: #8a5a2b;        /* warm umber */
  --accent-soft: #f0e6d8;
  --accent-ink: #6f4621;
  --good: #2f7d52;
  --good-soft: #e3f1e8;
  --bad: #b23b3b;
  --bad-soft: #f6e2e0;
  --shadow: 0 1px 2px rgba(35, 32, 27, 0.06), 0 8px 24px rgba(35, 32, 27, 0.07);
  --radius: 14px;
  --maxw: 860px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1814;
    --surface: #24211c;
    --surface-2: #2b2722;
    --ink: #ece6da;
    --ink-soft: #b3aa99;
    --line: #3a352d;
    --accent: #d59a5d;
    --accent-soft: #352d22;
    --accent-ink: #e7b984;
    --good: #6cc090;
    --good-soft: #21342a;
    --bad: #e08a86;
    --bad-soft: #382726;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over class-level display rules (.field/.filters
   use display:flex, which would otherwise override the UA [hidden] style). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ── Header ──────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
.modes { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.is-active { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }

main.wrap { flex: 1 0 auto; padding-top: 26px; padding-bottom: 48px; }

/* ── Filters ─────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 180px; min-width: 0; }
.field > span { font-size: 0.78rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
select {
  appearance: none;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238a5a2b' d='M6 8 0 0h12z'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 34px 10px 12px;
  cursor: pointer;
  width: 100%;
}
select:focus-visible, .btn:focus-visible, .mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.filter-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.count { font-size: 0.85rem; color: var(--ink-soft); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  border-radius: 9px;
  padding: 10px 18px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.05s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); padding: 7px 10px; font-size: 0.85rem; }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn.ghost.danger:hover { color: var(--bad); }
.btn.small { padding: 7px 13px; font-size: 0.85rem; }

/* ── Cards / panels ──────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.topic-chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 11px;
}
.type-chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}
.meta-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.progress-line { margin-left: auto; font-size: 0.82rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ── Flashcards ──────────────────────────────────────────────────────── */
.flashcard-stage { perspective: 1400px; }
.flashcard {
  position: relative;
  width: 100%;
  min-height: 280px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.flash-face.back { transform: rotateY(180deg); background: var(--surface-2); }
.flash-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px; }
.flash-text { font-family: var(--serif); font-size: 1.3rem; line-height: 1.5; }
.flash-face.back .flash-text { font-size: 1.12rem; line-height: 1.6; }
.flash-hint { margin-top: auto; padding-top: 18px; font-size: 0.8rem; color: var(--ink-soft); }
.deck-controls { display: flex; align-items: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.deck-controls .spacer { flex: 1; }
.known-pill { font-size: 0.8rem; color: var(--good); font-weight: 600; }

/* ── Quiz ────────────────────────────────────────────────────────────── */
.q-prompt { font-family: var(--serif); font-size: 1.32rem; line-height: 1.45; margin: 0 0 20px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 16px;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.12s, background 0.12s;
}
.choice:hover { border-color: var(--accent); }
.choice input { margin-top: 3px; accent-color: var(--accent); flex: 0 0 auto; }
.choice.is-correct { border-color: var(--good); background: var(--good-soft); }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.is-missed { border-color: var(--good); border-style: dashed; }
.choice .mark { margin-left: auto; font-weight: 700; }
.choice.is-correct .mark { color: var(--good); }
.choice.is-wrong .mark { color: var(--bad); }
.choice[aria-disabled="true"] { cursor: default; }

.tf-buttons { display: flex; gap: 12px; }
.tf-buttons .btn { flex: 1; padding: 16px; font-size: 1.05rem; }
.tf-buttons .btn.chosen { border-color: var(--accent); }

textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px;
  resize: vertical;
  min-height: 120px;
}
.long textarea { min-height: 220px; }

.feedback { margin-top: 20px; border-radius: 11px; padding: 16px 18px; border: 1px solid var(--line); }
.feedback.correct { background: var(--good-soft); border-color: var(--good); }
.feedback.wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback.review { background: var(--surface-2); }
.feedback h4 { margin: 0 0 8px; font-size: 0.95rem; }
.feedback .verdict { font-weight: 700; }
.feedback.correct .verdict { color: var(--good); }
.feedback.wrong .verdict { color: var(--bad); }
.sample { margin-top: 10px; }
.sample h5 { margin: 12px 0 4px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.sample p { margin: 0; }
.rubric { margin: 4px 0 0; padding-left: 20px; }
.rubric li { margin: 3px 0; }
.self-rate { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.self-rate span { font-size: 0.85rem; color: var(--ink-soft); }
.grade-note { margin-top: 12px; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; font-size: 0.92rem; }
.grade-note strong { color: var(--accent-ink); }

.q-actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; flex-wrap: wrap; }
.q-actions .spacer { flex: 1; }

/* ── Quiz summary ────────────────────────────────────────────────────── */
.summary { text-align: center; }
.summary .score-big { font-family: var(--serif); font-size: 3rem; font-weight: 600; color: var(--accent-ink); margin: 8px 0; }
.summary p { color: var(--ink-soft); }

/* ── Progress dashboard ──────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat .num { font-family: var(--serif); font-size: 2rem; font-weight: 600; }
.stat .lbl { font-size: 0.82rem; color: var(--ink-soft); }
.dash-section h3 { font-family: var(--serif); font-weight: 600; margin: 26px 0 12px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; align-items: center; margin-bottom: 10px; }
.bar-row .name { font-weight: 600; font-size: 0.92rem; }
.bar-row .frac { font-size: 0.82rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.strong > span { background: var(--good); }

.tutor-card { border-left: 3px solid var(--accent); }
.tutor-card .weak-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ── Study guide (embedded PDF) ──────────────────────────────────────── */
.guide { display: flex; flex-direction: column; gap: 12px; }
.guide-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
}
.guide-toolbar .spacer { flex: 1; }
.guide-title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; }
.guide-toolbar a.btn { text-decoration: none; }
.guide-frame {
  width: 100%;
  height: 78vh;
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.guide-fallback { text-align: center; font-size: 0.85rem; color: var(--ink-soft); margin: 0; }
.guide-fallback a { color: var(--accent-ink); }

/* ── Timeline ────────────────────────────────────────────────────────── */
.tl-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.tl-toggle input { accent-color: var(--accent); }
.tl-list { display: flex; flex-direction: column; }
.tl-era {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--accent-ink);
  margin: 22px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.tl-era:first-child { margin-top: 4px; }
.tl-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  align-items: baseline;
}
.tl-row.is-must { background: var(--accent-soft); }
.tl-year {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent-ink);
  font-size: 0.95rem;
  text-align: right;
}
.tl-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tl-event { font-weight: 600; }
.tl-star { color: var(--accent); }
.tl-detail { font-size: 0.88rem; color: var(--ink-soft); }

/* ── Dates study set ─────────────────────────────────────────────────── */
.dates-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.dates-controls .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; gap: 4px; }
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }
.choice-btn { appearance: none; width: 100%; text-align: left; font: inherit; color: var(--ink); }
.date-form { display: flex; gap: 10px; flex-wrap: wrap; }
.date-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
}
.date-input.is-correct { border-color: var(--good); background: var(--good-soft); }
.date-input.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.score-pill { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ── Misc ────────────────────────────────────────────────────────────── */
.empty { text-align: center; color: var(--ink-soft); padding: 50px 20px; font-size: 1.05rem; }

.site-footer { border-top: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; flex-wrap: wrap; }
.footer-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.data-mode-badge { font-size: 0.78rem; color: var(--ink-soft); }
.data-mode-badge b { color: var(--accent-ink); }

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (max-width: 560px) {
  .header-inner { gap: 10px; }
  .brand { font-size: 1.15rem; }
  .modes { width: 100%; }
  .mode-btn { flex: 1; }
  .filter-actions { width: 100%; justify-content: space-between; }
  .flash-text { font-size: 1.15rem; }
}

/* ── Speed mode ────────────────────────────────────────────────────────────── */
.speed-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 16px;
}
.speed-count { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.speed-streak { white-space: nowrap; min-width: 3.5em; text-align: right; color: var(--accent-ink); font-weight: 700; }
.speed-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}
.speed-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--good);
  transition: width 0.25s ease;
}

.speed-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  opacity: 1;
  transform: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.speed-card.fade-out { opacity: 0; transform: translateY(-10px); }

.speed-prompt { margin: 0 0 16px; font-family: var(--serif); font-size: 1.12rem; line-height: 1.45; }

.speed-choices { display: grid; gap: 10px; }
.speed-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.speed-choice:hover:not(:disabled) { border-color: var(--accent); }
.speed-choice:disabled { cursor: default; }
.speed-letter {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
}
.speed-choice.is-right { border-color: var(--good); background: var(--good-soft); }
.speed-choice.is-right .speed-letter { background: var(--good); color: #fff; }
.speed-choice.is-wrong-flash {
  border-color: var(--bad);
  background: var(--bad-soft);
  animation: speed-shake 0.3s ease;
}
.speed-choice.is-wrong-flash .speed-letter { background: var(--bad); color: #fff; }
@keyframes speed-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.speed-actions { min-height: 0; }
.speed-actions:not(:empty) { margin-top: 16px; display: flex; }

.speed-done {
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.speed-done h2 { margin: 0 0 10px; font-family: var(--serif); }
.speed-done p { margin: 4px 0; color: var(--ink-soft); }
.speed-done .btn { margin-top: 16px; }
