/* ============================================================
   Velvet Quill · Midnight luxe
   Fonts bundled locally (SIL OFL): Inter (interface), Fraunces (display), Newsreader (reading).
   ============================================================ */
@font-face { font-family: "Inter"; src: url("font-inter.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("font-fraunces.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("font-fraunces-italic.woff2") format("woff2"); font-weight: 100 900; font-style: italic; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url("font-newsreader.woff2") format("woff2"); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url("font-newsreader-italic.woff2") format("woff2"); font-weight: 200 800; font-style: italic; font-display: swap; }

/* ---------- Tokens: Midnight (default) ---------- */
:root {
  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-read: "Newsreader", Georgia, "Palatino Linotype", serif;

  --bg: #0d0a0e;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(214, 86, 133, .10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(140, 70, 160, .08), transparent 60%);
  --surface: #151017;
  --surface-2: #1b151e;
  --panel-2: #221a25;
  --glass: rgba(24, 18, 27, .72);
  --text: #f4ebe8;
  --text-2: #cdbfc3;
  --muted: #968790;
  --placeholder: #6b5d66;
  --border: rgba(255, 236, 244, .08);
  --border-strong: rgba(255, 236, 244, .16);
  --accent: #ea6f98;
  --accent-hover: #f287ab;
  --accent-grad: linear-gradient(135deg, #f08bb0 0%, #d95c88 52%, #b8426f 100%);
  --accent-soft: rgba(234, 111, 152, .14);
  --accent-text: #ffffff;
  --gold: #dcb48f;
  --danger: #ff6b78;
  --danger-soft: rgba(255, 107, 120, .12);
  --ok: #4fc591;
  --rec: #ff4d7e;
  --selection: rgba(234, 111, 152, .32);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow: 0 24px 60px -16px rgba(0, 0, 0, .75), 0 0 0 1px rgba(255, 236, 244, .05);
  --glow: 0 10px 34px -8px rgba(234, 111, 152, .55);
  --hl-top: inset 0 1px 0 rgba(255, 255, 255, .04);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --d1: 140ms;
  --d2: 220ms;
  --d3: 360ms;
  color-scheme: dark;
}

/* ---------- Tokens: Ivory (light) ---------- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f8f3ef;
    --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(196, 64, 112, .07), transparent 60%);
    --surface: #ffffff; --surface-2: #fcf8f6; --panel-2: #f2eae6; --glass: rgba(255, 255, 255, .78);
    --text: #1d1418; --text-2: #4b3b42; --muted: #7e6c74; --placeholder: #ab9aa2;
    --border: rgba(29, 20, 24, .09); --border-strong: rgba(29, 20, 24, .17);
    --accent: #b8325f; --accent-hover: #9c2850; --accent-grad: linear-gradient(135deg, #d4578a 0%, #b8325f 55%, #95244b 100%);
    --accent-soft: rgba(184, 50, 95, .09); --gold: #a4743f; --danger: #c43341; --danger-soft: rgba(196, 51, 65, .09); --ok: #22865b;
    --rec: #d81f55; --selection: rgba(184, 50, 95, .18);
    --shadow-sm: 0 1px 2px rgba(60, 20, 40, .06); --shadow: 0 24px 60px -18px rgba(60, 20, 40, .28), 0 0 0 1px rgba(29, 20, 24, .05);
    --glow: 0 10px 28px -10px rgba(184, 50, 95, .55); --hl-top: inset 0 1px 0 rgba(255, 255, 255, .7);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f8f3ef;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(196, 64, 112, .07), transparent 60%);
  --surface: #ffffff; --surface-2: #fcf8f6; --panel-2: #f2eae6; --glass: rgba(255, 255, 255, .78);
  --text: #1d1418; --text-2: #4b3b42; --muted: #7e6c74; --placeholder: #ab9aa2;
  --border: rgba(29, 20, 24, .09); --border-strong: rgba(29, 20, 24, .17);
  --accent: #b8325f; --accent-hover: #9c2850; --accent-grad: linear-gradient(135deg, #d4578a 0%, #b8325f 55%, #95244b 100%);
  --accent-soft: rgba(184, 50, 95, .09); --gold: #a4743f; --danger: #c43341; --danger-soft: rgba(196, 51, 65, .09); --ok: #22865b;
  --rec: #d81f55; --selection: rgba(184, 50, 95, .18);
  --shadow-sm: 0 1px 2px rgba(60, 20, 40, .06); --shadow: 0 24px 60px -18px rgba(60, 20, 40, .28), 0 0 0 1px rgba(29, 20, 24, .05);
  --glow: 0 10px 28px -10px rgba(184, 50, 95, .55); --hl-top: inset 0 1px 0 rgba(255, 255, 255, .7);
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14.5px/1.55 var(--font-ui);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-weight: 600; letter-spacing: -.01em; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
::placeholder { color: var(--placeholder); }
::selection { background: var(--selection); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { flex: none; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  transition: border-color var(--d1) var(--ease-out), box-shadow var(--d1) var(--ease-out), background var(--d1);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
select option { background: var(--surface); color: var(--text); }

/* ---------- Buttons ---------- */
.btn-accent, .btn-outline, .btn-danger, .btn-ghost {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; padding: 9px 18px; font-weight: 600; font-size: 14px; letter-spacing: .005em;
  border: 1px solid transparent; white-space: nowrap;
  transition: transform var(--d1) var(--ease-out), box-shadow var(--d2) var(--ease-out), background var(--d1), border-color var(--d1), color var(--d1), filter var(--d1);
}
.btn-accent { background: var(--accent-grad); color: var(--accent-text); box-shadow: var(--glow); }
.btn-accent:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-accent:active:not(:disabled) { transform: translateY(0) scale(.98); }
.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-ghost { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-lg { padding: 13px 24px; font-size: 15px; }
.btn-sm { padding: 6px 13px; font-size: 13px; align-self: flex-start; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-2);
  transition: background var(--d1), color var(--d1);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.text-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--text-2); font-weight: 500; padding: 7px 11px; border-radius: 10px; transition: background var(--d1), color var(--d1); }
.text-btn:hover { background: var(--panel-2); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 13px; padding: 0; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Loaders ---------- */
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%; flex: none;
  background: conic-gradient(from 0deg, transparent 0 25%, currentColor 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading { pointer-events: none; }
.is-loading > svg { display: none; }
.is-loading::before {
  content: ""; width: 15px; height: 15px; border-radius: 50%; flex: none;
  background: conic-gradient(from 0deg, transparent 0 25%, currentColor 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  animation: spin .8s linear infinite;
}
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(100deg, var(--panel-2) 30%, color-mix(in srgb, var(--panel-2) 55%, var(--border-strong)) 50%, var(--panel-2) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.6s var(--ease-in-out) infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skel-row { height: 52px; }
.skel-line { height: 12px; border-radius: 6px; }

/* ---------- Pop-ins (menus, cards, panels, toolbar) ---------- */
.pop:not([hidden]) { animation: pop-in var(--d2) var(--ease-out) both; transform-origin: var(--origin, top right); }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ---------- View transitions ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--d3); animation-timing-function: var(--ease-out); }
::view-transition-old(root) { animation-name: vt-out; }
::view-transition-new(root) { animation-name: vt-in; }
@keyframes vt-out { to { opacity: 0; transform: scale(.985); } }
@keyframes vt-in { from { opacity: 0; transform: scale(1.01); } }
.view:not([hidden]) { animation: view-in var(--d3) var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; } }
html.vt-running .view { animation: none; }

/* ---------- Menus ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 25; min-width: 240px;
  display: flex; flex-direction: column; padding: 6px;
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow);
}
.menu button { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; transition: background var(--d1); }
.menu button:hover { background: var(--accent-soft); }
.menu .ext { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ---------- Brand ---------- */
.wordmark { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 19px; letter-spacing: .01em; font-variation-settings: "opsz" 48; }
.wordmark em { font-style: italic; color: var(--accent); font-weight: 400; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-grad); color: #fff; box-shadow: var(--glow); }

/* ============ Home ============ */
.home { display: grid; grid-template-columns: 252px 1fr; height: 100%; }
.side-nav {
  display: flex; flex-direction: column; gap: 22px;
  padding: 24px 16px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 10px; background: none;
  color: var(--text-2); font-weight: 500; text-decoration: none; text-align: left;
  transition: background var(--d1), color var(--d1);
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); padding: 12px; border-radius: var(--r); background: var(--panel-2); }
.side-model { display: flex; flex-direction: column; min-width: 0; }
.side-model strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }

.home-main { overflow-y: auto; padding: 48px 56px 64px; }
.hero { max-width: 760px; margin-bottom: 44px; }
.eyebrow { margin: 0 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.hero h1 { margin: 0 0 22px; font-family: var(--font-display); font-weight: 400; font-size: clamp(30px, 4vw, 44px); line-height: 1.1; letter-spacing: -.02em; font-variation-settings: "opsz" 144, "SOFT" 50; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.hero-actions .btn-ghost { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.home-head h2 { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 22px; }
.search {
  display: flex; align-items: center; gap: 8px; width: 300px; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 14px; color: var(--muted);
  transition: border-color var(--d1), box-shadow var(--d1);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; padding: 9px 0; background: transparent; box-shadow: none !important; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.doc-card {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  height: 290px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), var(--hl-top);
  transition: transform var(--d2) var(--ease-out), box-shadow var(--d2) var(--ease-out), border-color var(--d2);
  animation: card-in var(--d3) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 35ms);
}
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } }
.doc-card:hover, .doc-card:focus-visible { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--border-strong); outline: none; }
.dc-cover {
  position: relative; height: 92px; flex: none;
  background:
    radial-gradient(120% 140% at 0% 0%, hsl(var(--h, 330) 70% 62% / .9), transparent 55%),
    radial-gradient(120% 140% at 100% 100%, hsl(calc(var(--h, 330) + 40) 60% 40% / .9), transparent 60%),
    linear-gradient(135deg, hsl(var(--h, 330) 45% 22%), hsl(calc(var(--h, 330) + 30) 50% 14%));
}
.dc-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 40%, var(--surface)); }
.dc-body { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 4px 18px 14px; }
.dc-title { font-family: var(--font-display); font-weight: 500; font-size: 18px; line-height: 1.25; margin-bottom: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dc-snippet {
  flex: 1; overflow: hidden; color: var(--text-2); font: 13.5px/1.55 var(--font-read);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.dc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--muted); }
.dc-date { font-size: 12px; color: var(--muted); }
.doc-del { border: 0; background: none; color: var(--muted); padding: 5px; border-radius: 8px; opacity: 0; transition: opacity var(--d1), background var(--d1), color var(--d1); }
.doc-card:hover .doc-del, .doc-del:focus-visible { opacity: 1; }
.doc-del:hover { color: var(--danger); background: var(--danger-soft); }
.new-card {
  align-items: center; justify-content: center; gap: 14px; color: var(--text-2); font-weight: 600;
  background: transparent; border: 1.5px dashed var(--border-strong); box-shadow: none;
}
.new-card:hover { border-color: var(--accent); color: var(--text); }
.new-card .plus {
  display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent-grad); color: #fff; box-shadow: var(--glow);
  transition: transform var(--d2) var(--ease-out);
}
.new-card:hover .plus { transform: rotate(90deg) scale(1.05); }
.empty-note { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.empty-state {
  grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px;
  padding: 56px 24px; border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
}
.empty-state .es-mark { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); }
.empty-state h3 { margin: 4px 0 0; font-family: var(--font-display); font-weight: 500; font-size: 22px; }
.empty-state p { margin: 0 0 8px; color: var(--text-2); max-width: 46ch; }

/* ============ Editor ============ */
.editor { display: flex; flex-direction: column; height: 100%; }
.ed-top {
  display: flex; align-items: center; gap: 6px; height: 58px; padding: 0 14px; flex: none;
  border-bottom: 1px solid var(--border); background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  position: relative; z-index: 15;
}
.save-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; color: var(--muted); background: var(--panel-2); transition: color var(--d2);
}
.save-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); transition: background var(--d2), transform var(--d2) var(--ease-out); }
.save-chip[data-state="saving"]::before { background: var(--gold); transform: scale(1.3); }
.spacer { flex: 1; }

.ed-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 392px; }
.doc-col { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.doc-paper { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 780px; margin: 0 auto; padding: 48px 56px 0; }
.doc-title {
  border: 0; padding: 0 0 20px; background: transparent; box-shadow: none !important;
  font-family: var(--font-display); font-weight: 500; font-size: 38px; line-height: 1.15; letter-spacing: -.02em;
  font-variation-settings: "opsz" 144, "SOFT" 30;
}
.doc-title:hover, .doc-title:focus { border: 0; box-shadow: none; }
#story {
  flex: 1; min-height: 0; resize: none; border: 0; padding: 0 0 140px; border-radius: 0; background: transparent; box-shadow: none !important;
  font: 19px/1.8 var(--font-read); color: var(--text); font-variation-settings: "opsz" 16;
  caret-color: var(--accent); scroll-behavior: auto;
}
#story:hover, #story:focus { border: 0; }
#story::selection, .doc-title::selection { background: var(--selection); }
.doc-foot {
  display: flex; align-items: center; gap: 16px; padding: 10px 56px; max-width: 780px; width: 100%; margin: 0 auto;
  font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border);
}
#status { margin-left: auto; transition: color var(--d2); }
#status.error { color: var(--danger); }
#status.busy { color: var(--accent); font-weight: 500; }
#status.busy::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: currentColor; vertical-align: 1px; animation: breathe 1.4s var(--ease-in-out) infinite; }
@keyframes breathe { 50% { opacity: .3; transform: scale(.8); } }

/* AI writing indicator */
.writing-bar {
  position: absolute; left: 50%; bottom: 66px; z-index: 6; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13.5px; font-weight: 500; white-space: nowrap;
  animation: bar-in var(--d3) var(--ease-out) both;
}
@keyframes bar-in { from { opacity: 0; transform: translate(-50%, 12px); } }
.wb-orb { display: inline-flex; gap: 4px; }
.wb-orb i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: orb 1.2s var(--ease-in-out) infinite; }
.wb-orb i:nth-child(2) { animation-delay: .15s; }
.wb-orb i:nth-child(3) { animation-delay: .3s; }
@keyframes orb { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: 1; } }
.wb-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.wb-stop { border: 0; border-radius: 999px; padding: 6px 14px; background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px; transition: background var(--d1), color var(--d1); }
.wb-stop:hover { background: var(--danger-soft); color: var(--danger); }
.writing #story { caret-color: transparent; }

/* Dictation */
.dictate-dock { position: absolute; right: 24px; bottom: 60px; display: flex; align-items: center; gap: 8px; z-index: 5; }
.lang { width: auto; border-radius: 999px; padding: 7px 28px 7px 12px; font-size: 12px; font-weight: 600; color: var(--text-2); background-color: var(--glass); backdrop-filter: blur(12px); }
.mic-fab {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 50px; padding: 0 20px 0 16px;
  border: 0; border-radius: 999px; background: var(--accent-grad); color: #fff; font-weight: 600; box-shadow: var(--glow);
  transition: transform var(--d1) var(--ease-out), filter var(--d1);
}
.mic-fab:hover { filter: brightness(1.08); transform: translateY(-1px); }
.mic-ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.mic-fab.on { background: var(--rec); }
.mic-fab.on .mic-ring { box-shadow: 0 0 0 2px var(--rec); animation: ring 1.6s var(--ease-out) infinite; }
@keyframes ring { from { transform: scale(1); opacity: .8; } to { transform: scale(1.35); opacity: 0; } }

/* Focus mode: just the page */
body.focus .assistant, body.focus .dictate-dock, body.focus .ed-top > :not(#focusBtn):not(.spacer) { opacity: 0; pointer-events: none; }
body.focus .ed-body { grid-template-columns: 1fr 0; }
body.focus .ed-top { border-color: transparent; background: transparent; backdrop-filter: none; }
.ed-body, .assistant, .dictate-dock, .ed-top > * { transition: opacity var(--d3) var(--ease-out), grid-template-columns var(--d3) var(--ease-out); }

/* ---------- Story plan ---------- */
.assistant { display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-left: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 80%, transparent); }
.as-head { padding: 22px 22px 12px; display: flex; flex-direction: column; gap: 2px; }
.as-head h2 { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 22px; }
.as-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.sec { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--hl-top); }
.sec > summary {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; list-style: none;
  font-weight: 600; font-size: 14px; border-radius: var(--r); transition: background var(--d1);
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary:hover { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.sec-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border-strong); transition: background var(--d2), border-color var(--d2); }
.sec.filled .sec-dot { background: var(--accent); border-color: var(--accent); }
.chev { margin-left: auto; color: var(--muted); transition: transform var(--d2) var(--ease-out); }
.sec[open] .chev { transform: rotate(90deg); }
.sec-body { display: flex; flex-direction: column; gap: 14px; padding: 2px 16px 16px; }
.sec[open] .sec-body { animation: sec-open var(--d2) var(--ease-out) both; }
@keyframes sec-open { from { opacity: 0; transform: translateY(-4px); } }

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card-title { font-weight: 600; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 12.5px; color: var(--text-2); }
.field input, .field select, .field textarea { font-weight: 400; font-size: 14px; color: var(--text); }
.field-head { display: flex; justify-content: space-between; align-items: center; }
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.pill { background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.pill-hot { background: var(--accent-grad); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 8px; }
input[type="range"] { accent-color: var(--accent); padding: 0; border: 0; background: none; box-shadow: none !important; }

.check-field { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; cursor: pointer; color: var(--text); font-weight: 400; }
.check-field input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.check-field .hint { display: block; margin-top: 2px; }

.pointers { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.pointers li { color: var(--muted); font-weight: 600; }
.pointers li::marker { color: var(--accent); }
.pointers .ptr { display: flex; gap: 4px; }
.pointers .ptr button { border: 0; background: none; color: var(--muted); padding: 0 8px; border-radius: 8px; font-size: 18px; transition: background var(--d1), color var(--d1); }
.pointers .ptr button:hover { color: var(--danger); background: var(--danger-soft); }

.as-actions { padding: 14px 14px 16px; border-top: 1px solid var(--border); background: var(--glass); display: flex; flex-direction: column; gap: 10px; }
.as-actions .row > button { flex: 1; padding: 11px 14px; }
.ask { position: relative; }
.ask input { border-radius: 999px; padding: 11px 48px 11px 16px; }
.ask-send {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--accent-grad); color: #fff; transition: filter var(--d1);
}
.ask-send:hover { filter: brightness(1.1); }

/* Selection toolbar */
.sel-toolbar {
  position: fixed; z-index: 20; display: flex; gap: 2px; padding: 5px;
  background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); --origin: bottom center;
}
.sel-toolbar button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text); transition: background var(--d1), color var(--d1); }
.sel-toolbar button:hover { background: var(--accent-soft); color: var(--accent); }

.interim {
  position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%); z-index: 30;
  max-width: min(640px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(18px); color: var(--text); border: 1px solid color-mix(in srgb, var(--rec) 60%, transparent);
  box-shadow: var(--shadow); font: 16px/1.5 var(--font-read);
}
.interim .who { color: var(--rec); font: 600 12px/1 var(--font-ui); text-transform: uppercase; letter-spacing: .08em; margin-right: 10px; }

/* ============ Welcome ============ */
.welcome { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(5, 3, 6, .6); backdrop-filter: blur(8px); animation: view-in var(--d3) var(--ease-out) both; }
.welcome-card { width: min(480px, 100%); padding: 34px 32px 24px; border-radius: 22px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: pop-in var(--d3) var(--ease-out) both; }
.w-step { animation: step-in var(--d3) var(--ease-out) both; }
@keyframes step-in { from { opacity: 0; transform: translateX(14px); } }
.w-num { font-family: var(--font-display); font-style: italic; font-size: 15px; color: var(--gold); }
.w-step h2 { margin: 6px 0 10px; font-family: var(--font-display); font-weight: 500; font-size: 28px; }
.w-step p { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.6; min-height: 72px; }
.welcome-foot { display: flex; align-items: center; gap: 10px; margin-top: 26px; }
.w-dots { display: flex; gap: 6px; margin-right: auto; }
.w-dots i { width: 7px; height: 7px; border-radius: 99px; background: var(--border-strong); transition: width var(--d2) var(--ease-out), background var(--d2); }
.w-dots i.on { width: 22px; background: var(--accent); }

/* Small screens (browser on a phone or narrow window) */
@media (max-width: 900px) {
  .home { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side-nav { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-nav .btn-block { width: auto; }
  .nav { flex-direction: row; }
  .nav .nav-item.active, .side-foot { display: none; }
  .home-main { padding: 28px 16px 48px; }
  .hero { margin-bottom: 32px; }
  .doc-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
  .doc-card { height: 240px; }
  .dc-cover { height: 64px; }
  .editor { height: auto; min-height: 100%; }
  .ed-body { grid-template-columns: 1fr; }
  .doc-col { min-height: 72vh; }
  .doc-paper { padding: 28px 16px 0; }
  .doc-title { font-size: 30px; }
  .doc-foot { padding: 10px 16px; }
  .assistant { border-left: 0; border-top: 1px solid var(--border); }
  .dictate-dock { position: fixed; right: 16px; bottom: 16px; z-index: 10; }
  .writing-bar { position: fixed; bottom: 84px; }
  #readTime { display: none; }
}

/* Respect "reduce motion" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
