:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --line: #d1d5db;
  --brand: #2563eb; --brand-text: #fff; --brand-soft: #dbeafe; --hit: #fff3a3; --play: #fde68a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f172a; --card: #1e293b; --text: #e5e7eb; --muted: #94a3b8; --line: #334155;
          --brand: #3b82f6; --brand-soft: #1e3a8a; --hit: #854d0e; --play: #92400e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.55; padding-bottom: 60px; }
button, select, input { font: inherit; }

.top { background: var(--brand); color: var(--brand-text); padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 30; }
.top h1 { font-size: 1.2rem; margin: 0; }
.home-link { color: var(--brand-text); text-decoration: none; font-size: .85rem; opacity: .9; white-space: nowrap; }
.home-link:hover { text-decoration: underline; }
.langpick { display: flex; align-items: center; gap: 8px; font-size: .9rem; white-space: nowrap; }
.langpick select { padding: 5px 8px; border-radius: 6px; border: 0; }

.layout { display: flex; align-items: flex-start; gap: 0; max-width: 1400px; margin: 0 auto; }

#sidebar { width: 380px; flex: none; max-width: 44vw; height: calc(100vh - 54px); position: sticky; top: 54px;
  overflow-y: auto; border-inline-end: 1px solid var(--line); padding: 14px; background: var(--bg); }

.searchbar { display: flex; gap: 6px; }
#searchBox { flex: 1; min-width: 0; padding: 9px 12px; border: 2px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); font-size: 1rem; }
#searchBox:focus { outline: none; border-color: var(--brand); }
#searchGo { flex: none; padding: 0 14px; border-radius: 8px; }
.hint { margin: 6px 0 10px; font-size: .78rem; color: var(--muted); }

.topic-header { background: var(--brand-soft); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.topic-name { font-weight: 700; font-size: 1rem; }
.topic-aliases { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.results-list { margin-bottom: 20px; }
.result-row { padding: 6px 6px; border-radius: 6px; cursor: pointer; border-bottom: 1px solid var(--line); }
.result-row:last-child { border-bottom: none; }
.result-row:hover { background: var(--brand-soft); }
.result-row.active { background: var(--brand); color: var(--brand-text); }
.result-ref { font-weight: 700; font-size: .78rem; font-variant-numeric: tabular-nums; }
.result-where { font-size: .72rem; color: var(--muted); }
.result-row.active .result-where { color: var(--brand-text); opacity: .85; }
.result-snippet { font-size: .82rem; margin-top: 2px; }

.topic-cat { margin-bottom: 20px; }
.topic-cat h2 { margin: 0 0 2px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); }
.topic-cat .hint { margin: 0 0 8px; }

.az-list { font-size: .9rem; }
.az-group { margin-bottom: 8px; }
.az-letter { font-weight: 700; font-size: .72rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 2px; padding-bottom: 1px; }
.az-item { padding: 3px 4px; cursor: pointer; border-radius: 5px; display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.az-item:hover { background: var(--brand-soft); }
.az-item.active { background: var(--brand); color: var(--brand-text); }
.az-item .az-cat { font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; flex: none; }
.az-item.active .az-cat { color: var(--brand-text); opacity: .8; }

.tree { font-size: .92rem; }
.t-group { margin-bottom: 10px; }
.t-group-title { font-weight: 700; font-size: .82rem; margin: 0 0 3px; color: var(--text); }
.t-being { padding: 3px 4px; cursor: pointer; border-radius: 5px; font-size: .9rem; }
.t-being:hover { background: var(--brand-soft); }
.t-being.active { background: var(--brand); color: var(--brand-text); }

.t-place { padding: 5px 4px; cursor: pointer; border-radius: 6px; display: flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; }
.t-place:hover { background: var(--brand-soft); }
.t-place .emoji { flex: none; }

#reading { flex: 1; min-width: 0; padding: 20px 24px 40px; max-width: 900px; }
.empty-hint { color: var(--muted); font-size: 1rem; padding: 40px 0; text-align: center; }

#bookBody { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 26px 26px; font-size: 1.08rem; }
#bookBody h1 { font-size: 1.6rem; text-align: center; margin: 18px 0; }
#bookBody h2 { font-size: 1.2rem; margin: 26px 0 8px; color: var(--brand); scroll-margin-top: 70px; }
#bookBody p { margin: 0 0 14px; scroll-margin-top: 70px; }
#bookBody p.flash { animation: flash 2.2s ease; }
@keyframes flash { 0%, 60% { background: var(--hit); } 100% { background: transparent; } }
.s { cursor: pointer; border-radius: 3px; }
.s:hover { background: var(--brand-soft); }
.s.playing { background: var(--play); }
sup.pn { color: var(--muted); font-size: .7em; margin-inline-end: 4px; font-weight: 600; }

#playerbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 2px solid var(--brand); padding: 10px 16px; display: flex; gap: 14px; align-items: center; justify-content: center; z-index: 50; }
#playerbar[hidden] { display: none; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  #sidebar { width: 100%; max-width: none; height: auto; position: static; max-height: 50vh; border-inline-end: none; border-bottom: 1px solid var(--line); }
  #reading { padding: 16px; max-width: none; }
}
