:root {
  --paper: #f3eee4;
  --paper-2: #ece5d8;
  --sheet: #fbf8f1;
  --ink: #1f1a14;
  --ink-2: #574d40;
  --ink-3: #847a6b;
  --ink-4: #b1a796;
  --rule: #ddd3c2;
  --rule-strong: #2a241c;
  --voice: #5b44d4;
  --voice-ink: #ffffff;
  --voice-wash: #ebe5fb;
  --voice-soft: #c9bdf5;
  --danger: #a1341c;
  --danger-wash: #f7e3dc;
  --ok: #3f6b45;
  --focus: #5b44d4;
  --shadow-sheet: 0 1px 2px rgb(60 44 20 / 0.06), 0 8px 24px -8px rgb(60 44 20 / 0.14);
  --shadow-float: 0 2px 4px rgb(40 30 15 / 0.08), 0 16px 40px -12px rgb(40 30 15 / 0.28);

  --ui: "Geist", ui-sans-serif, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --book: "Noto Naskh Arabic", "Source Serif 4", serif;
  --book-latin: "Source Serif 4", "Noto Naskh Arabic", serif;

  --r-sm: 6px;
  --r: 10px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17130f;
    --paper-2: #1e1913;
    --sheet: #221c16;
    --ink: #efe6d6;
    --ink-2: #c7b9a3;
    --ink-3: #978a76;
    --ink-4: #665c4e;
    --rule: #3a3128;
    --rule-strong: #d9ccb6;
    --voice: #a99bff;
    --voice-ink: #17130f;
    --voice-wash: #2c2545;
    --voice-soft: #4c3f8a;
    --danger: #f08a6c;
    --danger-wash: #3a2018;
    --ok: #93c79a;
    --focus: #a99bff;
    --shadow-sheet: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 30px -10px rgb(0 0 0 / 0.6);
    --shadow-float: 0 2px 6px rgb(0 0 0 / 0.4), 0 18px 44px -12px rgb(0 0 0 / 0.7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01";
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--ink-4); }
a:hover { text-decoration-color: var(--ink); }
::selection { background: var(--voice-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--ink-4) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 10px; border: 3px solid var(--paper); }
[hidden] { display: none !important; }
svg.lucide { width: 16px; height: 16px; stroke-width: 1.5; flex: none; }

.view { min-height: 100%; }

/* ---------- shared ---------- */

.double-rule {
  height: 6px;
  border-top: 3px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
  background: var(--sheet);
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--ink-4); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--paper-2); color: var(--ink); }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
.btn.danger { color: var(--danger); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  border: 0;
  background: transparent;
  color: var(--ink-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; pointer-events: none; }
.icon-btn svg.lucide { width: 18px; height: 18px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 99px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.chip:hover { color: var(--ink); border-color: var(--ink-4); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip svg.lucide { width: 14px; height: 14px; }

.appbar {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.appbar-end { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; letter-spacing: -0.01em; }
.brand span { font-weight: 300; color: var(--ink-2); }
.brand .mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background:
    linear-gradient(var(--paper), var(--paper)) 5px 6px / 12px 1.5px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 5px 9px / 12px 1px no-repeat,
    linear-gradient(var(--voice), var(--voice)) 6px 13px / 2px 4px no-repeat,
    linear-gradient(var(--voice), var(--voice)) 10px 12px / 2px 6px no-repeat,
    linear-gradient(var(--voice), var(--voice)) 14px 14px / 2px 3px no-repeat,
    var(--ink);
}

.account { position: relative; }
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 99px;
  background: var(--sheet);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.account-btn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.account-btn.low .dot { background: var(--danger); }
.account-btn small { color: var(--ink-3); font-size: 12px; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: var(--shadow-float);
  padding: 6px;
  z-index: 30;
}
.menu .menu-info { padding: 8px 10px 10px; border-bottom: 1px solid var(--rule); margin-bottom: 6px; font-size: 12.5px; color: var(--ink-2); display: grid; gap: 2px; }
.menu .menu-info b { font-weight: 500; color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }
.menu a, .menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 0;
  background: none;
  text-decoration: none;
  font-size: 13px;
  text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--paper-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: var(--r);
  box-shadow: var(--shadow-float);
  font-size: 13px;
  z-index: 50;
  animation: rise 0.25s var(--ease);
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }

.hint { margin: -2px 0 0; font-size: 12px; color: var(--ink-3); line-height: 1.45; }

/* ---------- connect ---------- */

.connect { display: grid; place-items: center; padding: 48px 24px; }
.connect-grid {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: clamp(32px, 7vw, 96px);
  align-items: center;
}
.connect-form .double-rule { width: 56px; margin-bottom: 28px; }
.wordmark { margin: 0; font-size: 40px; line-height: 1.05; font-weight: 400; letter-spacing: -0.03em; }
.wordmark span { font-weight: 300; color: var(--ink-2); }
.lede { margin: 12px 0 28px; font-size: 16px; line-height: 1.55; color: var(--ink-2); font-weight: 300; max-width: 38ch; }
.field-label { display: block; font-size: 12.5px; font-weight: 500; margin-bottom: 6px; }
.key-field {
  display: flex;
  align-items: center;
  border: 1px solid var(--rule);
  background: var(--sheet);
  border-radius: var(--r-sm);
  padding-right: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.key-field:focus-within { border-color: var(--ink-3); box-shadow: 0 0 0 3px var(--voice-wash); }
.key-field.invalid { border-color: var(--danger); }
.key-field input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 0;
  background: none;
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
.key-field input::placeholder { color: var(--ink-3); font-family: var(--ui); }
.field-error { margin: 8px 0 0; color: var(--danger); font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; margin: 14px 0 18px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--ink); width: 15px; height: 15px; }
.connect .btn.primary { height: 44px; font-size: 14px; }
.fineprint { margin: 22px 0 0; font-size: 12px; line-height: 1.6; color: var(--ink-3); max-width: 46ch; }

.specimen { margin: 0; }
.sheet { background: var(--sheet); border-radius: 4px; box-shadow: var(--shadow-sheet); }
.specimen-sheet { padding: 28px 34px 22px; font-family: var(--book); transform: rotate(-0.6deg); max-width: 520px; margin-inline: auto; }
.spec-running { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; color: var(--ink-3); margin-bottom: 6px; }
.spec-running em, .spec-folio em, .spec-pause { font: 400 11.5px/1 var(--ui); color: var(--ink-3); font-style: normal; letter-spacing: 0.01em; }
.spec-heading { display: block; margin: 22px 0 2px; font-size: 22px; font-weight: 600; line-height: 1.6; }
.spec-pause { display: inline-block; color: var(--voice); margin-bottom: 8px; }
.spec-body { margin: 0; font-size: 18px; line-height: 2.05; }
.spec-body mark {
  background: var(--voice-wash);
  color: inherit;
  border-radius: 3px;
  box-shadow: inset -2px 0 0 var(--voice);
  padding: 2px 4px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.spec-body s { color: var(--ink-4); text-decoration-color: var(--danger); }
.spec-notes { margin-top: 18px; font-size: 13.5px; color: var(--ink-2); line-height: 1.9; }
.spec-notes hr { width: 38%; margin: 0 0 8px auto; border: 0; border-top: 1px solid var(--ink-3); }
.spec-notes p { margin: 0; }
.spec-spoken { color: var(--voice); font-size: 13px; }
.spec-folio { display: flex; justify-content: space-between; align-items: baseline; margin-top: 18px; font: 500 13px var(--ui); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.specimen figcaption { margin: 22px auto 0; max-width: 52ch; font-size: 12.5px; color: var(--ink-3); line-height: 1.55; text-align: center; }

.menu .key-info code { font: 400 12.5px var(--mono); color: var(--ink); }
.menu .key-info span:last-child { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ---------- library ---------- */

.library-main { width: min(960px, 100% - 40px); margin: 0 auto; padding: 48px 0 80px; }
.library-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.library-head h1 { margin: 0; font-size: 30px; font-weight: 300; letter-spacing: -0.025em; }
.dropzone {
  border: 1px dashed var(--ink-4);
  border-radius: var(--r);
  padding: 36px 24px;
  text-align: center;
  color: var(--ink-2);
  transition: background 0.2s, border-color 0.2s;
  cursor: pointer;
}
.dropzone:hover { background: var(--paper-2); }
.dropzone.over { border-color: var(--voice); background: var(--voice-wash); border-style: solid; }
.dz-icon svg.lucide, svg.lucide.dz-icon { width: 26px; height: 26px; stroke-width: 1.25; color: var(--ink-3); }
.dz-title { margin: 10px 0 4px; font-size: 16px; color: var(--ink); }
.dz-sub { margin: 0 auto; max-width: 56ch; font-size: 13px; color: var(--ink-3); }
.library.empty .dropzone { padding: 96px 24px; }

.book-list:empty { display: none; }
.library-foot { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; font-size: 12.5px; color: var(--ink-3); }
.library-foot p { margin: 0; }
.book-list { list-style: none; margin: 32px 0 0; padding: 0; border-top: 1px solid var(--rule); }
.book {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 16px 8px;
  border-bottom: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s;
}
.book:hover { background: var(--paper-2); }
.book-thumb { width: 52px; aspect-ratio: 0.68; object-fit: cover; border-radius: 2px; background: var(--sheet); box-shadow: var(--shadow-sheet); }
.book-name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { margin-top: 3px; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.book-actions { display: flex; gap: 4px; align-items: center; }
.book-actions .confirm { font-size: 12.5px; color: var(--danger); display: flex; align-items: center; gap: 6px; }

/* ---------- workspace ---------- */

.workspace { height: 100%; display: grid; grid-template-rows: 60px minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.workspace .appbar { gap: 12px; padding-left: 8px; }
#backBtn { padding: 0 10px 0 8px; }
.book-title { min-width: 0; display: flex; align-items: center; gap: 16px; height: 24px; padding-left: 16px; border-left: 1px solid var(--rule); }
.book-title h1 { margin: 0; font-size: 15px; line-height: 24px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.analysis { display: inline-flex; align-items: center; gap: 6px; line-height: 24px; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.analysis svg.lucide { width: 14px; height: 14px; color: var(--ok); }
.analysis .bar { width: 72px; height: 3px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.analysis .bar i { display: block; height: 100%; background: var(--ink-2); transition: width 0.4s var(--ease); }
.analysis button { border: 0; background: none; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--ink-4); padding: 0; font-size: 12.5px; }

.work-grid { min-height: 0; display: grid; grid-template-columns: 196px minmax(0, 1fr) 320px; }
.rail, .reader, .panel { min-height: 0; overflow: auto; }

.rail { border-right: 1px solid var(--rule); padding: 10px 8px 24px; }
.rail-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 16px;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 6px 14px 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  text-align: left;
  color: var(--ink-2);
}
.rail-item:hover { background: var(--paper-2); }
.rail-item.current { background: var(--sheet); color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); }
.rail-item.speaking .rail-num { color: var(--voice); }
.rail-thumb { width: 34px; aspect-ratio: 0.68; border-radius: 2px; background: var(--sheet); box-shadow: 0 0 0 1px var(--rule); object-fit: cover; }
.rail-num { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rail-sub { font-size: 11px; color: var(--ink-3); }
.rail-state { width: 16px; height: 16px; display: grid; place-items: center; justify-self: end; }
.rail-state svg.lucide { width: 13px; height: 13px; }
.rail-state.done { color: var(--ok); }
.rail-state.err { color: var(--danger); }
.rail-state.busy::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink-4); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
.rail-state.idle::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-4); }
@keyframes spin { to { transform: rotate(360deg); } }

.reader { padding: 28px clamp(20px, 4vw, 56px) 120px; scroll-behavior: smooth; outline: none; }
.reader-hint { max-width: 760px; margin: 0 auto 28px; display: flex; align-items: flex-start; gap: 12px; padding: 12px 12px 12px 16px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--sheet); color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.reader-hint p { margin: 0; flex: 1; }
.reader-hint b { color: var(--ink); font-weight: 500; }
.reader-hint > svg.lucide { margin-top: 2px; color: var(--voice); }
.reader-hint .icon-btn { width: 28px; height: 28px; margin: -4px -4px -4px 0; }
.w { cursor: pointer; }
.blk:not(.off) .w:hover:not(.on) { background: var(--voice-wash); }
.blk.off .w { cursor: default; }
.page { max-width: 760px; margin: 0 auto 56px; position: relative; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.page-head .double-rule { flex: 1; }
.page-label { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.page-label b { color: var(--ink); font-weight: 500; }
.page-tools { display: flex; gap: 2px; }
.page-tools .icon-btn { width: 30px; height: 30px; }
.page-tools .icon-btn svg.lucide { width: 16px; height: 16px; }
.page-tools .icon-btn.on { background: var(--paper-2); color: var(--ink); }
.page-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; }
.page.with-scan .page-body { grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr); }
.page-scan { position: sticky; top: 0; align-self: start; }
.page-scan img { width: 100%; border-radius: 3px; box-shadow: var(--shadow-sheet); background: #fff; display: block; }

.page-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: -6px 0 14px; font-size: 11.5px; color: var(--ink-3); }
.meta-item { max-width: 100%; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; color: inherit; font-size: inherit; }
.meta-item:hover { color: var(--ink); }
.meta-item q { font-family: var(--book); font-size: 12.5px; quotes: none; color: var(--ink-2); max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-item .tag { text-decoration: underline; text-decoration-color: var(--ink-4); text-underline-offset: 3px; }
.meta-item.read .tag { color: var(--voice); text-decoration-color: var(--voice-soft); }

.blocks { display: grid; gap: 2px; }
.blk {
  position: relative;
  border-radius: 4px;
  padding: 4px 10px;
  margin: 0 -10px;
  transition: background 0.35s var(--ease), box-shadow 0.35s var(--ease), opacity 0.2s;
}
.blk:hover { background: color-mix(in oklab, var(--paper-2) 70%, transparent); }
.blk.speaking { background: var(--voice-wash); box-shadow: inset -2px 0 0 var(--voice); }
.blk[dir="ltr"].speaking { box-shadow: inset 2px 0 0 var(--voice); }
.w { border-radius: 3px; transition: background 0.12s, color 0.12s; }
.w.on { background: var(--voice); color: var(--voice-ink); box-shadow: 0 0 0 2px var(--voice); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.blk.off { opacity: 0.42; }
.blk.off:hover { opacity: 0.75; }
.blk-text { font-family: var(--book); font-size: 19px; line-height: 2.05; white-space: pre-wrap; overflow-wrap: anywhere; outline: none; }
.blk[dir="ltr"] .blk-text { font-family: var(--book-latin); font-size: 18px; line-height: 1.7; }
.blk-text[contenteditable="true"] { background: var(--sheet); box-shadow: 0 0 0 1px var(--ink-4); border-radius: 4px; padding: 2px 6px; margin: 0 -6px; cursor: text; }
.blk.heading { margin-top: 18px; }
.blk.heading:first-child { margin-top: 0; }
.blk.heading .blk-text { font-weight: 600; line-height: 1.7; }
.blk.h1 .blk-text { font-size: 28px; }
.blk.h2 .blk-text { font-size: 24px; }
.blk.h3 .blk-text { font-size: 20.5px; }
.blk.quote .blk-text, .blk.verse .blk-text { padding-inline-start: 18px; border-inline-start: 1px solid var(--ink-4); color: var(--ink-2); }
.blk.verse .blk-text { text-align: center; border: 0; padding: 0; }
.blk.list_item .blk-text { padding-inline-start: 18px; position: relative; }
.blk.list_item .blk-text::before { content: ""; position: absolute; inset-inline-start: 4px; top: 0.95em; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); }
.blk.caption .blk-text { font-size: 15px; color: var(--ink-2); }

.blk-tag { display: flex; align-items: center; gap: 6px; font: 500 11px/1 var(--ui); color: var(--ink-3); margin: 6px 0 2px; direction: ltr; }
.blk[dir="rtl"] .blk-tag { justify-content: flex-end; }
.blk-tag svg.lucide { width: 13px; height: 13px; }
.blk-tag .pause { color: var(--voice); font-weight: 400; }
.blk.explained { background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule); margin: 8px -10px; padding: 8px 12px 10px; }
.blk.explained.speaking { background: var(--voice-wash); box-shadow: inset 0 0 0 1px var(--voice-soft); }
.blk.explained .blk-text { font-size: 17px; color: var(--ink-2); line-height: 1.95; }
.blk-printed { font: 400 12px/1.6 var(--ui); color: var(--ink-3); margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--rule); direction: ltr; }
.blk-printed span { font-family: var(--book); font-size: 13.5px; color: var(--ink-2); }

.blk-tools {
  position: absolute;
  top: 2px;
  right: calc(100% + 4px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.blk:hover .blk-tools, .blk:focus-within .blk-tools { opacity: 1; pointer-events: auto; }
.blk-tools .icon-btn { width: 28px; height: 28px; background: var(--paper); }
.blk-tools .icon-btn:hover { background: var(--paper-2); }
.blk-tools .icon-btn svg.lucide { width: 15px; height: 15px; }
.blk-tools .icon-btn.play { color: var(--voice); }
.blk-edit-bar { display: flex; gap: 6px; margin: 8px 0 4px; direction: ltr; }
.blk[dir="rtl"] .blk-edit-bar { justify-content: flex-end; }

.notes { margin-top: 22px; padding-top: 4px; }
.notes-rule { width: 34%; border: 0; border-top: 1px solid var(--ink-3); margin: 0 0 6px; margin-inline-start: auto; }
.notes[dir="ltr"] .notes-rule { margin-inline-start: 0; }
.notes .blk-text { font-size: 15px; line-height: 1.9; color: var(--ink-2); }
.notes .blk[dir="ltr"] .blk-text { font-size: 14.5px; }
.notes .num { font-weight: 600; color: var(--ink); }

.page-skeleton { display: grid; gap: 14px; padding-top: 6px; }
.page-skeleton i { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--paper-2), var(--rule), var(--paper-2)); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }
.page-skeleton i:nth-child(3n) { width: 72%; margin-inline-start: auto; }
.page-skeleton p { margin: 0 0 4px; font-size: 12.5px; color: var(--ink-3); }
@keyframes shimmer { to { background-position: -200% 0; } }
.page-error { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--danger-wash); color: var(--danger); font-size: 13px; }
.page-error .btn { margin-left: auto; }
.page-empty { font-size: 13px; color: var(--ink-3); }

/* ---------- panel ---------- */

.panel { border-left: 1px solid var(--rule); padding: 4px 20px 32px; }
.panel-sec { padding: 18px 0; border-bottom: 1px solid var(--rule); display: grid; gap: 12px; }
.panel-sec:last-child { border-bottom: 0; }
.panel-sec h2, .panel-sec summary { margin: 0; font-size: 12px; font-weight: 500; color: var(--ink-3); letter-spacing: 0.02em; }
.panel-sec summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.panel-sec summary::-webkit-details-marker { display: none; }
.panel-sec summary::after { content: "+"; font-size: 16px; font-weight: 300; }
.panel-sec[open] summary::after { content: "–"; }
.advanced[open] { gap: 12px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-size: 13.5px; }
.switch input { appearance: none; order: 2; flex: none; width: 32px; height: 18px; border-radius: 99px; background: var(--rule); position: relative; transition: background 0.2s var(--ease); cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--sheet); box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.2s var(--ease); }
.switch input:checked { background: var(--ink); }
.switch input:checked::after { transform: translateX(14px); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; gap: 3px; background: var(--paper-2); border-radius: var(--r-sm); margin: -4px 0 2px; }
.segmented button { border: 0; background: none; border-radius: 4px; padding: 6px 4px; font-size: 12px; color: var(--ink-2); }
.segmented button.on { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); font-weight: 500; }
.segmented.disabled { opacity: 0.45; pointer-events: none; }

.slider { display: grid; gap: 6px; font-size: 13.5px; }
.slider > span { display: flex; justify-content: space-between; }
.slider output { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12.5px; }
input[type="range"] { appearance: none; width: 100%; height: 18px; background: none; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(var(--ink-2), var(--ink-2)) 0 / var(--fill, 50%) 100% no-repeat, var(--rule); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--rule); }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--ink-2); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--sheet); border: 1.5px solid var(--ink); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--sheet); border: 1.5px solid var(--ink); }

.field-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.field-inline input, .field-inline select { width: 120px; height: 32px; border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--r-sm); padding: 0 8px; font-variant-numeric: tabular-nums; }
.field-inline select { width: 180px; }

.voice-current {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 16px;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--sheet);
  text-align: left;
}
.voice-current:hover { border-color: var(--ink-4); }
.voice-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--paper-2); font: 500 14px var(--book); color: var(--ink); }
.voice-name { font-size: 14px; font-weight: 500; }
.voice-name span { font-family: var(--book); font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.voice-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-picker { border: 1px solid var(--rule); border-radius: var(--r); background: var(--sheet); padding: 10px; display: grid; gap: 8px; margin-top: -4px; }
.vp-filters { display: flex; gap: 6px; }
.vp-search { height: 32px; border: 1px solid var(--rule); background: var(--paper); border-radius: var(--r-sm); padding: 0 10px; font-size: 13px; outline: none; }
.vp-search:focus { border-color: var(--ink-3); }
.vp-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; display: grid; gap: 2px; }
.vp-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) 28px; gap: 8px; align-items: center; padding: 6px; border-radius: var(--r-sm); cursor: pointer; }
.vp-item:hover { background: var(--paper-2); }
.vp-item.selected { background: var(--voice-wash); }
.vp-item .voice-avatar { width: 28px; height: 28px; font-size: 12px; }
.vp-item .voice-name { font-size: 13px; }
.vp-item .icon-btn { width: 28px; height: 28px; }
.vp-item .icon-btn svg.lucide { width: 14px; height: 14px; }
.vp-empty { font-size: 12.5px; color: var(--ink-3); padding: 8px; }

.estimate { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
.estimate dt { color: var(--ink-2); }
.estimate dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.estimate dd.big { font-size: 15px; font-weight: 500; }
.estimate .warn { color: var(--danger); }
.confirm-box { border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--r); padding: 12px; display: grid; gap: 10px; }
.confirm-box p { margin: 0; font-size: 13px; line-height: 1.5; }
.confirm-box div { display: flex; gap: 6px; }
.gen-progress { height: 3px; border-radius: 3px; background: var(--rule); overflow: hidden; margin-top: -4px; }
.gen-progress div { height: 100%; width: 0; background: var(--voice); transition: width 0.4s var(--ease); }
.export-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 -10px; }

/* ---------- player ---------- */

.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 12px 20px 14px;
  border-top: 1px solid var(--rule);
  background: var(--sheet);
}
.player-controls { display: flex; align-items: center; gap: 6px; }
.play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--voice);
  color: var(--voice-ink);
  box-shadow: 0 2px 5px -1px rgb(20 14 6 / 0.25);
  transition: transform 0.15s var(--ease), filter 0.15s;
}
.play-btn:hover { filter: brightness(1.08); }
.play-btn:active { transform: scale(0.96); }
.play-btn svg.lucide { width: 20px; height: 20px; fill: currentColor; stroke-width: 1; }
.play-btn.loading svg.lucide { fill: none; stroke-width: 2; animation: spin 1s linear infinite; }
.play-btn:disabled { opacity: 0.4; pointer-events: none; }
.player-main { min-width: 0; display: grid; gap: 8px; }
.player-line { display: flex; align-items: baseline; gap: 16px; }
.now { flex: 1; min-width: 0; font-family: var(--book); font-size: 14.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now.idle { font-family: var(--ui); font-size: 13px; color: var(--ink-3); }
.time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.timeline { position: relative; height: 16px; cursor: pointer; outline-offset: 4px; }
.timeline::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 3px; border-radius: 3px; background: var(--rule); }
.tl-ready, .tl-played { position: absolute; left: 0; top: 7px; height: 3px; border-radius: 3px; width: 0; }
.tl-ready { background: var(--voice-soft); }
.tl-played { background: var(--voice); }
.tl-head { position: absolute; top: 3px; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; background: var(--voice); box-shadow: 0 0 0 3px var(--sheet); left: 0; opacity: 0; transition: opacity 0.2s; }
.timeline:hover .tl-head, .player.active .tl-head { opacity: 1; }
.player-end { display: flex; gap: 6px; }

/* ---------- responsive ---------- */

.panel-toggle { display: none; }

@media (max-width: 1180px) {
  .work-grid { grid-template-columns: 168px minmax(0, 1fr) 300px; }
  .page.with-scan .page-body { grid-template-columns: minmax(0, 1fr); }
  .page-scan { position: static; max-width: 340px; }
}
@media (max-width: 960px) {
  .connect-grid { grid-template-columns: minmax(0, 1fr); max-width: 520px; }
  .specimen-sheet { transform: none; }
  .work-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .rail { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--rule); padding: 8px 12px; }
  .rail-item { grid-template-columns: auto; width: auto; justify-items: center; padding: 6px; gap: 2px; }
  .rail-item .rail-thumb, .rail-item .rail-sub, .rail-item .rail-state { display: none; }
  .panel { position: fixed; inset: 60px 0 auto auto; width: min(360px, 100vw); bottom: 84px; background: var(--paper); z-index: 20; box-shadow: var(--shadow-float); transform: translateX(100%); transition: transform 0.3s var(--ease); }
  .panel.open { transform: none; }
  .panel-toggle { display: inline-grid; }
  .blk-tools { position: static; flex-direction: row; opacity: 1; pointer-events: auto; margin-bottom: 2px; justify-content: flex-end; display: none; }
  .blk.show-tools .blk-tools { display: flex; }
}
@media (max-width: 640px) {
  .connect { padding: 32px 16px; place-items: start center; }
  .wordmark { font-size: 32px; }
  .library-main { width: calc(100% - 32px); padding-top: 28px; }
  .book { grid-template-columns: 40px minmax(0, 1fr); }
  .book-thumb { width: 40px; }
  .book-actions { grid-column: 2; }
  .appbar { padding: 0 12px; gap: 8px; }
  .book-title .analysis { display: none; }
  .account-btn small { display: none; }
  #backBtn { padding: 0 8px; font-size: 0; gap: 0; }
  #backBtn svg.lucide { width: 18px; height: 18px; }
  .book-title h1 { max-width: none; }
  .page-meta .meta-item q { max-width: 16ch; }
  .reader { padding: 20px 16px 120px; }
  .blk-text { font-size: 18px; }
  .player { grid-template-columns: auto minmax(0, 1fr); gap: 14px; padding: 10px 12px 12px; }
  .player-end { display: none; }
  #prevBtn, #nextBtn { display: none; }
}
