/*
 * Layout and margin styling.
 *
 * Two rules here are load-bearing rather than cosmetic:
 *
 *   .novely-gutter has a FIXED width (3ch, matching GUTTER_WIDTH_CH). Pills stack
 *   inside it. A note arriving can never widen the column, so the prose never
 *   reflows under the cursor.
 *
 *   Nothing is `position: fixed` over the text and nothing animates into view.
 *   There are no popups in this stylesheet because there are no popups in this
 *   application.
 */

/*
 * The older names, aliased onto the token vocabulary rather than restated.
 *
 * They used to hold their own literal colours, and `body` was painted from
 * them. `tokens.css` owns the themed values, so switching to ink flipped every
 * panel and left the page itself paper-white -- a half-dark interface, from a
 * command that reported success. One vocabulary decides colour now; these are
 * names for parts of it, and they follow the theme because it does.
 *
 * tokens.css is linked first, so these resolve.
 */
:root {
  --ink: var(--text);
  --paper: var(--page);
  --rule: var(--border);
  --muted: var(--muted-1);
  --warn: var(--deletion, #a5563a);
  --pane-gap: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/*
 * What used to be here, and why it is not.
 *
 * A `@media (prefers-color-scheme: dark)` block set these four aliases to four
 * dark literals, and `body` to `#161513`. It predates the palettes, and once
 * they existed it fought them: an author on a machine in dark mode who chose
 * Paper got a cream card floating on a black page, and the Import row -- which
 * is painted with `--paper` -- came out charcoal, so the button read as a
 * full-width bar and only the word on it did anything.
 *
 * There is one vocabulary for colour now and it is `tokens.css`, driven by the
 * palette the author picked. The system's preference is not a third opinion:
 * `applyPalette` sets `color-scheme` from the chosen palette so the browser's
 * own chrome follows it, and nothing else in this file has a colour in it.
 *
 * `--accent` went the same way. It was `#3a6ea5`, a blue, declared here on
 * `:root` after `tokens.css` had already said what the accent was.
 */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

.novely-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.novely-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.novely-project {
  font-weight: 600;
}

.novely-notice {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 1;
}

.novely-switcher {
  display: flex;
  gap: 0.25rem;
  padding: 0 0.5rem;
}

.novely-switcher:empty {
  display: none;
}

.novely-grid {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr) minmax(16rem, 24rem);
  flex: 1;
  min-height: 0;
}

.novely-pane {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--rule);
}

.novely-pane-right {
  border-right: none;
}

/* --- narrow: one pane at a time (§15) ---------------------------------- */

@media (max-width: 900px) {
  .novely-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .novely-pane {
    border-right: none;
  }
}

/* --- filter chips ------------------------------------------------------ */

.novely-chip-bar {
  padding: 0.5rem;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  background: var(--paper);
}

.novely-filter-summary {
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.novely-filter-hidden {
  color: var(--warn);
  margin-left: 0.4rem;
}

.novely-chip-axes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.novely-chip-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.novely-chip-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  width: 4rem;
}

/* `.novely-chip` lives in `styles/chat.css` now, whole. */

.novely-chip-on {
  background: var(--ink);
  color: var(--paper);
}

/* --- navigator --------------------------------------------------------- */

.novely-nav-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
}

.novely-nav-toggle {
  font: inherit;
  font-size: 0.75rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}

.novely-nav-toggle-on {
  color: var(--ink);
  text-decoration: underline;
}

.novely-chapters {
  list-style: none;
  margin: 0;
  padding: 0;
}

.novely-chapter-button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.35rem 0.6rem;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.novely-chapter-open .novely-chapter-button {
  border-left-color: var(--accent);
  background: rgba(58, 110, 165, 0.08);
}

.novely-status-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex: none;
}

.novely-chapter-order {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  width: 1.5rem;
}

.novely-chapter-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.novely-words,
.novely-matter {
  color: var(--muted);
  font-size: 0.75rem;
}

.novely-external {
  color: var(--warn);
  font-size: 0.7rem;
}

.novely-counts {
  display: inline-flex;
  gap: 0.2rem;
}

.novely-count {
  font-size: 0.7rem;
  padding: 0 0.3rem;
  border-radius: 0.4rem;
  background: var(--rule);
}

/*
 * `.novely-count-proved` and its two siblings used to be here, with three literal
 * colours. Nothing renders them any more -- the gutter reads its colour from
 * `vocab.ts` via `--kind` -- and three dead colours in a stylesheet are three
 * colours a palette cannot reach.
 */

/* --- manuscript -------------------------------------------------------- */

.novely-manuscript {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.novely-manuscript-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}

.novely-chapter-heading {
  font-size: 1rem;
  margin: 0;
  flex: 1;
}

.novely-mode,
.novely-action {
  font: inherit;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 0.3rem;
  background: transparent;
  cursor: pointer;
}

.novely-mode-on {
  background: var(--ink);
  color: var(--paper);
}

.novely-action-warn {
  border-color: var(--warn);
  color: var(--warn);
}

/* `.novely-work-rail` likewise. */

.novely-work-rail:empty {
  display: none;
}

/*
 * `.novely-rail-pill` likewise. Its truncation -- one line, ellipsis, a maximum
 * width -- moved with it rather than being left behind here to apply invisibly.
 */

.novely-editor-host {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.cm-editor {
  height: 100%;
  font-family: 'Iowan Old Style', Georgia, serif;
  font-size: 1.02rem;
  line-height: 1.6;
}

/* The fixed-width margin. Notes stack inside it; the column never resizes. */
.novely-gutter {
  width: 3ch;
  min-width: 3ch;
  overflow: hidden;
}

/*
 * `.novely-pills` lives in `styles/manuscript.css`. The rule here declared
 * `flex-direction: column`, which the newer one does not mention and therefore
 * did not undo -- so the gutter's dots stacked downwards inside a row exactly
 * one line tall, and the second dot on a paragraph was drawn under the first.
 */

/* `.novely-pill` and `.novely-pill-closed` likewise. */

.novely-pill-author {
  border-radius: 50%;
}


.novely-pill-demoted {
  outline: 1px dashed var(--warn);
}

/* CriticMarkup: decorated, never hidden (except in Clean mode). */
.novely-critic {
  border-radius: 2px;
}

/*
 * The author's own marks, mixed from the palette rather than fixed.
 *
 * These were two literals -- a rust wash and a rust ink -- so a comment in a
 * dark palette was a rust smear on near-black, and in Black and gold it was
 * the one thing on the page that did not belong to the page.
 */
.novely-critic-comment {
  background: color-mix(in srgb, var(--deletion) 13%, transparent);
  color: color-mix(in srgb, var(--deletion) 78%, var(--text));
}

.novely-critic-highlight {
  background: color-mix(in srgb, var(--kind-violated) 28%, transparent);
}

.novely-critic-insertion {
  background: rgba(60, 160, 90, 0.18);
}

.novely-critic-deletion {
  background: rgba(200, 60, 60, 0.16);
  text-decoration: line-through;
}

.novely-critic-substitution {
  background: rgba(90, 120, 200, 0.16);
}

.novely-rendered:empty {
  display: none;
}

.novely-rendered {
  border-top: 1px solid var(--rule);
  padding: 0.6rem;
  overflow: auto;
  max-height: 45%;
}

.novely-inline-caption {
  font-size: 0.75rem;
  color: var(--muted);
}

.novely-export {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

/* --- inbox and notes --------------------------------------------------- */

.novely-inbox {
  padding: 0.5rem;
}

.novely-inbox-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.novely-inbox-head h2 {
  font-size: 0.9rem;
  margin: 0;
}

.novely-held {
  font-size: 0.75rem;
  color: var(--muted);
}

.novely-notes {
  list-style: none;
  margin: 0;
  padding: 0;
}

.novely-note {
  border-top: 1px solid var(--rule);
  padding: 0.4rem 0;
}

.novely-note-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  font-size: 0.72rem;
}

.novely-kind {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 0.3rem;
  border-radius: 0.3rem;
  background: var(--rule);
}

.novely-tag {
  padding: 0 0.3rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
}

.novely-note-author,
.novely-note-level {
  color: var(--muted);
}

.novely-note-body {
  margin: 0.25rem 0;
  font-size: 0.85rem;
}

.novely-note-demoted {
  font-size: 0.75rem;
  color: var(--warn);
  margin: 0.2rem 0;
}

.novely-note-actions,
.novely-card-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.novely-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.5rem;
}

/* --- context stack ----------------------------------------------------- */

.novely-context {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.novely-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  padding: 0.3rem;
  border-bottom: 1px solid var(--rule);
}

.novely-tab {
  font: inherit;
  font-size: 0.72rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}

.novely-tab-on {
  color: var(--ink);
  text-decoration: underline;
}

.novely-context-slot {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 0.5rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.novely-quote {
  margin: 0.3rem 0;
  padding-left: 0.5rem;
  border-left: 3px solid var(--rule);
  font-style: italic;
}

.novely-facts {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.8rem;
}

.novely-fact {
  display: flex;
  gap: 0.4rem;
  padding: 0.15rem 0;
  border-bottom: 1px solid var(--rule);
}

.novely-fact-attribute {
  color: var(--muted);
}

.novely-fact-proposed {
  opacity: 0.6;
}

/* --- the assembled app (§1) --------------------------------------------- */

/*
 * `mountApp` puts four things in the page: the shell, the two screens that take
 * over from it, and the host the overlays mount into. The shell owns its own
 * height, so this wrapper only has to be the column they sit in -- and the
 * shell's host is `display: contents` so that the frame is a direct child of it
 * and keeps the geometry `styles/shell.css` gives it.
 */
.novely-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.novely-app-shell {
  display: contents;
}

/* The overlays position themselves (fixed, scrim); this is only their home. */
.novely-app-overlays:empty {
  display: none;
}

/* --- decisions: the phone screen (§15) --------------------------------- */

.novely-screen-decisions {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.novely-decisions {
  width: 100%;
  max-width: 34rem;
}

.novely-card {
  border: 1px solid var(--rule);
  border-radius: 0.6rem;
  padding: 1rem;
  touch-action: pan-y;
}

.novely-card-progress {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.novely-question {
  font-size: 1.15rem;
  margin: 0.3rem 0 0.8rem;
}

.novely-options {
  list-style: none;
  margin: 0 0 0.8rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.novely-option {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  min-height: 3rem;
  padding: 0.6rem 0.7rem;
  text-align: left;
  font: inherit;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
}

.novely-option-recommended {
  border-color: var(--accent);
}

.novely-option-chosen {
  background: rgba(58, 110, 165, 0.12);
  border-width: 2px;
}

.novely-recommended-flag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.novely-option-consequences {
  font-size: 0.8rem;
  color: var(--muted);
}

.novely-action-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  min-height: 2.5rem;
  padding: 0 1rem;
}

.novely-card-error {
  color: var(--warn);
  font-size: 0.85rem;
}

/* --- import (§17) ------------------------------------------------------ */

.novely-screen-import {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 1.5rem 1rem 3rem;
}

/* `.novely-import` lives in `styles/overlays.css`. */

.novely-drop {
  border: 2px dashed var(--rule);
  border-radius: 0.8rem;
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
}

.novely-drop-over {
  border-color: var(--accent);
  background: rgba(58, 110, 165, 0.06);
}

.novely-drop-headline {
  font-size: 1.2rem;
  margin: 0 0 0.4rem;
}

.novely-drop-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.2rem 0;
}

.novely-file-input {
  display: none;
}

.novely-import-alternative {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.novely-import-busy {
  padding: 2rem 0;
  font-size: 1rem;
}

.novely-review-head h2 {
  font-size: 1.1rem;
  margin: 0 0 0.3rem;
}

.novely-review-summary {
  font-size: 1rem;
  margin: 0.2rem 0;
}

.novely-review-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.15rem 0;
}

.novely-review-chapters {
  list-style: none;
  margin: 0.8rem 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
}

.novely-review-chapter {
  display: flex;
  gap: 0.6rem;
  justify-content: space-between;
  padding: 0.1rem 0;
}

.novely-review-bulk {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.6rem 0;
}

.novely-proposals {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.novely-proposal {
  display: flex;
  gap: 0.6rem;
  align-items: start;
  padding: 0.6rem 0.3rem;
  border-bottom: 1px solid var(--rule);
}

.novely-proposal-off {
  opacity: 0.62;
}

.novely-proposal-weak {
  background: rgba(165, 86, 58, 0.05);
}

.novely-proposal-box {
  margin-top: 0.3rem;
  width: 1.1rem;
  height: 1.1rem;
  flex: none;
}

.novely-proposal-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  cursor: pointer;
}

.novely-proposal-preview {
  font-family: 'Iowan Old Style', Georgia, serif;
}

.novely-proposal-route {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.8rem;
}

.novely-proposal-to {
  font-weight: 600;
}

.novely-proposal-reason,
.novely-confidence {
  color: var(--muted);
  font-size: 0.8rem;
}

.novely-confidence-low {
  color: var(--warn);
  font-weight: 600;
}


.novely-review-count {
  flex: 1;
  font-size: 0.9rem;
}

.novely-import-failure h2 {
  color: var(--warn);
  font-size: 1.05rem;
}

.novely-failure-message {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  background: rgba(165, 86, 58, 0.1);
  padding: 0.1rem 0.3rem;
  border-radius: 0.2rem;
}

.novely-failure-detail {
  font-size: 0.9rem;
}

/* `.novely-verified` likewise. */

/*
 * Barlow Condensed on the chrome's headings (design system).
 *
 * The handoff is explicit about the split and about the exemption: chrome takes
 * Barlow, headings and dense labels take Barlow Condensed, and the manuscript
 * stays Literata *because it is the artifact rather than the chrome* — the same
 * reason `gutter.ts` refuses to reflow prose.
 *
 * Listed by class rather than by tag because this interface has almost no bare
 * `h1`/`h2`: the headings are components. Kept in one block so the next one has
 * an obvious place to go, instead of the rule being spread across six sheets
 * where it can be half-applied without anybody noticing.
 *
 * Codes, counts and anything monospaced are untouched: they are IBM Plex Mono
 * and that has not changed.
 */
.novely-top-title,
.novely-overlay-title,
.novely-projects-title,
.novely-phone-queue-title,
.novely-phone-chapter-title {
  font-family: var(--font-heading);
  letter-spacing: 0.01em;
}
