/* ============================================================
   Book2 Interactive Courseware — courseware.css
   Extends the Digital Scriptorium reading theme.
   Themes: paper (default), sepia, dark.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ----- palette: paper (default) ----- */
  --bg:        #FAF6EC;
  --bg-grain:  #F3ECDB;
  --surface:   #F4EEDF;
  --surface-2: #EFE7D4;
  --text:      #241B11;
  --muted:     #6A5C49;
  --faint:     #94866F;
  --accent:    #8A3517;   /* oxblood / sienna */
  --accent-ink:#732A11;
  --accent2:   #4A6741;   /* olive */
  --border:    #E2D8C3;
  --rule:      #D9CDB4;
  --quote-bg:  #F1E8D3;
  --mark:      rgba(138,53,23,0.10);
  --shadow:    rgba(48,33,16,0.13);

  /* ----- geometry ----- */
  --topbar-h:  56px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --font-body: 'Noto Serif SC', 'Songti SC', 'Source Han Serif SC', Georgia, serif;
  --font-ui:   'Noto Sans SC', 'PingFang SC', system-ui, sans-serif;
  --font-latin:'EB Garamond', 'Noto Serif SC', Georgia, serif;
}

/* ----- sepia ----- */
:root[data-theme="sepia"] {
  --bg:#F3E7CE; --bg-grain:#ECDCBE; --surface:#EBDDBF; --surface-2:#E4D3B0;
  --text:#3A2C19; --muted:#6E5B3E; --faint:#917A56;
  --accent:#9A4318; --accent-ink:#7E3413; --accent2:#566B36;
  --border:#DBC8A4; --rule:#D2BD96; --quote-bg:#E9D9B6; --mark:rgba(154,67,24,0.12);
  --shadow:rgba(60,40,18,0.16);
}

/* ----- dark ----- */
:root[data-theme="dark"] {
  --bg:#17140F; --bg-grain:#1C1813; --surface:#211C15; --surface-2:#272118;
  --text:#E4DAC8; --muted:#A89A82; --faint:#7E7361;
  --accent:#D98A4E; --accent-ink:#E59A5E; --accent2:#9DB87E;
  --border:#352D22; --rule:#3A3125; --quote-bg:#221D16; --mark:rgba(217,138,78,0.14);
  --shadow:rgba(0,0,0,0.5);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-image:
    radial-gradient(circle at 18% 12%, var(--bg-grain) 0, transparent 42%),
    radial-gradient(circle at 82% 78%, var(--bg-grain) 0, transparent 46%);
  background-attachment: fixed;
  transition: background-color 0.4s ease, color 0.4s ease;
}

::selection { background: var(--mark); }

a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-ink); text-decoration: underline; }

/* ===== Layout ===== */
.layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px) saturate(1.1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  gap: 16px;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.topbar-brand small {
  display: block;
  font-family: var(--font-latin);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--faint);
  text-transform: uppercase;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-nav a {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.topbar-nav a:hover,
.topbar-nav a.active {
  background: var(--mark);
  color: var(--accent);
  text-decoration: none;
}

/* ===== Progress bar ===== */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: var(--radius-pill);
  transition: width 0.35s ease;
}

/* ===== Dashboard grid ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

/* ===== Chapter card ===== */
.chapter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: 0 2px 8px -2px var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px -8px var(--shadow);
  border-color: var(--accent);
}

.chapter-card .card-kicker {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.chapter-card .card-title {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.chapter-card .card-meta {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--faint);
  margin-top: auto;
}

.chapter-card .card-progress {
  margin-top: 8px;
}

.chapter-card.done {
  border-left: 3px solid var(--accent2);
}

.chapter-card.visited {
  border-left: 3px solid var(--faint);
}

.chapter-card.done .card-meta {
  color: var(--accent2);
}

.chapter-card.visited .card-meta {
  color: var(--muted);
}

.chapter-card.current {
  border-left: 3px solid var(--accent);
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: #fff;
  text-decoration: none;
}

:root[data-theme="dark"] .btn-primary { color: #1a1610; }

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--mark);
  border-color: var(--accent);
  text-decoration: none;
}

.btn-primary:active,
.btn-secondary:active { transform: translateY(1px); }

/* ===== Question card ===== */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px -2px var(--shadow);
}

.question-card .q-text {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.55;
}

.question-card .q-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-card .q-option {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--muted);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.question-card .q-option:hover {
  border-color: var(--accent);
  background: var(--mark);
}

/* ===== Term flip card ===== */
.term-flip {
  position: relative;
  perspective: 800px;
  min-height: 140px;
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.term-flip:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  border-radius: var(--radius-md);
}

.term-flip .term-front,
.term-flip .term-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 6px -2px var(--shadow);
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.term-flip .term-front {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  transform: rotateY(0deg);
}

.term-flip .term-back {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  line-height: 1.7;
  text-align: center;
  transform: rotateY(180deg);
}

.term-flip.flipped .term-front { transform: rotateY(180deg); }
.term-flip.flipped .term-back { transform: rotateY(0deg); }

/* ===== Utility ===== */
.section-title {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  color: var(--faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 6px -2px var(--shadow);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 14px;
}

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Chapter page specifics ===== */
.chapter-header {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 28px;
}

.chapter-header .kicker,
.chapter-header .chapter-kicker {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.chapter-header h1,
.chapter-header .chapter-title {
  font-family: var(--font-body);
  font-size: clamp(1.6rem, 1rem + 2vw, 2.2rem);
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

#chapter-summary h2,
#scriptures h2,
#key-terms h2,
#outline h2,
#questions h2,
#questions h3 {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

#chapter-summary h2,
#scriptures h2,
#key-terms h2,
#outline h2,
#questions h2 {
  font-size: 16px;
  letter-spacing: 0.04em;
}

#questions h3 {
  font-size: 14px;
  color: var(--accent);
  margin-top: 18px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#scriptures ul,
#outline ul {
  list-style: none;
  padding-left: 0;
}

#scriptures li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-body);
  color: var(--text);
}

#scriptures li:last-child { border-bottom: none; }

.term-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.term-pill {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: var(--mark);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
}

#outline ul { padding-left: 0; }

#outline li {
  padding: 6px 0;
  font-family: var(--font-body);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

#outline li:last-child { border-bottom: none; }

#outline .level-2 { padding-left: 0; font-weight: 700; }
#outline .level-3 { padding-left: 20px; }
#outline .level-4 { padding-left: 40px; color: var(--muted); }

.question-card .question-text {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.55;
}

.answer-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.answer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--mark);
}

#mark-done {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 28px auto 0;
}

#mark-done.done {
  background: var(--accent2);
  border-color: var(--accent2);
}

#prev-next {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

#prev-next .nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
  white-space: nowrap;
}

#prev-next .nav-btn:hover {
  background: var(--mark);
  border-color: var(--accent);
  text-decoration: none;
}

#prev-next .nav-btn:active { transform: translateY(1px); }

/* ===== Review page specifics ===== */
.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.quiz-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.question-card .question-meta {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.question-card .question-text {
  margin-bottom: 14px;
}

.question-card .reveal-answer {
  margin-top: 10px;
}

.answer-hint {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent2);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
}

.scripture-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

details.scripture-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

details.scripture-group summary {
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--accent);
}

details.scripture-group ul {
  list-style: none;
  padding-left: 0;
  margin-top: 10px;
}

details.scripture-group li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-body);
  color: var(--text);
}

details.scripture-group li:last-child { border-bottom: none; }

#flashcards h2,
#quiz h2,
#scripture-review h2 {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

#flashcards .hint,
#quiz .hint {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--faint);
  margin-bottom: 14px;
}

#flashcards .empty,
#quiz .empty,
#scripture-review .empty {
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .container { padding: 20px; }
  .dashboard-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
  .topbar { padding: 0 16px; }
}

@media (max-width: 768px) {
  body { font-size: 16px; }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--topbar-h);
    padding: 8px 14px;
    gap: 8px;
  }
  .topbar-brand { font-size: 13px; }
  .topbar-nav { gap: 4px; }
  .topbar-nav a { padding: 6px 10px; font-size: 12px; }
  .container { padding: 16px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .chapter-card { padding: 16px; }
  .question-card { padding: 16px; }
  .flashcard-grid { grid-template-columns: 1fr; }
  #prev-next { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Export actions ===== */
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.export-actions .btn-secondary,
.export-actions a.btn-secondary {
  min-width: 120px;
}

/* ===== Print page ===== */
.print-page {
  background: #fff;
  color: #000;
}

.print-page .topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.print-page #print-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px;
  font-family: var(--font-body);
  line-height: 1.75;
}

.print-header {
  text-align: center;
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 2px solid #000;
}

.print-header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
}

.print-header p {
  font-size: 14px;
  color: #333;
  margin: 4px 0;
}

.print-part {
  margin-bottom: 32px;
}

.print-part h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ccc;
}

.print-chapter {
  margin-bottom: 24px;
}

.print-chapter h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #222;
}

.print-qa {
  margin-bottom: 16px;
}

.print-q,
.print-a {
  font-size: 15px;
  margin-bottom: 6px;
}

.print-a {
  color: #333;
}

.no-print {
  display: inherit;
}

@media print {
  @page { margin: 18mm; }
  .no-print { display: none !important; }
  body { background: white !important; color: black !important; }
  .print-header { page-break-after: avoid; }
  .print-part, .print-chapter { page-break-inside: auto; orphans: 3; widows: 3; }
  .print-qa { page-break-inside: avoid; }
}
