/* editor.css — the BabelMe companion editor design system.
   Identity: the Transcribe family — near-black ink ground, one warm orange accent (spent on
   primary actions and human-edit marks), teal reserved strictly for live/link state.
   Document body is a real reading serif; UI chrome is quiet system sans.
   Themes: dark (default) and paper, via [data-theme] tokens. Print renders the document alone. */

:root {
  --bg: #0e1114;
  --bg-elev: #151b21;
  --bg-elev2: #1c242d;
  --page: #12171d;
  --text: #ece9e4;
  --text-soft: #c7c3bc;
  --muted: #97a1ab;
  --hairline: rgba(255, 255, 255, .09);
  --hairline-strong: rgba(255, 255, 255, .16);
  --accent: #ff8a3d;
  --accent-ink: #2b1503;
  --accent-soft: rgba(255, 138, 61, .13);
  --live: #34d3be;
  --live-soft: rgba(52, 211, 190, .12);
  --danger: #f47067;
  --shadow: 0 10px 34px rgba(0, 0, 0, .45);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", Palatino, Charter, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
[data-theme="paper"] {
  --bg: #edeae2;
  --bg-elev: #f6f3ec;
  --bg-elev2: #efebe1;
  --page: #fbf9f4;
  --text: #262219;
  --text-soft: #4b463d;
  --muted: #645e54;                 /* AA at small sizes on --page */
  --hairline: rgba(40, 30, 10, .12);
  --hairline-strong: rgba(40, 30, 10, .22);
  --accent: #b85408;
  --accent-ink: #fff;
  --accent-soft: rgba(184, 84, 8, .1);
  --live: #0a6a5e;                  /* darkened: 11px chip text must clear AA on paper */
  --live-soft: rgba(10, 106, 94, .1);
  --danger: #a33227;                /* darkened for the same reason */
  --shadow: 0 10px 30px rgba(60, 45, 20, .18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }   /* the hidden attribute must beat component display rules */
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar ---------- */
.ed-topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.ed-wordmark { font: 700 13px/1 var(--sans); letter-spacing: .34em; margin-right: 2px; }
.ed-surface-tag {
  font: 600 10px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--hairline-strong);
  padding: 5px 9px; border-radius: 999px; white-space: nowrap;
}
.ed-topbar .spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font: 600 11px/1 var(--sans); letter-spacing: .05em;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--hairline-strong); color: var(--muted);
  white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.chip.live { color: var(--live); border-color: color-mix(in srgb, var(--live) 45%, transparent); background: var(--live-soft); }
.chip.live .dot { background: var(--live); animation: ed-pulse 1.6s ease-in-out infinite; }
.chip.warn { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.chip.warn .dot { background: var(--danger); }
@keyframes ed-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: var(--muted);
}
.icon-btn:hover { background: var(--bg-elev2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--muted); }
.icon-btn svg { width: 17px; height: 17px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 13px/1 var(--sans);
  padding: 9px 15px; border-radius: 10px;
  border: 1px solid var(--hairline-strong); color: var(--text);
}
.btn:hover { background: var(--bg-elev2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn svg { width: 15px; height: 15px; }

/* ---------- document canvas ---------- */
.ed-scroll { min-height: calc(100vh - 55px); }
.ed-page {
  max-width: 47.5em;
  margin: 26px auto 40vh;
  padding: 54px 64px 72px;
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
@media (max-width: 760px) { .ed-page { margin: 0 0 40vh; padding: 30px 18px 60px; border-radius: 0; border-left: 0; border-right: 0; } }

.ed-title {
  font: 600 32px/1.22 var(--serif);
  letter-spacing: -.012em;
  color: var(--text);
  margin: 0 0 6px;
  min-height: 1.22em;
}
.ed-title:empty::before { content: attr(data-placeholder); color: var(--muted); }
.ed-title:focus { outline: none; }
.ed-meta {
  font: 500 11px/1.6 var(--sans); letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 34px;
  display: flex; gap: 14px; flex-wrap: wrap;
}

/* ---------- blocks ---------- */
.ed-blocks { font: 17.5px/1.7 var(--serif); }
.blkrow { position: relative; padding: 2px 0; border-radius: 8px; }
.blkrow .gutter {
  position: absolute; left: -58px; top: 2px;
  display: flex; gap: 2px; opacity: .3; transition: opacity .12s;
}
.blkrow:hover .gutter, .blkrow:focus-within .gutter { opacity: 1; }
@media (pointer: coarse) {
  .blkrow .gutter { opacity: .5; left: -52px; }
  /* ≥44px touch targets on touch devices (review finding) */
  .gutter button { width: 36px; height: 36px; }
  .icon-btn { width: 44px; height: 44px; }
  .img-tools button { padding: 12px 16px; }
  .fmt-bar button { min-width: 42px; height: 42px; }
}
.gutter button {
  width: 25px; height: 25px; border-radius: 7px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.gutter button:hover { background: var(--bg-elev2); color: var(--text); }
.gutter svg { width: 15px; height: 15px; }
.gutter .drag { cursor: grab; }

.blkrow.dragging { opacity: .4; }
.blkrow.drop-before::before {
  content: ""; position: absolute; left: 0; right: 0; top: -2px; height: 3px;
  border-radius: 2px; background: var(--accent);
}

/* content editables */
.bc { min-height: 1.3em; white-space: pre-wrap; word-wrap: break-word; }
.bc:focus { outline: none; }
.bc:empty::before { content: attr(data-placeholder); color: var(--muted); }
.bc mark { background: color-mix(in srgb, var(--accent) 38%, transparent); color: inherit; padding: 0 .08em; border-radius: 3px; }

.blk-transcript .bc { color: var(--text); }
.blk-transcript { padding-left: 12px; margin-left: -12px; border-left: 2px solid transparent; }
.blk-transcript.human { border-left-color: color-mix(in srgb, var(--accent) 65%, transparent); }
.blk-transcript.gap .bc { color: var(--muted); font-style: italic; }
.blk-heading .bc { font-weight: 650; letter-spacing: -.008em; }
.blk-heading[data-level="1"] .bc { font-size: 1.55em; line-height: 1.28; margin-top: .5em; }
.blk-heading[data-level="2"] .bc { font-size: 1.3em; line-height: 1.3; margin-top: .4em; }
.blk-heading[data-level="3"] .bc { font-size: 1.12em; line-height: 1.35; margin-top: .3em; }
.blk-quote .bc { border-left: 3px solid var(--hairline-strong); padding-left: 16px; color: var(--text-soft); }
.blk-bullet { display: flex; gap: 10px; }
.blk-bullet::before { content: "•"; color: var(--accent); flex: none; line-height: 1.7; }
.blk-bullet .bc { flex: 1; }
.blk-note .bc {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  border-radius: 10px; padding: 13px 17px; margin: 6px 0;
  font-family: var(--sans); font-size: .86em; line-height: 1.6;
}
.blk-divider { padding: 14px 0; }
.blk-divider hr { border: 0; border-top: 1px solid var(--hairline-strong); margin: 0; }

/* image */
.blk-image figure { margin: 10px auto; text-align: center; }
.blk-image.w-s figure { width: 38%; } .blk-image.w-m figure { width: 62%; }
.blk-image.w-l figure { width: 85%; } .blk-image.w-full figure { width: 100%; }
.blk-image img {
  max-width: 100%; border-radius: 10px; display: block; margin: 0 auto;
  box-shadow: 0 3px 18px rgba(0, 0, 0, .3);
}
.blk-image img.scan { filter: grayscale(1) contrast(1.25) brightness(1.08); }
.blk-image figcaption { margin-top: 8px; }
.blk-image figcaption .bc { font: 13px/1.55 var(--sans); color: var(--muted); text-align: center; }
.img-tools {
  display: flex; gap: 4px; justify-content: center; margin-top: 8px;
  opacity: 0; transition: opacity .12s;
}
.blkrow:hover .img-tools, .blkrow:focus-within .img-tools { opacity: 1; }
.img-tools button {
  font: 600 11px/1 var(--sans); padding: 6px 10px; border-radius: 7px;
  border: 1px solid var(--hairline-strong); color: var(--muted);
}
.img-tools button:hover { color: var(--text); background: var(--bg-elev2); }
.img-tools button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

/* formula */
.blk-formula .fx { text-align: center; padding: 10px 6px; overflow-x: auto; cursor: pointer; border-radius: 10px; }
.blk-formula .fx:hover { background: var(--bg-elev); }
.blk-formula .fx code {
  font: 15px/1.6 var(--mono);
  background: var(--bg-elev2); padding: 7px 13px; border-radius: 8px; display: inline-block;
}
.fx-editor { background: var(--bg-elev); border: 1px solid var(--hairline-strong); border-radius: 12px; padding: 14px; margin: 6px 0; }
.fx-editor textarea {
  width: 100%; min-height: 58px; resize: vertical;
  font: 14px/1.6 var(--mono); color: var(--text);
  background: var(--page); border: 1px solid var(--hairline-strong); border-radius: 8px; padding: 10px 12px;
}
.fx-editor textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.fx-editor .fx-palette { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.fx-editor .fx-palette button {
  min-width: 38px; height: 34px; padding: 0 9px; border-radius: 8px;
  border: 1px solid var(--hairline-strong); color: var(--text-soft);
  font: 500 15px/1 var(--serif);
}
.fx-editor .fx-palette button:hover { background: var(--bg-elev2); color: var(--text); border-color: var(--accent); }
.fx-editor .fx-preview { min-height: 34px; text-align: center; padding: 12px 4px 4px; overflow-x: auto; }
.fx-editor .fx-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.fx-editor .hint { font: 12px/1.4 var(--sans); color: var(--muted); margin-right: auto; }

/* ---------- floating format bar ---------- */
.fmt-bar {
  position: fixed; z-index: 60; display: flex; gap: 2px;
  background: var(--bg-elev2); border: 1px solid var(--hairline-strong);
  border-radius: 11px; padding: 4px; box-shadow: var(--shadow);
}
.fmt-bar button {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px;
  font: 600 14px/1 var(--serif); color: var(--text-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.fmt-bar button:hover { background: var(--bg-elev); color: var(--text); }
.fmt-bar .b { font-weight: 800; } .fmt-bar .i { font-style: italic; } .fmt-bar .u { text-decoration: underline; }
.fmt-bar .hl { color: var(--accent); }

/* ---------- menus ---------- */
.ed-menu {
  position: fixed; z-index: 70; min-width: 240px;
  max-height: min(70vh, 480px); overflow-y: auto;   /* tall menus scroll, never clip */
  background: var(--bg-elev2); border: 1px solid var(--hairline-strong);
  border-radius: 13px; padding: 6px; box-shadow: var(--shadow);
  font-family: var(--sans);
}
.ed-menu .mi {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; border-radius: 9px; text-align: left;
  font: 500 13.5px/1.2 var(--sans); color: var(--text);
}
.ed-menu .mi:hover, .ed-menu .mi.sel { background: var(--bg-elev); }
.ed-menu .mi svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.ed-menu .mi .sub { display: block; font: 400 11.5px/1.3 var(--sans); color: var(--muted); margin-top: 2px; }
.ed-menu .sep { height: 1px; background: var(--hairline); margin: 6px 8px; }
.ed-menu .mi.danger { color: var(--danger); } .ed-menu .mi.danger svg { color: var(--danger); }
.ed-menu .mlabel { font: 600 10px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 8px 11px 4px; }

/* ---------- empty-document onboarding hint ---------- */
.ed-hint {
  margin-top: 26px; padding: 18px 20px;
  border: 1px dashed var(--hairline-strong); border-radius: 12px;
  display: flex; flex-direction: column; gap: 13px;
  font: 14px/1.5 var(--sans); color: var(--muted);
}
.ed-hint .hi { display: flex; align-items: center; gap: 12px; }
.ed-hint .hi svg { width: 17px; height: 17px; flex: none; color: var(--accent); }
.ed-hint b { color: var(--text-soft); font-weight: 650; }

/* ---------- live tail + follow pill ---------- */
.ed-live {
  display: none; align-items: flex-start; gap: 10px;
  margin-top: 18px; padding: 13px 16px;
  border: 1px dashed color-mix(in srgb, var(--live) 45%, transparent);
  border-radius: 12px; background: var(--live-soft);
  font: 15.5px/1.6 var(--serif); color: var(--text-soft);
}
.ed-live.on { display: flex; }
.ed-live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); flex: none; margin-top: 8px; animation: ed-pulse 1.6s ease-in-out infinite; }

.follow-pill {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 50;
  display: none; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink);
  font: 600 13px/1 var(--sans); padding: 11px 18px; border-radius: 999px;
  box-shadow: var(--shadow);
}
.follow-pill.on { display: inline-flex; }

/* ---------- multi-select ---------- */
.blkrow.sel { background: var(--accent-soft); box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 40%, transparent); }
.sel-bar {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(90px); z-index: 65;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev2); border: 1px solid var(--hairline-strong);
  border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow);
  font: 600 13px/1 var(--sans); transition: transform .18s;
}
.sel-bar.on { transform: translateX(-50%) translateY(0); }
.sel-bar .cnt { color: var(--muted); padding: 0 4px; min-width: 84px; }
.sel-bar .btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

/* ---------- toast ---------- */
.ed-toast {
  position: fixed; bottom: 26px; right: 26px; z-index: 80;
  background: var(--bg-elev2); border: 1px solid var(--hairline-strong); color: var(--text);
  font: 500 13px/1.4 var(--sans); padding: 12px 16px; border-radius: 11px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: all .18s; pointer-events: none;
  max-width: 340px;
}
.ed-toast.on { opacity: 1; transform: none; }

/* ---------- pairing shell (companion) ---------- */
.pair-wrap { max-width: 430px; margin: 13vh auto 0; padding: 0 20px; text-align: center; }
.pair-card { background: var(--bg-elev); border: 1px solid var(--hairline); border-radius: 18px; padding: 38px 30px; box-shadow: var(--shadow); }
.pair-card h1 { font: 600 24px/1.3 var(--serif); margin: 0 0 8px; }
.pair-card p { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.pair-card input {
  width: 100%; text-align: center;
  font: 700 30px/1 var(--mono); letter-spacing: .35em; text-transform: uppercase;
  color: var(--text); background: var(--page);
  border: 1px solid var(--hairline-strong); border-radius: 12px; padding: 16px 8px 16px calc(8px + .35em);
  margin-bottom: 16px;
}
.pair-card input:focus { outline: 2px solid var(--accent); }
.pair-err { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-top: 14px; }

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

/* ---------- print: the document alone, as a clean paper artifact ---------- */
@media print {
  body { background: #fff; }
  .ed-topbar, .gutter, .img-tools, .follow-pill, .ed-toast, .ed-live, .fmt-bar, .ed-menu { display: none !important; }
  .ed-scroll { min-height: 0; }
  .ed-page {
    max-width: none; margin: 0; padding: 0;
    background: #fff; border: 0; border-radius: 0; box-shadow: none;
    color: #1c1a16;
  }
  .ed-page, .ed-blocks, .ed-title { color: #1c1a16; }
  .blk-note .bc { background: #f6efe3; border-color: #eadfc9; }
  .blk-transcript.human { border-left-color: transparent; }
  @page { margin: 1in; }
  .blk-heading .bc { break-after: avoid; }
  .blk-image figure, .blk-note .bc, .blk-formula .fx { break-inside: avoid; }
}
