/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff; --bg2: #f5f4f0; --bg3: #eeecea;
  --border: rgba(0,0,0,0.12); --border-md: rgba(0,0,0,0.22);
  --text: #1a1a18; --muted: #6b6a66; --hint: #9b9a96;
  --blue: #378ADD; --blue-bg: #E6F1FB; --blue-text: #0C447C;
  --green: #1D9E75; --green-bg: #EAF3DE; --green-text: #3B6D11;
  --amber: #EF9F27; --amber-bg: #FAEEDA; --amber-text: #854F0B;
  --red: #E24B4A; --red-bg: #FCEBEB; --red-text: #A32D2D;
  --coral-bg: #FAECE7; --coral-text: #993C1D;
  --radius: 8px; --radius-lg: 12px; --sidebar-w: 210px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a; --bg2: #252523; --bg3: #2e2e2b;
    --border: rgba(255,255,255,0.1); --border-md: rgba(255,255,255,0.2);
    --text: #f0ede8; --muted: #9b9a96; --hint: #6b6a66;
    --blue-bg: #0c2d4a; --blue-text: #85B7EB;
    --green-bg: #0c2e1e; --green-text: #5DCAA5;
    --amber-bg: #2e1e06; --amber-text: #FAC775;
    --red-bg: #2e0c0c; --red-text: #F09595;
    --coral-bg: #2e1008; --coral-text: #F0997B;
  }
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.6; color: var(--text); background: var(--bg3); }
a { cursor: pointer; text-decoration: none; color: inherit; }
input, select, textarea, button { font: inherit; }
h1 { font-size: 22px; font-weight: 500; }
h3 { font-size: 15px; font-weight: 500; margin-bottom: 10px; }
.hidden { display: none !important; }

/* ── Auth ── */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg3); }
.auth-box { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 32px; width: 380px; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo-mark { font-size: 28px; font-weight: 700; letter-spacing: 0.05em; color: var(--blue); }
.auth-logo-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tab-row { display: flex; border-bottom: 0.5px solid var(--border); margin-bottom: 20px; }
.tab-btn { flex: 1; padding: 8px; background: none; border: none; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -0.5px; }
.tab-btn.active { color: var(--text); border-bottom-color: var(--blue); font-weight: 500; }
.auth-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; margin-top: 12px; }
.auth-form input { width: 100%; padding: 8px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); }
.auth-form input:focus { outline: none; border-color: var(--blue); }
.form-error { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 16px; }
.hint { font-size: 11px; color: var(--hint); font-weight: 400; }
.hint a { color: var(--blue); }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 0.5px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto; }
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 28px 32px; max-width: 1100px; }

/* ── Sidebar ── */
.sidebar-logo { padding: 20px 16px 16px; border-bottom: 0.5px solid var(--border); }
.logo-mark { font-size: 16px; font-weight: 700; letter-spacing: 0.05em; color: var(--blue); }
.logo-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.nav-section { padding: 12px 16px 4px; font-size: 10px; font-weight: 500; color: var(--hint); letter-spacing: 0.06em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 16px; font-size: 13px; color: var(--muted); cursor: pointer; border-left: 2px solid transparent; border: none; background: none; width: 100%; text-align: left; }
.nav-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: var(--bg3); }
.nav-item.active { color: var(--text); background: var(--bg); border-left: 2px solid var(--blue); font-weight: 500; }
.sidebar-footer { margin-top: auto; border-top: 0.5px solid var(--border); padding: 8px 0; }
.logout-btn { color: var(--muted); }
.user-chip { padding: 6px 16px; font-size: 11px; color: var(--hint); }

/* ── Screens ── */
.screen.hidden { display: none; }
.page-header { margin-bottom: 20px; }

/* ── Stats ── */
.stat-grid { display: grid; grid-template-columns: repeat(5,1fr); gap: 10px; margin-bottom: 24px; }
.stat-card { background: var(--bg2); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-val { font-size: 24px; font-weight: 500; }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ── Session history ── */
.session-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 0.5px solid var(--border); }
.session-date { font-size: 11px; color: var(--muted); width: 72px; flex-shrink: 0; }
.session-bar-wrap { flex: 1; height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.session-bar-fill { height: 100%; border-radius: 3px; }
.session-pct { font-size: 12px; font-weight: 500; width: 32px; text-align: right; }

/* ── Weak areas ── */
.weak-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.weak-title { font-size: 13px; font-weight: 500; }
.weak-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.progress-bar { height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--blue); transition: width 0.3s; }

/* ── Buttons ── */
.btn-primary { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; background: var(--blue); color: #fff; border: none; border-radius: var(--radius); font: inherit; font-size: 13px; cursor: pointer; }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; background: none; color: var(--muted); border: 0.5px solid var(--border-md); border-radius: var(--radius); font: inherit; font-size: 13px; cursor: pointer; }
.btn-ghost:hover { background: var(--bg2); color: var(--text); }
.full-w { width: 100%; justify-content: center; margin-top: 16px; }

/* ── Pill filters ── */
.filter-section { margin-bottom: 14px; }
.filter-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pill-group { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 4px 12px; border: 0.5px solid var(--border-md); border-radius: 20px; background: var(--bg2); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; transition: background 0.12s, color 0.12s, border-color 0.12s; }
.pill:hover { border-color: var(--blue); color: var(--text); }
.pill.active { background: var(--blue-bg); color: var(--blue-text); border-color: transparent; font-weight: 500; }

/* ── Search ── */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input { flex: 1; padding: 9px 12px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 14px; }
.search-bar input:focus { outline: none; border-color: var(--blue); }
.filter-row { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-btn { padding: 4px 12px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.filter-btn.active { background: var(--blue-bg); color: var(--blue-text); border-color: transparent; }
.result-item { padding: 14px 0; border-bottom: 0.5px solid var(--border); }
.result-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; flex-wrap: wrap; }
.result-text { font-size: 13px; line-height: 1.6; color: var(--text); }
.badge { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: var(--radius); font-weight: 500; }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-coral { background: var(--coral-bg); color: var(--coral-text); }

/* ── Quiz / Flashcard ── */
.setup-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; max-width: 600px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; }
.form-group label { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.form-group select, .form-group input[type=number] { padding: 8px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); }
.hint-text { font-size: 12px; color: var(--muted); line-height: 1.5; }
.quiz-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.quiz-progress-label { font-size: 13px; color: var(--muted); }
.question-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; margin: 16px 0; }
.question-source { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.question-text { font-size: 15px; line-height: 1.65; margin-bottom: 18px; }
.question-text.long { max-height: 260px; overflow-y: auto; padding-right: 6px; border: 0.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--bg2); font-size: 14px; margin-bottom: 14px; }
.question-text.long::-webkit-scrollbar { width: 4px; }
.question-text.long::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }
.explanation-text { font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
.choice-btn { display: block; width: 100%; text-align: left; padding: 11px 14px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; margin-bottom: 8px; transition: border-color 0.12s, background 0.12s; }
.choice-btn:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-bg); }
.choice-btn.correct { border-color: var(--green); background: var(--green-bg); color: var(--green-text); }
.choice-btn.wrong { border-color: var(--red); background: var(--red-bg); color: var(--red-text); }
.answer-reveal { margin-top: 16px; padding: 14px; background: var(--bg2); border-radius: var(--radius); border-left: 3px solid var(--blue); }
.citation-block { margin-top: 10px; padding: 10px 12px; background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); }
.citation-title { font-size: 12px; font-weight: 500; margin-bottom: 3px; }
.citation-ref { font-size: 12px; color: var(--muted); }
.next-btn { margin-top: 14px; }
.result-card { max-width: 400px; margin: 60px auto; text-align: center; background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 36px; }
.result-score { font-size: 56px; font-weight: 500; color: var(--blue); }
.result-label { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.result-card .btn-primary, .result-card .btn-ghost { margin: 6px 4px; }

/* ── Compare ── */
.compare-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 16px; }
.compare-col { border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.compare-head { padding: 10px 14px; font-size: 11px; font-weight: 500; letter-spacing: 0.03em; }
.compare-head.rules { background: var(--blue-bg); color: var(--blue-text); }
.compare-head.casebook { background: var(--green-bg); color: var(--green-text); }
.compare-head.mechanics { background: var(--amber-bg); color: var(--amber-text); }
.compare-body { padding: 12px 14px; font-size: 13px; line-height: 1.65; color: var(--text); min-height: 80px; }

/* ── Upload ── */
.upload-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; }
.upload-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; margin-top: 12px; }
.upload-card input[type=text], .upload-card input[type=number], .upload-card select { width: 100%; padding: 8px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; }
.drop-zone { border: 1.5px dashed var(--border-md); border-radius: var(--radius-lg); padding: 32px; text-align: center; cursor: pointer; margin-top: 14px; transition: border-color 0.15s, background 0.15s; }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--blue); background: var(--blue-bg); }
.drop-label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.drop-hint { font-size: 11px; color: var(--hint); margin-top: 4px; }
.source-row { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.source-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-rules { background: var(--blue); }
.dot-casebook { background: var(--green); }
.dot-mechanics { background: var(--amber); }
.source-info { flex: 1; }
.source-name { font-size: 13px; font-weight: 500; }
.source-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ── Settings ── */
.settings-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; max-width: 480px; }
.settings-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; margin-top: 10px; }
.settings-card input { width: 100%; padding: 8px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; }

/* ── Content Editor ── */
.editor-controls { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; }
.editor-controls .form-group { display: flex; flex-direction: column; }
.editor-controls label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.editor-controls input, .editor-controls select { padding: 7px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit; font-size: 13px; }

.editor-chunk-row { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; display: flex; gap: 10px; align-items: flex-start; }
.chunk-drag-handle { cursor: grab; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 2px 0; flex-shrink: 0; user-select: none; opacity: 0.4; transition: opacity 0.15s; }
.editor-chunk-row:hover .chunk-drag-handle { opacity: 0.8; }
.chunk-drag-handle:active { cursor: grabbing; }
.chunk-dragging { opacity: 0.4; border-style: dashed; }
.chunk-drag-over { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }

.editor-chunk-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.editor-chunk-content { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 8px; font-family: monospace; white-space: pre-wrap; word-break: break-word; max-height: 80px; overflow: hidden; }
.editor-chunk-actions { display: flex; gap: 6px; }

.editor-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.editor-modal.hidden { display: none !important; }
.editor-modal-box { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; }
.editor-modal-box .form-group { display: flex; flex-direction: column; }
.editor-modal-box label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.editor-modal-box input, .editor-modal-box select { padding: 8px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; }

.question-meta-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.question-meta-row .question-source { flex: 1; margin-bottom: 0; }

.flag-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.flag-btn:hover { color: var(--text); }
.flag-btn.flagged { color: #f59e0b; }
.flag-btn svg { width: 15px; height: 15px; }

.report-question-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
  opacity: 0.6;
}
.report-question-btn:hover { color: #e07b00; opacity: 1; }
.report-question-btn.reported { color: #e07b00; opacity: 1; }
.report-question-btn svg { width: 15px; height: 15px; }


/* ── NEW: Flagged count badge on nav item ── */
.flagged-badge {
  margin-left: auto;
  background: #f59e0b;
  color: #000;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* ── NEW: Previous button row under quiz/flashcard ── */
.quiz-nav-row {
  display: flex;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}

/* ── NEW: Flagged questions screen ── */
.flagged-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.flagged-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.flagged-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.unflag-btn {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--muted);
  padding: 2px 6px;
}
.unflag-btn:hover { color: var(--red); }

.flagged-choice {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 4px;
  margin-bottom: 4px;
  color: var(--muted);
}
.flagged-choice-correct {
  background: rgba(29, 158, 117, 0.1);
  color: var(--text);
  font-weight: 500;
}
.choice-letter { font-weight: 600; flex-shrink: 0; }
.correct-tick { margin-left: auto; color: var(--green); font-weight: 700; }

.flagged-explanation {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg3);
  border-radius: 6px;
  border-left: 2px solid var(--blue);
}

/* ── Content Reports ─────────────────────────────────────────── */
.report-card {
  background: var(--bg2);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  border-left: 3px solid var(--border-md);
}
.report-card.open  { border-left-color: #e07b00; }
.report-card.resolved { border-left-color: var(--green); }
.report-card.dismissed { border-left-color: var(--border-md); opacity: 0.65; }

.report-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.report-card-meta {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
}
.report-card-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.report-comment {
  font-style: italic;
  color: var(--text);
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--bg3, var(--bg));
  border-radius: 4px;
  font-size: 13px;
}
.report-content-preview {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg3, var(--bg));
  padding: 8px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-family: monospace;
  line-height: 1.5;
  white-space: pre-wrap;
}
.report-admin-note {
  font-size: 12px;
  color: var(--green);
  margin-bottom: 8px;
  padding: 5px 10px;
  background: var(--bg3, var(--bg));
  border-radius: 4px;
}
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.report-btn { color: #e07b00 !important; }
/* ── Book accuracy ── */
.book-accuracy-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.book-acc-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.book-acc-header { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.book-acc-score { font-size: 32px; font-weight: 500; line-height: 1; }
.book-acc-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }

.badge-gray {
  background: var(--border-md);
  color: var(--muted);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* ── Weekly goal bar ── */
.weekly-goal-wrap { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.weekly-goal-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.weekly-goal-label { font-size: 13px; color: var(--text); }
.weekly-goal-pct { font-size: 13px; font-weight: 600; }

/* ── Search result expand ── */
.result-expand-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font: inherit;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg2);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.result-expand-btn:hover:not(:disabled) { color: var(--blue); border-color: var(--blue); }
.result-expand-btn:disabled { opacity: 0.5; cursor: default; }
.result-expand-btn svg { width: 12px; height: 12px; flex-shrink: 0; }
.result-full-content {
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-text-expanded {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 6px;
}

/* ── Search term highlighting ── */
mark.search-highlight {
  background: #fff3b0;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
@media (prefers-color-scheme: dark) {
  mark.search-highlight { background: #5a4a00; color: #ffe680; }
}

/* ── Weekly goal history ── */
.wh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  padding: 0;
}
.wh-toggle:hover { color: var(--text); }
.wh-chevron { width: 13px; height: 13px; flex-shrink: 0; transition: transform 0.2s; }
.wh-history { margin-top: 10px; border-top: 0.5px solid var(--border); padding-top: 10px; }
.wh-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 0.5px solid var(--border); font-size: 12px; }
.wh-row:last-child { border-bottom: none; }
.wh-date { width: 110px; flex-shrink: 0; color: var(--muted); }
.wh-bar-wrap { flex: 1; height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.wh-bar-fill { height: 100%; border-radius: 3px; }
.wh-count { width: 60px; text-align: right; flex-shrink: 0; font-size: 11px; }
.wh-hit { width: 16px; text-align: center; flex-shrink: 0; font-size: 13px; }

/* ── Per-position accuracy ── */
.pos-acc-grid { display: flex; flex-direction: column; gap: 8px; }
.pos-acc-row { display: grid; grid-template-columns: 180px 1fr 44px 52px; align-items: center; gap: 12px; }
.pos-acc-label { font-size: 13px; display: flex; align-items: center; }
.pos-acc-bar-wrap .progress-bar { margin-top: 0; }
.pos-acc-pct { font-size: 13px; font-weight: 600; text-align: right; }
.pos-acc-sub { font-size: 11px; color: var(--muted); text-align: right; }

/* ── Activity heatmap ── */
.heatmap-wrap-full { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.heatmap-inner { display: flex; gap: 24px; align-items: flex-start; }
.heatmap-left { flex: 1; min-width: 0; }
.heatmap-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 16px; }
.heatmap-title { font-size: 13px; font-weight: 500; color: var(--text); }
.heatmap-legend { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.heatmap-legend-cell { display: inline-block; width: 11px; height: 11px; border-radius: 2px; }
.heatmap-grid-wrap { display: flex; gap: 4px; }
.heatmap-day-labels { display: flex; flex-direction: column; gap: 2px; padding-top: 18px; }
.heatmap-day-lbl { height: 15px; font-size: 10px; color: var(--muted); line-height: 15px; width: 24px; }
.heatmap-scroll { overflow-x: auto; flex: 1; }
.heatmap-month-row { display: flex; gap: 3px; margin-bottom: 2px; }
.heatmap-month-lbl { width: 15px; font-size: 10px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.heatmap-grid { display: flex; gap: 3px; }
.heatmap-col { display: flex; flex-direction: column; gap: 3px; flex-shrink: 0; }
.heatmap-cell { width: 15px; height: 15px; border-radius: 2px; cursor: default; transition: opacity 0.1s; }
.heatmap-cell:hover { opacity: 0.75; }
.heatmap-stats-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; border-left: 0.5px solid var(--border); padding-left: 24px; flex-shrink: 0; align-self: center; min-width: 320px; }
.heatmap-stats-col { display: flex; flex-direction: column; gap: 14px; }
.heatmap-stat-row { display: flex; align-items: flex-start; gap: 8px; }
.heatmap-stat-icon { font-size: 16px; line-height: 1; margin-top: 1px; flex-shrink: 0; }
.heatmap-stat-val { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.2; white-space: nowrap; }
.heatmap-stat-lbl { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ════════════════════════════════════════════════
   RESPONSIVE — mobile first breakpoint ≤ 768px
   iPhone 16 Pro Max portrait = 430px
   ════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Layout: sidebar → bottom tab bar ── */
  :root { --sidebar-w: 0px; }

  .app { flex-direction: column; padding-bottom: 60px; }

  .sidebar {
    position: fixed;
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 60px;
    flex-direction: row;
    border-right: none;
    border-top: 0.5px solid var(--border);
    overflow-y: visible;
    overflow-x: auto;
    z-index: 200;
  }

  /* Hide sidebar chrome that doesn't belong in tab bar */
  .sidebar-logo,
  .nav-section,
  .sidebar-footer,
  .user-chip { display: none; }

  /* Nav items become tab buttons */
  .nav-item {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 10px;
    font-size: 10px;
    border-left: none;
    border-top: 2px solid transparent;
    flex: 1;
    min-width: 52px;
    white-space: nowrap;
  }
  .nav-item svg { width: 18px; height: 18px; }
  .nav-item.active {
    border-left: none;
    border-top: 2px solid var(--blue);
    color: var(--blue);
    background: none;
    font-weight: 500;
  }
  .flagged-badge { margin-left: 0; font-size: 9px; padding: 1px 4px; }

  /* ── Main content ── */
  .main-content {
    margin-left: 0;
    padding: 16px;
    max-width: 100%;
  }

  h1 { font-size: 18px; }
  h3 { font-size: 14px; }

  /* ── Auth ── */
  .auth-box { width: 100%; max-width: 100%; margin: 16px; padding: 24px 20px; }

  /* ── Stat grid: 2 cols on mobile ── */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-val { font-size: 20px; }

  /* ── Two-col → single col ── */
  .two-col { grid-template-columns: 1fr; gap: 16px; }

  /* ── Book accuracy: 1 col ── */
  .book-accuracy-grid { grid-template-columns: 1fr; }
  .book-acc-score { font-size: 26px; }

  /* ── Compare grid: 1 col ── */
  .compare-grid { grid-template-columns: 1fr; }

  /* ── Form rows: 1 col ── */
  .form-row { grid-template-columns: 1fr; }

  /* ── Setup card: full width ── */
  .setup-card { max-width: 100%; padding: 16px; }

  /* ── Question card ── */
  .question-card { padding: 14px 16px; }
  .question-text { font-size: 14px; }
  .choice-btn { padding: 10px 12px; font-size: 13px; }

  /* ── Result card ── */
  .result-card { margin: 24px auto; padding: 24px 20px; max-width: 100%; }
  .result-score { font-size: 44px; }

  /* ── Session rows: hide bar on very small screens ── */
  .session-bar-wrap { display: none; }
  .session-date { width: auto; }

  /* ── Settings ── */
  .settings-card { max-width: 100%; }

  /* ── Position accuracy: fluid columns ── */
  .pos-acc-row { grid-template-columns: 1fr 40px 40px; }
  .pos-acc-sub { display: none; }

  /* ── Weekly history ── */
  .wh-date { width: 80px; font-size: 11px; }

  /* ── Heatmap: stack stats below grid ── */
  .heatmap-inner { flex-direction: column; gap: 16px; }
  .heatmap-stats-panel {
    border-left: none;
    border-top: 0.5px solid var(--border);
    padding-left: 0;
    padding-top: 16px;
    min-width: 0;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
  }
  .heatmap-stat-val { white-space: normal; }
  .heatmap-cell { width: 12px; height: 12px; }
  .heatmap-month-lbl { width: 12px; }
  .heatmap-col { gap: 2px; }
  .heatmap-grid { gap: 2px; }
  .heatmap-month-row { gap: 2px; }

  /* ── Editor modal: full screen on mobile ── */
  .editor-modal { padding: 0; align-items: flex-end; }
  .editor-modal-box {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px 16px;
  }

  /* ── Search ── */
  .search-bar { flex-direction: column; }
  .search-bar input { font-size: 16px; } /* prevent iOS zoom on focus */

  /* ── Upload ── */
  .drop-zone { padding: 20px; }

  /* ── Page header ── */
  .page-header { margin-bottom: 14px; }
}

/* ── Narrow phones (≤ 390px) ── */
@media (max-width: 390px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 12px; }
  .nav-item { font-size: 9px; padding: 6px 6px; min-width: 44px; }
}

/* ── Nav label swap: show short label on mobile ── */
@media (max-width: 768px) {
  .nav-item .nav-label { display: none; }
  .nav-item::after { content: attr(data-label); font-size: 10px; }
  .nav-item.logout-btn::after { content: ''; } /* hide sign out text on mobile */
  .nav-item.logout-btn { display: none; } /* hide sign out in tab bar entirely */
}

/* ── Question quality rating ── */
.quality-rating-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.quality-label { font-size: 12px; color: var(--muted); }
.quality-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: var(--radius); border: 0.5px solid var(--border-md); background: var(--bg2); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; transition: all 0.12s; }
.quality-btn svg { width: 13px; height: 13px; }
.quality-good:hover:not(:disabled) { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.quality-bad:hover:not(:disabled)  { border-color: var(--red);   color: var(--red);   background: var(--red-bg);   }
.quality-btn:disabled { opacity: 0.4; cursor: default; }
.quality-reason-wrap { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; width: 100%; }
.quality-reason-select { padding: 5px 8px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; font-size: 12px; }

/* ── Quality review cards ── */
.quality-review-card { background: var(--bg); border: 0.5px solid var(--border-md); border-left: 3px solid var(--red); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.quality-review-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.quality-review-question { font-size: 13px; line-height: 1.6; color: var(--text); font-weight: 500; }

/* ── User management ── */
.user-mgmt-stats {}
.user-table { border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.user-table-head { display: grid; grid-template-columns: 2fr 80px 80px 90px 90px 90px 1fr; gap: 0; padding: 10px 16px; background: var(--bg2); font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.user-table-row { display: grid; grid-template-columns: 2fr 80px 80px 90px 90px 90px 1fr; gap: 0; padding: 12px 16px; border-top: 0.5px solid var(--border); align-items: center; background: var(--bg); transition: background 0.1s; }
.user-table-row:hover { background: var(--bg2); }
.user-disabled { opacity: 0.6; }
.user-name { font-size: 13px; font-weight: 500; }
.user-email { font-size: 11px; color: var(--muted); margin-top: 1px; }
.user-joined { font-size: 10px; color: var(--hint); margin-top: 2px; }
.user-stat { font-size: 13px; color: var(--text); }
.user-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.user-actions .btn-ghost { padding: 4px 8px; }

@media (max-width: 768px) {
  .user-table-head { display: none; }
  .user-table-row { grid-template-columns: 1fr; gap: 8px; }
  .user-stat::before { content: attr(data-label) ': '; color: var(--muted); font-size: 11px; }
}

/* ── Chunk question pool panel ── */
.chunk-questions-panel { margin-top: 10px; border-top: 0.5px solid var(--border); padding-top: 10px; }
.cqp-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cqp-row { padding: 8px 0; border-bottom: 0.5px solid var(--border); }
.cqp-row:last-child { border-bottom: none; }
.cqp-q-text { font-size: 12px; color: var(--text); line-height: 1.5; margin-bottom: 4px; }
.cqp-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cqp-row-flagged { background: var(--red-bg) !important; border-radius: var(--radius); padding: 6px 8px; margin: 2px 0; }

/* ── Question cleanup modal ── */
.cleanup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.cleanup-col { display: flex; flex-direction: column; }
.cleanup-col-header { font-size: 13px; font-weight: 600; color: var(--text); padding-bottom: 6px; border-bottom: 1.5px solid var(--border-md); min-height: 32px; display: flex; align-items: center; justify-content: space-between; }
.cleanup-before { width: 100%; padding: 7px 10px; border: 0.5px solid var(--border); border-radius: var(--radius); background: var(--bg3); color: var(--muted); font: inherit; font-size: 13px; resize: vertical; }
.cleanup-after  { width: 100%; padding: 7px 10px; border: 0.5px solid var(--border-md); border-radius: var(--radius); background: var(--bg2); color: var(--text); font: inherit; font-size: 13px; resize: vertical; }
.cleanup-highlight { background: #fff3b0; border-radius: 2px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { .cleanup-highlight { background: #5a4a00; color: #ffe680; } }
@media (max-width: 768px) { .cleanup-grid { grid-template-columns: 1fr; } }
