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

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

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

h1, h2 { margin: 0; }

h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.subtitle, .status, .empty { color: var(--muted); margin: 0.25rem 0 0; }

main {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 3px 14px var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.row { display: flex; align-items: center; gap: 0.65rem; }
.wrap { flex-wrap: wrap; }

button, .file-label {
  border: 1px solid var(--line);
  background: var(--quote-bg);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
.file-label input { display: none; }
.file-label.secondary { font-weight: 600; }

progress { width: 100%; height: 0.8rem; margin-top: 0.8rem; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  color: var(--muted);
  margin-bottom: 0.8rem;
}
.stats strong { color: var(--text); }

.controls, .search-row, .export-row { margin-top: 0.7rem; }
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;
}

.reader { padding: clamp(1rem, 3vw, 2rem); }
.quote-card { max-width: 780px; margin: 0 auto; }
.quote-content { font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.04rem, 2vw, 1.24rem); }
.quote-content h2 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.12rem;
  margin: 0 0 0.7rem;
}
.quote-content .meta, .quote-content .source { color: var(--muted); font-size: 0.78em; }
.quote-content .quote { background: var(--quote-bg); border-radius: 14px; padding: 1rem; border: 1px solid var(--line); }
.quote-content .dialogue-line { margin: 0.18rem 0 0.32rem; }
.quote-content .speaker { font-weight: 800; }
.quote-content .comments {
  margin-top: 1rem;
  border-left: 3px solid var(--line);
  padding-left: 0.9rem;
  color: var(--muted);
  font-size: 0.82em;
}
.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; }

.favorite-box {
  margin-top: 1.4rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  display: flex;
  justify-content: center;
}
.favorite-btn {
  min-width: min(100%, 360px);
  font-size: 1rem;
}
.favorite-btn.is-fav { background: #f59e0b; color: #111827; border-color: #f59e0b; }

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: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  button, .file-label { width: 100%; }
  .row { align-items: stretch; }
  .stats { flex-direction: column; gap: 0.25rem; }
}
