:root {
  --font-body: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --fs: 19px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
[data-theme="dark"]  { --bg:#121418; --panel:#1b1e24; --panel2:#23272f; --line:#2c313a; --text:#e7e3da; --muted:#9a968c; --accent:#d1ab6e; --now:rgba(209,171,110,.13); }
[data-theme="sepia"] { --bg:#f4ecd8; --panel:#ebe1c8; --panel2:#e2d6b8; --line:#d3c5a2; --text:#3b2f22; --muted:#7a6a55; --accent:#8a5a1c; --now:rgba(138,90,28,.12); }
[data-theme="light"] { --bg:#fbfbf9; --panel:#f0efeb; --panel2:#e6e4de; --line:#dcd9d1; --text:#1f1f1c; --muted:#6c6a63; --accent:#8b5e1a; --now:rgba(139,94,26,.10); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font-ui); min-height: 100dvh; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .25rem;
  padding: calc(.4rem + var(--safe-t)) .5rem .4rem; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.where { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.where .arc { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.where .ttl { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; color: var(--text); }
.icon:hover { background: var(--panel); }
.icon:disabled { opacity: .3; }

/* Reading column */
.reader { max-width: 40rem; margin: 0 auto; padding: 1.5rem 1.25rem calc(11rem + var(--safe-b));
  font-family: var(--font-body); font-size: var(--fs); line-height: 1.65; }
.reader h1 { font-weight: normal; font-size: 1.45em; line-height: 1.3; margin: .5rem 0 1.75rem; text-wrap: balance; }
.reader p { margin: 0 0 .85em; padding: .1em .5em; margin-left: -.5em; margin-right: -.5em; border-radius: 6px; cursor: pointer; transition: background .2s; }
.reader p.d { border-left: 3px solid var(--c, var(--muted)); padding-left: .75em; margin-left: -.5em; }
.reader p .who { display: block; font-family: var(--font-ui); font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--c, var(--muted)); margin-bottom: .1em; }
.reader p.now, .reader h1.now { background: var(--now); }
.reader .brk { text-align: center; color: var(--muted); letter-spacing: .6em; margin: 1.6em 0; font-size: .8em; }
.reader .brk.now { color: var(--accent); }
.reader .hint { color: var(--muted); text-align: center; font-family: var(--font-ui); font-size: 15px; }
.endnav { display: flex; gap: .75rem; justify-content: center; margin-top: 2.5rem; font-family: var(--font-ui); }
.btn { font-family: var(--font-ui); font-size: 14px; padding: .6rem 1rem; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 600; }

/* Player */
.player { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: color-mix(in srgb, var(--panel) 96%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.progress { height: 3px; background: var(--line); }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.controls { display: flex; justify-content: center; align-items: center; gap: .5rem; padding: .5rem 0 .1rem; }
.play { width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: var(--bg); display: grid; place-items: center; }
.play svg { width: 26px; height: 26px; }
.play .i-play path { fill: currentColor; }
.play .i-pause { display: none; }
body.playing .play .i-play { display: none; }
body.playing .play .i-pause { display: block; stroke-width: 3; }
.status { display: flex; justify-content: center; align-items: center; gap: .75rem; padding: 0 1rem .55rem; font-size: 12px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 600; padding: .25rem .6rem; border-radius: 99px; border: 1px solid var(--line); color: var(--text); min-width: 3.5rem; }

/* Sheets */
dialog.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 40rem; max-height: 88dvh; border-radius: 16px 16px 0 0;
  background: var(--bg); color: var(--text); box-shadow: 0 -10px 40px rgba(0,0,0,.4); display: none; flex-direction: column; }
dialog.sheet[open] { display: flex; }
dialog::backdrop { background: rgba(0,0,0,.5); }
@media (min-width: 760px) { dialog.sheet { margin: auto; border-radius: 16px; max-height: 80vh; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .5rem .25rem 1.25rem; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.sheet > section, .sheet .toc, .sheet .form { overflow: auto; padding: 0 1.25rem calc(1.5rem + var(--safe-b)); }
.sheet input[type=search] { margin: .25rem 1.25rem .75rem; padding: .65rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 16px; }

.tabs { display: flex; gap: .25rem; margin: 0 1.25rem .75rem; background: var(--panel); padding: 3px; border-radius: 10px; }
.tabs button { flex: 1; padding: .5rem; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--bg); color: var(--text); font-weight: 600; }

.toc details { border-bottom: 1px solid var(--line); }
.toc summary { padding: .8rem 0; font-weight: 600; color: var(--accent); cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary span { color: var(--muted); font-weight: normal; font-size: 13px; }
.toc a { display: block; padding: .55rem .5rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 15px; }
.toc a:hover { background: var(--panel); }
.toc a.cur { background: var(--now); font-weight: 600; }
.toc a small { color: var(--muted); margin-left: .35rem; }

/* Cast / pronunciation / settings rows */
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.row { display: grid; grid-template-columns: 1fr auto; gap: .4rem .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); align-items: center; }
.row .name { font-weight: 600; font-size: 15px; }
.row .name small { color: var(--muted); font-weight: normal; margin-left: .3rem; }
.row .sub { grid-column: 1 / -1; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row select, .form select, .row input[type=text], .form input[type=text] { font: inherit; font-size: 14px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .5rem; min-width: 0; }
.row select { flex: 1 1 12rem; }
.row label.mini { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.row input[type=range] { width: 6.5rem; accent-color: var(--accent); }
.small { font-size: 13px; padding: .35rem .65rem; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.pron-row { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: .4rem; align-items: center; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.pron-row input[type=text] { width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; min-width: 0; }
.pron-row.off input[type=text] { opacity: .45; }
.form .field { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.form .field input[type=range] { width: 10rem; accent-color: var(--accent); }
.form .field input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; margin: .75rem 0; }
.flex { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }

.toast { position: fixed; left: 50%; bottom: calc(9.5rem + var(--safe-b)); transform: translateX(-50%) translateY(10px); background: var(--text); color: var(--bg);
  padding: .55rem .9rem; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.actionable { pointer-events: auto; display: flex; align-items: center; gap: .75rem; }
.toast-act { font-weight: 700; color: var(--bg); text-decoration: underline; padding: .2rem .1rem; }

/* Phase 5: cloud voices */
.meter { display: grid; grid-template-columns: 6.5rem 1fr auto; gap: .6rem; align-items: center; font-size: 13px; margin: .35rem 0; }
.meter-bar { height: 8px; background: var(--panel); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.meter-bar i { display: block; height: 100%; background: var(--accent); }
.badge { border: 1px solid var(--line); border-radius: 99px; padding: 0 .4rem; font-size: 11px !important; }
.badge.t-chirp3hd { border-color: #b48ad6; color: #b48ad6 !important; }
.badge.t-neural2 { border-color: #5aa6c8; color: #5aa6c8 !important; }
.badge.t-wavenet { border-color: #7fb069; color: #7fb069 !important; }
.seg { display: flex; gap: .75rem; font-size: 14px; }
.seg label { display: flex; gap: .3rem; align-items: center; }
.row input[type=range]:disabled { opacity: .35; }
body.buffering .play { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
