/* HOUSE STYLE — design system
   Direction: "blue pencil on warm paper" (SPEC §3.5).
   Light = warm off-white paper; dark = charcoal paper, same accent logic.
   Severity: info = quiet gray-blue · style = blue-pencil blue · warn = amber.
   Voice features get the violet accent. Do not add colors outside the tokens. */

:root {
  /* paper + ink */
  --paper: #f6f1e7;
  --paper-raised: #fdfaf3;
  --paper-sunken: #efe8da;
  --ink: #2b2820;
  --ink-soft: #6b6557;
  --line: #ddd4c2;

  /* accents */
  --pencil: #2563a8;        /* blue-pencil blue: style findings, primary actions */
  --pencil-soft: #2563a826;
  --amber: #b97c10;         /* warnings */
  --amber-soft: #b97c1026;
  --info: #7a7466;
  --info-soft: #7a746622;
  --voice: #7c4dbd;         /* fingerprint / voice match family */
  --voice-soft: #7c4dbd22;
  --danger: #b3372e;

  --radius: 8px;
  --shadow: 0 2px 10px rgb(43 40 32 / .08);

  /* THE LOAD-BEARING FONT RULES (editor mirror trick, see editor.js):
     one editor font, fixed metrics, ligatures off. Change these four
     values together or highlights drift off the text. */
  --editor-font: Charter, Georgia, Cambria, "Times New Roman", serif;
  --editor-size: 17px;
  --editor-leading: 1.7;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --paper: #23211c;
  --paper-raised: #2b2922;
  --paper-sunken: #1c1a16;
  --ink: #e8e2d4;
  --ink-soft: #a39c8a;
  --line: #3a372e;
  --pencil: #6da8e8;
  --pencil-soft: #6da8e826;
  --amber: #d99a2b;        /* echoes the Live Wire amber from the arcade dark theme */
  --amber-soft: #d99a2b26;
  --info: #8d877a;
  --info-soft: #8d877a22;
  --voice: #a47fe0;
  --voice-soft: #a47fe022;
  --danger: #e06058;
  --shadow: 0 2px 12px rgb(0 0 0 / .35);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --paper: #23211c; --paper-raised: #2b2922; --paper-sunken: #1c1a16;
    --ink: #e8e2d4; --ink-soft: #a39c8a; --line: #3a372e;
    --pencil: #6da8e8; --pencil-soft: #6da8e826;
    --amber: #d99a2b; --amber-soft: #d99a2b26;
    --info: #8d877a; --info-soft: #8d877a22;
    --voice: #a47fe0; --voice-soft: #a47fe022;
    --danger: #e06058; --shadow: 0 2px 12px rgb(0 0 0 / .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* Chrome-on-Android "font boosting" inflates text it deems too small whenever the page
   overflows the screen — which un-syncs the editor mirror from the textarea. Never. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 15px;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--pencil); font-size: 20px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.tagline { color: var(--ink-soft); font-size: 12px; }

.view-tabs { display: flex; gap: 2px; background: var(--paper-sunken); border-radius: var(--radius); padding: 3px; }
.tab {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.tab.is-active { background: var(--paper-raised); color: var(--ink); box-shadow: var(--shadow); }

.topbar-stats { display: flex; gap: 14px; margin-left: auto; color: var(--ink-soft); font-size: 13px; }
.stat b { color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-voice b { color: var(--voice); }

.topbar-controls { display: flex; align-items: center; gap: 10px; }
.mode-toggle { display: flex; background: var(--paper-sunken); border-radius: var(--radius); padding: 3px; }
.mode-toggle button {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.mode-toggle button.is-active { background: var(--pencil); color: #fff; }
.icon-btn {
  border: 1px solid var(--line); background: var(--paper-raised); color: var(--ink);
  border-radius: var(--radius); width: 32px; height: 32px; cursor: pointer; font-size: 15px;
}

/* ---------- views ---------- */
main { flex: 1; display: flex; min-height: 0; }
.view { display: none; flex: 1; min-height: 0; }
.view.is-active { display: flex; }

/* ---------- editor view ---------- */
.view-editor { gap: 0; }
.editor-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.editor-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }

/* mirror + textarea: metrics MUST match exactly */
.editor-backdrop, .editor-input {
  position: absolute; inset: 0;
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  line-height: var(--editor-leading);
  font-variant-ligatures: none;
  letter-spacing: normal;
  word-spacing: normal;
  padding: 36px clamp(24px, 8vw, 120px) 120px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border: 0;
}
.editor-backdrop { overflow: hidden; pointer-events: none; }
.editor-mirror { color: transparent; min-height: 100%; }
.editor-input {
  width: 100%; height: 100%;
  background: transparent; color: var(--ink);
  caret-color: var(--pencil);
  resize: none; outline: none; overflow-y: auto;
}
.editor-input::placeholder { color: var(--ink-soft); opacity: .7; }

/* finding marks live in the mirror, behind the real text */
.editor-mirror mark {
  color: transparent;
  border-radius: 2px;
  background: transparent;
}
.editor-mirror mark.sev-style { background: var(--pencil-soft); box-shadow: 0 2px 0 var(--pencil); }
.editor-mirror mark.sev-warn  { background: var(--amber-soft);  box-shadow: 0 2px 0 var(--amber); }
.editor-mirror mark.sev-info  { background: var(--info-soft); }
.editor-mirror mark.sev-voice { background: var(--voice-soft);  box-shadow: 0 2px 0 var(--voice); }
/* Write mode: the linter shuts up */
[data-mode="write"] .editor-mirror mark { background: transparent; box-shadow: none; }

/* ---------- EKG rhythm strip ---------- */
.ekg {
  height: 56px;
  border-top: 1px solid var(--line);
  background: var(--paper-raised);
  display: flex; align-items: stretch; gap: 10px;
  padding: 6px 18px;
}
.ekg-label { align-self: center; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .12em; }
/* width:0 + min-width:0: an svg with a viewBox has an intrinsic aspect ratio, so at
   ~44px tall it "wants" ~440px of width — wide enough to blow the layout past a phone
   screen and trigger Chrome's font boosting. Let flexbox alone decide the width. */
.ekg svg { flex: 1; height: 100%; width: 0; min-width: 0; }
.ekg rect { fill: var(--pencil); opacity: .55; }
.ekg rect.long { fill: var(--amber); opacity: .8; }
.ekg rect.flagged { fill: var(--danger); opacity: .8; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 320px; flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--paper-raised);
  overflow-y: auto;
  padding: 14px;
}
.sidebar-head { display: flex; align-items: baseline; justify-content: space-between; }
.sidebar-head h2 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); }
.lint-status { font-size: 11px; color: var(--ink-soft); }

.write-mode-note {
  font-size: 13px; color: var(--ink-soft);
  background: var(--paper-sunken); border-radius: var(--radius); padding: 10px 12px;
}
[data-mode="edit"] .write-mode-note { display: none; }
[data-mode="write"] .report-groups { opacity: .45; }

.report-group { border-bottom: 1px solid var(--line); padding: 6px 0; }
.report-group summary {
  cursor: pointer; font-weight: 600; font-size: 13.5px;
  display: flex; justify-content: space-between; align-items: center;
  list-style: none;
}
.report-group summary::-webkit-details-marker { display: none; }
.report-group .count {
  background: var(--paper-sunken); color: var(--ink-soft);
  border-radius: 10px; padding: 1px 8px; font-size: 11.5px; font-variant-numeric: tabular-nums;
}
.group-empty { font-size: 12.5px; color: var(--ink-soft); }

.findings-list { list-style: none; margin: 6px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.findings-list li {
  font-size: 13px; padding: 7px 9px; border-radius: 6px; cursor: pointer;
  border-left: 3px solid var(--info);
  background: var(--paper);
}
.findings-list li:hover { background: var(--paper-sunken); }
.findings-list li.sev-style { border-left-color: var(--pencil); }
.findings-list li.sev-warn  { border-left-color: var(--amber); }
.findings-list li .excerpt { color: var(--ink-soft); font-style: italic; display: block; margin-top: 2px; }

/* ---------- popover ---------- */
.popover {
  position: absolute; z-index: 50;
  max-width: 320px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
.popover-msg { margin: 0 0 8px; font-size: 13.5px; }
.popover-actions { display: flex; gap: 6px; }

/* ---------- panels (voice / rules views) ---------- */
.panel {
  flex: 1; overflow-y: auto;
  padding: 28px clamp(18px, 6vw, 80px) 80px;
  max-width: 860px; margin: 0 auto;
}
.panel h2 { margin-top: 0; }
.lede { color: var(--ink-soft); max-width: 60ch; line-height: 1.55; }
.hint { font-size: 13px; color: var(--ink-soft); }
.muted { color: var(--ink-soft); font-weight: 400; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }

#corpus-paste {
  width: 100%; min-height: 120px;
  background: var(--paper-raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; font-family: var(--editor-font); font-size: 15px;
}
.corpus-sources { list-style: none; padding: 0; font-size: 13px; color: var(--ink-soft); }
.corpus-sources li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.confidence { font-size: 13px; color: var(--voice); }

.voice-score-wrap { display: flex; align-items: center; gap: 18px; }
.voice-score {
  font-size: 44px; font-weight: 800; color: var(--voice);
  font-variant-numeric: tabular-nums;
}
.voice-caption { font-size: 13px; color: var(--ink-soft); max-width: 36ch; }
.drift-list li { margin: 6px 0; font-size: 14px; }
.metric-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.metric-cards .card {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; font-size: 13px;
}

/* ---------- rules view ---------- */
.preset-row label { font-size: 13px; color: var(--ink-soft); }
select, input[type="text"] {
  background: var(--paper-raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 14px;
}
.rules-list { list-style: none; padding: 0; }
.rules-list li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.rules-list .rule-id { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--ink-soft); min-width: 110px; }
.rules-list .sev { font-size: 11px; border-radius: 9px; padding: 1px 8px; }
.rules-list .sev-warn { background: var(--amber-soft); color: var(--amber); }
.rules-list .sev-style { background: var(--pencil-soft); color: var(--pencil); }
.report-toggles { margin: 18px 0; }
.danger-zone { margin-top: 40px; border-top: 1px solid var(--line); padding-top: 14px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--paper-raised); color: var(--ink);
  border-radius: var(--radius); padding: 7px 14px; cursor: pointer; font-size: 13.5px;
}
.btn:hover { background: var(--paper-sunken); }
.btn-primary { background: var(--pencil); border-color: var(--pencil); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--pencil); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-small { padding: 4px 10px; font-size: 12.5px; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line);
  background: var(--paper-raised);
  padding: 8px 18px; font-size: 12.5px; color: var(--ink-soft);
}
.footer a { color: var(--pencil); }
.footer p { margin: 4px 0; }

/* ---------- editor toolbar ---------- */
.editor-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-bottom: 1px solid var(--line);
  background: var(--paper-raised); flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }
.tool-btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 6px; padding: 5px 11px; cursor: pointer; font-size: 12.5px;
}
.tool-btn:hover { background: var(--paper-sunken); }
.tool-btn:disabled { opacity: .45; cursor: not-allowed; }
.tool-btn.is-on { background: var(--voice); border-color: var(--voice); color: #fff; }

/* export dropdown (native <details>) */
.export-menu { position: relative; }
.export-menu summary { list-style: none; display: inline-block; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20;
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 4px; min-width: 180px; display: flex; flex-direction: column;
}
.export-pop button {
  border: 0; background: none; color: var(--ink); text-align: left;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.export-pop button:hover { background: var(--paper-sunken); }

/* print: only the draft, clean type */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block; position: absolute; left: 0; top: 0; width: 100%;
    padding: 0 8%; color: #000; background: #fff;
    font-family: Georgia, "Times New Roman", serif; font-size: 12pt; line-height: 1.6;
  }
  #print-area h1 { font-size: 18pt; margin: 0 0 16pt; }
  #print-area p { margin: 0 0 10pt; }
}

/* ---------- paragraph heatmap (left-gutter minimap; clears the scrollbar) ---------- */
.heatmap {
  position: absolute; top: 0; left: 0; bottom: 0; width: 9px; z-index: 6;
  display: flex; flex-direction: column; gap: 2px; padding: 8px 2px;
  background: transparent; pointer-events: auto;
}
.hm-band { width: 100%; border-radius: 2px; cursor: pointer; background: var(--pencil); }
.hm-band[data-level="ok"]   { background: var(--ink-soft); opacity: .16; }
.hm-band[data-level="soft"] { background: var(--pencil); opacity: calc(.35 + var(--d) * .55); }
.hm-band[data-level="warn"] { background: var(--danger); opacity: calc(.45 + var(--d) * .5); }
.hm-band:hover { outline: 2px solid var(--ink); outline-offset: -1px; }

/* ---------- read-aloud highlight (must beat the write-mode mute rule) ---------- */
.editor-mirror mark.reading,
[data-mode="write"] .editor-mirror mark.reading {
  background: var(--voice-soft);
  box-shadow: inset 0 0 0 2px var(--voice);
  border-radius: 3px;
}

/* ---------- editing scorecard ---------- */
.scorecard {
  background: var(--paper-sunken); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px;
}
.scorecard-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft);
  margin-bottom: 8px;
}
.scorecard-tools { display: flex; gap: 8px; }
.link-btn { border: 0; background: none; color: var(--pencil); cursor: pointer; font-size: 11px; padding: 0; text-transform: none; letter-spacing: 0; }
.link-btn:hover { text-decoration: underline; }
.sc-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; padding: 3px 0; }
.sc-label { color: var(--ink-soft); }
.sc-vals { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.sc-vals b { color: var(--ink); }
.sc-arrow { color: var(--ink-soft); font-size: 11px; }
.sc-delta { font-size: 11.5px; font-weight: 700; padding: 0 5px; border-radius: 8px; }
.sc-delta.good { color: #1c7a45; background: #1c7a4522; }
.sc-delta.bad  { color: var(--amber); background: var(--amber-soft); }
.sc-delta.flat { color: var(--ink-soft); }
[data-theme="dark"] .sc-delta.good { color: #5fd08c; background: #5fd08c22; }

/* ---------- WordPress import block + crutches ---------- */
.wp-import { margin: 14px 0; padding: 12px; background: var(--paper-sunken); border-radius: var(--radius); }
.wp-import label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 6px; }
.wp-import input { width: 220px; max-width: 100%; }
.crutch-section { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
#crutch-list li { cursor: pointer; }
#crutch-list li:hover { color: var(--voice); }

/* ---------- add-rule form + rule remove ---------- */
.add-rule { margin: 16px 0 8px; padding: 14px; background: var(--paper-sunken); border-radius: var(--radius); }
.add-rule h3 { margin: 0 0 6px; font-size: 15px; }
.add-rule-row select { min-width: 92px; }
.add-rule-row #rule-value { flex: 1; min-width: 140px; }
.grow { flex: 1; min-width: 200px; }
.rule-error { color: var(--danger); min-height: 1em; }

/* spelling + offline toggles */
.spell-settings { margin: 16px 0; padding: 14px; background: var(--paper-sunken); border-radius: var(--radius); }
.spell-settings h3 { margin: 0 0 8px; font-size: 15px; }
.switch-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 14px; cursor: pointer; }
.switch-row input { margin-top: 4px; flex-shrink: 0; width: 16px; height: 16px; }
.switch-row input:disabled { opacity: .4; cursor: not-allowed; }
.switch-row input:disabled + span { opacity: .55; }
body[data-offline="on"] .needs-online { display: none !important; }
.rules-list li { position: relative; }
.rule-desc { flex: 1; }
.rule-remove {
  border: 0; background: none; color: var(--ink-soft); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 4px; border-radius: 4px;
}
.rule-remove:hover { color: var(--danger); }

/* ---------- history view ---------- */
.history-head { display: flex; align-items: baseline; gap: 12px; }
.snap-flash { color: var(--pencil); font-size: 13px; opacity: 0; transition: opacity .2s; }
.snap-flash.show { opacity: 1; }
.history-grid { display: grid; grid-template-columns: 240px 1fr; gap: 18px; margin-top: 16px; align-items: start; }
.snap-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.snap-item {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; cursor: pointer;
  background: var(--paper-raised);
}
.snap-item:hover { background: var(--paper-sunken); }
.snap-item.is-active { border-color: var(--pencil); box-shadow: inset 3px 0 0 var(--pencil); }
.snap-title { display: block; font-size: 13.5px; font-weight: 600; }
.snap-meta { display: block; font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.snap-diff { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--paper-raised); min-height: 120px; }
.snap-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.snap-stat { font-size: 12.5px; margin: 0 0 10px; }
.snap-stat .ins, .diff-body ins { color: #1c7a45; }
.snap-stat .del, .diff-body del { color: var(--danger); }
.diff-body {
  font-family: var(--editor-font); font-size: 15px; line-height: 1.7;
  white-space: pre-wrap; overflow-wrap: break-word; max-height: 60vh; overflow-y: auto;
}
.diff-body ins { background: #1c7a4522; text-decoration: none; border-radius: 2px; }
.diff-body del { background: var(--danger-soft, #b3372e22); border-radius: 2px; }
[data-theme="dark"] .snap-stat .ins, [data-theme="dark"] .diff-body ins { color: #5fd08c; }
[data-theme="dark"] .diff-body ins { background: #5fd08c22; }

/* ---------- modal (WordPress export) ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgb(20 18 14 / .45); padding: 18px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 22px 24px; max-width: 440px; width: 100%; }
.modal-card h3 { margin: 0 0 8px; }
.modal-card label { display: block; font-size: 13px; color: var(--ink-soft); margin: 12px 0 0; }
.modal-card label input { display: block; width: 100%; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.wpx-status { min-height: 1em; }
.wpx-status a { color: var(--pencil); }

/* ---------- account bar + auth modal (optional sign-in) ---------- */
.acct { position: relative; }
.acct-btn {
  border: 1px solid var(--line); background: var(--paper-raised); color: var(--ink);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer; font-size: 13.5px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acct-btn:hover { background: var(--paper-sunken); }
.acct-btn.is-in { border-color: var(--pencil); color: var(--pencil); font-weight: 600; }

.acct-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 210;
  width: 250px; background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px; font-size: 13.5px;
}
.acct-menu[hidden] { display: none; }
.acct-id { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.acct-name { font-weight: 600; }
.acct-email { font-size: 12px; word-break: break-all; }
.acct-usage { margin: 10px 0; }
.acct-usage .meter { height: 7px; background: var(--paper-sunken); border-radius: 4px; overflow: hidden; }
.acct-usage .meter-fill { height: 100%; background: var(--pencil); transition: width .2s ease; }
.acct-usage.near .meter-fill { background: var(--amber); }
.acct-usage .muted { font-size: 11.5px; }
.acct-actions { display: flex; flex-direction: column; gap: 2px; }
.acct-link {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  color: var(--ink); cursor: pointer; font-size: 13px; padding: 6px 8px; border-radius: 6px;
  text-decoration: none;
}
.acct-link:hover { background: var(--paper-sunken); }
.acct-link.strong { color: var(--pencil); font-weight: 600; }
.acct-link[data-act="delete"] { color: var(--danger); }

/* auth modal: tabbed sign-in / register, sharing the generic .modal shell */
.acct-card { max-width: 420px; }
.acct-tabs { display: flex; gap: 4px; background: var(--paper-sunken); border-radius: var(--radius); padding: 3px; margin-bottom: 14px; }
.acct-tab { flex: 1; border: 0; background: transparent; color: var(--ink-soft); padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.acct-tab.is-active { background: var(--paper-raised); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.acct-pane { display: none; }
.acct-pane.is-active { display: block; }
.acct-pane h3 { margin: 0 0 8px; }
.acct-pane label { display: block; font-size: 13px; color: var(--ink-soft); margin: 12px 0 0; }
.acct-pane label input[type="text"], .acct-pane label input[type="email"], .acct-pane label input[type="password"] {
  display: block; width: 100%; margin-top: 4px;
}
.acct-row-min { margin-top: 8px; }
.acct-check { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-size: 12.5px; color: var(--ink-soft); }
.acct-check input { margin-top: 2px; flex: none; }
.acct-check a { color: var(--pencil); }
.acct-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.acct-status { min-height: 1em; margin-top: 10px; }
.acct-status.ok { color: #1c7a45; }
[data-theme="dark"] .acct-status.ok { color: #5fd08c; }
.acct-status.err { color: var(--danger); }

/* ---------- responsive: sidebar becomes bottom sheet ---------- */
@media (max-width: 900px) {
  .view-editor { flex-direction: column; }
  .sidebar {
    width: 100%; max-height: 28vh;   /* was 38vh — editor needs the height more */
    border-left: 0; border-top: 1px solid var(--line);
  }
  /* Compact topbar from 4 rows → 2 rows:
     Row 1: brand (left) + Write/Edit toggle + Sign-in (right, auto margin)
     Row 2: Editor/Voice/Rules/History tabs (full width)
     Hidden: decorative icon, word-count stats bar, theme toggle (rarely changed) */
  .topbar { gap: 10px; }
  .tagline { display: none; }
  .topbar-stats { display: none; }
  #theme-toggle { display: none; }
  .brand-mark { display: none; }
  .brand { flex-shrink: 1; min-width: 0; }
  .brand h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-controls { flex-shrink: 0; margin-left: auto; }
  .mode-toggle button { padding: 4px 9px; font-size: 12.5px; }
  .view-tabs { order: 10; flex-basis: 100%; }
  .tab { flex: 1; text-align: center; padding: 5px 4px; font-size: 12.5px; }
  .editor-backdrop, .editor-input { padding: 20px 28px 80px 16px; }
  .heatmap { width: 7px; }
  .history-grid { grid-template-columns: 1fr; }
  /* account dropdown: pin to viewport edges so it doesn't fall off-screen;
     top clears the new 2-row topbar (~105px) */
  .acct-menu { position: fixed; left: 12px; right: 12px; top: 108px; width: auto; }
}

/* on-screen keyboard open (browsers that resize the layout viewport): give every
   pixel back to the text — drop the rhythm strip, shrink the findings panel */
@media (max-height: 520px) {
  .ekg { display: none; }
  .sidebar { max-height: 30vh; }
}

@media (prefers-reduced-motion: no-preference) {
  .tab, .mode-toggle button, .btn { transition: background .12s ease, color .12s ease; }
}

/* ---------- toast / nudge cards (bottom center) ---------- */
.toast-stack {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(560px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; width: 100%; pointer-events: auto;
  background: var(--paper-raised); color: var(--ink); border: 1px solid var(--line);
  border-left: 3px solid var(--pencil); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 13.5px; line-height: 1.4;
  opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease;
}
.toast.toast-in { opacity: 1; transform: none; }
.toast.toast-out { opacity: 0; transform: translateY(8px); }
.toast-msg { flex: 1; }
.toast .btn-small { flex-shrink: 0; }
.toast-x { border: 0; background: none; color: var(--ink-soft); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
.toast-x:hover { color: var(--ink); }

/* ---------- saved-voice switcher ---------- */
.voice-switcher {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.voice-switcher[hidden] { display: none; }
.voice-switcher label { font-size: 13px; color: var(--ink-soft); }
.voice-switcher select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); color: var(--ink); min-width: 140px; font: inherit;
}

/* ---------- drafts dropdown (native <details>, mirrors the export menu) ---------- */
.drafts-menu { position: relative; }
.drafts-menu summary { list-style: none; display: inline-block; }
.drafts-menu summary::-webkit-details-marker { display: none; }
.drafts-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 25;
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; min-width: 260px; max-height: 60vh; overflow-y: auto;
}
.draft-new-btn {
  width: 100%; border: 1px dashed var(--line); background: none; color: var(--pencil);
  border-radius: 6px; padding: 7px; cursor: pointer; font-size: 13px; margin-bottom: 6px;
}
.draft-new-btn:hover { background: var(--paper-sunken); }
.drafts-list { list-style: none; margin: 0; padding: 0; }
.draft-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.draft-item.is-current { background: var(--pencil-soft); }
.draft-open {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  border: 0; background: none; color: var(--ink); text-align: left; padding: 6px 8px;
  border-radius: 6px; cursor: pointer; min-width: 0;
}
.draft-open:hover { background: var(--paper-sunken); }
.draft-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.draft-date { font-size: 11px; color: var(--ink-soft); }
.draft-mini { border: 0; background: none; color: var(--ink-soft); cursor: pointer; font-size: 15px; line-height: 1; padding: 4px 6px; border-radius: 6px; flex-shrink: 0; }
.draft-mini:hover { color: var(--danger); background: var(--paper-sunken); }
.draft-empty { padding: 8px; font-size: 13px; }

/* In dark the pencil blue is a pale tint, so the text on it is dark instead of white (Swatter #249).
   Kept at the end of the file so it wins over the base rules. */
[data-theme="dark"] .mode-toggle button.is-active, [data-theme="dark"] .btn-primary { color: #10233b; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .mode-toggle button.is-active, [data-theme="auto"] .btn-primary { color: #10233b; }
}
