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

:root {
  --bg: #f5f0eb;
  --surface: #ffffff;
  --text: #2c2a27;
  --muted: #8a8480;
  --accent: #5a7a5c;
  --accent-light: #e8f0e8;
  --danger: #c0392b;
  --warn: #d4a017;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  line-height: 1.5;
}

/* ── Layout shells ─────────────────────────────────────── */
.view { display: none; min-height: 100vh; }
.view.active { display: flex; flex-direction: column; }

.view-inner {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Session view ──────────────────────────────────────── */
#view-session .view-inner { gap: 24px; }

.session-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.session-header p {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

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

.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.book-card-num {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 24px;
  text-align: center;
}
.book-card-info { flex: 1; }
.book-card-title { font-weight: 600; font-size: 1rem; }
.book-card-meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.book-card-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-new    { background: var(--accent-light); color: var(--accent); }
.badge-review { background: #fdf3e3; color: #9a6f00; }
.badge-echo   { background: #f0f0f0; color: var(--muted); }

.session-footer { margin-top: auto; padding-top: 24px; }
.session-footer .btn-secondary { width: 100%; margin-top: 10px; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
}
.btn-primary:hover { background: #4a6a4c; }
.btn-primary:disabled { background: #ccc; cursor: default; }

.btn-secondary {
  display: inline-block;
  padding: 10px 20px;
  background: transparent;
  color: var(--muted);
  border: 1.5px solid #ddd;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover { border-color: var(--text); color: var(--text); }

.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.library-header .btn-secondary { flex: 0 0 auto; }
.library-book-card {
  width: 100%;
  border: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.library-book-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
}
.empty-state p { margin-top: 8px; font-size: 0.9rem; }

/* ── Reader view ───────────────────────────────────────── */
#view-reader {
  background: #1a1a1a;
  color: #f0ece8;
}

#view-reader .view-inner {
  max-width: 860px;
  padding: 0;
  gap: 0;
}

.reader-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #111;
}
.reader-book-title {
  font-size: 0.9rem;
  color: #aaa;
  font-weight: 500;
}
.reader-page-count {
  font-size: 0.85rem;
  color: #666;
}
.reader-controls-top {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 6px;
  border-radius: 6px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.icon-btn.active { color: #7db87f; }

/* Image area */
.reader-image-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 75%; /* 4:3 */
  background: #0d0d0d;
  overflow: hidden;
}
.reader-image-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.reader-image-wrap .img-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: #444;
}
.reader-image-wrap .img-placeholder span { font-size: 2rem; }
.reader-image-wrap .img-placeholder p { font-size: 0.85rem; }

/* Audio bar */
.reader-audio-bar {
  background: #111;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.audio-play-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.4rem;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.audio-play-btn:hover { background: #4a6a4c; transform: scale(1.05); }
.audio-play-btn:active { transform: scale(0.97); }
.audio-play-btn.playing { background: #3a5a3c; }
.audio-play-btn.no-audio {
  background: #333;
  cursor: default;
  color: #555;
}

.audio-status {
  font-size: 0.82rem;
  color: #666;
  flex: 1;
}
.audio-status.playing { color: #7db87f; }
.audio-status.missing { color: #555; font-style: italic; }

.audio-pack-select {
  max-width: 220px;
  background: #1f1f1f;
  color: #ddd;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.audio-pack-select[hidden] { display: none; }

/* Text area */
.reader-text-area {
  padding: 20px 24px;
  background: #1a1a1a;
  min-height: 80px;
  display: flex;
  align-items: center;
}
.reader-text-area.text-hidden .page-text { opacity: 0; pointer-events: none; }

.page-text {
  font-size: 1.35rem;
  line-height: 1.5;
  color: #e8e0d5;
  transition: opacity 0.2s;
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* Navigation */
.reader-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #111;
  gap: 12px;
}

.nav-btn {
  padding: 12px 28px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.nav-btn-prev {
  background: #2a2a2a;
  color: #aaa;
}
.nav-btn-prev:hover:not(:disabled) { background: #333; color: #fff; }
.nav-btn-next {
  background: var(--accent);
  color: #fff;
}
.nav-btn-next:hover:not(:disabled) { background: #4a6a4c; }
.nav-btn:disabled { opacity: 0.3; cursor: default; }

.nav-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}
.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #444;
  transition: background 0.2s, transform 0.2s;
}
.nav-dot.active { background: var(--accent); transform: scale(1.3); }
.nav-dot.seen { background: #666; }

/* ── Check view ────────────────────────────────────────── */
#view-check {
  background: #f5f0eb;
}
#view-check .view-inner {
  justify-content: center;
  gap: 28px;
  text-align: center;
}

.check-book-title { font-size: 0.95rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.check-heading { font-size: 1.3rem; font-weight: 600; }
.check-subtext { color: var(--muted); font-size: 0.95rem; }

.check-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.check-btn {
  padding: 18px 24px;
  border-radius: var(--radius);
  border: 2.5px solid transparent;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 14px;
}
.check-btn:active { transform: scale(0.98); }

.check-btn-gotit  { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.check-btn-gotit:hover  { background: #d0e8d0; }
.check-btn-sortof { background: #fdf3e3; color: #9a6f00; border-color: #d4a017; }
.check-btn-sortof:hover { background: #fae8c0; }
.check-btn-lostit { background: #fdf0f0; color: var(--danger); border-color: var(--danger); }
.check-btn-lostit:hover { background: #fad8d8; }

.check-btn-icon { font-size: 1.5rem; }
.check-btn-label { flex: 1; }
.check-btn-desc { display: block; font-size: 0.78rem; font-weight: 400; opacity: 0.7; margin-top: 2px; }

/* ── Session complete ──────────────────────────────────── */
#view-done {
  background: var(--bg);
}
#view-done .view-inner {
  justify-content: center;
  align-items: center;
  gap: 20px;
  text-align: center;
}
.done-icon { font-size: 4rem; }
.done-heading { font-size: 1.6rem; font-weight: 700; }
.done-subtext { color: var(--muted); max-width: 320px; }
.done-stats {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow);
}
.done-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.9rem;
  color: var(--muted);
  border-bottom: 1px solid #f0ece8;
}
.done-stat-row:last-child { border-bottom: none; }
.done-stat-row strong { color: var(--text); }
.done-stat-result { display: flex; flex-direction: column; align-items: flex-end; }
.done-stat-next { font-size: 0.75rem; color: var(--muted); }

/* ── Settings / debug overlay ──────────────────────────── */
.settings-bar {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 100;
}
.settings-btn {
  background: rgba(0,0,0,0.12);
  border: none;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s;
}
.settings-btn:hover { background: rgba(0,0,0,0.2); color: var(--text); }

/* ── Misc ──────────────────────────────────────────────── */
.spacer { flex: 1; }

audio { display: none; }

@media (max-width: 480px) {
  .reader-topbar { padding: 10px 14px; }
  .reader-audio-bar { padding: 12px 14px; }
  .reader-text-area { padding: 16px 14px; }
  .reader-nav { padding: 12px 14px; }
  .page-text { font-size: 1.15rem; }
  .nav-btn { padding: 10px 18px; }
}
