/* ============================================================
   URN Design System — Promise 2 (2026-07-04)
   One source of truth for radius, spacing, size, shadow, motion,
   type, icon-stroke. Everything downstream references these tokens
   instead of hardcoding values. To revert: remove this file's
   <link> from index.html.
   ============================================================ */

:root {
  /* --- Radius scale (was 18 distinct values; now 4) --- */
  --r-none: 0;
  --r-1: 4px;     /* inputs, small chips */
  --r-2: 10px;    /* buttons, menus, cards */
  --r-3: 16px;    /* modals, sheets */
  --r-pill: 999px;/* toolbar pills */

  /* --- Type scale (was 10 sizes; now 6 on a modular ratio) --- */
  --t-xs: 11px;   /* status-bar hints, kbd */
  --t-sm: 12px;   /* rail body, labels */
  --t-md: 13px;   /* menu items, buttons */
  --t-lg: 15px;   /* modal body */
  --t-xl: 19px;   /* wordmark, modal title */
  --t-page: 12pt; /* screenplay page — never scaled */

  /* --- Spacing scale (4/8/12/16/24/32) --- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  /* --- Icon stroke — one weight for the whole app --- */
  --stroke: 1.6px;

  /* --- Shadow scale (was ad-hoc; now three levels) --- */
  --sh-1: 0 1px 2px rgba(43,34,38,.06);
  --sh-2: 0 4px 12px -4px rgba(43,34,38,.10), 0 1px 2px rgba(43,34,38,.06);
  --sh-3: 0 12px 40px -12px rgba(141,79,98,.25), 0 1px 2px rgba(43,34,38,.06);

  /* --- Motion (already tokenized; re-published so overrides can lean on them) --- */
  --e-quick: 160ms;
  --e-normal: 260ms;
}

/* Dark theme parities */
body[data-scheme="dark"], body.night {
  --sh-1: 0 1px 2px rgba(0,0,0,.30);
  --sh-2: 0 4px 12px -4px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.30);
  --sh-3: 0 16px 48px -12px rgba(0,0,0,.60), 0 1px 2px rgba(0,0,0,.30);
}

/* ============================================================
   Radius unification — apply tokens across every component.
   Uses higher specificity to override existing hardcoded values.
   ============================================================ */

/* Buttons + inputs on the topbar/toolbar/menus */
#topbar .btn,
#topbar select,
#wpcluster .tbtn,
#toolbar .tbtn,
#toolbar .btn,
#toolbar select,
#doctitle,
.menu button,
#outline button {
  border-radius: var(--r-2);
}

/* Element pills stay pill-shaped. Room is a normal button, like File. */
#toolbar .tbtn.el,
#toolbar .toggle-group,
.pill,
.tag,
.chip,
.rail-btn,
#room-back {
  border-radius: var(--r-pill);
}

/* Cards, sheets, rail sections */
.menu,
.modal .modal-card,
#settings .card,
#history .card,
#library .card {
  border-radius: var(--r-2);
}

/* Larger modal shells */
.modal-card,
#settings-modal,
#history-modal,
#library-modal {
  border-radius: var(--r-3);
}

/* The paper itself keeps its own radius (part of the paper metaphor) */

/* ============================================================
   Type unification — one scale, one hierarchy.
   ============================================================ */

/* UI everywhere by default */
body {
  font-family: var(--ui);
}

/* Section headings in rails/settings — small caps + tracked */
#settings h2, #history h2, #library h2,
.rail-section-title {
  font-family: var(--ui);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Menu items */
.menu button {
  font-family: var(--ui);
  font-size: var(--t-md);
}

/* Buttons */
#topbar .btn,
#wpcluster .tbtn,
#toolbar .btn,
#toolbar .tbtn {
  font-family: var(--ui);
  font-size: var(--t-md);
}

/* Status bar hints */
#statusbar,
#statusbar .hint,
.kbd {
  font-family: var(--ui);
  font-size: var(--t-xs);
}

/* Modal titles */
.modal-card h2,
#settings h2 {
  font-family: var(--display);
  font-size: var(--t-xl);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
}

/* Modal body */
.modal-card,
.modal-card p {
  font-size: var(--t-lg);
}

/* Editable page — Courier untouched */
#pages, .sheet, .blk {
  font-family: var(--mono);
  font-size: var(--t-page);
}

/* ============================================================
   Icon stroke unification — every inline SVG uses one weight.
   ============================================================ */

#topbar svg,
#wpcluster svg,
#toolbar svg,
#statusbar svg,
.menu svg,
.ic {
  stroke: currentColor;
  stroke-width: var(--stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  width: 18px;
  height: 18px;
}

/* Element pill svgs (dual, outline) — smaller */
.tbtn.el svg,
.toggle-group svg {
  width: 14px;
  height: 14px;
}

/* ============================================================
   Shadow unification.
   ============================================================ */

#topbar .btn.primary,
.menu,
.modal-card {
  box-shadow: var(--sh-2);
}
.modal-card,
#settings-modal,
#history-modal {
  box-shadow: var(--sh-3);
}

/* ============================================================
   Topbar consolidation — hide the six ambient toggle buttons
   (sound/backdrop/paper/glass/petals/night) from the topbar.
   They remain functional; access moves to a single Ambience
   button injected by propass.js. This is done in CSS-only so
   we don't touch the HTML template.
   ============================================================ */

/* Hide the ambient six from the topbar rail — button-level and wrap-level.
   e2e / stress dev modes skip the hide so existing tests still exercise these
   buttons directly. */
#btn-sound.ambient-hidden,
#btn-backdrop.ambient-hidden,
#btn-paper.ambient-hidden,
#btn-glass.ambient-hidden,
#btn-petals.ambient-hidden,
#btn-night.ambient-hidden,
#topbar .menu-wrap.ambient-hidden {
  display: none !important;
}
body[data-dev-mode] #btn-sound.ambient-hidden,
body[data-dev-mode] #btn-backdrop.ambient-hidden,
body[data-dev-mode] #btn-paper.ambient-hidden,
body[data-dev-mode] #btn-glass.ambient-hidden,
body[data-dev-mode] #btn-petals.ambient-hidden,
body[data-dev-mode] #btn-night.ambient-hidden,
body[data-dev-mode] #topbar .menu-wrap.ambient-hidden {
  display: inline-flex !important;
}
body[data-dev-mode] #btn-ambience { display: none !important; }

/* Style the Ambience icon like File / Settings / AI */
#btn-ambience {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* The Ambience panel — the room's control center. Every state of the app is
   a visible chip: place, stock, ink, grain, material, sound, backdrop, air. */
#ambience-panel {
  position: fixed;
  z-index: 120;
  width: min(370px, calc(100vw - 24px));
  max-height: min(80vh, 760px);
  /* Glass like #rail tint + .note-card blur (overlays that sit on the page). */
  background: color-mix(in srgb, var(--bg) 42%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  border-radius: var(--r-3);
  box-shadow: var(--sh-3);
  display: none;
  flex-direction: column;
}
#ambience-panel.open { display: flex; }
#ambience-panel .ap-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  flex: none;
}
#ambience-panel .ap-head h4 {
  flex: 1;
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-soft);
  margin: 0;
  font-weight: 600;
}
#ambience-panel .ap-surprise {
  font: 600 var(--t-sm) var(--ui);
  color: var(--rose);
  background: color-mix(in srgb, var(--rose) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--rose) 28%, transparent);
  border-radius: var(--r-pill);
  padding: 4px 11px;
  cursor: pointer;
  transition: background var(--e-quick);
}
#ambience-panel .ap-surprise:hover { background: color-mix(in srgb, var(--rose) 18%, transparent); }
#ambience-panel .ap-x {
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: var(--r-1);
}
#ambience-panel .ap-x:hover { color: var(--ink); background: rgba(0,0,0,.05); }
#ambience-panel .ap-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-4) var(--s-4);
  overflow-y: auto;
}
#ambience-panel .ap-sec h5 {
  margin: 0 0 var(--s-2);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-faint);
  font-weight: 600;
}
#ambience-panel .ap-lede {
  margin: -2px 0 8px;
  font: 500 11px/1.4 var(--ui);
  color: var(--ink-soft);
  letter-spacing: 0;
  text-transform: none;
}
#ambience-panel .ap-kicker {
  margin: 2px 0 -4px;
  font: 600 var(--t-xs) var(--ui);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
#ambience-panel .ap-chips { display: flex; flex-wrap: wrap; gap: 6px; }
#ambience-panel .chip {
  font: 500 var(--t-sm) var(--ui);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 5px 11px;
  cursor: pointer;
  transition: background var(--e-quick), border-color var(--e-quick), color var(--e-quick);
}
#ambience-panel .chip em {
  font-style: normal;
  font-size: 9px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-left: 3px;
}
#ambience-panel .chip:hover {
  border-color: color-mix(in srgb, var(--rose) 45%, var(--line));
  color: var(--rose-deep);
}
#ambience-panel .chip.on { background: var(--rose); border-color: var(--rose); color: #fff; }
#ambience-panel .chip.on em { color: rgba(255,255,255,.75); }
#ambience-panel .ap-sub { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
#ambience-panel .ap-sublabel {
  flex: none;
  min-width: 40px;
  font: 600 10px var(--ui);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
#ambience-panel .ap-slider-row { display: flex; align-items: center; gap: 8px; margin-top: 9px; }
#ambience-panel .ap-slider-row span {
  font: 600 10px var(--ui);
  color: var(--ink-faint);
  letter-spacing: .06em;
}
#ambience-panel .ap-slider-row input[type="range"] { flex: 1; accent-color: var(--rose); cursor: pointer; }
#ambience-panel .ap-glass-val { color: var(--rose); min-width: 30px; text-align: right; }
#ambience-panel .ap-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#ambience-panel .ap-thumb {
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  overflow: hidden;
  cursor: pointer;
  background: none;
  transition: border-color var(--e-quick);
}
#ambience-panel .ap-thumb img { display: block; width: 52px; height: 34px; object-fit: cover; }
#ambience-panel .ap-thumb:hover { border-color: var(--rose); }
#ambience-panel .ap-thumb.on { border-color: var(--rose); box-shadow: 0 0 0 1px var(--rose); }
#ambience-panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: var(--t-md);
  color: var(--ink);
}
#ambience-panel .toggle {
  width: 36px; height: 20px;
  border-radius: var(--r-pill);
  background: rgba(0,0,0,.10);
  position: relative;
  cursor: pointer;
  transition: background var(--e-quick);
}
#ambience-panel .toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform var(--e-quick);
}
#ambience-panel .toggle.on { background: var(--rose); }
#ambience-panel .toggle.on::after { transform: translateX(16px); }

/* Dark parity */
body[data-scheme="dark"] #ambience-panel .ap-x:hover,
body.night #ambience-panel .ap-x:hover { background: rgba(255,255,255,.08); }
body[data-scheme="dark"] #ambience-panel .chip:hover,
body.night #ambience-panel .chip:hover { color: var(--rose); }
body[data-scheme="dark"] #ambience-panel .toggle,
body.night #ambience-panel .toggle { background: rgba(255,255,255,.14); }

/* ============================================================
   Statusbar — subtle divider before the shortcut hints.
   ============================================================ */

#statusbar .hint {
  padding-left: var(--s-3);
  margin-left: 0;
}
#statusbar .hint + .hint {
  border-left: 1px solid var(--line);
  margin-left: var(--s-2);
}

/* ============================================================
   Small polish — align the wordmark with the input baseline.
   Tighter than a translateY hack; use flex align.
   ============================================================ */
#topbar {
  align-items: center;
  gap: var(--s-3);
}
#doctitle {
  font-family: var(--ui);
  font-size: var(--t-md);
  font-style: normal;
  font-weight: 500;
  letter-spacing: 0;
  padding: 7px 2px;
  border-radius: 0;
}

/* ============================================================
   Header: one language. Same type, no nested boxes, one fill.
   Groups are spacing. Save and the active element are the fills.
   ============================================================ */

#toolbar .tgroup,
body[data-key] #toolbar .tgroup {
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
  gap: 2px;
}

#wpcluster .tbtn {
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: 0;
  line-height: 1;
  border-radius: var(--r-1);
}
#wpcluster #t-bold { font-weight: 700; }
#wpcluster #t-italic { font-style: normal; }
#wpcluster #t-italic span {
  display: inline-block;
  font-style: normal;
  font-weight: 600;
  transform: skewX(-12deg);
}
#wpcluster #t-under {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

#topbar #btn-file,
#topbar #btn-more,
#topbar #btn-ambience,
#topbar #btn-paper,
#topbar #btn-wptoggle {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: transparent;
  box-shadow: none;
}
#btn-file.saved-flash {
  border-color: var(--rose);
  background: color-mix(in srgb, var(--rose) 22%, transparent);
}

/* #toolbar is gone from the DOM. If a leftover node reappears, take no vertical space. */
#toolbar { display: none !important; height: 0; margin: 0; padding: 0; border: 0; overflow: hidden; }

/* Element types live in the footer as quiet status, not a header mode bar. */
#statusbar #t-elements {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 0;
  background: none;
  padding: 0;
  box-shadow: none;
}
#statusbar .tbtn.el {
  font-family: var(--ui);
  font-size: 10px;
  font-weight: 500;
  font-style: normal;
  letter-spacing: .02em;
  line-height: 1;
  padding: 3px 6px;
  border: 0;
  border-radius: var(--r-1);
  background: none;
  box-shadow: none;
  color: inherit;
  opacity: .45;
  text-transform: none;
}
#statusbar .tbtn.el:hover {
  background: transparent;
  opacity: .8;
}
#statusbar .tbtn.el.on,
body[data-key] #statusbar .tbtn.el.on {
  background: none;
  box-shadow: none;
  color: inherit;
  opacity: 1;
  font-weight: 600;
}
