:root {
  --bg: #fbfaf8; --surface: #ffffff; --ink: #1c1b19; --ink-2: #5d5a55; --ink-3: #8f8b84;
  --line: #e8e5df; --accent: #5b4bf0; --accent-ink: #ffffff; --accent-soft: rgba(91, 75, 240, .11);
  --warn: #c98a12; --shadow: 0 10px 30px rgba(28, 27, 25, .10), 0 1px 3px rgba(28, 27, 25, .08);
  --ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Charter, "Book Antiqua", Georgia, serif;
  --read: var(--serif); --size: 20px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1b1b19; --ink: #ecebe8; --ink-2: #aaa6a0; --ink-3: #77736d;
  --line: #2a2a27; --accent: #8c7dff; --accent-ink: #12111f; --accent-soft: rgba(140, 125, 255, .16);
  --warn: #e0a93b; --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1b1b19; --ink: #ecebe8; --ink-2: #aaa6a0; --ink-3: #77736d;
    --line: #2a2a27; --accent: #8c7dff; --accent-ink: #12111f; --accent-soft: rgba(140, 125, 255, .16);
    --warn: #e0a93b; --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--ui); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex: none; }
.mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--bg);
  font: 700 17px/1 var(--serif); }
.name { font-weight: 650; letter-spacing: -.01em; }
.urlbar { flex: 1; display: flex; max-width: 640px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 4px 4px 16px; transition: border-color .15s, box-shadow .15s; }
.urlbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.urlbar input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; }
.urlbar input::placeholder { color: var(--ink-3); }
.urlbar button { border: 0; border-radius: 999px; padding: 7px 18px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.urlbar button:hover { filter: brightness(1.08); }
.actions { display: flex; gap: 4px; flex: none; }
.icon { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-2); }
.icon:hover { background: var(--accent-soft); color: var(--ink); }
.icon.small { width: 32px; height: 32px; }
.icon[aria-pressed="true"] { color: var(--accent); }
.icon svg { width: 19px; height: 19px; }
.badge { position: absolute; top: 3px; right: 2px; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent);
  color: var(--accent-ink); font: 600 10px/16px var(--ui); text-align: center; }

/* ---------- hero ---------- */
main { padding: 0 20px 170px; }
#hero { max-width: 700px; margin: 12vh auto 0; text-align: center; }
#hero h1 { margin: 0 0 18px; font: 600 clamp(40px, 7vw, 68px)/1.04 var(--serif); letter-spacing: -.025em; }
#hero h1 em { color: var(--accent); font-style: italic; }
#hero p { margin: 0 auto 28px; max-width: 520px; color: var(--ink-2); font-size: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; color: var(--ink-2); font-size: 14px; }
.chip:hover { border-color: var(--accent); color: var(--ink); }

/* ---------- article ---------- */
#article { max-width: 680px; margin: 7vh auto 0; }
.kicker { display: flex; gap: 12px; align-items: center; color: var(--ink-3); font-size: 13px; letter-spacing: .02em; }
.kicker span + span::before { content: ""; display: inline-block; width: 3px; height: 3px; border-radius: 50%; background: currentColor; margin-right: 12px; vertical-align: middle; }
#title { margin: 10px 0 8px; font: 600 clamp(32px, 5vw, 46px)/1.1 var(--serif); letter-spacing: -.02em; }
.status { margin: 6px 0 18px; font-size: 13px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.status.done::before { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.reader { margin-top: 26px; font: var(--size)/1.72 var(--read); }
.reader p { margin: 0 0 1.15em; animation: rise .35s ease both; }
.reader p.swap { animation: fade .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes fade { from { opacity: .35; } }
.reader.sans { font-family: var(--ui); line-height: 1.7; }
.reader p.pend { color: var(--ink-3); }

.reader .sw { border-radius: 4px; }
.reader .hd { cursor: pointer; }
.reader.show-changes .sw { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); color: inherit; }
.reader.show-changes .hd { text-decoration: underline dotted color-mix(in srgb, var(--warn) 80%, transparent); text-underline-offset: 4px; text-decoration-thickness: 1.5px; }
.reader .sw, .reader .hd { cursor: pointer; transition: background .15s; }
.reader .hd:hover, .reader .sw:hover { background: color-mix(in srgb, var(--warn) 16%, transparent); }

/* voices */
.reader.voice p { white-space: pre-line; }
.reader.voice.poetic p, .reader.voice.greentext p { text-align: left; }
.reader.voice.poetic { font-style: italic; }
.reader .gt { display: block; color: #4a8f2d; font: .88em/1.65 ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; }
:root[data-theme="dark"] .reader .gt { color: #8fc46a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .reader .gt { color: #8fc46a; } }
.reader.voice.greentext { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px 8px; }

/* ---------- dock ---------- */
.dock { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 15; width: min(760px, calc(100vw - 24px));
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); padding: 10px 12px 12px; }
.dock-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.blurb { flex: 1; color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--accent-soft); flex: none; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.lens { position: relative; display: flex; border-radius: 12px; background: var(--accent-soft); padding: 3px; overflow-x: auto; scrollbar-width: none; }
.lens::-webkit-scrollbar { display: none; }
.lens button { position: relative; z-index: 1; flex: 1 0 auto; min-width: 38px; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); transition: color .2s; white-space: nowrap; }
.lens button.on { color: var(--accent-ink); }
.lens button:hover:not(.on) { color: var(--ink); }
.thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 9px; background: var(--accent);
  transition: transform .28s cubic-bezier(.3, 1.2, .5, 1), width .28s cubic-bezier(.3, 1.2, .5, 1); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .28); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(380px, 100vw); background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); transform: translateX(105%); transition: transform .3s cubic-bezier(.3, .9, .3, 1); display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.pane { padding: 18px 18px 40px; overflow-y: auto; }
.pane h3 { margin: 22px 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.pane h3:first-child { margin-top: 0; }
.pane label { display: block; margin: 14px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.pane input[type="text"], .pane input[type="password"], .pane select { display: block; width: 100%; margin-top: 6px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 400; color: var(--ink); }
.pane input[type="range"] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
.muted { color: var(--ink-3); font-size: 13px; font-weight: 400; }
.row { display: flex; gap: 8px; margin-top: 14px; }
.btn { border: 0; border-radius: 10px; padding: 8px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: var(--accent-soft); color: var(--ink); }
.words { list-style: none; margin: 0; padding: 0; }
.words li { display: flex; gap: 10px; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.words b { font-weight: 650; }
.words i { color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.words .def { display: block; color: var(--ink-2); font-size: 13px; margin-top: 3px; line-height: 1.4; }
.words button { align-self: flex-start; border: 0; background: transparent; color: var(--ink-3); font-size: 18px; line-height: 1; }
.words button:hover { color: var(--ink); }

/* ---------- tooltip + toast ---------- */
.tip { position: fixed; z-index: 40; max-width: 290px; padding: 11px 13px; border-radius: 12px; background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow); font-size: 13px; line-height: 1.4; pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; }
.tip.on { opacity: 1; transform: none; }
.tip b { font-size: 15px; }
.tip .now { color: color-mix(in srgb, var(--accent) 60%, var(--bg)); margin: 2px 0; }
.tip .hint { opacity: .6; font-size: 11.5px; margin-top: 6px; }
.toast { position: fixed; z-index: 50; left: 50%; top: 74px; transform: translate(-50%, -12px); padding: 9px 16px; border-radius: 999px; background: var(--ink);
  color: var(--bg); font-size: 13px; font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b3261e; color: #fff; }

@media (max-width: 720px) {
  .name { display: none; }
  .top { gap: 8px; padding: 10px 12px; }
  .blurb { display: none; }
  main { padding: 0 16px 170px; }
  #hero { margin-top: 8vh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
