:root {
  --bg: #121216;
  --panel: #1a1a20;
  --panel-2: #22222a;
  --panel-3: #2a2a34;
  --line: #2e2e38;
  --text: #e8e6e3;
  --muted: #9a97a0;
  --accent: #e0779a;
  --accent-2: #f0c060;
  --user: #8fb8e8;
  --world: #b9a8e0;
  --danger: #e57373;
  --radius: 10px;
  --column: 860px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body { display: flex; flex-direction: column; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

button, select, textarea, input { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1b0f14; font-weight: 600; }
button.danger { color: var(--danger); }
button.tiny { padding: 2px 9px; font-size: 12px; border-radius: 6px; }
.icon-button {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 2px 8px; font-size: 16px; line-height: 1.2;
}
.icon-button:hover:not(:disabled) { color: var(--text); border-color: var(--line); }

select, input[type="text"], textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 0;
}
textarea { resize: vertical; line-height: 1.45; }
input[type="text"]:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 8px; }

/* The reading column: everything in the room lines up on it. */
.column { max-width: var(--column); margin: 0 auto; width: 100%; }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { margin: 0 8px 0 0; font-size: 15px; letter-spacing: .18em; color: var(--accent-2); }
.view-tabs { display: flex; gap: 4px; margin-right: auto; background: var(--bg); padding: 3px; border-radius: 10px; border: 1px solid var(--line); }
.view-tab { background: none; border: none; border-radius: 7px; padding: 5px 14px; color: var(--muted); font-size: 14px; }
.view-tab[aria-pressed="true"] { background: var(--panel-3); color: var(--text); }
.view-tab:hover:not([aria-pressed="true"]) { color: var(--text); }
.project-picker select { min-width: 200px; max-width: 40vw; }
.usage-pill {
  font-size: 12px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}

/* --- story room layout --- */
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}
.layout.inspecting { grid-template-columns: 250px minmax(0, 1fr) var(--inspector-w, 340px); }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 16px 12px;
}
.sidebar-heading-row { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 0 8px; margin-bottom: 8px; }
.sidebar-heading {
  font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text); margin: 0;
}
.sidebar section + section { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }

.scene-list, .character-list { list-style: none; margin: 0; padding: 0; }

.scene-list button {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
  border-radius: 8px; padding: 8px 10px; line-height: 1.3;
}
.scene-list button:hover { background: var(--panel-2); }
.scene-list button.active { background: var(--panel-2); border-color: var(--line); color: var(--accent-2); }
.scene-list .branch { display: block; font-size: 12px; color: var(--muted); }

.character-list li + li { margin-top: 6px; }
.character-card {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.character-card.inspected { border-color: var(--c, var(--accent)); }
.character-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); flex-shrink: 0; }
.character-meta { min-width: 0; }
.character-meta strong { display: block; font-weight: 600; }
.character-meta small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inline-form { display: flex; flex-direction: column; gap: 8px; margin: 4px 4px 12px; }
.inline-form-row { display: flex; justify-content: flex-end; gap: 8px; }
.inline-form.compact { flex-direction: row; align-items: center; margin-top: 10px; }
.inline-form.compact select { flex: 1; min-width: 0; }

/* --- room --- */
.room { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty-state { flex: 1; display: grid; place-items: center; color: var(--muted); }
.scene-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.scene-header { padding: 20px 28px 14px; border-bottom: 1px solid var(--line); }
.scene-title-row { display: flex; align-items: center; gap: 6px; }
.scene-header h2 { margin: 0; font-size: 24px; letter-spacing: .01em; }
.scene-branch { margin: 4px 0 0; color: var(--accent-2); font-size: 13px; }
.scene-description { margin: 8px 0 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.scene-description:empty { display: none; }
.scene-edit-form { margin: 10px 0 0; }

.flow { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.flow-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.flow-label {
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); width: 92px; flex-shrink: 0;
}
.flow-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.flow-none { color: var(--muted); font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 4px 2px 4px; font-size: 14px;
}
.chip-go {
  background: none; border: none; padding: 3px 10px; color: var(--accent-2); cursor: pointer; font-weight: 600; border-radius: 999px;
}
.chip-go:hover { background: var(--panel-3); }
.chip-label { color: var(--muted); font-style: italic; font-size: 13px; max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-remove { background: none; border: none; color: var(--muted); padding: 0 8px; line-height: 1; font-size: 15px; }
.chip-remove:hover { color: var(--danger); }
.chip.in .chip-label { margin-right: 8px; }
.flow-form { flex-direction: row; flex-wrap: wrap; align-items: center; margin: 4px 0 0; }
.flow-form select { min-width: 180px; }
.flow-form input { flex: 1; min-width: 180px; }

/* --- story timeline --- */
.story-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.story { flex: 1; overflow-y: auto; padding: 24px 28px 8px; }
.story > * { max-width: var(--column); margin-left: auto; margin-right: auto; }

.event { position: relative; padding: 4px 0 2px; margin-bottom: 22px; }
.event-who {
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: 5px;
}
.event-text { line-height: 1.65; white-space: pre-wrap; font-size: 16px; }
.event.user .event-who { color: var(--user); }
.event.world .event-who { color: var(--world); }
.event.world .event-text { font-style: italic; color: #cfc8e6; }
.event.character { padding-left: 14px; border-left: 3px solid var(--c, var(--accent)); }
.event.character .event-who { color: var(--c, var(--accent)); }
.event.system .event-who { color: var(--muted); }
.event.action .event-text { font-style: italic; }
.event-empty { color: var(--muted); }

.event.settle { animation: settle 1.6s ease-out; border-radius: 6px; }
@keyframes settle {
  from { background: rgba(224, 119, 154, .16); }
  to { background: transparent; }
}

.event-tools { margin-top: 4px; min-height: 22px; }
.replay-button { opacity: 0; transition: opacity .12s; }
.event:hover .replay-button, .event:focus-within .replay-button, .replay-button:focus { opacity: 1; }
.replay-form { flex-direction: row; flex-wrap: wrap; align-items: center; margin: 6px 0 0; }
.replay-form input { flex: 1; min-width: 200px; }
.replay-note { font-size: 12px; color: var(--muted); width: 100%; }
@media (hover: none) { .replay-button { opacity: 1; } }

.jump-newest {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  border-radius: 999px; background: var(--panel-3); box-shadow: 0 4px 16px rgba(0,0,0,.4);
  font-size: 13px; padding: 6px 14px;
}

/* --- proposals: clearly not canon yet --- */
.proposals { padding: 0 28px; max-height: 42vh; overflow-y: auto; }
.proposal {
  max-width: var(--column); margin: 6px auto 14px; padding: 14px 16px;
  border: 2px dashed var(--c, var(--accent)); border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, rgba(255,255,255,.015) 0 10px, transparent 10px 20px), var(--panel);
}
.proposal-who { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c, var(--accent)); margin-bottom: 8px; }
.proposal-badge {
  font-size: 11px; letter-spacing: .1em; color: var(--bg); background: var(--c, var(--accent));
  border-radius: 4px; padding: 1px 6px;
}
.proposal-text { line-height: 1.65; white-space: pre-wrap; margin-bottom: 12px; color: #d6d3d0; font-size: 16px; }
.proposal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.proposal-editor {
  width: 100%; background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 8px; padding: 10px 12px; line-height: 1.55; margin-bottom: 6px;
}
.proposal-note { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

/* --- composer --- */
.composer { border-top: 1px solid var(--line); padding: 10px 28px 14px; background: var(--panel); }
.composer textarea {
  width: 100%; resize: none; min-height: 48px; max-height: 30vh; overflow-y: auto;
  border-radius: var(--radius); padding: 10px 12px;
}
.composer-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.turn-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.turn-label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.turn-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.turn-chip {
  display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 4px 12px 4px 10px;
  border-color: var(--c, var(--accent)); font-size: 14px;
}
.turn-chip .character-dot { width: 8px; height: 8px; }
.turn-chip:hover:not(:disabled) { background: var(--panel-3); border-color: var(--c, var(--accent)); }

/* --- inspector --- */
.inspector {
  border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 16px 16px 24px; min-width: 0;
}
.inspector-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.inspector-name { margin: 0; font-size: 18px; color: var(--c, var(--accent)); }
.inspector-role { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.inspector-role:empty { display: none; }
.inspector-tabs { display: flex; gap: 4px; margin: 14px 0 8px; border-bottom: 1px solid var(--line); }
.inspector-tab { font-size: 13px; font-weight: 600; padding: 6px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.inspector-tab.active { color: var(--text); border-bottom-color: var(--c, var(--accent)); }
.inspector-where { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.4; }
.memory-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.memory {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.memory-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.memory-stars { color: var(--accent-2); font-size: 12px; letter-spacing: 1px; }
.memory-stars .dim { color: var(--line); }
.memory-type { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.memory-text { line-height: 1.5; font-size: 14px; }
.memory-origin { margin-top: 6px; font-size: 12px; color: var(--muted); font-style: italic; }
.memory-empty { color: var(--muted); font-size: 14px; line-height: 1.5; }
.inspector-count { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* --- storyboard --- */
.board-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.board-toolbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.board-hint { color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }
.board-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.board-legend span::before { content: ""; display: inline-block; width: 26px; vertical-align: middle; margin-right: 6px; border-top: 2px solid var(--accent-2); }
.board-legend .legend-branch::before { border-top: 2px dashed var(--muted); }
.board-canvas {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #24242c 1px, transparent 1px);
  background-size: 22px 22px;
}
.board-sizer { position: relative; min-width: 100%; min-height: 100%; }
.board-surface { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.board-edges { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.board-edges .edge-flow { stroke: var(--accent-2); stroke-width: 2; fill: none; }
.board-edges .edge-branch { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 6 5; fill: none; }
.board-edges .edge-draft { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4; fill: none; }
.board-edges .edge-label { fill: var(--muted); font-size: 12px; font-style: italic; }

.edge-remove {
  position: absolute; transform: translate(-50%, -50%); width: 22px; height: 22px; padding: 0;
  border-radius: 50%; font-size: 13px; line-height: 1; color: var(--muted); background: var(--panel-2);
  opacity: .0; transition: opacity .12s;
}
.edge-remove:hover, .edge-remove:focus { opacity: 1; color: var(--danger); border-color: var(--danger); }
.board-canvas:hover .edge-remove { opacity: .7; }
@media (hover: none) { .edge-remove { opacity: .8; } }

.scene-card {
  position: absolute; width: 210px; padding: 12px 14px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  cursor: grab; touch-action: none; user-select: none;
}
.scene-card:hover { border-color: var(--muted); }
.scene-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scene-card.current { border-color: var(--accent-2); }
.scene-card.dragging { cursor: grabbing; box-shadow: 0 12px 30px rgba(0,0,0,.55); z-index: 5; }
.scene-card.link-target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,119,154,.35); }
.scene-card.branch { border-style: dashed; }
.card-title { font-weight: 700; font-size: 15px; letter-spacing: .02em; text-transform: uppercase; margin-bottom: 2px; padding-right: 14px; }
.card-branch { font-size: 12px; color: var(--accent-2); margin-bottom: 4px; }
.card-desc {
  font-size: 13px; color: var(--muted); line-height: 1.4; margin: 4px 0 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.card-people { display: flex; gap: 4px; flex-wrap: wrap; }
.card-person { display: inline-flex; align-items: center; gap: 4px; }
.card-person .character-dot { width: 7px; height: 7px; }
.card-open { padding: 2px 10px; font-size: 12px; }
.card-handle {
  position: absolute; right: -8px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%; padding: 0;
  background: var(--accent); border: 3px solid var(--bg); cursor: crosshair; touch-action: none;
}
.card-handle:hover { transform: translateY(-50%) scale(1.25); }

/* --- character creator --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,5,8,.7); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto;
}
.modal {
  width: min(680px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); display: flex; flex-direction: column; max-height: 92vh;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field > span b { color: var(--accent); font-weight: 600; }
.field input, .field textarea { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  cursor: text;
}
.tag-input:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.tag-input input { flex: 1; min-width: 140px; border: none; background: none; padding: 3px 4px; outline: none !important; }
.tag {
  display: inline-flex; align-items: center; gap: 2px; background: var(--panel-3); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 13px;
}
.tag button { background: none; border: none; padding: 0 6px; color: var(--muted); font-size: 14px; line-height: 1; }
.tag button:hover { color: var(--danger); }
.tag-hint { font-size: 12px; color: var(--muted); }

/* --- 0016A: scene menu, delete panel, inspector actions, edit warning --- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: 100%; left: 0; z-index: 30; min-width: 200px; margin-top: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; flex-direction: column;
}
.menu button { background: none; border: none; text-align: left; padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.menu button:hover { background: var(--panel-3); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }

.delete-panel {
  margin-top: 12px; padding: 14px 16px; border: 1px solid var(--danger); border-radius: var(--radius);
  background: rgba(229, 115, 115, .07);
}
.delete-panel h3 { margin: 0 0 6px; font-size: 16px; }
.delete-panel p { margin: 6px 0; font-size: 14px; line-height: 1.5; }
.delete-panel ul { margin: 6px 0 8px; padding-left: 20px; font-size: 14px; line-height: 1.6; }
.delete-panel .note { color: var(--muted); font-size: 13px; }
.delete-panel .row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.delete-panel .branch-link { background: none; border: none; padding: 0; color: var(--accent-2); text-decoration: underline; cursor: pointer; }
button.danger-solid { background: var(--danger); border-color: var(--danger); color: #1b0f0f; font-weight: 700; }

.inspector-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.creator-warning {
  margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5;
  background: rgba(240, 192, 96, .08); border: 1px solid rgba(240, 192, 96, .35); color: #e9d9b0;
}

/* --- 0016B: state editors, inspector tabs --- */
.state-block { margin-top: 12px; }
.state-block:empty { display: none; }
.state-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.state-title { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.state-pill {
  display: inline-flex; gap: 6px; align-items: baseline; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}
.state-pill b { font-weight: 600; color: var(--muted); }
.state-empty { font-size: 13px; color: var(--muted); }
.state-saved { font-size: 12px; color: #8fcf7f; }
.kv-editor { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.kv-hint { font-size: 12px; color: var(--muted); margin: 0 0 4px; line-height: 1.45; }
.kv-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 6px; align-items: center; }
.kv-row input { width: 100%; background: var(--panel); }
.kv-row .kv-remove { background: none; border: none; color: var(--muted); padding: 0 6px; font-size: 16px; }
.kv-row .kv-remove:hover { color: var(--danger); }
.kv-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.kv-status { font-size: 12px; color: var(--accent-2); flex: 1; }
.inspector .kv-row { grid-template-columns: 90px 1fr auto; }
.inspector .state-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

button.inspector-tab { background: none; border: none; border-radius: 0; border-bottom: 2px solid transparent; }
button.inspector-tab:hover { color: var(--text); }
.bond-group + .bond-group { margin-top: 14px; }
.bond-head { font-size: 13px; font-weight: 700; margin: 0 0 6px; color: var(--c, var(--text)); }
.memory-conf { font-size: 12px; color: var(--muted); }

/* --- 0016C: zoom/pan, status, duplicate --- */
.board-canvas { touch-action: none; cursor: grab; }
.board-canvas.panning { cursor: grabbing; }
.zoom-controls { display: inline-flex; align-items: center; gap: 4px; }
.zoom-level { min-width: 54px; }
.menu-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 6px 10px 2px; }
.menu button[aria-checked="true"]::after { content: " ✓"; color: var(--accent-2); }

.scene-card.status-completed { opacity: .72; border-left: 3px solid #8fcf7f; }
.scene-card.status-abandoned { opacity: .45; }
.scene-card.status-abandoned .card-title { text-decoration: line-through; text-decoration-color: var(--muted); }
.scene-card.status-completed:hover, .scene-card.status-abandoned:hover { opacity: 1; }
.card-status { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: middle; }
.status-completed .card-status { color: #8fcf7f; border-color: rgba(143,207,127,.4); }

.scene-list button.status-completed, .scene-list button.status-abandoned { color: var(--muted); }
.scene-list button.status-abandoned { opacity: .6; }
.scene-tag { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; margin-left: 6px; color: var(--muted); }
.scene-status-note { margin: 4px 0 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* --- 0016B+: details tab, resizable inspector, clickable provenance --- */
.inspector { position: relative; }
.inspector-resize {
  position: absolute; left: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 5;
}
.inspector-resize:hover, .inspector-resize.dragging { background: linear-gradient(90deg, transparent 2px, var(--accent) 2px, var(--accent) 4px, transparent 4px); }
.sheet-view { display: flex; flex-direction: column; gap: 14px; }
.sheet-line { font-size: 14px; color: var(--text); margin: 0; }
.sheet-section h4 { margin: 0 0 5px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.sheet-section p { margin: 0; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.sheet-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.sheet-chip { font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.origin-link { background: none; border: none; padding: 0; color: var(--accent-2); font: inherit; font-style: italic; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.kv-status.warn { color: var(--danger); }
@media (max-width: 1100px) { .inspector-resize { display: none; } }

/* --- per-scene ⋯ in the scene list --- */
.scene-list li { position: relative; }
.scene-list li > button:first-child { padding-right: 36px; }
.scene-list .scene-more {
  position: absolute; right: 4px; top: 6px; width: 28px; height: 26px; padding: 0;
  border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted);
  text-align: center; font-size: 16px; line-height: 1; opacity: 0; transition: opacity .12s;
}
.scene-list li:hover .scene-more, .scene-list .scene-more:focus-visible,
.scene-list .scene-more[aria-expanded="true"], .scene-list li.current .scene-more { opacity: 1; }
.scene-list .scene-more:hover { color: var(--text); border-color: var(--line); background: var(--panel-3); }
@media (hover: none) { .scene-list .scene-more { opacity: 1; } }
.menu.floating { position: fixed; top: 0; left: 0; margin: 0; z-index: 45; }

/* --- Bring an AI / connected characters --- */
.heading-actions { display: inline-flex; gap: 4px; }
.heading-actions button { white-space: nowrap; }
.sidebar-heading-row { flex-wrap: wrap; gap: 6px; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.provider-card {
  text-align: left; padding: 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
}
.provider-card strong { font-size: 15px; }
.provider-card span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.provider-card:hover:not(:disabled) { border-color: var(--accent); }
.bring-intro { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.notice {
  margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5;
  background: rgba(240, 192, 96, .08); border: 1px solid rgba(240, 192, 96, .35); color: #e9d9b0;
}
.notice.danger { background: rgba(229, 115, 115, .08); border-color: rgba(229, 115, 115, .4); color: #f0c4c4; }
.notice b { color: inherit; }
.saved-key { font-size: 13px; color: #8fcf7f; }
.field input[type="password"], .field input[type="email"] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; color: inherit; }
.field input[type="password"]:focus, .field input[type="email"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field small { font-size: 12px; color: var(--muted); line-height: 1.4; }
.connected-tag { font-size: 11px; letter-spacing: .06em; color: var(--muted); }
.outbound-preview {
  white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; line-height: 1.5;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0; max-height: 260px; overflow: auto;
}
@media (max-width: 720px) { .provider-grid { grid-template-columns: 1fr; } }

.outbound-preview.tall { max-height: 50vh; }
.continuity-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.continuity-grid dt { color: var(--muted); }
.continuity-grid dd { margin: 0; }

.key-status { font-size: 12px; color: var(--muted); min-height: 1em; }
.key-status.ok { color: #8fcf7f; }
.field input:disabled { opacity: .45; cursor: not-allowed; }

/* --- round mode --- */
.round-toggle { margin-left: auto; }
.round-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px;
  padding: 8px 10px; border: 1px dashed var(--accent-2); border-radius: var(--radius); background: rgba(240, 192, 96, .05);
}
.round-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2); }
.round-pick { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.round-pick input { accent-color: var(--accent-2); }
.round-step { font-size: 14px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.round-step.done { color: #8fcf7f; border-color: rgba(143,207,127,.4); }
.round-step.now { color: var(--text); border-color: var(--accent-2); }
.round-step.skipped { text-decoration: line-through; }
.round-hint { font-size: 12px; color: var(--muted); flex-basis: 100%; }

.autopilot-switch { border-color: var(--accent); font-weight: 600; }
.picker-extras { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-basis: 100%; }
.autopilot-lengths { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.round-hint-inline { font-size: 12px; color: var(--muted); }
.consent { flex-basis: 100%; display: flex; gap: 8px; align-items: flex-start; font-size: 12px; line-height: 1.45; color: #e9d9b0; }
.limit-needed { flex-basis: 100%; font-size: 13px; color: var(--danger); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.limit-input { width: 80px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; color: inherit; font: inherit; }
.autopilot-tag {
  margin-left: 8px; font-size: 10px; letter-spacing: .1em; color: var(--muted); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px; vertical-align: middle; font-weight: 600; cursor: help;
}

/* --- toast --- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; max-width: min(640px, 90vw); box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.error { border-color: var(--danger); }

/* --- narrow screens --- */
@media (max-width: 1100px) {
  .layout.inspecting { grid-template-columns: 250px minmax(0, 1fr); }
  .inspector {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 92vw); z-index: 40;
    box-shadow: -10px 0 30px rgba(0,0,0,.5);
  }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 8px 12px; }
  .project-picker select { min-width: 0; max-width: 55vw; }
  .usage-pill { display: none; }
  .layout, .layout.inspecting { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); max-height: 36vh; }
  .story, .scene-header, .proposals, .composer { padding-left: 16px; padding-right: 16px; }
  .field-grid { grid-template-columns: 1fr; }
  .board-toolbar { padding: 8px 12px; }
  .board-legend { display: none; }
}

/* --- portraits (avatars) --- */
.avatar {
  --size: 40px;
  position: relative; display: inline-grid; place-items: center; flex-shrink: 0;
  width: var(--size); height: var(--size); border-radius: 50%; overflow: hidden;
  background: var(--panel-3); border: 2px solid var(--c, var(--accent));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .35);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-initial { font-weight: 700; color: var(--c, var(--accent)); font-size: calc(var(--size) * .44); line-height: 1; }
.avatar-xs { --size: 20px; border-width: 1.5px; }
.avatar-sm { --size: 30px; }
.avatar-md { --size: 40px; }
.avatar-lg { --size: 56px; }
.avatar-world { border-color: var(--world); background: transparent; box-shadow: none; border: none; }

.event.has-avatar { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 12px; }
.event.has-avatar > .avatar { grid-row: 1 / span 3; align-self: start; margin-top: 2px; }
.event.has-avatar > :not(.avatar) { grid-column: 2; }
.event.character.has-avatar { padding-left: 12px; }

.character-card .avatar { margin-right: 2px; }
.turn-chip .avatar, .proposal-who .avatar { margin-right: 2px; }
.proposal-who { gap: 8px; }

.inspector-head { align-items: center; }
.inspector-title { flex: 1; min-width: 0; }
.portrait-button {
  position: relative; padding: 0; border: none; background: none; border-radius: 50%; flex-shrink: 0;
}
.portrait-button:hover:not(:disabled) { border: none; }
.portrait-button .portrait-edit {
  position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  opacity: 0; transition: opacity .15s;
}
.portrait-button:hover .portrait-edit, .portrait-button:focus-visible .portrait-edit { opacity: 1; }

.portrait-modal { width: min(440px, 94vw); }
.portrait-stage { position: relative; width: 280px; height: 280px; margin: 4px auto 0; }
.portrait-stage canvas {
  width: 280px; height: 280px; border-radius: 50%; display: block; cursor: grab; touch-action: none;
  background: repeating-conic-gradient(var(--panel-2) 0 25%, var(--panel-3) 0 50%) 0 0 / 24px 24px;
  border: 2px solid var(--accent-2); box-shadow: 0 0 0 6px rgba(0, 0, 0, .25);
}
.portrait-stage canvas:active { cursor: grabbing; }
.portrait-stage canvas:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 4px; }
.portrait-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; pointer-events: none; color: var(--muted); font-size: 14px; }
.portrait-zoom { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.portrait-zoom input { flex: 1; accent-color: var(--accent-2); }
.portrait-pick-row { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.portrait-pick span {
  display: inline-block; padding: 6px 14px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
}
.portrait-pick:hover span { border-color: var(--accent-2); }
.portrait-pick:focus-within span { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.portrait-hint { font-size: 12px; color: var(--muted); line-height: 1.45; }

/* --- voice (0020) --- */
.voice-block { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.voice-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.voice-tag { font-size: 11px; letter-spacing: .06em; color: var(--muted); }
.voice-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.voice-name { font-size: 14px; margin-right: auto; }
.voice-status { font-size: 12px; color: var(--muted); }
.voice-modal { width: min(620px, 96vw); }
.voice-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.voice-tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 12px; color: var(--muted); font-weight: 600; font-size: 14px; }
.voice-tab.active { color: var(--text); border-bottom-color: var(--accent-2); }
.voice-pane { display: flex; flex-direction: column; gap: 12px; }
.voice-key-new { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.voice-pick { display: flex; flex-direction: column; gap: 10px; }
.voice-list-wrap { display: flex; flex-direction: column; gap: 6px; }
.voice-list { list-style: none; margin: 0; padding: 4px; max-height: 190px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.voice-option { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.voice-option small { color: var(--muted); font-size: 12px; }
.voice-option:hover, .voice-option:focus-visible { background: var(--panel-3); outline: none; }
.voice-option.selected { background: var(--panel-3); box-shadow: inset 3px 0 0 var(--accent-2); }
.voice-list-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }
.voice-test-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.voice-note { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
#voice-design-form.disabled { opacity: .5; pointer-events: none; }
.voice-fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.voice-fieldset legend { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.seg input:checked + span { border-color: var(--accent-2); color: var(--accent-2); background: rgba(240, 205, 116, .08); }
.seg input:focus-visible + span { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.vd-scales { display: flex; flex-direction: column; gap: 6px; }
.vd-scale { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.vd-scale .vd-high { text-align: left; }
.vd-scale .vd-low { text-align: right; }
.vd-scale input { accent-color: var(--accent-2); width: 100%; }
.vd-previews { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.vd-preview { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.vd-letter { font-weight: 700; width: 20px; color: var(--accent-2); }
.vd-preview .primary { margin-left: auto; }

/* --- story audio (0021) --- */
.audio-wrap .menu.audio-menu { min-width: 290px; padding: 8px 10px; gap: 2px; }
.audio-toggle.muted { opacity: .45; }
.audio-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 5px 2px; cursor: pointer; }
.audio-row small { color: var(--muted); font-size: 11px; }
.audio-row.sub { padding-left: 24px; font-size: 13px; color: var(--muted); }
.audio-row input[type=checkbox] { accent-color: var(--accent-2); }
.audio-preset-row select { flex: 1; min-width: 0; font-size: 12px; padding: 4px 6px; }
.audio-volume input { flex: 1; accent-color: var(--accent-2); }
.audio-note { margin: 4px 2px 2px; font-size: 11px; line-height: 1.45; color: var(--muted); }
.event-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.audio-tools { display: inline-flex; gap: 4px; }
.audio-play { min-width: 34px; }
.event:not(:hover):not(:focus-within):not(.speaking) .audio-regen { opacity: .6; }
@keyframes speaking-ring { 0%, 100% { box-shadow: 0 0 0 2px var(--c, var(--accent-2)), 0 0 6px var(--c, var(--accent-2)); } 50% { box-shadow: 0 0 0 3px var(--c, var(--accent-2)), 0 0 16px var(--c, var(--accent-2)); } }
.event.speaking > .avatar, .character-card.speaking .avatar { animation: speaking-ring 1.2s ease-in-out infinite; }
.event.world.speaking > .avatar { animation: none; filter: drop-shadow(0 0 8px rgba(240, 205, 116, .7)); }
.event.speaking .audio-play { border-color: var(--accent-2); color: var(--accent-2); }
@media (prefers-reduced-motion: reduce) {
  .event.speaking > .avatar, .character-card.speaking .avatar { animation: none; box-shadow: 0 0 0 3px var(--c, var(--accent-2)); }
}
.audio-none { opacity: .45; }
.audio-none:hover { opacity: .8; }
