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

:root {
  --bg:        #0d0f18;
  --surface:   #161927;
  --surface2:  #1f2235;
  --surface3:  #252840;
  --border:    #2a2e4a;
  --accent:    #4f8ef7;
  --accent-lo: rgba(79,142,247,0.12);
  --purple:    #7c6af7;
  --purple-lo: rgba(124,106,247,0.14);
  --green:     #22c55e;
  --text:      #e4eaf6;
  --text2:     #8892b0;
  --text3:     #4a5278;
  --sidebar-w: 280px;
  --header-h:  52px;
  --radius:    12px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  flex-shrink: 0;
  z-index: 20;
}

#menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
}
#menu-btn:hover { background: var(--surface2); color: var(--text); }

.header-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.header-book {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}
.header-name {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-pill {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.25);
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.03em;
}

#search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
  width: 170px;
  outline: none;
  transition: border-color 0.2s, width 0.2s;
}
#search-input:focus { border-color: var(--accent); width: 210px; }
#search-input::placeholder { color: var(--text3); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}
#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-group { padding: 8px 0; }
.sidebar-group + .sidebar-group { border-top: 1px solid var(--border); }

.sidebar-group-label {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 8px 14px 6px;
}

.page-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
  position: relative;
}
.page-item:hover { background: var(--surface2); }
.page-item.active {
  background: var(--accent-lo);
  border-left-color: var(--accent);
}
.page-item.read .page-num::after {
  content: " ✓";
  color: var(--green);
  font-size: 10px;
}

.page-num {
  font-size: 11px;
  color: var(--text3);
  min-width: 30px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.page-item.active .page-num { color: var(--accent); }

.page-label {
  font-size: 12px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  line-height: 1.35;
}
.page-item.active .page-label { color: var(--text); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  flex-shrink: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-content    { background: rgba(79,142,247,0.12);  color: #6ea8fa; }
.badge-questions  { background: rgba(124,106,247,0.15); color: #a594f9; }
.badge-summary    { background: rgba(34,197,94,0.12);   color: #6ee7a0; }
.badge-objectives { background: rgba(251,191,36,0.12);  color: #fcd34d; }

/* ── Main ────────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
#main::-webkit-scrollbar { width: 5px; }
#main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Welcome ─────────────────────────────────────────────────────────────── */
.welcome {
  max-width: 480px;
  margin: 72px auto;
  padding: 0 24px;
  text-align: center;
}
.welcome-emoji { font-size: 52px; margin-bottom: 18px; line-height: 1; }
.welcome h2 { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.welcome > p { font-size: 15px; color: var(--text2); margin-bottom: 24px; }

.welcome-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.stat-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  min-width: 80px;
}
.stat-num { font-size: 24px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 2px; }

.welcome-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text2);
}

/* ── Page viewer ─────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 28px 48px;
}

/* Top bar */
.page-topbar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 22px;
}
.page-topbar-left { flex: 1; min-width: 0; }
.page-topbar h2 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 4px;
}
.page-topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text2);
}

.page-nav { display: flex; gap: 6px; flex-shrink: 0; }
.nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { border-color: var(--accent); color: var(--text); background: var(--accent-lo); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

.mark-read-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
}
.mark-read-btn.done {
  border-color: var(--green);
  color: var(--green);
  background: rgba(34,197,94,0.08);
}
.mark-read-btn:hover:not(.done) { border-color: var(--text2); color: var(--text); }

/* Image card */
.img-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
  position: relative;
}
.img-skeleton {
  width: 100%;
  padding-bottom: 140%;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.img-card img {
  width: 100%;
  display: block;
  cursor: zoom-in;
  opacity: 0;
  transition: opacity 0.3s ease;
  position: absolute;
  top: 0; left: 0;
}
.img-card img.loaded { opacity: 1; position: relative; }

/* Text card */
.text-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 24px;
}
.text-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.text-card-header .enhanced-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.text-body {
  font-size: 15px;
  line-height: 1.78;
  color: var(--text);
}
.text-body h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.text-body h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 16px 0 6px;
}
.text-body p {
  margin-bottom: 12px;
}
.text-body ul {
  margin: 8px 0 14px 20px;
}
.text-body li {
  margin-bottom: 5px;
}
.text-body h2:first-child,
.text-body h3:first-child { margin-top: 0; }

/* No-text notice */
.no-text-notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text2);
}
.no-text-notice .icon { font-size: 20px; flex-shrink: 0; }

/* ── Photo toggle ────────────────────────────────────────────────────────── */
.photo-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  padding: 11px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  text-align: left;
}
.photo-toggle-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-lo); }

.photo-collapse {
  display: none;
  margin-bottom: 18px;
}
.photo-collapse.open { display: block; }

/* ── Quiz ────────────────────────────────────────────────────────────────── */
.quiz-section { margin-top: 8px; }
.quiz-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.quiz-count {
  font-size: 12px;
  color: var(--text2);
  font-weight: 400;
  margin-left: auto;
}

.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.q-card:focus-within { border-color: var(--purple); }

.q-num {
  font-size: 10px;
  font-weight: 800;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}
.q-stem {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.55;
  margin-bottom: 16px;
  color: var(--text);
}

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

.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.45;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.opt:hover { border-color: var(--purple); background: var(--purple-lo); }
.opt.selected {
  border-color: var(--purple);
  background: var(--purple-lo);
}

.opt-letter {
  font-weight: 800;
  font-size: 13px;
  color: var(--text3);
  min-width: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}
.opt.selected .opt-letter { color: var(--purple); }
.opt-text { color: var(--text2); }
.opt.selected .opt-text { color: var(--text); }
.opt.correct {
  border-color: var(--green) !important;
  background: rgba(34,197,94,0.12) !important;
}
.opt.correct .opt-letter { color: var(--green) !important; }
.opt.wrong {
  border-color: var(--wrong, #ef4444) !important;
  background: rgba(239,68,68,0.1) !important;
}
.opt.wrong .opt-letter { color: #ef4444 !important; }
.answer-verdict {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 8px;
}
.verdict-correct { background: rgba(34,197,94,0.12); color: var(--green); }
.verdict-wrong   { background: rgba(239,68,68,0.1);  color: #ef4444; }
.answer-expl {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
  line-height: 1.5;
  border-top: 1px solid currentColor;
  padding-top: 7px;
}

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

.reveal-btn {
  background: none;
  border: 1.5px solid var(--purple);
  color: var(--purple);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.reveal-btn:hover, .reveal-btn.active {
  background: var(--purple-lo);
  border-color: var(--purple);
}

.answer-photo {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.answer-photo-label {
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  background: var(--surface2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.answer-photo img {
  width: 100%;
  display: block;
  cursor: zoom-in;
}

/* ── Lightbox ────────────────────────────────────────────────────────────── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5,6,14,0.95);
  z-index: 100;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 20px;
}
#lightbox.open { display: flex; }

#lb-img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.9);
  cursor: default;
  user-select: none;
}

#lb-close {
  position: absolute;
  top: 18px;
  right: 20px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#lb-close:hover { background: rgba(255,255,255,0.2); }

#lb-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  pointer-events: none;
  white-space: nowrap;
}

/* ── Notes ───────────────────────────────────────────────────────────────── */
.notes-section {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.notes-header .notes-icon { font-size: 14px; margin-right: 6px; }
.notes-saved {
  font-size: 11px;
  font-weight: 400;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s;
}
.notes-saved.show { opacity: 1; }
.notes-textarea {
  width: 100%;
  min-height: 120px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
  padding: 16px 18px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}
.notes-textarea::placeholder { color: var(--text3); }

.note-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fbbf24;
  flex-shrink: 0;
  display: none;
}
.has-note .note-dot { display: block; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  #menu-btn { display: block; }
  .header-name { display: none; }
  #search-input { width: 120px; }
  #search-input:focus { width: 150px; }

  #sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.6);
  }
  #sidebar.open { transform: translateX(0); }

  .page-wrap { padding: 16px 16px 40px; }
  .page-topbar { flex-wrap: wrap; }
  .page-nav { width: 100%; }
  .nav-btn { flex: 1; text-align: center; }
  .progress-pill { display: none; }
}
