:root {
  --bg: #12100e;
  --panel: #1c1915;
  --panel-2: #26221c;
  --ink: #f4ece1;
  --muted: #9a8f80;
  --line: #3c342b;
  --accent: #e0a04a;
  --accent-2: #c45c32;
  --good: #7d9a62;
  --warn: #c9a227;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --font: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(224, 160, 74, 0.25);
}
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
a { color: var(--accent); text-decoration: none; touch-action: manipulation; }
a:hover { text-decoration: underline; }
button, .btn, [role="button"] { touch-action: manipulation; }
code { font-size: 0.92em; background: rgba(255,255,255,0.06); padding: 0.1em 0.35em; border-radius: 4px; }
img { max-width: 100%; display: block; }

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail {
  padding: 1.4rem 1.1rem;
  border-right: 1px solid var(--line);
  background: #16130f;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.rail-top { flex: 1; min-height: 0; overflow-y: auto; }
.brand { display: flex; gap: 0.7rem; align-items: center; color: inherit; text-decoration: none; margin-bottom: 1.6rem; }
.brand-mark { width: 2.2rem; height: 2.2rem; display: grid; place-items: center; background: var(--accent); color: #1a1208; font-weight: 700; border-radius: 6px; }
.brand strong { display: block; letter-spacing: 0.02em; }
.brand em { display: block; font-style: normal; color: var(--muted); font-size: 0.8rem; }
.rail nav { display: flex; flex-direction: column; gap: 0.25rem; }
.rail nav a { color: var(--ink); padding: 0.45rem 0.6rem; border-radius: 6px; }
.rail nav a.on, .rail nav a:hover { background: var(--panel-2); text-decoration: none; }
.rail-note { color: var(--muted); font-size: 0.72rem; word-break: break-all; margin-top: 1.5rem; }
.rail-signin-hint {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.rail-account {
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.rail-account-details { position: relative; }
.rail-account-trigger {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  width: 100%;
  padding: 0.55rem 0.45rem;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  list-style: none;
}
.rail-account-trigger::-webkit-details-marker { display: none; }
.rail-account-trigger:hover,
.rail-account-details[open] > .rail-account-trigger {
  background: var(--panel-2);
  text-decoration: none;
}
.rail-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #1a1208;
  font-weight: 700;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.rail-avatar-guest {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px dashed var(--line);
}
.rail-account-text {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
  text-align: left;
}
.rail-account-text strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-account-text em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-account-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.35rem);
  display: grid;
  gap: 0.15rem;
  padding: 0.35rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 20;
}
.rail-account-link {
  display: block;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.85rem;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.rail-account-link:hover { background: var(--panel-2); text-decoration: none; }
.rail-account-menu form { margin: 0; }

.stage { padding: 1.6rem 2rem 3rem; max-width: 1800px; width: 100%; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1.4rem; }
.page-head h1 { display: flex; align-items: center; gap: 0.55rem; font-family: var(--serif); font-weight: 500; margin: 0 0 0.35rem; font-size: 2rem; }
.status-light {
  display: inline-block;
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  border-radius: 50%;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
  vertical-align: middle;
}
.status-light-ok { background: #6fbf6a; }
.status-light-stale { background: #e3c04a; }
.status-light-missing { background: #d4544a; }
.status-light-ready { background: #6fbf6a; }
.status-light-warning { background: #e3c04a; }
.status-light-broken { background: #d4544a; }
.status-light-lettering-stale {
  background: linear-gradient(90deg, #6fbf6a 50%, #e3c04a 50%);
}
.iteration-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.85rem; }
.iteration-row { border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 0.85rem; }
.iteration-head { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; margin-bottom: 0.35rem; }
.iteration-edit .row, .iteration-add .row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.iteration-edit label, .iteration-add label { display: block; margin: 0.45rem 0; }
.lineage-summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 0.85rem;
}
.reader-leaf-caption .status-light { margin-right: 0.35rem; }
.sheet td:first-child { width: 1.5rem; text-align: center; }
.lede, .hint, .muted, .kicker { color: var(--muted); }
.lede { margin: 0; max-width: 52rem; line-height: 1.45; }
.kicker { margin: 0 0 0.3rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.hint { font-size: 0.85rem; }

.btn { appearance: none; border: 0; background: var(--accent); color: #1a1208; font: inherit; font-weight: 600; padding: 0.5rem 0.85rem; border-radius: 6px; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.accent { background: var(--accent-2); color: #fff; }
.btn.small { font-size: 0.8rem; padding: 0.3rem 0.55rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.head-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; }
.page-flip { display: flex; align-items: center; gap: 0.5rem; }
.page-flip-btn { white-space: nowrap; }
.page-flip-btn:hover { text-decoration: none; }
.page-flip-btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
.page-flip-count { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.scene-nav { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.scene-nav-btn { white-space: nowrap; }
.scene-nav-btn:hover { text-decoration: none; }
.scene-nav-btn.disabled { opacity: 0.4; pointer-events: none; }
.scene-nav-btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
.scene-nav-count { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.scene-nav .btn.ghost { padding: 0.4rem 0.8rem; }

.sheet { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
.sheet-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}
.sheet th, .sheet td { text-align: left; padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--line); }
.sheet th { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.05em; text-transform: uppercase; }
.scene-row { position: relative; cursor: pointer; }
.scene-row:hover td,
.scene-row:active td { background: rgba(255, 255, 255, 0.03); }
.scene-row .row-link {
  display: inline-block;
  min-width: 2.75rem;
  min-height: 2.75rem;
  line-height: 2.75rem;
  text-align: center;
}
.scene-row .row-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
}
.scene-row td > *:not(a):not(button) { pointer-events: none; }
.scene-row .btn,
.scene-row button,
.scene-row a:not(.row-link) {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}
.scene-cards {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0.65rem;
}
.scene-card {
  display: grid;
  gap: 0.45rem;
  padding: 0.95rem 1rem;
  min-height: 3.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
}
.scene-card:hover,
.scene-card:active {
  background: var(--panel-2);
  text-decoration: none;
}
.scene-card-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.scene-card-number {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.scene-card-heading {
  line-height: 1.35;
  font-family: var(--serif);
}
.scene-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.scene-card-counts { color: var(--muted); }
.clip { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 0.75rem; }
.pill.good { background: rgba(125, 154, 98, 0.2); color: #c5d8b0; }
.pill.warn { background: rgba(201, 162, 39, 0.18); color: #e6d08a; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.7rem; }
.card h2, .card h3 { margin: 0 0 0.7rem; font-family: var(--serif); font-weight: 500; }
.mini { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0.8rem 0 0.35rem; }
.inventory-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.integrity-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin: 0 0 1rem; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.75rem 1rem; margin-bottom: 0.5rem; }
.settings-form h2 { margin-top: 1.2rem; }
.settings-form h2:first-child { margin-top: 0; }
.integrity-grid .card h2 { font-size: 1.05rem; }
.inventory-sort { display: flex; flex-direction: column; gap: 0.3rem; min-width: 12rem; color: var(--muted); font-size: 0.85rem; }
.inventory-sort select { margin-top: 0; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list-head,
.item-list li a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.6rem 4.2rem 3.4rem;
  gap: 0.45rem 0.55rem;
  align-items: baseline;
}
.item-list-head {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 0 0.35rem;
  border-bottom: 1px solid var(--line);
}
.item-list-head span:not(:first-child),
.item-list .item-appears,
.item-list .item-mentions,
.item-list .count { text-align: right; font-variant-numeric: tabular-nums; }
.item-list li a { color: inherit; padding: 0.45rem 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.item-list .item-name { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: baseline; min-width: 0; }
.item-list .count { margin-left: 0; color: var(--muted); font-size: 0.8rem; }
.item-list .item-appears,
.item-list .item-mentions { color: var(--muted); font-size: 0.8rem; }
.appearance-scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.appearance-scenes h3 { margin: 0 0 0.35rem; font-size: 1rem; font-family: var(--serif); font-weight: 500; }
.appearance-shots { list-style: none; margin: 0; padding: 0; }
.appearance-shots li a { display: block; padding: 0.28rem 0; border-bottom: 1px solid var(--line); color: inherit; }
.appearance-shots li a:hover { color: var(--accent); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

label { display: block; margin: 0 0 0.8rem; color: var(--muted); font-size: 0.85rem; }
input, textarea { width: 100%; margin-top: 0.3rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.65rem; font: inherit; }
textarea { resize: vertical; line-height: 1.45; }
.upload { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.ref-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.8rem; }
.ref-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #000; cursor: zoom-in; }
.ref-tile { display: grid; gap: 0.45rem; }
.ref-tile.is-default img { outline: 2px solid var(--accent); outline-offset: 2px; }

.prose { line-height: 1.55; }
.prose.paper { background: #f3ead9; color: #2a231b; padding: 1.4rem 1.6rem; border-radius: 10px; }
.prose.paper a { color: #8a4b16; }
.prose h1, .prose h2, .prose h3 { font-family: var(--serif); }
.facts { display: grid; gap: 0.35rem; }
.facts div { display: flex; justify-content: space-between; gap: 1rem; }
.facts dt { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0; padding: 0; }
.chips a { background: var(--panel-2); color: var(--ink); padding: 0.2rem 0.55rem; border-radius: 999px; }

.tabs { display: flex; gap: 0.3rem; margin: 0 0 1.1rem; border-bottom: 1px solid var(--line); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs a { color: var(--muted); padding: 0.55rem 0.8rem; border-bottom: 2px solid transparent; white-space: nowrap; flex: 0 0 auto; min-height: 2.75rem; display: inline-flex; align-items: center; }
.tabs a.on { color: var(--ink); border-color: var(--accent); text-decoration: none; }
.md-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.md-edit .paper { max-height: 70vh; overflow: auto; }
/* A whole markdown document, so keep it scrollable rather than page-length. */
.md-edit .token-input { max-height: 70vh; font-size: 0.86rem; }

.stepper {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
  width: 100%;
}
.stepper:has(> .shot-nav) {
  grid-template-columns: minmax(13rem, 16rem) minmax(0, 1fr);
}
.shot-nav {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0 0.4rem;
  min-width: 13rem;
}
.shot-nav-label {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.shot-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0.85rem 0.45rem;
}
.shot-nav-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.shot-nav-select-all input { margin: 0; }
.shot-nav-bulk {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0 0.65rem 0.55rem;
  padding: 0.55rem 0.65rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.shot-nav-bulk-count { font-size: 0.78rem; color: var(--muted); }
.shot-nav-bulk-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.shot-nav ul { list-style: none; margin: 0; padding: 0; }
.shot-nav li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
}
.shot-nav-check {
  display: flex;
  align-items: center;
  padding: 0 0 0 0.65rem;
  cursor: pointer;
}
.shot-nav-checkbox { margin: 0; }
.shot-nav-item { display: grid; grid-template-columns: 2.6rem 1fr; gap: 0.45rem; align-items: center; padding: 0.4rem 0.75rem 0.4rem 0.35rem; color: inherit; text-decoration: none; font-size: 0.86rem; border-left: 3px solid transparent; }
.shot-nav-item:hover { background: rgba(255, 255, 255, 0.04); text-decoration: none; }
.shot-nav-item.on { background: var(--panel-2); border-left-color: var(--accent); }
.shot-nav-n { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); font-variant-numeric: tabular-nums; justify-self: end; }
.shot-nav-item.on .shot-nav-n { color: var(--accent); }
.shot-nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper-main { min-width: 0; }
.shot { min-width: 0; }
.shot-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.shot-bar h2 { display: flex; align-items: center; gap: 0.45rem; margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.25rem; }
.shot-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(22rem, 28rem);
  gap: 1.15rem;
  align-items: start;
  width: 100%;
}
.shot-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  min-width: 0;
}
.shot-pane { min-width: 0; padding: 0.75rem; }
.shot-pane img[data-lightbox] { cursor: zoom-in; }
.shot-pane-label {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.shot-compare.is-pending [data-pane="new"] {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
.shot-meta { position: sticky; top: 1rem; min-width: 0; }
.shot-meta input, .shot-meta textarea { min-width: 0; }
.shot-actions { margin-top: 0.2rem; flex-wrap: wrap; }
.shot-save-status { margin: 0.35rem 0 0; min-height: 1.1em; }
.shot-progress {
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.shot-progress-bar {
  height: 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.shot-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s linear;
}
.shot-progress.is-ok .shot-progress-fill { background: var(--good); }
.shot-progress.is-error .shot-progress-fill { background: var(--accent-2); }
.shot-progress.is-overtime .shot-progress-fill {
  animation: shot-progress-pulse 1.2s ease-in-out infinite;
}
.shot-progress-status {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.shot-progress-copy {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}
.shot-progress-detail {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}
.shot-progress-stages {
  margin-top: 0.55rem;
}
.shot-progress-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}
.shot-progress-image {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.12rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.shot-progress-image.is-active {
  border-color: var(--accent);
  color: var(--text);
}
.shot-progress-image.is-done {
  border-color: color-mix(in srgb, var(--good) 55%, var(--line));
  color: #c5d8b0;
}
.shot-progress-image.is-error {
  border-color: var(--accent-2);
  color: #e8b4a4;
}
.shot-progress-image.is-active::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  animation: shot-progress-pulse 1.2s ease-in-out infinite;
}
.shot-progress.is-cancelled .shot-progress-fill { background: var(--muted); }
.shot-progress-spinner {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: shot-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
@keyframes shot-spin {
  to { transform: rotate(360deg); }
}
@keyframes shot-progress-pulse {
  50% { opacity: 0.5; }
}
.art { min-width: 0; padding: 0.75rem; }
.art img {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 11rem);
  object-fit: contain;
  border-radius: 8px;
  background: #000;
}
.art figcaption { margin: 0.45rem 0 0; color: var(--muted); font-size: 0.8rem; }
.placeholder { min-height: min(52vh, 28rem); display: grid; place-items: center; background: repeating-linear-gradient(-45deg, #1a1713, #1a1713 8px, #221e18 8px, #221e18 16px); color: var(--muted); border-radius: 8px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.page-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem; cursor: pointer; }
.page-card:hover { border-color: var(--accent); }
.page-card:has(.page-card-link:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.page-card-link { color: inherit; text-decoration: none; }
.page-card-link:hover { text-decoration: none; }
.page-card-link::after { content: ""; position: absolute; inset: 0; z-index: 0; border-radius: 10px; }
.page-card a:not(.page-card-link),
.page-card button { position: relative; z-index: 1; }
.page-card .page-placeholder .slot { z-index: 1; }
.page-card header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.45rem; }
.page-card-heading { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.page-card .status-light { position: relative; z-index: 1; }
.page-card img { width: 100%; aspect-ratio: 13 / 7.5; object-fit: cover; background: #000; border-radius: 6px; }

.pages-sheet { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: 1.2rem; align-items: start; }
.pages-main { min-width: 0; }
.layout-chat { position: sticky; top: 1rem; }
.layout-chat h2 { margin: 0 0 0.25rem; }
.layout-chat > .hint { margin: 0 0 0.75rem; }
.chat-log { display: flex; flex-direction: column; gap: 0.55rem; max-height: 42vh; overflow: auto; margin: 0 0 0.85rem; min-height: 4rem; }
.chat-msg { padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.9rem; white-space: pre-wrap; line-height: 1.4; }
.chat-user { background: var(--panel-2); align-self: flex-end; max-width: 95%; }
.chat-assistant { background: #16130f; border: 1px solid var(--line); max-width: 95%; }
.chat-error-msg { border-color: var(--accent-2); color: #e8b4a4; }
.chat-status { margin: 0; color: var(--accent); font-size: 0.85rem; }
.chat-error { margin: 0.45rem 0 0; color: #e8b4a4; font-size: 0.85rem; }
.layout-chat.is-working [data-chat-send] { opacity: 0.55; }
.layout-chat .token-input {
  min-height: 0;
  max-height: 12rem;
  font-size: 0.9rem;
  line-height: 1.4;
}
.layout-chat .token-input.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}
.layout-chat .chat-msg .token-chip { font-size: 0.85em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.unused-shots { margin-top: 1.4rem; }
.unused-shots header { margin-bottom: 0.7rem; }
.unused-shots h2 { margin: 0 0 0.2rem; font-family: var(--serif); font-weight: 500; }
.unused-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
.unused-item { position: relative; min-width: 0; }
.unused-delete {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 2;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(28, 25, 21, 0.92);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.unused-delete:hover { background: var(--accent-2); border-color: var(--accent-2); color: #1a1210; }
.unused-card { display: grid; gap: 0.35rem; color: inherit; text-decoration: none; background: var(--panel); border: 1px dashed var(--warn); border-radius: 10px; padding: 0.5rem; }
.unused-card:hover { text-decoration: none; border-color: var(--accent); }
.unused-card img, .unused-card .placeholder { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; min-height: 0; }
.unused-card .placeholder { min-height: 0; font-size: 0.75rem; }
.unused-card .badge { display: inline-block; width: max-content; padding: 0.12rem 0.45rem; border-radius: 999px; background: rgba(201, 162, 39, 0.18); color: #e6d08a; font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase; }
.unused-card strong { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.available-layouts { margin-top: 1.4rem; }
.available-layouts header { margin-bottom: 0.7rem; }
.available-layouts h2 { margin: 0 0 0.2rem; font-family: var(--serif); font-weight: 500; }
.layout-catalog { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; }
.layout-card { display: grid; gap: 0.4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem; }
.layout-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.layout-card p { margin: 0; }
.layout-diagram { pointer-events: none; }
.layout-diagram .slot { font-size: 0.65rem; }

.page-placeholder { position: relative; aspect-ratio: 13 / 7.5; background: #0c0b0a; border-radius: 6px; overflow: hidden; }
.page-placeholder .slot { position: absolute; border: 1px solid #4a4034; background: #16130f; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 0.7rem; }
.page-placeholder a.slot { color: inherit; text-decoration: none; z-index: 1; }
.page-placeholder a.slot:hover { border-color: var(--accent); text-decoration: none; color: var(--ink); }
.page-placeholder .slot img { width: 100%; height: 100%; object-fit: cover; }
.page-placeholder .slot.is-empty { border-style: dashed; color: #8a8074; }
.page-placeholder .slot.is-pending { border-color: #6a5f52; }
.page-placeholder .slot-label { padding: 0.15rem 0.35rem; text-align: center; line-height: 1.2; }
/* A shaped slot is clipped to its frame outline, so a label centred in the
   slot box lands in the removed corner and gets cut off. --label-x/y put it
   on the shape's own centroid instead. */
.page-placeholder .slot.is-shaped { place-items: start; }
.page-placeholder .slot.is-shaped > span {
  position: absolute;
  left: var(--label-x, 50%);
  top: var(--label-y, 50%);
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
/* Catalogue thumbnails are ~145px wide, so a panel name only fits a shaped
   slot's roomiest band at a smaller size. */
.layout-diagram .slot.is-shaped > span { font-size: 0.5rem; }
.page-live { width: 100%; }
.crop-lock { display: flex; justify-content: flex-end; margin: 0 0 0.5rem; }
.crop-lock .btn.is-unlocked { border-color: var(--accent); color: var(--accent); }
[data-crop-locked="1"] .page-live .slot-pan,
[data-crop-locked="1"] .crop-viewport { cursor: pointer; touch-action: auto; }
.page-live .slot-pan { cursor: grab; touch-action: none; user-select: none; }
.page-live .slot-pan.is-panning,
.crop-viewport.is-panning { cursor: grabbing; }
.page-live .crop-viewport {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
}
.crop-viewport img.is-crop,
.page-placeholder .slot img.is-crop {
  width: auto;
  height: auto;
  max-width: none;
  object-fit: fill;
}
.page-live .slot-contain img { object-fit: contain; }
.last-render { margin: 0; }
.last-render figcaption { margin-bottom: 0.4rem; font-size: 0.8rem; }
.frame-shot-link { display: block; color: inherit; text-decoration: none; }
.frame-shot-link:hover { text-decoration: none; }
.frame-shot-link:hover .placeholder { color: var(--ink); }

.dialog { width: min(1280px, 96vw); max-height: 92vh; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem 1.3rem; }
.dialog::backdrop { background: rgba(0,0,0,0.65); }
.dialog-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; }
.prompt-dialog { width: min(1100px, 96vw); height: min(88vh, 52rem); max-height: 88vh; padding: 0; flex-direction: column; }
.prompt-dialog[open] { display: flex; }
.prompt-dialog .dialog-head { margin: 0; padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--line); align-items: center; }
.prompt-dialog .dialog-head h2 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.prompt-dialog .dialog-head .row { margin-left: auto; flex-shrink: 0; }
.prompt-dialog-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.prompt-dialog-refs {
  flex: 0 0 auto;
  padding: 0.75rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: #0e0c0a;
}
.prompt-dialog-refs[hidden] { display: none; }
.prompt-dialog-refs .mini { margin: 0 0 0.55rem; }
.prompt-dialog-ref-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.7rem;
  max-height: 16rem;
  overflow: auto;
}
.prompt-dialog-ref-list figure { margin: 0; position: relative; }
.prompt-ref-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}
.prompt-ref-remove:hover { background: #8b2e2e; }
.prompt-dialog-foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--line);
  background: #0e0c0a;
}
.prompt-dialog-foot .hint { margin: 0; }
.prompt-dialog-foot .row { margin-left: auto; }
.prompt-dialog-ref-list img,
.prompt-dialog-ref-missing {
  width: 100%;
  height: 7.5rem;
  object-fit: contain;
  border-radius: 6px;
  background: #000;
  border: 1px solid var(--line);
}
.prompt-dialog-ref-list img { cursor: zoom-in; }

.lightbox {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 5vh 5vw;
  border: 0;
  background: transparent;
  color: var(--ink);
}
.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox::backdrop { background: rgba(0, 0, 0, 0.86); }
.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #000;
}
.lightbox-close {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(28, 25, 21, 0.92);
  color: var(--ink);
  font: inherit;
  font-size: 1.55rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: var(--panel-2); }
.prompt-dialog-ref-missing {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}
.prompt-dialog-ref-list figcaption {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
  word-break: break-word;
}
.prompt-dialog-body textarea {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  height: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  resize: none;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 1rem 1.15rem 1.5rem;
  background: #14110e;
  color: var(--ink);
}
.frame-detail-head { display: flex; flex-wrap: wrap; gap: 0.45rem 0.7rem; align-items: baseline; }
.frame-detail-head .btn { margin-left: auto; }
.page-detail { display: grid; gap: 1rem; }
.page-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: 1rem; align-items: start; }
.page-detail-art { min-width: 0; }
.page-editor [data-page-render-progress] {
  margin: -0.6rem 0 1.1rem;
}
.page-editor .lettering-dock { max-height: calc(100vh - 8rem); position: sticky; top: 1rem; }
.lettering-dock { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem 1rem 1.1rem; max-height: min(70vh, 36rem); overflow: auto; display: flex; flex-direction: column; }
.lettering-dock h2 { margin: 0 0 0.25rem; font-family: var(--serif); font-weight: 500; font-size: 1.15rem; }
.lettering-dock > .hint { margin: 0 0 0.85rem; }
.lettering-frame { margin: 0 0 1rem; }
.lettering-frame:last-child { margin-bottom: 0; }
.lettering-frame h3 { margin: 0 0 0.5rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.lettering-item { display: grid; gap: 0.4rem; margin: 0 0 0.65rem; padding: 0.7rem 0.75rem; background: #f3ead9; color: #2a231b; border: 1px solid #d7c9b0; }
.lettering-item header { display: flex; flex-wrap: wrap; gap: 0.35rem 0.55rem; align-items: baseline; }
.lettering-kind { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.lettering-who { font-weight: 650; }
.lettering-note { color: #6f6456; font-size: 0.8rem; }
.lettering-item textarea { margin-top: 0; background: rgba(255,255,255,0.72); color: inherit; border-color: #cbbba3; }
.lettering-item.caption { border-radius: 4px; background: #241e18; color: #f4ece1; border-color: #4a4034; }
.lettering-item.caption .lettering-note { color: var(--muted); }
.lettering-item.caption textarea { background: rgba(0,0,0,0.35); color: #f4ece1; border-color: #4a4034; }
.lettering-item.speech { border-radius: 18px; }
.lettering-item.thought { border-radius: 26px; border-style: dashed; }
.lettering-item.broadcast { border-radius: 8px; background: #e8e2d4; }
.lettering-item.sfx { border-radius: 6px; background: #f0d9b8; font-style: italic; }
.lettering-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.lettering-status { font-size: 0.8rem; color: #4d6a3d; }
.lettering-item.caption .lettering-status { color: #c5d8b0; }
.lettering-item.caption .btn.ghost { color: #f4ece1; border-color: #4a4034; }
.lettering-who-select {
  font: inherit;
  font-weight: 650;
  max-width: 10rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  border: 1px solid #cbbba3;
  background: rgba(255,255,255,0.85);
  color: inherit;
}
.lettering-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.55rem;
}
.lettering-add select {
  font: inherit;
  font-size: 0.8rem;
  max-width: 9rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}
.lettering-empty-hint { margin: -0.15rem 0 0.55rem; font-size: 0.78rem; }
.lettering-place { margin-top: 1.1rem; padding: 0.75rem 0 0; border-top: 1px solid var(--line); position: sticky; bottom: -1.1rem; background: var(--panel-2); z-index: 1; }
.lettering-place h3 { margin: 0 0 0.25rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.lettering-place select { margin-top: 0.25rem; max-width: 100%; }
.lettering-item.is-pinned { outline: 2px solid var(--accent); outline-offset: 1px; }
.page-full { width: 100%; border-radius: 8px; background: #000; }
.crop-viewport { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: #000; border-radius: 8px; cursor: grab; user-select: none; touch-action: none; }
.crop-viewport img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.flashes { list-style: none; padding: 0; margin: 0 0 1rem; }
.flashes li { background: rgba(224, 160, 74, 0.15); border: 1px solid var(--accent); padding: 0.5rem 0.75rem; border-radius: 8px; }
.empty { color: var(--muted); padding: 2rem 0; }
.llm-check-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.55rem; }
.llm-check-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 0.35rem 0.75rem; align-items: center; padding: 0.65rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.llm-check-row .clip { grid-column: 1 / -1; }
.llm-check-row .muted:last-child { justify-self: end; }
.job-toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 0.8rem 0.85rem 0.8rem 1rem;
  border-radius: 10px;
  max-width: 28rem;
  box-shadow: var(--shadow);
  z-index: 40;
}
.job-toast.hidden { display: none; }
.job-toast-message { flex: 1; min-width: 0; white-space: pre-wrap; line-height: 1.4; }
.job-toast-dismiss {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.15rem 0.45rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.job-toast-dismiss:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }

.confirm-dialog {
  width: min(36rem, 94vw);
  max-height: 90vh;
  padding: 0;
  flex-direction: column;
}
.confirm-dialog[open] { display: flex; }
.confirm-dialog .dialog-head {
  margin: 0;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.confirm-dialog .dialog-head h2 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.confirm-dialog-body {
  padding: 1rem 1.1rem 1.15rem;
  display: grid;
  gap: 1rem;
  min-height: 0;
  overflow: auto;
}
.warn-copy {
  margin: 0;
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(201, 162, 39, 0.12);
  border-radius: 8px;
  color: #e6d08a;
  line-height: 1.45;
}
.images-confirm-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.images-confirm-target {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.check {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
}
.check input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.15rem 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.check span { display: grid; gap: 0.25rem; min-width: 0; }
.check strong { color: var(--ink); font-weight: 650; }
.check em { color: var(--muted); font-style: normal; font-size: 0.82rem; line-height: 1.4; }
.job-progress-bar {
  height: 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.job-progress-bar > div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.28s ease;
}
.job-progress-bar.is-ok > div { background: var(--good); }
.job-progress-bar.is-error > div { background: var(--accent-2); }
.job-progress-step { margin: 0; font-weight: 600; line-height: 1.4; }
.job-stages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.job-stages li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 0.88rem;
}
.job-stages li.is-active { border-color: var(--accent); }
.job-stages li.is-done { color: #c5d8b0; }
.job-stages li.is-error { border-color: var(--accent-2); color: #e8b4a4; }
.job-stages .job-stage-meta { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.job-log-wrap summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
}
.job-log-wrap pre {
  margin: 0.5rem 0 0;
  max-height: 12rem;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.4;
  background: #14110e;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.job-log-path {
  margin: 0.45rem 0 0;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
}

body.reader-mode .stage {
  max-width: none;
  padding: 1rem 1.4rem 1.5rem;
}
.reader {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: calc(100vh - 2.5rem);
}
.reader-toolbar {
  flex: 0 0 auto;
}
.reader-toolbar-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.reader-toolbar h1 {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0;
  font-size: 1.85rem;
}
.reader-meta { margin: 0.25rem 0 0; color: var(--muted); }
.reader-board {
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "prev spread next"
    ".    pos    .";
  align-items: center;
  column-gap: 0.55rem;
  row-gap: 0.4rem;
  min-height: 0;
  width: 100%;
}
.reader-flip-prev { grid-area: prev; }
.reader-flip-next { grid-area: next; }
.reader-counter {
  grid-area: pos;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}
.reader-flip {
  justify-self: center;
  align-self: center;
  /* Caption row sits above each leaf; nudge so the control lines up with the art. */
  margin-top: 1.6rem;
  min-width: 6.75rem;
  min-height: 2.75rem;
  padding: 0.65rem 0.8rem;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}
.reader-flip:hover { text-decoration: none; }
.reader-flip[aria-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}
.reader-spread {
  grid-area: spread;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.55rem;
  width: 100%;
  min-width: 0;
  background: #0a0908;
  padding: 0.45rem 0.55rem 0.55rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.reader-slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.reader-slot:hover { text-decoration: none; }
.reader-slot.is-blank { cursor: default; }
.reader-leaf-caption {
  display: block;
  min-height: 1.35rem;
  margin: 0 0 0.28rem;
  padding: 0 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-leaf-caption.is-empty { visibility: hidden; }
.reader-leaf {
  display: block;
  aspect-ratio: 13 / 7.5;
  min-width: 0;
  background: #14110e;
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  position: relative;
}
.reader-leaf[data-leaf="left"] {
  border-right: 3px solid #1c1814;
  box-shadow: inset -10px 0 14px -10px rgba(0, 0, 0, 0.65);
}
.reader-leaf[data-leaf="right"] {
  border-left: 1px solid #2a241c;
  box-shadow: inset 10px 0 14px -10px rgba(0, 0, 0, 0.55);
}
.reader-leaf img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.reader-blank,
.reader-pending {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 1rem;
  background: linear-gradient(180deg, #16130f, #0e0c0a);
}
.reader-pending strong {
  display: block;
  color: var(--ink);
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.reader-keys { margin: 0; text-align: center; }
.reader-leaf.is-blank { cursor: default; }

@media (max-width: 1200px) {
  .shot-workspace { grid-template-columns: 1fr; }
  .shot-meta { position: relative; top: 0; }
  .art img { max-height: min(70vh, 36rem); }
  .shot-compare { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .inventory-grid, .integrity-grid, .split, .md-edit, .stepper, .page-detail-grid, .pages-sheet { grid-template-columns: 1fr; }
  .shot-nav { position: relative; top: 0; max-height: 12rem; min-width: 0; }
  .reader { min-height: 0; }
}
@media (max-width: 720px) {
  .stage { padding: 1rem 1rem 2rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 1.55rem; }
  .scene-cards { display: grid; }
  .scene-sheet-desktop { display: none; }
  .btn { min-height: 2.75rem; padding: 0.65rem 1rem; }
  .btn.small { min-height: 2.5rem; padding: 0.45rem 0.75rem; }
  .rail nav a { min-height: 2.75rem; display: flex; align-items: center; }
  .shot-nav-item { min-height: 2.75rem; padding-top: 0.55rem; padding-bottom: 0.55rem; }
  .shot-nav-check { min-width: 2.75rem; justify-content: center; }
  .shot-bar .btn { min-width: 2.75rem; }
  .scene-nav-btn { min-height: 2.75rem; display: inline-flex; align-items: center; }
  .shot-compare { grid-template-columns: 1fr; }
  .reader-board {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas:
      "spread spread spread"
      "prev pos next";
    align-items: stretch;
    column-gap: 0.45rem;
  }
  .reader-flip {
    margin-top: 0;
    justify-self: stretch;
    min-width: 0;
  }
  .reader-counter {
    align-self: center;
    font-size: 0.8rem;
    padding: 0 0.2rem;
  }
}
@media (max-width: 420px) {
  .reader-spread { grid-template-columns: 1fr; gap: 0.35rem; }
  .reader-leaf[data-leaf="left"],
  .reader-leaf[data-leaf="right"] {
    border: 0;
    box-shadow: none;
  }
}

.mention-menu {
  position: fixed;
  z-index: 80;
  min-width: 14rem;
  max-width: min(22rem, calc(100vw - 1.5rem));
  max-height: min(18rem, 50vh);
  overflow: auto;
  margin: 0;
  padding: 0.3rem 0;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.mention-menu[hidden] { display: none; }
.mention-group {
  padding: 0.4rem 0.7rem 0.2rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.mention-option {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.mention-option strong { font-weight: 650; }
.mention-option span { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-option.is-active,
.mention-option:hover { background: rgba(224, 160, 74, 0.16); }
/* Beats the grey ".mention-option span" rule above, which would otherwise
   wash out the chip text. Kind-specific colours still win, being later. */
.mention-option .token-chip { flex: 0 0 auto; color: #000; font-size: 0.9rem; }
.mention-option .mention-image { color: var(--muted); font-size: 0.78rem; }

/* Inventory references. A chip is one atomic @token. */
:root {
  --ref-character: #4cc2ff;
  --ref-location: #ff9ec7;
  --ref-prop: #a6e08a;
  --ref-panel: #8ec5ff;
  --ref-unknown: #d98b6a;
}
.token-chip {
  display: inline-block;
  border-radius: 4px;
  padding: 0 0.28em;
  color: #000;
  background: var(--panel-2);
  font-weight: 600;
  font-size: 0.94em;
  line-height: 1.35;
  white-space: nowrap;
  vertical-align: baseline;
  cursor: default;
  user-select: none;
}
.token-chip[data-kind="character"] { background: var(--ref-character); }
.token-chip[data-kind="location"] { background: var(--ref-location); }
.token-chip[data-kind="prop"] { background: var(--ref-prop); }
.token-chip[data-kind="panel"] { background: var(--ref-panel); }
.token-chip[data-kind="unknown"] {
  background: transparent;
  color: var(--ref-unknown);
  box-shadow: inset 0 0 0 1px var(--ref-unknown);
}
/* A token naming one specific picture rather than the item's usual one. */
.token-chip[data-image="1"] { box-shadow: inset 0 0 0 1px rgba(16, 14, 12, 0.55); }

.token-input {
  width: 100%;
  margin-top: 0.3rem;
  min-height: 2.1rem;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font: inherit;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-y: auto;
  cursor: text;
}
.token-input:focus {
  outline: none;
  border-color: var(--accent);
}
.token-input:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}
.token-input[data-multiline="0"] { white-space: pre; overflow-x: auto; }
.token-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.15rem 0 0.8rem;
  font-size: 0.74rem;
  color: var(--muted);
}
.token-legend .token-chip { font-size: 0.72rem; }

/* Lettering studio: drag balloons by hand over the bare page art. */
.letter-studio {
  margin: 0 0 1.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.letter-bar {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}
.letter-bar h2 { margin: 0 0 0.2rem; font-family: var(--serif); font-weight: 500; font-size: 1.15rem; }
.letter-bar .hint { margin: 0; max-width: 46rem; }
.letter-bar .actions { align-items: center; flex-shrink: 0; }
.letter-status { color: var(--muted); font-size: 0.82rem; }
.letter-status[data-tone="error"] { color: #e58b7b; }
.letter-status[data-tone="ok"] { color: var(--good); }

.letter-stage {
  position: relative;
  background: #0b0a09;
  touch-action: none;
  user-select: none;
}
.letter-stage img[data-letter-backdrop] { width: 100%; height: auto; }
.letter-bridges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.letter-bridges line { stroke: #14110d; stroke-opacity: 0.9; stroke-linecap: round; }
.letter-items { position: absolute; inset: 0; }

.letter-item {
  position: absolute;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: grab;
  color: #14110d;
  background: #fdfcf8;
  border: 2px solid #14110d;
  border-radius: 50%;
  padding: 0.1em 0.6em;
  overflow: hidden;
}
.letter-item.is-dragging { cursor: grabbing; }
.letter-item.is-active { box-shadow: 0 0 0 2px var(--accent); }
.letter-item.is-dirty { border-color: var(--accent-2); }
.letter-item[data-kind="thought"] { border-style: dashed; border-radius: 46%; }
.letter-item[data-kind="caption"],
.letter-item[data-kind="broadcast"] {
  border-radius: 4px;
  background: #16151a;
  color: #f4ece1;
  border-color: #efe9df;
  place-items: center start;
  text-align: left;
}
.letter-item[data-kind="broadcast"] { border-color: #f0b040; }
.letter-item[data-kind="sfx"] {
  background: transparent;
  border-style: dashed;
  border-color: rgba(196, 92, 50, 0.9);
  border-radius: 6px;
  color: #ce2018;
  font-weight: 700;
}
.letter-text {
  white-space: pre;
  pointer-events: none;
  font-family: "Comic Sans MS", "Marker Felt", var(--font);
}
.letter-item[data-family="caption"] .letter-text { font-family: Arial, Helvetica, var(--font); font-weight: 700; }
.letter-item[data-family="sfx-loud"] .letter-text { font-family: Impact, "Arial Black", var(--font); }
.letter-item[data-family="sfx"] .letter-text { font-family: "Bradley Hand", "Marker Felt", var(--font); font-weight: 700; }

.letter-grip {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  cursor: ew-resize;
  background: transparent;
}
.letter-grip::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 34%;
  min-height: 8px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
}
.letter-item:hover .letter-grip::after,
.letter-item.is-active .letter-grip::after { opacity: 0.9; }
.letter-grip[data-edge="left"] { left: -6px; }
.letter-grip[data-edge="right"] { right: -6px; }

.letter-tail {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #14110d;
  cursor: crosshair;
  z-index: 3;
}
.letter-tail-line { stroke: var(--accent); stroke-opacity: 0.75; stroke-dasharray: 6 5; }

.novel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }

.login-card { width: min(100%, 28rem); padding: 1.5rem; display: grid; gap: 0.85rem; }
.login-form { display: grid; gap: 0.75rem; }
.login-form label { display: grid; gap: 0.25rem; font-size: 0.9rem; }
.login-form input { padding: 0.45rem 0.55rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }
.form-stack { display: grid; gap: 0.75rem; }
.form-stack label { display: grid; gap: 0.25rem; }
.novel-row { margin: 0; }
.novel-pick-form { margin: 0; }
.novel-pick {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: inherit;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  font: inherit;
}
.novel-pick:hover { border-color: var(--accent); }
.novel-row.is-active .novel-pick {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(224, 160, 74, 0.35);
}
.novel-pick-main { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.35rem; }
.novel-pick-path { display: block; font-size: 0.78rem; color: var(--muted); word-break: break-all; }
.novel-row.is-active .pill { background: rgba(224, 160, 74, 0.18); color: var(--accent); }
.pill.muted { background: rgba(120, 120, 120, 0.18); color: var(--muted); }

.admin-user-row,
.admin-member-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.admin-user-row:last-child,
.admin-member-row:last-child { border-bottom: 0; }
.admin-user-main { display: grid; gap: 0.2rem; min-width: 12rem; flex: 1 1 14rem; }
.admin-user-meta { font-size: 0.82rem; color: var(--muted); }
.admin-user-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.admin-user-actions,
.admin-member-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.admin-inline-form summary { list-style: none; cursor: pointer; }
.admin-inline-form summary::-webkit-details-marker { display: none; }
.form-stack.compact { margin-top: 0.55rem; min-width: 14rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin: 0; }
.inline-form select {
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
}

.page-head-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.audit-table-wrap { overflow-x: auto; }
.audit-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.audit-table th,
.audit-table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.audit-table th { color: var(--muted); font-weight: 600; }
.audit-table code { font-size: 0.82rem; }
