/* ===================================================================
   NIOS Study Hub — Stylesheet
   Design concept: an exam-prep "ruled notebook" — the notes viewer
   carries an actual margin rule (the red vertical line every Indian
   school notebook has), set in a warm paper palette. Three themes:
   light / sepia (default) / dark, all driven by CSS variables.
   =================================================================== */

* { box-sizing: border-box; }

:root {
  --font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-body: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;

  --shadow-card: 0 1px 2px rgba(20, 16, 10, 0.06), 0 4px 16px rgba(20, 16, 10, 0.05);
}

/* ---------- Theme: sepia (default) ---------- */
body[data-theme="sepia"] {
  --bg: #F1E6CD;
  --bg-elevated: #F8F0DC;
  --paper: #FBF4E3;
  --ink: #2E2417;
  --ink-muted: #6B5C45;
  --ink-faint: #9A8B6E;
  --rule-line: #D9C9A3;
  --margin-rule: #B33A3A;
  --accent: #2D5C4F;
  --accent-ink: #FBF4E3;
  --accent-soft: #DCE7DF;
  --border: #DCC9A0;
  --highlight-yellow: #F2D875;
  --highlight-green: #A9D8AE;
  --highlight-pink: #F0AFC2;
  --danger: #B33A3A;
}

/* ---------- Theme: light ---------- */
body[data-theme="light"] {
  --bg: #F6F4EF;
  --bg-elevated: #FFFFFF;
  --paper: #FFFFFF;
  --ink: #211F1C;
  --ink-muted: #5C594F;
  --ink-faint: #9C988A;
  --rule-line: #E5E1D6;
  --margin-rule: #C2453F;
  --accent: #1F6F5C;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1EFE9;
  --border: #E5E1D6;
  --highlight-yellow: #FCE588;
  --highlight-green: #B7E3BB;
  --highlight-pink: #F4BBCD;
  --danger: #C2453F;
}

/* ---------- Theme: dark ---------- */
body[data-theme="dark"] {
  --bg: #18140F;
  --bg-elevated: #211B14;
  --paper: #221C15;
  --ink: #EAE0CB;
  --ink-muted: #B6A98C;
  --ink-faint: #877957;
  --rule-line: #3A311F;
  --margin-rule: #C9605C;
  --accent: #6FB99A;
  --accent-ink: #122019;
  --accent-soft: #233029;
  --border: #3A311F;
  --highlight-yellow: #7A6B2C;
  --highlight-green: #2F5C3D;
  --highlight-pink: #6B3A4C;
  --danger: #C9605C;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

input, select, textarea {
  font-family: var(--font-body);
}

::selection {
  background: var(--highlight-yellow);
  color: #211F1C;
}

.muted { color: var(--ink-muted); }
.small { font-size: 0.82rem; }

/* =================== TOP BAR =================== */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand i { color: var(--margin-rule); }

.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn:hover { background: var(--accent-soft); color: var(--ink); }

.nav-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.theme-switch {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.theme-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* =================== APP / PAGES =================== */

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page {
  display: none;
  padding: 24px;
  flex: 1;
  min-height: 0;
}

.page.active {
  display: flex;
  flex-direction: column;
}

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  margin: 28px 0 14px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
}

.card h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 12px;
  font-size: 1.05rem;
}

/* =================== DASHBOARD =================== */

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 18px;
}

.goal-card { display: flex; flex-direction: column; align-items: center; text-align: center; }

.radial-wrap { position: relative; width: 140px; height: 140px; margin: 6px 0 14px; }
.radial { width: 100%; height: 100%; transform: rotate(-90deg); }
.radial-bg { fill: none; stroke: var(--rule-line); stroke-width: 10; }
.radial-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.4s ease;
}
.radial-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
}
.radial-label small { font-family: var(--font-body); font-weight: 500; font-size: 0.7rem; color: var(--ink-muted); }

.goal-controls { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; justify-content: center; }

button#goal-add-5, button#goal-add-15 {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

.goal-target-edit {
  width: 100%;
  text-align: left;
  font-size: 0.8rem;
  color: var(--ink-muted);
}
.goal-target-edit label { display: block; margin-bottom: 4px; }
.goal-target-edit input {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.exam-card { display: flex; flex-direction: column; }
.countdown {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.6rem;
  color: var(--margin-rule);
  line-height: 1;
  margin: 8px 0 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.countdown small { font-family: var(--font-body); font-size: 0.85rem; font-weight: 600; color: var(--ink-muted); }
.exam-card label { font-size: 0.8rem; color: var(--ink-muted); margin-top: auto; margin-bottom: 4px; }
.exam-card input {
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.subjects-overview-card { display: flex; flex-direction: column; justify-content: center; }
.overall-bar-wrap { display: flex; align-items: center; gap: 10px; }
.overall-bar { flex: 1; height: 10px; background: var(--rule-line); border-radius: 999px; overflow: hidden; }
.overall-bar-fg { height: 100%; width: 0%; background: var(--accent); transition: width 0.4s ease; }
#overall-bar-label { font-weight: 700; font-family: var(--font-display); }

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.subject-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  border-left: 4px solid var(--margin-rule);
}
.subject-card:hover { transform: translateY(-2px); }
.subject-card h4 {
  font-family: var(--font-display);
  margin: 0 0 6px;
  font-size: 1.05rem;
}
.subject-card .sub-progress-bar {
  height: 6px;
  background: var(--rule-line);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.subject-card .sub-progress-fg {
  height: 100%;
  background: var(--accent);
}
.subject-card .sub-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
}

/* =================== READER (3-COLUMN) =================== */

.reader-layout {
  display: grid;
  grid-template-columns: 260px 1fr 300px;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.reader-col {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.reader-left-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.reader-left-header select {
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.left-tabs, .right-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.left-tab-btn, .right-tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-bottom: 2px solid transparent;
}

.left-tab-btn.active, .right-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.left-tab-panel, .right-tab-panel {
  display: none;
  padding: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.left-tab-panel.active, .right-tab-panel.active { display: block; }

.toc-list, .highlights-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.86rem;
}

.toc-list li {
  margin-bottom: 2px;
}

.toc-list a {
  display: block;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
}

.toc-list a:hover { background: var(--accent-soft); color: var(--ink); }
.toc-list a.toc-h2 { padding-left: 20px; font-size: 0.82rem; }

.highlights-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}
.highlights-list .hl-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  margin-top: 4px;
}
.highlights-list .hl-text { flex: 1; line-height: 1.4; }
.highlights-list button.hl-delete {
  background: none;
  border: none;
  color: var(--ink-faint);
  flex: none;
}
.highlights-list button.hl-delete:hover { color: var(--danger); }

.weightage-blueprint { font-size: 0.82rem; }
.weightage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule-line);
}
.weightage-row:last-child { border-bottom: none; }
.weightage-marks {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
}

/* ---- Middle: Notes viewer with notebook margin rule (signature element) ---- */

.reader-middle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
}

.reader-middle-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 0;
}

#mark-complete-btn.completed {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.notes-viewer {
  flex: 1;
  overflow-y: auto;
  background:
    repeating-linear-gradient(
      var(--paper),
      var(--paper) 31px,
      var(--rule-line) 32px
    );
  background-attachment: local;
  position: relative;
  padding: 24px 36px 60px 56px;
  font-family: var(--font-display);
  font-size: 1.02rem;
  line-height: 32px;
}

.notes-viewer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 38px;
  width: 2px;
  background: var(--margin-rule);
  opacity: 0.55;
}

.notes-viewer h1, .notes-viewer h2, .notes-viewer h3 {
  font-family: var(--font-display);
  line-height: 32px;
  margin: 0;
  scroll-margin-top: 16px;
}
.notes-viewer h1 { font-size: 1.5rem; font-weight: 700; }
.notes-viewer h2 { font-size: 1.2rem; font-weight: 600; color: var(--accent); }
.notes-viewer h3 { font-size: 1.05rem; font-weight: 600; }
.notes-viewer p { margin: 0 0 0; }
.notes-viewer ul, .notes-viewer ol { margin: 0; padding-left: 1.4em; }
.notes-viewer code {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.85em;
}
.notes-viewer strong { color: var(--margin-rule); font-weight: 700; }
.notes-viewer .katex-display { line-height: normal; margin: 6px 0; }

mark.user-highlight {
  border-radius: 2px;
  padding: 0 1px;
}
mark.user-highlight.yellow { background: var(--highlight-yellow); }
mark.user-highlight.green { background: var(--highlight-green); }
mark.user-highlight.pink { background: var(--highlight-pink); }

/* ---- Right: recall panels ---- */

.flashcard-wrap {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flashcard {
  width: 100%;
  min-height: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  cursor: pointer;
  user-select: none;
}
.flashcard .fc-hint {
  position: absolute;
  bottom: 8px;
  font-size: 0.68rem;
  color: var(--ink-faint);
  font-family: var(--font-body);
}
.flashcard-inner { position: relative; width: 100%; }

.flashcard-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.flashcard-nav button {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  color: var(--ink);
}

.qa-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg);
}
.qa-item .qa-question {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 8px;
}
.qa-item textarea.recall-draft-input {
  width: 100%;
  min-height: 70px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  padding: 8px;
  font-family: var(--font-body);
  font-size: 0.84rem;
  resize: vertical;
}
.qa-item button.reveal-btn {
  margin-top: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}
.qa-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.qa-compare-col {
  font-size: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.qa-compare-col h5 {
  margin: 0 0 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

/* =================== SELECTION TOOLTIP =================== */

.selection-tooltip {
  position: absolute;
  z-index: 999;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px;
  display: flex;
  gap: 5px;
  box-shadow: var(--shadow-card);
}
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  padding: 0;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.swatch.yellow { background: var(--highlight-yellow); }
.swatch.green { background: var(--highlight-green); }
.swatch.pink { background: var(--highlight-pink); }
.swatch.clear { background: var(--bg); color: var(--ink-muted); }

/* =================== PRACTICE PAGE =================== */

.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 20px;
}

.practice-selectors {
  display: flex;
  gap: 10px;
}

.practice-selectors select {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
}

.practice-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.practice-tab-btn {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-weight: 700;
  font-size: 0.84rem;
  padding: 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.practice-tab-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.practice-tab-panel { display: none; flex: 1; min-height: 0; }
.practice-tab-panel.active { display: flex; flex-direction: column; }

/* ---- Flashcards (full page) ---- */

.practice-flashcard-stage {
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.practice-flashcard-wrap {
  min-height: 280px;
  display: flex;
}

.practice-flashcard {
  width: 100%;
  min-height: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  position: relative;
  border-left: 4px solid var(--margin-rule);
}

.practice-flashcard .fc-hint {
  position: absolute;
  bottom: 14px;
  font-size: 0.74rem;
  font-weight: 500;
  font-family: var(--font-body);
  color: var(--ink-faint);
}

.practice-flashcard .fc-face-label {
  position: absolute;
  top: 14px;
  left: 18px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-body);
  color: var(--accent);
}

/* ---- Quiz ---- */

.quiz-intro {
  max-width: 560px;
  margin: 40px auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#quiz-start-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-active { max-width: 640px; margin: 0 auto; width: 100%; }

.quiz-progress-bar {
  height: 8px;
  background: var(--rule-line);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}
.quiz-progress-fg { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s ease; }

.quiz-question-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-top: 14px;
  box-shadow: var(--shadow-card);
}

.quiz-question-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.quiz-options { display: flex; flex-direction: column; gap: 10px; }

.quiz-option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.92rem;
  color: var(--ink);
}

.quiz-option-btn:hover:not(:disabled) { background: var(--accent-soft); }

.quiz-option-btn .opt-letter {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--rule-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex: none;
}

.quiz-option-btn.correct {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.quiz-option-btn.correct .opt-letter { background: var(--accent); color: var(--accent-ink); }

.quiz-option-btn.incorrect {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--bg));
}
.quiz-option-btn.incorrect .opt-letter { background: var(--danger); color: #fff; }

.quiz-option-btn:disabled { cursor: default; }

.quiz-explanation {
  margin-top: 14px;
  font-size: 0.84rem;
  color: var(--ink-muted);
  background: var(--bg);
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.quiz-next-btn {
  margin-top: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-weight: 700;
}

.quiz-results {
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  text-align: center;
}
.quiz-results h3 {
  font-family: var(--font-display);
  font-size: 1.6rem;
}
#quiz-review-list { text-align: left; margin-top: 18px; }
.quiz-review-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 0.86rem;
}
.quiz-review-item .qri-q { font-weight: 700; margin-bottom: 6px; }
.quiz-review-item .qri-status { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.quiz-review-item.right .qri-status { color: var(--accent); }
.quiz-review-item.wrong .qri-status { color: var(--danger); }

#quiz-retake-btn {
  margin-top: 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-weight: 700;
}

/* ---- Practice Q&A (full page, wider than sidebar version) ---- */

.practice-qa-wrap {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

/* =================== SEARCH PAGE =================== */

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 12px 18px;
  max-width: 600px;
  color: var(--ink-muted);
}
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 1rem;
  color: var(--ink);
}

.search-results {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  max-width: 800px;
}
.search-results li {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--bg-elevated);
  cursor: pointer;
}
.search-results li:hover { background: var(--accent-soft); }
.search-results .sr-meta {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}
.search-results .sr-preview { font-size: 0.88rem; }
.search-results mark { background: var(--highlight-yellow); border-radius: 2px; }

/* =================== IMPORT MODAL / FAB =================== */

.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 1.1rem;
  box-shadow: var(--shadow-card);
  z-index: 60;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 10, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 90%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 86vh;
  overflow-y: auto;
}
.modal h3 { font-family: var(--font-display); margin: 0 0 8px; }
.modal label { font-size: 0.78rem; color: var(--ink-muted); margin-top: 8px; }
.modal input, .modal select, .modal textarea {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}
.modal textarea { font-family: var(--font-mono); font-size: 0.82rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.modal-actions button:not(.ghost) {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-weight: 700;
}

/* =================== RESPONSIVE =================== */

@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .subjects-overview-card { grid-column: span 2; }
  .reader-layout { grid-template-columns: 220px 1fr; }
  .reader-right { display: none; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .subjects-overview-card { grid-column: span 1; }
  .reader-layout { grid-template-columns: 1fr; }
  .reader-left { max-height: 240px; }
  .page { padding: 14px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Focus visibility */
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* =================== MANAGE PAGE =================== */

#page-manage { padding: 0; overflow: hidden; }

.manage-layout {
  display: grid;
  grid-template-columns: 220px 220px 1fr;
  height: 100%;
  min-height: 0;
  flex: 1;
}

.manage-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
  overflow: hidden;
}

.manage-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex: none;
}

.manage-col-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
}
.icon-btn:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.manage-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.manage-list li {
  border-radius: var(--radius-md);
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-muted);
  transition: background 0.1s;
  margin-bottom: 2px;
}
.manage-list li:hover { background: var(--accent-soft); color: var(--ink); }
.manage-list li.active { background: var(--accent); color: var(--accent-ink); }
.manage-list li .manage-item-name { flex: 1; }
.manage-list li .manage-item-del {
  opacity: 0;
  background: none;
  border: none;
  color: inherit;
  font-size: 0.72rem;
  padding: 2px 4px;
}
.manage-list li:hover .manage-item-del { opacity: 0.5; }
.manage-list li:hover .manage-item-del:hover { opacity: 1; }

.manage-empty { padding: 16px; display: block; }

.manage-editor-col {
  border-right: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.manage-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--ink-faint);
  gap: 10px;
  font-size: 2.5rem;
}
.manage-placeholder p { font-size: 0.9rem; margin: 0; }

.manage-editor-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  flex: none;
  background: var(--bg-elevated);
}

.manage-editor-header h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.manage-editor-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ink-muted);
  cursor: pointer;
}
.toggle-label input[type="checkbox"] { accent-color: var(--accent); }

.small-btn {
  padding: 5px 10px;
  font-size: 0.78rem;
}

/* ---- PDF Upload card ---- */

.pdf-upload-card {
  margin: 16px 18px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex: none;
}

.pdf-upload-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.pdf-upload-header i { color: var(--danger); font-size: 1.3rem; margin-top: 2px; }

.pdf-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 22px;
  border: 2px dashed var(--border);
  margin: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 0.88rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.pdf-drop-zone i { font-size: 1.6rem; color: var(--ink-faint); }
.pdf-drop-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }

.pdf-browse-label {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.pdf-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

#pdf-progress {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  font-size: 0.84rem;
  color: var(--ink-muted);
}

.pdf-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--ink-muted);
  gap: 8px;
  flex-wrap: wrap;
}

.pdf-result-actions {
  display: flex;
  gap: 6px;
}

.pdf-result-actions button:not(.ghost) {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 700;
}
.pdf-result-actions button:not(.ghost):hover { background: var(--accent); color: var(--accent-ink); }

.pdf-extracted {
  width: 100%;
  display: block;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 10px 12px;
  resize: vertical;
  min-height: 120px;
  max-height: 260px;
  outline: none;
}

/* ---- Content editor tabs ---- */

.editor-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-top: 16px;
  flex: none;
}

.editor-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-muted);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.editor-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.editor-tab-panel { display: none; flex: 1; flex-direction: column; min-height: 0; }
.editor-tab-panel.active { display: flex; }

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex: none;
}

.content-editor {
  flex: 1;
  border: none;
  outline: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  padding: 18px;
  resize: none;
  min-height: 340px;
}

.editor-status {
  padding: 6px 18px 10px;
  min-height: 26px;
  flex: none;
}

/* ---- Modals (new subject / lesson) ---- */

.modal input[type="number"] { width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--ink); }

/* =================== RESPONSIVE MANAGE =================== */

@media (max-width: 1100px) {
  .manage-layout { grid-template-columns: 200px 1fr; }
  .manage-lessons-col { display: none; }
}

@media (max-width: 720px) {
  .manage-layout { grid-template-columns: 1fr; }
  .manage-subjects-col { max-height: 200px; }
}

/* =================== GUIDE PAGE =================== */

.guide-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 24px 60px;
  width: 100%;
}

.guide-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 42px;
  box-shadow: var(--shadow-card);
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.8;
}

.guide-container h1 {
  font-size: 1.9rem;
  font-weight: 700;
  margin: 0 0 6px;
  border-bottom: 2px solid var(--margin-rule);
  padding-bottom: 10px;
}

.guide-container h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 2em 0 0.5em;
  color: var(--accent);
}

.guide-container h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.4em 0 0.4em;
}

.guide-container p { margin: 0 0 0.9em; }

.guide-container ul, .guide-container ol {
  margin: 0.4em 0 0.9em;
  padding-left: 1.6em;
}

.guide-container li { margin-bottom: 0.3em; }

.guide-container code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
}

.guide-container pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0.8em 0 1.2em;
}

.guide-container pre code {
  background: none;
  padding: 0;
  font-size: 0.83em;
  color: var(--ink);
}

.guide-container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.6em 0 1.2em;
}

.guide-container th {
  background: var(--accent-soft);
  text-align: left;
  padding: 8px 12px;
  font-weight: 700;
  border: 1px solid var(--border);
}

.guide-container td {
  padding: 7px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
}

.guide-container tr:nth-child(even) td { background: var(--bg); }

.guide-container strong { font-weight: 700; color: var(--margin-rule); }

.guide-container blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.6em 0;
  padding: 6px 14px;
  color: var(--ink-muted);
}

.guide-container hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}
