:root {
  --bg: #f5f3ee;
  --panel: #fffaf1;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9d2c5;
  --accent: #1e40af;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #0f766e;
  --shadow: rgba(17, 24, 39, 0.10);
  --quote-bg: #fffdf8;
  --bottom-h: 74px;
}

body.dark {
  --bg: #111827;
  --panel: #182235;
  --text: #f5f6f8;
  --muted: #b6c0cf;
  --line: #334155;
  --accent: #60a5fa;
  --accent-text: #0f172a;
  --danger: #fb7185;
  --ok: #5eead4;
  --shadow: rgba(0, 0, 0, 0.25);
  --quote-bg: #101827;
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }
body {
  margin: 0;
  padding: 0 0 calc(var(--bottom-h) + env(safe-area-inset-bottom)) 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  overscroll-behavior-x: none;
}

.book-shell { min-height: calc(100vh - var(--bottom-h)); }
.reader {
  min-height: calc(100vh - var(--bottom-h) - env(safe-area-inset-bottom));
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 1.5rem max(1rem, env(safe-area-inset-left));
}
.quote-card {
  max-width: 880px;
  margin: 0 auto;
  min-height: calc(100vh - var(--bottom-h) - 2rem);
  touch-action: pan-y;
}
.quote-content {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.18rem, 2.35vw, 1.58rem);
  line-height: 1.42;
  padding-bottom: 1.2rem;
}
.quote-content h2 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(1.18rem, 2.6vw, 1.7rem);
  margin: 0 0 0.85rem;
  line-height: 1.2;
}
.quote-content .meta,
.quote-content .source { color: var(--muted); font-size: 0.78em; }
.quote-content .quote {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  margin: 0.7rem 0 0;
}
.quote-content .dialogue-line { margin: 0.16rem 0 0.33rem; }
.quote-content .speaker { font-weight: 900; }
.quote-content .comments {
  margin-top: 1.15rem;
  border-left: 3px solid var(--line);
  padding-left: 0.9rem;
  color: var(--muted);
  font-size: 0.78em;
}
.quote-content .comments h3 { margin: 0 0 0.4rem; font-size: 0.95em; }
.quote-content .comment { margin: 0.65rem 0; }
.quote-content .comment-author { font-weight: 800; margin-bottom: 0.1rem; }
.quote-content hr { display: none; }

.empty-fullscreen,
.empty {
  max-width: 760px;
  margin: 22vh auto 0;
  color: var(--muted);
  text-align: center;
  font-size: 1.1rem;
}
.empty button { margin-top: 1rem; }

.book-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  min-height: var(--bottom-h);
  display: grid;
  grid-template-columns: 0.75fr 1fr 0.85fr 1fr 0.75fr;
  gap: 0.45rem;
  padding: 0.55rem max(0.7rem, env(safe-area-inset-left)) calc(0.55rem + env(safe-area-inset-bottom)) max(0.7rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.book-nav button { width: 100%; min-width: 0; padding: 0.55rem 0.35rem; font-size: 2.45rem; line-height: 1; }
#bottomPrevBtn { order: 1; }
#bottomDislikeBtn { order: 2; }
#settingsBtn { order: 3; }
#bottomLikeBtn { order: 4; }
#bottomNextBtn { order: 5; }

button, .file-label, select {
  border: 1px solid var(--line);
  background: var(--quote-bg);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  font-weight: 750;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.file-label input { display: none; }
.file-label.secondary { font-weight: 650; }
select { appearance: none; padding-right: 1.4rem; }
input[type="search"] {
  flex: 1 1 260px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--quote-bg);
  color: var(--text);
  padding: 0 1rem;
  font-size: 1rem;
}
progress { width: 100%; height: 0.8rem; margin-top: 0.8rem; }

.like-btn.is-liked, #bottomLikeBtn.is-liked { background: var(--ok); color: #06201c; border-color: var(--ok); }
.dislike-btn.is-disliked, #bottomDislikeBtn.is-disliked { background: var(--danger); color: #fff; border-color: var(--danger); }

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
.settings-overlay.open { display: block; }
.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.42);
}
.settings-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(760px, 96vw);
  overflow: auto;
  background: var(--bg);
  padding: env(safe-area-inset-top) max(1rem, env(safe-area-inset-right)) calc(var(--bottom-h) + 1rem) max(1rem, env(safe-area-inset-left));
  box-shadow: -8px 0 28px rgba(0,0,0,0.2);
}
.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
}
.close-btn { font-size: 2rem; line-height: 1; width: 48px; height: 48px; padding: 0; }
h1, h2 { margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.subtitle, .status, .hint, .version-line { color: var(--muted); margin: 0.25rem 0 0; }
.version-line strong { color: var(--text); }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 3px 14px var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
summary { cursor: pointer; font-weight: 800; font-size: 1.05rem; }
.row { display: flex; align-items: center; gap: 0.65rem; }
.wrap { flex-wrap: wrap; }
.stats { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--muted); margin-bottom: 0.8rem; }
.stats strong { color: var(--text); }
.hidden-stat { display: none; }
.controls, .search-row, .export-row, .settings-actions { margin-top: 0.7rem; }
.sync-code-row { margin-top: 0.8rem; }
.sync-code-label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 750; color: var(--muted); }
.sync-code-label input {
  min-width: min(520px, 88vw);
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--quote-bg);
  color: var(--text);
  padding: 0 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
}

.selection-list { max-width: 900px; margin: 0 auto; }
.list-tabs { margin: 0.8rem 0; }
.selection-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  margin: 0.6rem 0;
  background: var(--quote-bg);
}
.selection-item h3 { margin: 0 0 0.4rem; }
.selection-item p { margin: 0.25rem 0; color: var(--muted); }
.selection-item .mini-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.55rem; }

body.dark .quote-content .speaker-1, body.dark .quote-content [style*="#1e88e5"] { color: #93c5fd !important; -webkit-text-fill-color: #93c5fd !important; }
body.dark .quote-content .speaker-2, body.dark .quote-content [style*="#e53935"] { color: #fca5a5 !important; -webkit-text-fill-color: #fca5a5 !important; }
body.dark .quote-content .speaker-3, body.dark .quote-content [style*="#d4a100"] { color: #fde68a !important; -webkit-text-fill-color: #fde68a !important; }

@media (max-width: 700px) {
  .reader { padding-left: 0.9rem; padding-right: 0.9rem; }
  .quote-content { font-size: 1.18rem; }
  .book-nav { grid-template-columns: 0.75fr 1fr 0.85fr 1fr 0.75fr; gap: 0.35rem; }
  .book-nav button { font-size: 2.25rem; }
  button, .file-label, select { width: 100%; }
  .book-nav button { width: 100%; }
  .row { align-items: stretch; }
  .stats { flex-direction: column; gap: 0.25rem; }
}

#settingsBtn { pointer-events: auto; touch-action: manipulation; }
