/* santi — annotated 三体 reader · styles ported from reader/assets/css/main.css */
/* ---------- theme ---------- */
:root {
  --bg: #faf8f4;
  --fg: #26241f;
  --muted: #8b867c;
  --line: #e6e1d6;
  --panel: #ffffff;
  --chip-bg: #f1ede3;
  --chip-fg: #4a463d;
  --accent: #a4552a;
  --active-bg: #efe7da;
  --shadow: 0 12px 40px rgba(40, 32, 18, 0.18);
}
:root[data-theme='dark'] {
  --bg: #15171b;
  --fg: #d9d5cc;
  --muted: #807d74;
  --line: #2a2e35;
  --panel: #1c1f25;
  --chip-bg: #242830;
  --chip-fg: #c4c0b6;
  --accent: #d08252;
  --active-bg: #262b33;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei',
    -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }

.app { display: flex; min-height: 100vh; }

/* ---------- progress bar ---------- */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 60; pointer-events: none;
}
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 300px; flex: none; height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0;
}
.side-head { padding: 18px 16px 10px; position: sticky; top: 0; background: var(--panel); z-index: 5; border-bottom: 1px solid var(--line); }
.side-head h1 { margin: 0; font-size: 20px; letter-spacing: 0.06em; }
.side-head .sub { display: block; font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; margin-top: 2px; }
.totals { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
.side-back { display: inline-block; margin-bottom: 8px; font-size: 11.5px; color: var(--muted); text-decoration: none; letter-spacing: 0.05em; }
.side-back:hover { color: var(--accent); }

.tree { padding: 10px 10px 40px; }
.tree-empty { color: var(--muted); padding: 20px 14px; }
.book-title {
  margin: 18px 6px 6px; font-size: 13px; letter-spacing: 0.05em;
  color: var(--accent); text-transform: uppercase;
}
.chap { margin: 2px 0 4px; }
.chap-head {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 6px; font-size: 13px; color: var(--fg);
}
.chap-no { flex: none; min-width: 22px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.chap-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { flex: none; font-size: 10.5px; color: var(--muted); background: var(--chip-bg); border-radius: 8px; padding: 1px 6px; }
.count.alldone { color: var(--panel); background: var(--accent); }
.segs { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 6px 6px 34px; }
.seg {
  min-width: 30px; padding: 3px 7px; border-radius: 7px;
  font-size: 12px; background: var(--chip-bg); color: var(--chip-fg);
  border: 1px solid transparent; font-variant-numeric: tabular-nums;
}
.seg:hover { border-color: var(--accent); }
.seg.active { background: var(--accent); color: var(--panel); }
.seg.untrans { opacity: 0.55; border-style: dashed; border-color: currentColor; }
.seg.untrans.active { opacity: 0.85; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 3px; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.nav-btn { padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; background: var(--panel); }
.nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.crumb { flex: 1; min-width: 0; text-align: center; font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb-book { color: var(--fg); }
.crumb-sep { margin: 0 6px; }
.badge-todo {
  margin-left: 8px; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); border: 1px dashed var(--accent); border-radius: 6px; padding: 1px 6px;
}
.icon-btn { font-size: 17px; line-height: 1; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--active-bg); }

.reader { max-width: 46rem; width: 100%; margin: 0 auto; padding: 36px 28px 120px; }
.reader.empty { color: var(--muted); text-align: center; }
.error { color: #c0392b; }
.ch-title { font-size: calc(var(--han) * 1.25); margin: 0 0 4px; font-weight: 600; }
.meta-line { color: var(--muted); font-size: 12.5px; margin: 0 0 30px; border-bottom: 1px solid var(--line); padding-bottom: 14px; }

/* ---------- paragraphs & sentences ---------- */
.para {
  position: relative;
  font-size: var(--han);
  line-height: 1.95;
  margin: 0 0 1.4em;
  text-align: justify;
}
.para-play {
  position: absolute; top: -0.35em; right: -0.4em;
  opacity: 0; transition: opacity 0.15s;
  font-size: 0.55em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 50%;
  width: 1.9em; height: 1.9em; background: var(--panel);
}
.para:hover .para-play, .para-play:focus-visible { opacity: 0.9; }
.para-play.playing, .para-play:hover { color: var(--accent); border-color: var(--accent); }

.sent { cursor: pointer; border-radius: 3px; outline: none; }
.sent.is-focused .zh, .sent:focus-visible .zh {
  background: linear-gradient(transparent 62%, var(--active-bg) 62%);
  box-shadow: 0 0 0 1px var(--line);
}
.sent.playing .zh { color: var(--accent); }

.play {
  display: inline-block; vertical-align: baseline;
  font-size: 0.5em; color: var(--accent);
  opacity: 0; margin-left: 0.35em; transition: opacity 0.15s;
  border: 1px solid var(--line); border-radius: 50%;
  width: 1.9em; height: 1.9em; line-height: 1.7em; background: var(--panel);
}
.sent:hover .play, .sent.is-focused .play, .play:focus-visible { opacity: 0.85; }
.play:hover { opacity: 1 !important; transform: scale(1.1); }

/* reveal blocks live in the DOM but are shown only per reveal-mode + pinyin position */
.reveal { display: inline-block; max-width: 100%; vertical-align: top; margin: 0.15em 0 0.45em; text-align: left; }
.reveal-above { margin: 0 0 0.15em; }
.reader .reveal { display: none; }
.reader[data-reveal='always'] .reveal,
.reader .sent.is-focused .reveal { display: inline-block; }
.reader[data-py='below'] .rev-above,
.reader[data-py='above'] .rev-below { display: none !important; }
.reveal .py {
  display: block;
  font-family: 'PingFang SC', 'Segoe UI', sans-serif;
  font-size: var(--py); line-height: 1.5;
  color: var(--accent); letter-spacing: 0.02em;
}
.reveal .en {
  display: block;
  font-size: var(--en); line-height: 1.55;
  color: var(--muted); margin-top: 2px;
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip {
  position: relative;
  display: inline-flex; align-items: baseline; gap: 5px;
  background: var(--chip-bg); color: var(--chip-fg);
  border-radius: 7px; padding: 3px 8px; font-size: calc(var(--en) - 1px);
}
.chip:hover { background: var(--accent); color: var(--panel); }
.chip-zh { font-weight: 600; }
.chip-py { font-style: italic; opacity: 0.75; font-size: 0.85em; }
.chip::after {
  content: attr(data-gloss);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  font-size: 11.5px; line-height: 1.35; padding: 4px 9px; border-radius: 6px;
  white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none; transition: opacity 0.12s; z-index: 20;
}
.chip:hover::after { opacity: 1; }

/* ---------- settings panel ---------- */
.settings-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  z-index: 100; display: flex; justify-content: flex-end;
}
.settings-backdrop[hidden] { display: none; }
.settings {
  width: 330px; max-width: 92vw; height: 100%; overflow-y: auto;
  background: var(--panel); box-shadow: var(--shadow);
  padding: 18px 20px 30px;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.settings-head h2 { margin: 0; font-size: 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0; }
.set-row > label:first-child, .lab { font-size: 13px; color: var(--fg); }
.set-row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.slider-row { display: block; }
.slider-row .lab { display: flex; justify-content: space-between; margin-bottom: 4px; }
.slider-row .lab b { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type='range'] { width: 100%; accent-color: var(--accent); }
.toggle { border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px; font-size: 13px; }
.toggle:hover { border-color: var(--accent); }
.seg-group { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-group button { padding: 5px 11px; font-size: 12.5px; color: var(--muted); }
.seg-group button + button { border-left: 1px solid var(--line); }
.seg-group button.on { background: var(--accent); color: var(--panel); }
.voice-select {
  width: 100%; padding: 7px 9px; font-size: 12.5px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px;
}
.hint { font-size: 11.5px; color: var(--muted); }
.hint.foot { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; max-height: 42vh; border-right: none; border-bottom: 1px solid var(--line); }
  .side-head { position: static; }
  .reader { padding: 24px 18px 90px; }
}