:root,
html[data-track="official"] {
  --bg: #f3f1ea;
  --bg-sidebar: #e8e6de;
  --ink: #1b1d22;
  --muted: #5c5f68;
  --accent: #3e4c5e;
  --border: #d0cdc4;
  --bar: #3e4c5e;
  --danger: #8a2f2f;
  --surface: #fff;
  --mix: #fff;
  --wash: rgba(27, 29, 34, 0.05);
  --on-accent: #fff;
  --chart-grid: #d0cdc4;
  --accent-soft: #e8dfd0;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --max-read: 42rem;
  --topbar-h: 3.25rem;
  --nav-h: 3.5rem;
}

html[data-track="draft"] {
  --bg: #f8f0e2;
  --bg-sidebar: #f1e3cc;
  --ink: #2b1e14;
  --muted: #7d6248;
  --accent: #a0562c;
  --border: #e3d0b6;
  --bar: #c4783c;
  --surface: #fff;
}

html[data-mode="note"] {
  --bg: #eef3ee;
  --bg-sidebar: #e1ebe2;
  --ink: #1a221c;
  --muted: #5a6b5e;
  --accent: #3f5c46;
  --border: #c9d6cb;
  --bar: #3f5c46;
  --surface: #fff;
}

html[data-theme="noir"],
html[data-theme="noir"][data-track="official"] {
  color-scheme: dark;
  --bg: #12141a;
  --bg-sidebar: #0c0e12;
  --ink: #e8e4dc;
  --muted: #9a958c;
  --accent: #c4a882;
  --border: #2a2e36;
  --bar: #8b3a3a;
  --danger: #c45c5c;
  --surface: #1a1d24;
  --mix: #1a1d24;
  --wash: rgba(232, 228, 220, 0.07);
  --on-accent: #efe6dc;
  --chart-grid: #3a3f4a;
  --accent-soft: #2a2430;
  --beta-ok: #7eb88a;
  --beta-warn: #d4925a;
  --beta-danger: #d47a7a;
}

html[data-theme="noir"][data-track="draft"] {
  --bg: #16120f;
  --bg-sidebar: #100d0b;
  --ink: #efe6dc;
  --muted: #a89888;
  --accent: #c4783c;
  --border: #3a3028;
  --bar: #a0562c;
  --surface: #1e1914;
  --mix: #1e1914;
  --wash: rgba(239, 230, 220, 0.07);
  --on-accent: #efe6dc;
  --chart-grid: #4a3e34;
}

html[data-theme="noir"][data-mode="note"] {
  --bg: #121612;
  --bg-sidebar: #0d100d;
  --ink: #dce8dc;
  --muted: #8a9a8c;
  --accent: #6a8f72;
  --border: #2a332c;
  --bar: #3f5c46;
  --surface: #171c17;
  --mix: #171c17;
  --wash: rgba(220, 232, 220, 0.07);
  --on-accent: #dce8dc;
  --chart-grid: #3a443c;
}

/* Erzrael: same cool paper-dark language as Sarah (noir), stone instead of fire. */
html[data-theme="ember"],
html[data-theme="ember"][data-track="official"] {
  color-scheme: dark;
  --bg: #12141a;
  --bg-sidebar: #0c0e12;
  --ink: #e8e4dc;
  --muted: #9a958c;
  --accent: #c2b8a8;
  --border: #2a2e36;
  --bar: #6e6860;
  --danger: #c45c5c;
  --surface: #1a1d24;
  --mix: #1a1d24;
  --wash: rgba(232, 228, 220, 0.07);
  --on-accent: #12141a;
  --chart-grid: #3a3f4a;
  --accent-soft: #24262c;
  --beta-ok: #7eb88a;
  --beta-warn: #c2b8a8;
  --beta-danger: #d47a7a;
}

html[data-theme="ember"][data-track="draft"] {
  --bg: #151310;
  --bg-sidebar: #100e0c;
  --ink: #eee6dc;
  --muted: #a3988c;
  --accent: #c4b49a;
  --border: #342e28;
  --bar: #7a6a58;
  --surface: #1c1a16;
  --mix: #1c1a16;
  --wash: rgba(238, 230, 220, 0.07);
  --on-accent: #151310;
  --chart-grid: #423c34;
}

html[data-theme="ember"][data-mode="note"] {
  --bg: #121612;
  --bg-sidebar: #0d100d;
  --ink: #dce8dc;
  --muted: #8a9a8c;
  --accent: #6a8f72;
  --border: #2a332c;
  --bar: #3f5c46;
  --surface: #171c17;
  --mix: #171c17;
  --wash: rgba(220, 232, 220, 0.07);
  --on-accent: #dce8dc;
  --chart-grid: #3a443c;
}

/* Alice démo — jardin / pays des merveilles (lecture + Board, pas Forge). */
html[data-theme="green"],
html[data-theme="green"][data-track="official"] {
  --bg: #eef4ec;
  --bg-sidebar: #e2ebe0;
  --ink: #1a241c;
  --muted: #5a6b5e;
  --accent: #2d6b45;
  --border: #c5d4c8;
  --bar: #3a7d52;
  --danger: #8a3f3f;
  --surface: #f8fbf7;
  --mix: #f8fbf7;
  --wash: rgba(26, 36, 28, 0.05);
  --on-accent: #fff;
  --chart-grid: #c5d4c8;
  --accent-soft: #d8e8dc;
}

html[data-theme="green"][data-track="draft"] {
  --bg: #f0f4e8;
  --bg-sidebar: #e6ecd9;
  --ink: #24281a;
  --muted: #6b6f58;
  --accent: #4a7a3a;
  --border: #d0d8c0;
  --bar: #4a8c5c;
  --surface: #fafcf6;
  --mix: #fafcf6;
  --wash: rgba(36, 40, 26, 0.05);
  --on-accent: #fff;
  --chart-grid: #d0d8c0;
  --accent-soft: #e0ecd4;
}

html[data-theme="green"][data-mode="note"] {
  --bg: #e8f2ea;
  --bg-sidebar: #dce9df;
  --ink: #142018;
  --muted: #4f6b58;
  --accent: #2f6b48;
  --border: #bdd0c4;
  --bar: #3a7d52;
  --surface: #f5faf6;
  --mix: #f5faf6;
  --wash: rgba(20, 32, 24, 0.05);
  --on-accent: #fff;
  --chart-grid: #bdd0c4;
}

html[data-theme="green"] .track-btn[data-track="official"].active {
  background: var(--bar);
  color: var(--on-accent);
}

html[data-theme="noir"] .track-btn[data-track="official"].active {
  background: #8b3a3a;
  color: var(--on-accent);
}

html[data-theme="ember"] .track-btn[data-track="official"].active {
  background: var(--bar);
  color: #e8e4dc;
}

html:is([data-theme="noir"], [data-theme="ember"]) .hl-filter_word,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-filter_word,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-filter_word {
  background: color-mix(in srgb, #e8a838 28%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-passive,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-passive,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-passive {
  background: color-mix(in srgb, #c45050 28%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-weak_verb,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-weak_verb,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-weak_verb {
  background: color-mix(in srgb, #8a5cbf 28%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-repetition,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-repetition,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-repetition,
html:is([data-theme="noir"], [data-theme="ember"]) .style-rep-word.hl-repetition {
  background: color-mix(in srgb, #c4b44a 28%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-repetition_distant,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-repetition_distant,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-repetition_distant,
html:is([data-theme="noir"], [data-theme="ember"]) .style-rep-word.hl-repetition_distant {
  background: color-mix(in srgb, #4a8cc2 22%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-tell,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-tell,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-tell {
  background: color-mix(in srgb, #c45050 22%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) .hl-cliché,
html:is([data-theme="noir"], [data-theme="ember"]) .hl-cliche,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-cliché,
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-cliche,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-cliché,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-cliche {
  background: color-mix(in srgb, #d4a030 24%, var(--surface));
}
html:is([data-theme="noir"], [data-theme="ember"]) mark.hl-sensory_filter,
html:is([data-theme="noir"], [data-theme="ember"]) .style-count.hl-sensory_filter {
  background: color-mix(in srgb, #c4783c 26%, var(--surface));
}

html:is([data-theme="noir"], [data-theme="ember"]) .reader-text mark.hl-current {
  outline-color: var(--accent);
}

body,
.topbar,
.sidebar,
.context-bar,
.chapter-nav {
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg);
  height: 100dvh;
  overflow: hidden;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 3px 0 var(--bar);
}

.brand {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  cursor: pointer;
}

.brand:hover {
  filter: brightness(0.85);
}

.apps-wrap {
  position: relative;
}

.apps-list {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 30;
  min-width: 8.5rem;
  padding: 0.35rem 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.apps-list a {
  display: block;
  padding: 0.45rem 0.85rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--ink);
  text-decoration: none;
}

.apps-list a:hover,
.apps-list a:focus {
  background: var(--bg-sidebar);
  color: var(--accent);
}

.apps-list[hidden] {
  display: none !important;
}

.topbar-actions {
  margin-left: auto;
}

.context-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.35rem;
  padding: 0.3rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.8125rem;
}

.context-bar[hidden] {
  display: none !important;
}

.context-chapter {
  border: none;
  background: transparent;
  padding: 0.2rem 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-chapter:hover {
  text-decoration: underline;
}

.context-sep {
  color: var(--muted);
  flex-shrink: 0;
}

.context-note {
  font-weight: 600;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  color: var(--ink);
  border-radius: 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg,
.audio-player-btn svg,
.fab svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.ico-bars {
  display: block;
  width: 1.05rem;
  height: 0.72rem;
  border-top: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 1.5px no-repeat;
}

.btn-split-caret {
  font-size: 0;
}
.btn-split-caret::after {
  content: "";
  display: block;
  width: 0.38rem;
  height: 0.38rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  margin: 0.05rem auto 0.15rem;
}

.icon-btn:hover {
  background: var(--border);
}

.icon-btn.is-recording {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.icon-btn.is-recording svg {
  animation: dictate-pulse 1.2s ease-in-out infinite;
}

@keyframes dictate-pulse {
  50% { opacity: 0.4; }
}

.dictate-hud {
  position: fixed;
  left: 50%;
  bottom: 1.15rem;
  transform: translateX(-50%);
  z-index: 90;
  width: min(28rem, calc(100vw - 1.5rem));
  padding: 0.7rem 0.85rem 0.55rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--ink) 12%, transparent);
  font-family: var(--sans);
}

.dictate-hud-inner {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.dictate-rec-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.dictate-hud.is-record .dictate-rec-dot {
  background: var(--danger);
  animation: dictate-rec-blink 1s steps(1, end) infinite;
}

.dictate-hud.is-voice .dictate-rec-dot {
  background: var(--accent);
  animation: none;
}

.dictate-hud.is-transcribe .dictate-rec-dot,
.dictate-hud.is-blocked .dictate-rec-dot {
  background: var(--accent);
  animation: none;
}

@keyframes dictate-rec-blink {
  50% { opacity: 0; }
}

.dictate-timer {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  min-width: 2.7rem;
  color: var(--ink);
}

.dictate-wave {
  flex: 1 1 auto;
  display: block;
  width: 10.5rem;
  height: 1.7rem;
  color: var(--accent);
}

.dictate-voice {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 3.6rem;
}

.dictate-hud.is-voice .dictate-voice {
  color: var(--accent);
}

.dictate-busy {
  width: 0.8rem;
  height: 0.8rem;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: dictate-spin 0.75s linear infinite;
}

@keyframes dictate-spin {
  to { transform: rotate(360deg); }
}

.dictate-stop {
  flex-shrink: 0;
}

.dictate-hud-hint {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

@media (max-width: 420px) {
  .dictate-wave {
    width: 6.5rem;
  }
  .dictate-voice {
    min-width: 0;
  }
}

.track-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-sidebar);
}

.track-btn {
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.8125rem;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  color: var(--muted);
}

.track-btn[data-track="official"].active {
  background: #3e4c5e;
  color: #fff;
}

.track-btn[data-track="draft"].active {
  background: #a0562c;
  color: #fff;
}

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--bg);
}

.sidebar {
  width: min(18rem, 88vw);
  flex-shrink: 0;
  min-height: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

#btn-close-sidebar {
  display: none;
}

.chapter-list {
  overflow-y: auto;
  padding: 0.5rem;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.sidebar-foot {
  flex-shrink: 0;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.sidebar-foot #btn-import-md {
  opacity: 0.45;
}

.sidebar-foot #btn-import-md:hover,
.sidebar-foot #btn-import-md:focus-visible {
  opacity: 1;
}

.btn-block {
  width: 100%;
}

.chapter-link {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 0.65rem 0.75rem;
  border-radius: 0.4rem;
  cursor: pointer;
  color: var(--ink);
}

.chapter-link:hover {
  background: var(--wash);
}

.chapter-link.active {
  background: var(--bg);
  font-weight: 600;
}

.chapter-link .num {
  color: var(--muted);
  font-size: 0.75rem;
  margin-right: 0.35rem;
}

.chapter-link .dot {
  display: inline-block;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 0.35rem;
  vertical-align: middle;
}

.chapter-link-add {
  color: var(--accent);
  opacity: 0.72;
}

.chapter-link-add:hover,
.chapter-link-add:focus-visible {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.chapter-link-add .chapter-add-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  margin-right: 0.15rem;
  vertical-align: -0.15em;
}

.chapter-link-add .chapter-add-ico svg {
  width: 100%;
  height: 100%;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 15;
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1rem calc(var(--nav-h) + 1rem);
}

.welcome {
  max-width: var(--max-read);
  margin: 2rem auto;
  text-align: center;
  color: var(--muted);
  font-family: var(--sans);
}

.stack-status {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stack-status li {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.stack-status li.ok {
  color: #2f6b45;
  border-color: #b7d4c0;
  background: #e8f4eb;
}

.stack-status li.down {
  color: #8a2f2f;
  border-color: #e3b6b6;
  background: #f8eaea;
}

.reader,
.editor {
  max-width: var(--max-read);
  margin: 0 auto;
}

.reader-head {
  margin-bottom: 1.5rem;
}

.chapter-kicker {
  margin: 0 0 0.25rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.chapter-title {
  margin: 0 0 0.75rem;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  font-weight: 500;
  line-height: 1.3;
}

.title-editable {
  cursor: text;
}

.title-editable:hover {
  color: var(--accent);
}

.title-rename-input {
  display: block;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  font-weight: 500;
  line-height: 1.3;
  color: inherit;
  background: var(--surface, #fff);
  border: 1px solid var(--accent);
  border-radius: 4px;
}

.editor-note-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
}

.editor-note-head .chapter-title {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.editor-note-head .icon-btn {
  flex-shrink: 0;
}

.ctx-menu {
  position: fixed;
  z-index: 200;
  min-width: 9rem;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.ctx-menu button {
  display: block;
  width: 100%;
  padding: 0.45rem 0.85rem;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.ctx-menu button:hover,
.ctx-menu button:focus {
  background: var(--accent-soft, #e8dfd0);
}

.diff-hint {
  margin: 0 0 0.75rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--accent);
  font-style: italic;
}

.style-hint {
  margin: 0 0 0.75rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--muted);
}

.reader-toolbar .btn.active {
  background: var(--accent-soft, #e8dfd0);
  color: var(--accent);
}

.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  font-family: var(--sans);
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
}

.prose {
  font-size: 1.0625rem;
}

.prose h1,
.prose h2,
.prose h3 {
  font-weight: 500;
  line-height: 1.35;
  margin: 1.75rem 0 0.75rem;
}

.prose p {
  margin: 0 0 1rem;
  text-align: justify;
  hyphens: auto;
}

.prose em {
  font-style: italic;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  width: 4rem;
  margin: 2.5rem auto;
}

.prose blockquote {
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.85rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-sidebar);
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
}

.prose blockquote p {
  margin: 0;
  text-align: left;
  hyphens: none;
}

.prose h3 {
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.hl-filter_word { background: #fef3e0; border-bottom: 2px solid #e8a838; }
.hl-passive { background: #f8eaea; border-bottom: 2px solid #c45050; }
.hl-weak_verb { background: #f0e8f5; border-bottom: 2px solid #8a5cbf; }
.hl-repetition { background: #e8f0f8; border-bottom: 2px solid #4a8cc2; }
.hl-tell { background: #fdf0f0; border-bottom: 2px dashed #c45050; }
.hl-cliché { background: #fdf5e0; border-bottom: 2px dashed #d4a030; }

.notes-panel {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.notes-head h3 {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.notes-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.notes-actions .icon-btn {
  min-width: 2rem;
  min-height: 2rem;
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.notes-list li {
  margin: 0 0 0.35rem;
}

.note-link {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-sidebar);
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.4rem;
  cursor: pointer;
  color: var(--ink);
}

.note-item {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  margin: 0 0 0.45rem;
}

.note-item.dragging {
  opacity: 0.55;
}

.note-item.drop-target .note-link {
  border-color: var(--accent);
}

.note-drag {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  width: 1.6rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}

.note-drag:active {
  cursor: grabbing;
}

.note-drag span {
  display: block;
  width: 0.85rem;
  height: 2px;
  margin: 0 auto;
  border-radius: 1px;
  background: currentColor;
}

.note-item .note-link {
  flex: 1 1 auto;
  min-width: 0;
}

.note-delete-btn {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}

.note-delete-btn:hover {
  color: var(--danger);
  background: rgba(138, 47, 47, 0.08);
}

.note-delete-btn.confirm,
#btn-delete-note.confirm {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(138, 47, 47, 0.1);
  font-weight: 500;
  box-shadow: none;
}

#btn-delete-note.confirm {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.note-link:hover {
  border-color: var(--accent);
}

.note-link .meta {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.dictate-status {
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--accent);
  margin: 0 0 0.75rem;
}

.dictate-help {
  margin: 0 0 0.75rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
}

.dictate-help summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.dictate-help summary:hover {
  color: var(--accent);
}

.dictate-tags {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.5;
}

.dictate-tags code {
  font-size: 0.78rem;
  background: var(--bg-sidebar);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
}

.notes-list.nested {
  margin: 0.5rem 0 0 0.75rem;
}

.chapter-nav.is-back {
  justify-content: center;
}

.editor-tabs {
  display: none;
  gap: 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.editor-tab {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.875rem;
  padding: 0.65rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.editor-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.editor-text {
  width: 100%;
  min-height: 50vh;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--surface, #fff);
  color: var(--ink);
  resize: vertical;
}

.editor-preview {
  min-height: 50vh;
  padding: 0.25rem 0;
}

.editor-write-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
}

.write-status {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--accent);
  font-style: italic;
}

.write-result {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  white-space: pre-wrap;
}

.write-result button {
  margin-top: 0.35rem;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chapter-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 10;
}

@media (min-width: 769px) {
  .chapter-nav {
    left: min(18rem, 88vw);
  }
}

.audio-player {
  position: fixed;
  bottom: var(--nav-h);
  left: 50%;
  transform: translateX(-50%);
  width: min(40rem, calc(100vw - 1.5rem));
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  z-index: 11;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--ink) 14%, transparent);
}

.audio-player-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.audio-player-track {
  position: relative;
  width: 100%;
}

.audio-player-part-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.audio-player-part-markers .part-segment {
  position: absolute;
  top: 0;
  bottom: 0;
  background: transparent;
}

.audio-player-part-markers .part-segment.is-active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.audio-player-part-markers .part-boundary {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--accent) 50%, var(--border));
  transform: translateX(-50%);
}

.audio-player-range {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 1.35rem;
  accent-color: var(--accent);
  cursor: pointer;
  background: transparent;
}

.audio-player-range::-webkit-slider-runnable-track {
  height: 0.3rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 34%, var(--border));
}

.audio-player-range::-webkit-slider-thumb {
  margin-top: -0.22rem;
}

.audio-player-range::-moz-range-track {
  height: 0.3rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 34%, var(--border));
}

.audio-player-range::-moz-range-progress {
  height: 0.3rem;
  border-radius: 999px;
  background: var(--accent);
}

.audio-player-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}

#tts-time-current,
#tts-time-total {
  color: var(--ink);
  font-weight: 500;
  flex-shrink: 0;
}

#tts-chunk-label {
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

.audio-player-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.audio-player-btn svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.audio-player-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.audio-player-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  color: var(--ink);
}

#btn-tts-play {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

#btn-tts-play:hover:not(:disabled) {
  filter: brightness(1.08);
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.chapter-nav[hidden],
.audio-player[hidden],
.fab-edit[hidden] {
  display: none !important;
}

.fab-edit {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--nav-h) + 0.9rem);
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  z-index: 12;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  opacity: 0.82;
}

.fab-edit:hover {
  opacity: 1;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 18;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop.open {
    display: block;
  }

  #btn-close-sidebar {
    display: block;
  }

  .editor-tabs {
    display: flex;
  }
}

@media (min-width: 769px) {
  .sidebar {
    align-self: stretch;
    height: auto;
    max-height: none;
    min-height: 0;
  }

  #btn-menu {
    display: none;
  }

  .editor-preview {
    display: none !important;
  }

  .editor.layout-split .editor-text,
  .editor.layout-split .editor-preview {
    display: block !important;
  }

  @media (min-width: 900px) {
    .editor.layout-split {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 1rem;
      max-width: 56rem;
    }

    .editor.layout-split .editor-tabs {
      display: none;
    }

    .editor.layout-split .editor-note-head,
    .editor.layout-split .editor-write-tools,
    .editor.layout-split .editor-actions {
      grid-column: 1 / -1;
    }

    .editor.layout-split .editor-text,
    .editor.layout-split .editor-preview {
      min-height: 60vh;
    }
  }
}

@media (min-width: 769px) and (max-width: 899px) {
  .editor-tab[data-tab="preview"].active ~ .editor-text {
    display: none;
  }
}

.export-menu {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.export-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.export-menu-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.export-menu-toggle-icon svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.export-panel {
  position: fixed;
  z-index: 120;
  min-width: 13.5rem;
  padding: 0.25rem;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}

.export-panel[hidden] {
  display: none !important;
}

.export-panel-item {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  font-family: var(--sans);
  padding: 0.55rem 0.6rem;
  border-radius: 0.35rem;
  cursor: pointer;
  color: var(--ink);
}

.export-panel-item:hover,
.export-panel-item:focus-visible {
  background: var(--bg-sidebar, rgba(0, 0, 0, 0.04));
  outline: none;
}

.export-panel-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface, #fff) 88%, var(--border) 12%);
}

.export-panel-icon svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.export-panel-copy {
  display: block;
  min-width: 0;
}

.export-panel-copy strong {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.25;
}

.export-panel-copy span {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.chapter-export-mount {
  margin-left: auto;
}

.atelier-export-mount,
.capture-export-mount {
  display: inline-flex;
  align-items: center;
}
