:root {
  color-scheme: dark;
  --bg: #0b0c0d; --surface: #141617; --surface-2: #1b1e20; --surface-3: #25292c;
  --border: #232729; --border-strong: #343a3e;
  --fg: #e9edef; --fg-2: #b8c1c6; --muted: #808b91;
  --accent: #a99cf0; --accent-soft: rgba(169, 156, 240, .14); --on-accent: #120e26;
  --primary: #e9edef; --on-primary: #0b0c0d;
  --ok: #6cc08b; --warn: #d8b25a; --err: #e47f76;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r-card: 16px; --r-box: 20px; --r-btn: 12px;
  --fast: .12s; --med: .18s; --nav-w: 84px; --col-w: 460px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff; --surface: #f4f6f7; --surface-2: #eceff1; --surface-3: #dfe4e7;
  --border: #e0e5e8; --border-strong: #ccd3d7;
  --fg: #0f1315; --fg-2: #38434a; --muted: #5f6b72;
  --accent: #5846c2; --accent-soft: rgba(88, 70, 194, .12); --on-accent: #ffffff;
  --primary: #0f1315; --on-primary: #ffffff;
  --ok: #2c8650; --warn: #94680f; --err: #c0433a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--mono); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; padding: 8px 12px; background: var(--primary); color: var(--on-primary); border-radius: var(--r-btn); z-index: 10; }
.skip:focus { left: 8px; }

.app { min-height: 100%; padding-left: var(--nav-w); }
main { max-width: var(--col-w); margin: 0 auto; padding: 48px 16px 40px; }

/* nav: rail on desktop, bottom bar on phones */
.nav { position: fixed; inset: 0 auto 0 0; width: var(--nav-w); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; border-right: 1px solid var(--border); background: var(--bg); }
.logo { display: grid; place-items: center; height: 48px; margin-bottom: 12px; color: var(--fg); }
.item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 10px 0; border-radius: 14px; color: var(--muted); text-decoration: none; font-size: 12px; transition: background var(--fast), color var(--fast); }
.item:hover { color: var(--fg); }
.item[aria-current="page"] { background: var(--surface-2); color: var(--fg); }
@media (max-width: 720px) {
  .app { padding-left: 0; padding-bottom: 76px; }
  main { padding-top: 32px; }
  .nav { inset: auto 0 0 0; width: auto; flex-direction: row; justify-content: space-around; padding: 8px; border-right: 0; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); z-index: 5; }
  .logo { display: none; }
  .item { flex: 1; max-width: 110px; }
}

.brand { text-align: center; margin-bottom: 28px; }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.native { color: var(--muted); font-size: 16px; font-weight: 400; margin-left: 6px; }
.tag { color: var(--fg-2); margin: 8px 0 0; }
h2 { margin: 0 0 12px; font-size: 13px; font-weight: 500; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; margin-bottom: 12px; }
label { display: block; margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; margin-bottom: 12px; }
.row:last-child { margin-bottom: 0; }

input, select, textarea { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--surface-2); color: var(--fg); font: inherit; }
textarea { padding: 10px 12px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="range"] { padding: 0; min-height: 28px; accent-color: var(--accent); background: transparent; border: 0; }
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { height: 44px; padding: 0 16px; border: 1px solid var(--primary); border-radius: var(--r-btn); background: var(--primary); color: var(--on-primary); font: 500 13px var(--mono); cursor: pointer; white-space: nowrap; transition: opacity var(--fast), background var(--fast); }
.btn:hover:not(:disabled) { opacity: .88; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--border-strong); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); opacity: 1; }
.btn:disabled { opacity: .4; cursor: default; }

details { margin-top: 4px; color: var(--muted); font-size: 13px; }
summary { cursor: pointer; padding: 6px 0; }
details textarea { margin-top: 8px; }
#status { margin: 10px 0 0; min-height: 1.45em; color: var(--muted); font-size: 12px; }
#status.err { color: var(--err); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.engine { display: flex; align-items: center; gap: 10px; margin: 0; padding: 12px; border-radius: var(--r-btn); color: var(--fg); font-size: 14px; cursor: pointer; }
.engine:hover { background: var(--surface-2); }
.engine .state { margin-left: auto; font-size: 12px; color: var(--ok); }
.engine.off { opacity: .55; cursor: default; }
.engine.off .state { color: var(--muted); }
.ctl { margin-bottom: 14px; }
.ctl:last-child { margin-bottom: 0; }
.ctl output { float: right; }

progress { display: block; width: 100%; height: 6px; margin-top: 14px; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-3); accent-color: var(--accent); }
progress::-webkit-progress-bar { background: var(--surface-3); }
progress::-webkit-progress-value { background: var(--accent); transition: width var(--med); }
progress::-moz-progress-bar { background: var(--accent); }
.prose p { margin: 0 0 12px; color: var(--fg-2); }
.prose p:last-child { margin: 0; }
.prose b { color: var(--fg); font-weight: 500; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* reader */
main { max-width: var(--main-w, var(--col-w)); }
.toolbar { display: flex; justify-content: flex-end; margin: 4px 0 8px; }
.aa { position: relative; margin: 0; }
.aa summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-btn); color: var(--fg); font-weight: 500; }
.aa summary::-webkit-details-marker { display: none; }
.aa[open] summary { background: var(--surface-2); }
.aa .panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 4; width: 260px; padding: 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-card); box-shadow: 0 10px 32px rgba(0, 0, 0, .35); }
.aa .panel label { margin-top: 10px; }
.aa .panel label:first-child { margin-top: 0; }
.aa .panel output { float: right; }

.reader { --r-font: "Source Serif 4", Georgia, serif; --r-size: 19px; --r-lh: 1.75; font-family: var(--r-font); font-size: var(--r-size); line-height: var(--r-lh); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 28px 24px; margin-bottom: 24px; color: var(--fg); }
.reader[data-font="sans"] { --r-font: "Inter", system-ui, sans-serif; }
.reader[data-font="mono"] { --r-font: var(--mono); }
.reader[data-tone="sepia"] { background: #f4ecd8; color: #3b2f20; border-color: #e2d6b8; --accent: #8a5a1c; --accent-soft: rgba(138, 90, 28, .16); --muted: #7a6a52; }
.reader h2 { font: 600 1.15em var(--r-font); color: inherit; margin: 0 0 1.2em; text-align: center; }
.reader p { margin: 0 0 1.1em; padding: 2px 10px; margin-left: -10px; margin-right: -10px; border-left: 3px solid transparent; border-radius: 8px; transition: background var(--med), border-color var(--med); }
.reader p[data-i] { cursor: pointer; scroll-margin-top: 30vh; }
.reader p[data-i]:hover { background: var(--accent-soft); }
.reader p.now { background: var(--accent-soft); border-left-color: var(--accent); }
.reader p.resume { border-left-color: var(--muted); }
.reader p.empty { color: var(--muted); font: 14px var(--mono); text-align: center; margin: 0; cursor: default; }

.bar { position: fixed; left: var(--nav-w); right: 0; bottom: 0; z-index: 4; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.bar progress { margin: 0; height: 3px; border-radius: 0; }
.bar-row { display: flex; align-items: center; gap: 8px; max-width: var(--main-w, var(--col-w)); margin: 0 auto; padding: 10px 16px; }
.bar .pos { margin-left: auto; color: var(--muted); font-size: 12px; }
.icon { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid transparent; border-radius: var(--r-btn); background: transparent; color: var(--fg-2); cursor: pointer; }
.icon:hover { background: var(--surface-2); color: var(--fg); }
.icon[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
#play { min-width: 132px; }
@media (max-width: 720px) {
  .bar { left: 0; bottom: 72px; }
  main { padding-bottom: 150px; }
  .reader { padding: 22px 18px; }
}

/* welcome dialog */
dialog { max-width: min(420px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--border-strong); border-radius: var(--r-box); background: var(--surface); color: var(--fg); font: inherit; box-shadow: 0 10px 32px rgba(0, 0, 0, .4); }
dialog::backdrop { background: rgba(0, 0, 0, .62); }
dialog p { margin: 0 0 20px; color: var(--fg-2); line-height: 1.55; }

.reader p.ready::after { content: ""; float: right; width: 6px; height: 6px; margin: .75em 2px 0 10px; border-radius: 50%; background: var(--accent); opacity: .6; }

.steps { margin: 0 0 12px; padding-left: 20px; color: var(--fg-2); }
.steps li { margin-bottom: 8px; }
.bm { display: inline-block; padding: 4px 10px; border: 1px dashed var(--accent); border-radius: var(--r-btn); color: var(--accent); text-decoration: none; font-weight: 500; cursor: grab; }
