/* workspace/editor/editor.css: the chapter folio under a sticky toolbar (tokens.css only).
   editor.js sets --ws-step (the reading app's text size). */

/* ---- ProseMirror's required CSS (vendor README 3.1) ---- */
.ProseMirror { position: relative; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces;
  -webkit-font-variant-ligatures: none; font-variant-ligatures: none; font-feature-settings: "liga" 0; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
.ProseMirror [draggable][contenteditable=false] { user-select: text; }
.ProseMirror-selectednode { outline: 2px solid currentColor; }
img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; }

/* ---- one text column: toolbar, head, prose ---- */
#ws-editor-pane {
  --ws-step: 1; --ws-ems: 38; --ws-gutter: clamp(12px, 3vw, 48px); --ws-leaf: clamp(20px, 4.5vw, 80px);
  --ws-text: clamp(14px, calc(clamp(16px, 10.5px + .45vw, 26px) * var(--ws-step)), 36px);
  --ws-folio: min(100% - 2 * var(--ws-gutter), var(--ws-text) * var(--ws-ems) + 2 * var(--ws-leaf));
  display: flex; flex-direction: column; overflow-y: auto; scroll-padding-top: 64px;
}
#ws-editor-pane[data-ws-width="narrow"] { --ws-ems: 32; }
#ws-editor-pane[data-ws-width="wide"] { --ws-ems: 46; }

/* ---- toolbar ---- */
#ws-toolbar {
  position: sticky; top: 0; z-index: 4; flex: none; display: flex; align-items: center; gap: 2px;
  min-height: 44px; padding: 5px calc((100% - var(--ws-folio)) / 2 + var(--ws-leaf) - 8px);
  background: var(--paper); border-bottom: 1px solid var(--hairline); font: var(--ui-size, 13px)/1.3 var(--font-ui);
  container: ws-tb / inline-size;
}
#ws-toolbar button, .ws-display > summary, #ws-focus-exit {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 32px;
  min-height: 32px; padding: 0 8px; font: inherit; color: var(--ink-soft); background: transparent;
  border: 1px solid transparent; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
#ws-toolbar button:hover:not(:disabled), .ws-display > summary:hover, .ws-display[open] > summary { background: var(--paper-3); color: var(--ink); }
#ws-toolbar button:disabled { opacity: .45; cursor: default; }
#ws-toolbar button[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--hairline-2); color: var(--accent-text); }
#ws-btn-italic, #ws-btn-bold { padding: 0; font: 17px/1 var(--font-serif) !important; }
#ws-btn-italic { font-style: italic !important; }
#ws-btn-bold { font-weight: 700 !important; }
#ws-btn-scene-break, #ws-btn-undo { margin-left: 6px; }

/* 16px stroke icons in the button's ink */
#ws-btn-scene-break::before, #ws-btn-undo::before, #ws-btn-redo::before, #ws-focus-exit::before {
  content: ""; flex: none; width: 16px; height: 16px; background: currentColor;
  -webkit-mask: var(--ws-icon) center / 16px no-repeat; mask: var(--ws-icon) center / 16px no-repeat;
}
#ws-btn-scene-break { --ws-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='4.75' r='1.6'/%3E%3Ccircle cx='4.25' cy='11.25' r='1.6'/%3E%3Ccircle cx='11.75' cy='11.25' r='1.6'/%3E%3C/svg%3E"); }
#ws-btn-undo { --ws-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.25 3.75 3.25 6.75l3 3'/%3E%3Cpath d='M3.25 6.75h6a3.5 3.5 0 0 1 0 7h-1.5'/%3E%3C/svg%3E"); }
#ws-btn-redo { --ws-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9.75 3.75 3 3-3 3'/%3E%3Cpath d='M12.75 6.75h-6a3.5 3.5 0 0 0 0 7h1.5'/%3E%3C/svg%3E"); }
#ws-focus-exit { --ws-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='m4.25 4.25 7.5 7.5m0-7.5-7.5 7.5'/%3E%3C/svg%3E"); }

/* ---- word count ---- */
#ws-word-count {
  margin-left: auto; min-width: 0; padding: 0 6px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums;
}
#ws-word-count span + span::before { content: " \b7  "; }
/* narrower: stack the counts, then a compact bar, then no counts (fits 44px targets) */
@container ws-tb (max-width: 560px) {
  #ws-word-count { display: grid; justify-items: end; line-height: 1.2; }
  #ws-word-count span + span::before { content: none; }
}
@container ws-tb (max-width: 450px) {
  #ws-toolbar button { margin: 0; }
  #ws-toolbar #ws-btn-scene-break { font-size: 0; gap: 0; }
  #ws-word-count { padding: 0; }
}
@container ws-tb (max-width: 350px) { #ws-word-count { visibility: hidden; } }

/* ---- page settings (Aa) ---- */
.ws-display { position: relative; flex: none; }
.ws-display > summary { list-style: none; font: 15px/1 var(--font-serif); }
.ws-display > summary::-webkit-details-marker { display: none; }
.ws-display-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 6; display: grid; gap: 10px;
  width: max-content; max-width: calc(100vw - 24px); padding: 12px 14px; font-size: 13px;
  color: var(--ink-soft); background: var(--card-bg); border: 1px solid var(--hairline-2);
  border-radius: 8px; box-shadow: var(--shadow);
}
.ws-pref { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 32px; }
.ws-seg { display: inline-flex; border: 1px solid var(--hairline-2); border-radius: 7px; overflow: hidden; }
#ws-toolbar .ws-seg button { border: 0; border-radius: 0; padding: 0 10px; }
#ws-toolbar .ws-seg button + button { border-left: 1px solid var(--hairline-2); }

/* ---- the folio: one paper leaf ---- */
.ws-folio {
  flex: 1 0 auto; width: var(--ws-folio); margin: clamp(12px, 3vh, 40px) auto clamp(20px, 5vh, 64px);
  padding: clamp(22px, 5vh, 64px) var(--ws-leaf) clamp(32px, 9vh, 112px); background: var(--card-bg);
  border: 1px solid var(--hairline); border-radius: 3px; box-shadow: var(--ws-sheet-shadow, var(--shadow));
}
#ws-editor-pane.ws-typewriter .ws-folio { padding-bottom: 50vh; }

/* ---- head ---- */
#ws-editor-head { padding-bottom: clamp(16px, 3.5vh, 36px); }
.ws-running-head {
  display: flex; align-items: center; gap: 14px; min-height: 1.5em; font: 11px/1.5 var(--font-ui);
  letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint);
}
.ws-running-head::after { content: ""; flex: 1; border-top: 1px solid var(--hairline); }
.ws-chapter-no { margin-top: clamp(14px, 3vh, 30px); font: italic calc(var(--ws-text) * .95)/1.3 var(--font-serif); color: var(--ink-soft); }
.ws-chapter-no:empty { display: none; }
#ws-chapter-title {
  display: block; width: 100%; margin: 4px 0 0; padding: 2px 0 4px;
  font: 600 calc(var(--ws-text) * 1.55)/1.2 var(--font-serif); color: var(--ink); background: transparent;
  border: 0; border-bottom: 1px solid transparent;
}
#ws-chapter-title:focus { outline: none; border-bottom-color: var(--accent); }
#ws-chapter-title::placeholder { color: var(--ink-faint); }
#ws-chapter-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#ws-chapter-flags:empty { display: none; }
.ws-flag {
  font: 12px/1.5 var(--font-ui); padding: 1px 9px; border-radius: 999px; background: var(--chip-low-bg);
  color: var(--chip-low-fg); border: 1px solid var(--hairline);
}
.ws-flag-reading, .ws-flag-archived { background: var(--chip-med-bg); color: var(--chip-med-fg); }
.ws-flag-conflict { background: var(--caution-bg); color: var(--caution-fg); }

.ws-readonly-note { margin-top: 12px; padding: 8px 12px; font: 13px/1.45 var(--font-ui); color: var(--caution-fg);
  background: var(--caution-bg); border-radius: 6px; }
.ws-readonly-note:empty { display: none; }

/* ---- conflict banner ---- */
#ws-conflict-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding: 12px 14px;
  font: 14px/1.45 var(--font-ui); color: var(--ink); background: var(--caution-bg);
  border: 1px solid var(--hairline-2); border-left: 3px solid var(--caution-fg); border-radius: 8px;
}
#ws-conflict-banner[hidden] { display: none; }
#ws-conflict-banner p { flex: 1 0 100%; margin: 0 0 2px; }
#ws-conflict-banner button {
  min-height: 34px; padding: 4px 14px; font: 13px var(--font-ui); color: var(--accent-text);
  background: transparent; border: 1px solid var(--hairline-2); border-radius: 6px; cursor: pointer;
}
#ws-conflict-banner button:hover { background: var(--paper-3); }
#ws-conflict-banner #ws-btn-compare-conflict { color: var(--on-accent, var(--paper)); background: var(--accent); border-color: var(--accent); }
#ws-conflict-banner #ws-btn-compare-conflict:hover { filter: brightness(.92); }

/* ---- prose ---- */
#ws-editor { font-family: var(--font-serif); font-size: var(--ws-text); line-height: 1.72; color: var(--ink); }
#ws-editor .ProseMirror { outline: none; min-height: 8em; caret-color: var(--accent); }
#ws-editor ::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }
#ws-editor .ws-scene p { margin: 0 0 .75em; }
/* literal scenes keep their lines; a blank line is one paragraph gap */
#ws-editor .ws-scene[data-lay="lit"] p { margin: 0; }
#ws-editor .ws-scene[data-lay="lit"] p:has(> br:only-child) { height: .75em; }

/* scene divider: CSS, never document text */
.ws-scene + .ws-scene::before {
  content: "* * *"; display: block; text-align: center; color: var(--ink-faint);
  font-family: var(--font-serif); letter-spacing: .5em; margin: 1.5em 0;
}

/* a writable blank chapter invites the first line (not while an IME composes) */
#ws-editor.ws-blank:not(.ws-composing) [contenteditable=true] > .ws-scene:first-child > p:first-child::before {
  content: "Begin the chapter here\2026"; position: absolute; pointer-events: none; font-style: italic;
  color: var(--ink-faint);
}

/* ---- focus mode: exit and status fade while idle ---- */
#ws-app.ws-focus #ws-toolbar { display: none; }
#ws-app.ws-focus .ws-folio { background: transparent; border-color: transparent; box-shadow: none; }
#ws-focus-exit { position: fixed; top: 10px; right: 12px; z-index: 60; font: 13px var(--font-ui); color: var(--ink-faint); }
#ws-focus-status {
  position: fixed; left: 50%; bottom: 12px; z-index: 59; transform: translateX(-50%); padding: 2px 10px;
  border-radius: 99px; font: 12px/1.4 var(--font-ui); color: var(--ink-faint); white-space: nowrap; pointer-events: none;
}
/* a paper halo over text beneath */
#ws-focus-exit, #ws-focus-status { background: var(--paper); box-shadow: 0 0 12px 10px var(--paper); }
#ws-focus-exit:hover, #ws-focus-exit:focus-visible { color: var(--ink); background: var(--paper-2); border-color: var(--hairline-2); }
#ws-focus-exit[hidden] { display: none; }
.ws-idle > #ws-focus-exit:not(:focus-visible):not(:hover), .ws-idle > #ws-focus-status { opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
  html:not([data-motion="reduce"]) :is(#ws-focus-exit, #ws-focus-status) { transition: opacity .5s; }
}

/* ---- touch (no Esc hint) and small screens ---- */
@media (hover: none), (max-width: 760px) {
  #ws-toolbar button, .ws-display > summary, #ws-focus-exit { min-width: 44px; min-height: 44px; }
  .ws-pref { min-height: 44px; }
}
@media (hover: none) { #ws-focus-exit { font-size: 0; gap: 0; } }
@media (max-width: 760px) {
  #ws-editor-pane { --ws-text: max(16px, calc(16px * var(--ws-step))); }
  #ws-conflict-banner button { min-height: 44px; }
  #ws-focus-status { left: 16px; top: 14px; bottom: auto; transform: none; }
  #ws-app.ws-focus .ws-folio { padding-top: 60px; }
}

/* ---- phones: the page is the screen ---- */
@media (max-width: 600px) {
  #ws-editor-pane { --ws-gutter: 0px; --ws-leaf: 16px; }
  .ws-folio { margin: 0; padding-top: 18px; background: transparent; border: 0; box-shadow: none; }
  .ws-pref:first-child { display: none; }
}
