:root {
  color-scheme: dark;
  --bg: #111317;
  --panel: #191c22;
  --panel-2: #14171d;
  --line: #2d323c;
  --text: #ece4d4;
  --muted: #9a9284;
  --accent: #d48c4a;
  --accent-soft: #362518;
  --ally: #5da68a;
  --ally-bg: #162620;
  --spy: #d06154;
  --spy-bg: #2a1716;
  --main: #e3b267;
  --main-bg: #292014;
  --clue: #7898b8;
  --clue-bg: #18212b;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 "Microsoft YaHei", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button {
  background: #232730; border: 1px solid #353b46; border-radius: 6px;
  padding: 6px 11px; transition: background-color .15s, border-color .15s;
}
button:hover:not(:disabled) { background: #2e333e; border-color: #535b6a; }
button:disabled { opacity: .4; cursor: default; }
button.primary {
  background: linear-gradient(180deg, #c98242, #a8622a);
  border-color: #d89657; color: #191008; font-weight: 700;
}
button.primary:hover { background: linear-gradient(180deg, #d8904f, #b76d31); }

.studio-shell { display: grid; grid-template-rows: 52px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.studio-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 18px; background: #16191f; border-bottom: 1px solid var(--line);
}
.studio-brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.studio-mark {
  width: 29px; height: 29px; display: grid; place-items: center; border-radius: 6px;
  background: #2c2118; border: 1px solid #755130; color: #f0cf93; font: 18px Georgia, serif;
}
.studio-brand strong { font-size: 15px; letter-spacing: .12em; color: #f4e6cb; }
.studio-brand span { color: var(--muted); font-size: 12px; border-left: 1px solid var(--line); padding-left: 10px; }

.studio-tabs { display: flex; align-items: center; gap: 6px; background: #101216; padding: 4px; border-radius: 8px; border: 1px solid #272b34; }
.studio-tab {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 5px 14px; border-radius: 5px; font-weight: 600; letter-spacing: .04em;
}
.studio-tab:hover { color: var(--text); background: #1e222a; border-color: transparent; }
.studio-tab[aria-selected="true"] {
  background: var(--accent-soft); color: #f7deb3; border-color: #825632;
}
.studio-actions { display: flex; align-items: center; gap: 8px; }
.studio-actions a {
  text-decoration: none; color: #f5dfb9; background: #261d15; border: 1px solid #6b4b2e;
  padding: 5px 12px; border-radius: 6px; font-size: 12px;
}
.studio-actions a:hover { background: #3a2a1d; }

.studio-views { position: relative; min-height: 0; }
.studio-view { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.embed-frame { width: 100%; height: 100%; border: 0; background: #121418; }

/* Infinite Canvas Workspace (shared by Story Organizer & Game Flow) */
.canvas-workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px;
  height: 100%; min-height: 0;
}
.canvas-main { display: grid; grid-template-rows: 46px minmax(0, 1fr); min-width: 0; min-height: 0; }
.canvas-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; overflow-x: auto;
  background: #16191f; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.canvas-toolbar select, .canvas-toolbar input[type="search"] {
  background: #111318; border: 1px solid #343a46; border-radius: 5px;
  padding: 4px 8px; font-size: 12px; color: var(--text);
}
.canvas-toolbar input[type="search"] { width: 165px; }
.toolbar-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; flex: none; }
.toolbar-spacer { flex: 1; }
.canvas-toolbar button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: #f7d9aa; }

.canvas-viewport {
  position: relative; overflow: hidden; cursor: grab;
  background-color: #0d0f13;
  background-image:
    radial-gradient(#262b35 1.1px, transparent 1.1px),
    linear-gradient(to right, #171a20 1px, transparent 1px),
    linear-gradient(to bottom, #171a20 1px, transparent 1px);
  background-size: 24px 24px, 120px 120px, 120px 120px;
  user-select: none;
}
.canvas-viewport.panning { cursor: grabbing; }
.canvas-world {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  transform-origin: 0 0;
}
.canvas-edges {
  position: absolute; left: -6000px; top: -6000px; width: 12000px; height: 12000px;
  overflow: visible; pointer-events: none;
}
.edge-group { pointer-events: visibleStroke; cursor: pointer; }
.edge-path { fill: none; stroke-width: 2.2; transition: opacity .18s, stroke-width .18s; }
.edge-path.series { stroke: #d8a55d; stroke-width: 2.8; }
.edge-path.parallel { stroke: #6ca6c9; stroke-dasharray: 6 5; }
.edge-path.conflict { stroke: #d86255; }
.edge-path.support { stroke: #5db28f; }
.edge-path.causal { stroke: #d4964c; stroke-dasharray: 6 4; }
.edge-path.note { stroke: #8c92a4; stroke-dasharray: 4 4; }
.edge-label-bg { fill: #15181ee6; stroke: #2f3540; stroke-width: 1; rx: 4; }
.edge-label-text { fill: #d9cfb8; font-size: 11px; font-family: "Microsoft YaHei", sans-serif; text-anchor: middle; dominant-baseline: central; }

.canvas-node {
  position: absolute; width: 256px; padding: 11px 13px; border-radius: 8px;
  background: #1b1f26; border: 1.5px solid #353c48;
  box-shadow: 0 10px 24px #00000070; cursor: move;
  transition: border-color .15s, box-shadow .15s, opacity .18s;
}
.canvas-node:hover { border-color: #6b7488; }
.canvas-node.selected { border-color: #f0b56d; box-shadow: 0 0 0 2px #d48c4a55, 0 14px 30px #00000099; z-index: 6; }
.canvas-node.connect-src { border-color: #6bd4a8; box-shadow: 0 0 0 2px #5db28f66; }
.canvas-node.dimmed { opacity: .22; }
.canvas-node.highlighted { border-color: #f4c171; box-shadow: 0 0 0 2px #e3a74d66, 0 12px 26px #00000099; }

.canvas-node[data-kind="main"], .canvas-node[data-kind="series"] {
  width: 274px; background: linear-gradient(165deg, #282015, #1b1814); border-color: #9e733b;
}
.canvas-node[data-kind="ally"] { background: linear-gradient(165deg, #16241f, #141b19); border-color: #3e7a62; }
.canvas-node[data-kind="spy"] { background: linear-gradient(165deg, #281717, #1b1416); border-color: #914139; }
.canvas-node[data-kind="clue"] { background: linear-gradient(165deg, #17202b, #141920); border-color: #486788; }
.canvas-node[data-kind="parallel"] { background: linear-gradient(165deg, #16232b, #141b22); border-color: #4f7e9c; }
.canvas-node[data-kind="ending"] { width: 280px; background: linear-gradient(165deg, #271e19, #191618); border-color: #a17148; }
.canvas-node[data-kind="cg"] { width: 244px; background: linear-gradient(165deg, #1f1b26, #16151c); border-color: #6d588f; }
.canvas-node[data-kind="note"] { background: linear-gradient(165deg, #242117, #1b1a14); border-color: #827345; }

.node-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 5px; }
.node-badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 10px;
  letter-spacing: .05em; font-weight: 700; background: #2a303b; color: #dcd3c2;
}
.canvas-node[data-kind="main"] .node-badge, .canvas-node[data-kind="series"] .node-badge { background: #4a351b; color: #f5d292; }
.canvas-node[data-kind="ally"] .node-badge { background: #1d4234; color: #9ce0c4; }
.canvas-node[data-kind="spy"] .node-badge { background: #4f201c; color: #f7b0a8; }
.canvas-node[data-kind="clue"] .node-badge { background: #21374d; color: #a9cdf2; }
.canvas-node[data-kind="parallel"] .node-badge { background: #1f3c4e; color: #9cd6f5; }
.canvas-node[data-kind="ending"] .node-badge { background: #4b311d; color: #f5cc9a; }
.canvas-node[data-kind="cg"] .node-badge { background: #36284d; color: #cfb8f7; }

.node-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.node-title { margin: 0 0 5px; font-size: 14px; font-weight: 700; color: #f5ebd6; }
.node-summary {
  margin: 0; font-size: 12px; color: #c7beb0; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.node-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.node-tag { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: #111419; border: 1px solid #2e3440; color: #b5ad9e; }

/* Parallel group container backdrop */
.parallel-lane-box {
  position: absolute; border: 1.5px dashed #4a718a88; border-radius: 12px;
  background: #141f2738; pointer-events: none;
}
.parallel-lane-box span {
  position: absolute; left: 14px; top: -11px; padding: 1px 8px; border-radius: 4px;
  background: #17242e; border: 1px solid #3c6078; color: #9ad1ee; font-size: 11px;
}

.canvas-hud {
  position: absolute; left: 14px; bottom: 14px; z-index: 8;
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  background: #171a20e6; border: 1px solid var(--line); border-radius: 8px; backdrop-filter: blur(6px);
}
.canvas-hud button { padding: 3px 8px; font-size: 12px; }
.canvas-hud span { font: 11px var(--mono); color: var(--muted); min-width: 44px; text-align: center; }

.canvas-legend {
  position: absolute; right: 14px; bottom: 14px; z-index: 8;
  display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 10px;
  background: #171a20e6; border: 1px solid var(--line); border-radius: 8px; font-size: 11px; color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-swatch { width: 16px; height: 3px; border-radius: 2px; }

/* Right Inspector Drawer */
.canvas-inspector {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
.inspector-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.inspector-head small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.inspector-head h3 { margin: 4px 0 0; font-size: 16px; color: #f6e7cb; }
.inspector-body { flex: 1; overflow: auto; padding: 14px 16px; display: grid; gap: 12px; align-content: start; }
.ins-block {
  padding: 10px 12px; border-radius: 6px; background: var(--panel-2); border: 1px solid #282d37;
}
.ins-block h4 { margin: 0 0 6px; font-size: 12px; color: #e2b97e; letter-spacing: .04em; }
.ins-block p, .ins-block li { margin: 4px 0; font-size: 12px; color: #d4cbb9; line-height: 1.6; }
.ins-block ul { margin: 4px 0; padding-left: 16px; }
.ins-field { display: grid; gap: 5px; }
.ins-field label { font-size: 11px; color: var(--muted); }
.ins-field input, .ins-field textarea, .ins-field select {
  width: 100%; background: #101318; border: 1px solid #323844; border-radius: 5px;
  padding: 6px 8px; color: var(--text); font-size: 12px;
}
.ins-field textarea { min-height: 82px; resize: vertical; line-height: 1.55; }
.ins-actions { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 960px) {
  .canvas-workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 260px; }
  .canvas-inspector { border-left: 0; border-top: 1px solid var(--line); }
}
