/* Основные цвета, шрифты и анимации. celestial.css задаёт оформление созвездия. */
:root {
  color-scheme: dark;
  font-family: var(--font-ui);
  --ink: #f1f3ee;
  --muted: #a5b0b1;
  --quiet: #718082;
  --canvas: #070b12;
  --panel: #10161f;
  --panel-2: #171f2a;
  --line: #495568;
  --border: #2c3746;
  --orange: #ff884d;
  --cyan: #79cad8;
  --yellow: #e6d16a;
  --danger: #db7e71;
  --header-h: 64px;
  --font-ui: "Golos Text", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  --font-display: Georgia, serif;
  --starfield-duration: 8s;
  --starfield-opacity-min: .5;
  --starfield-opacity-max: .86;
  --star-breathe-duration: 3.2s;
  --star-opacity-min: .75;
  --star-scale-min: .88;
  --star-scale-max: 1.06;
  --line-hit-width: 16px;
  --line-breathe-duration: 3.6s;
  --line-glow-radius: 3px;
  --spark-glow-inner: 5px;
  --spark-glow-outer: 10px;
  --spark-trail-width: 1.5px;
  --spark-flare-width: .65px;
  --spark-core-color: #fff9e6;
  --spark-flame-opacity: .85;
  --event-appear-duration: .48s;
  --toast-transition-duration: .16s;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--canvas); color: var(--ink); }

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

.app-shell { min-height: 100vh; overflow: hidden; }

.topbar {
  height: var(--header-h);
  display: grid;
  grid-template-columns: 156px minmax(180px, 1fr) auto;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: #0c1118;
  padding: 0 18px;
}

.project-title { display: flex; align-items: center; gap: 11px; color: var(--quiet); font-family: var(--font-mono); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.project-title input { width: min(46vw, 420px); background: transparent; border: 0; border-bottom: 1px solid transparent; padding: 7px 0; color: var(--ink); font-family: var(--font-ui); font-size: 1rem; text-transform: none; letter-spacing: 0; outline: 0; }
.project-title input:focus { border-bottom-color: var(--orange); }

.top-actions { display: flex; align-items: center; gap: 9px; }
.save-state { color: var(--quiet); font-family: var(--font-mono); font-size: .72rem; min-width: 72px; text-align: right; }
.button { min-height: 38px; border: 1px solid var(--border); border-radius: 3px; padding: 0 15px; background: transparent; cursor: pointer; }
.button:hover { border-color: var(--muted); }
.button.primary { border-color: var(--orange); background: var(--orange); color: #271a14; font-weight: 600; }
.button.primary:hover { background: #ff9a66; }
.play-icon { display: inline-block; width: 0; height: 0; margin-right: 8px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid currentColor; }

.workspace { height: calc(100vh - var(--header-h)); display: grid; grid-template-columns: 76px minmax(0, 1fr) 320px; }

.toolrail { z-index: 5; border-right: 1px solid var(--border); background: #0c1118; padding: 14px 8px; display: flex; flex-direction: column; gap: 7px; }
.tool { min-height: 58px; border: 1px solid transparent; border-radius: 3px; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 2px; cursor: pointer; font-size: .68rem; }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.tool:hover { color: var(--ink); background: #131a23; }
.tool.active { color: var(--orange); border-color: #68452f; background: #211a17; }

.canvas-wrap { position: relative; overflow: hidden; background: radial-gradient(ellipse at 48% 44%, #111b28 0%, #090e17 48%, var(--canvas) 100%); user-select: none; }
.canvas-grid {
  position: absolute;
  inset: 0;
  opacity: .78;
  background-image:
    radial-gradient(circle at 12% 18%, #eaf4ff 0 1px, transparent 1.3px),
    radial-gradient(circle at 71% 11%, #8fa4bd 0 1px, transparent 1.3px),
    radial-gradient(circle at 87% 31%, #dfe9f3 0 1px, transparent 1.4px),
    radial-gradient(circle at 23% 72%, #8295aa 0 1px, transparent 1.3px),
    radial-gradient(circle at 62% 83%, #e7eef7 0 1px, transparent 1.3px),
    radial-gradient(circle at 44% 21%, #667991 0 .8px, transparent 1.2px);
  background-size: 239px 211px, 307px 271px, 197px 257px, 353px 229px, 277px 311px, 181px 193px;
  animation: starfield-breathe var(--starfield-duration) ease-in-out infinite alternate;
}
@keyframes starfield-breathe { from { opacity: var(--starfield-opacity-min); } to { opacity: var(--starfield-opacity-max); } }
.connections, .nodes-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.connections { overflow: visible; }
.connection-base { fill: none; stroke: var(--line); stroke-width: 1.15; stroke-opacity: .52; vector-effect: non-scaling-stroke; }
.connection-group.related .connection-base { stroke: #74839a; stroke-opacity: .82; }
.edge-hit { fill: none; stroke: transparent; stroke-width: var(--line-hit-width); cursor: pointer; vector-effect: non-scaling-stroke; }
.edge-energy {
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  stroke-opacity: .78;
  filter: drop-shadow(0 0 var(--line-glow-radius) var(--edge-color));
  vector-effect: non-scaling-stroke;
  animation:
    line-ignite var(--edge-duration) cubic-bezier(.3, .05, .18, 1) var(--edge-delay) forwards,
    line-breathe var(--line-breathe-duration) ease-in-out calc(var(--edge-delay) + var(--edge-duration)) infinite alternate;
}
#spark-layer { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; z-index: 3; pointer-events: none; }
.spark-particle { filter: drop-shadow(0 0 var(--spark-glow-inner) var(--spark-color)); } /* unslop-ignore: requested fire sparks */
.spark-trail { fill: none; stroke-width: var(--spark-trail-width); stroke-linecap: round; }
.spark-halo, .spark-ember, .spark-flame { fill: var(--spark-color); }
.spark-halo { opacity: .4; }
.spark-flame { opacity: var(--spark-flame-opacity); }
.spark-core { fill: var(--spark-core-color); }
.spark-flare { fill: none; stroke: var(--spark-core-color); stroke-width: var(--spark-flare-width); stroke-linecap: round; }
.spark-head { filter: drop-shadow(0 0 var(--spark-glow-outer) var(--spark-color)); } /* unslop-ignore: compact luminous spark head */
.canvas-wrap.paused .edge-energy, .canvas-wrap.paused .canvas-grid { animation-play-state: paused; }
@keyframes line-ignite { from { stroke-dashoffset: 1; stroke-opacity: .12; } to { stroke-dashoffset: 0; stroke-opacity: .9; } }
@keyframes line-breathe { from { stroke-opacity: .55; } to { stroke-opacity: 1; } }

.node { position: absolute; width: 190px; min-height: 54px; transform: translate(-14px, -27px); padding: 9px 11px 9px 34px; border: 1px solid transparent; background: transparent; color: var(--ink); text-align: left; cursor: grab; touch-action: none; }
.node.revealable { opacity: 0; animation: event-appear var(--event-appear-duration) cubic-bezier(.2, .7, .2, 1) var(--reveal-delay) forwards; }
.canvas-wrap.paused .node.revealable { animation-play-state: paused; }
@keyframes event-appear {
  0% { opacity: 0; filter: blur(3px); }
  65% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; filter: blur(0); }
}
.node.align-right { transform: translate(-176px, -27px); padding: 9px 34px 9px 11px; text-align: right; }
.node.align-right .node-dot { left: auto; right: 9px; }
.node.align-right.root .node-dot { left: auto; right: 6px; }
.node:hover { background: #101721d9; border-color: #334052; }
.node.selected { background: #141c27; border-color: #627187; }
.node.connect-source { background: #302821; border-color: var(--orange); }
.node.selected::before, .node.selected::after { content: ""; position: absolute; inset: -4px; pointer-events: none; background: linear-gradient(var(--orange), var(--orange)) left top / 8px 1px no-repeat, linear-gradient(var(--orange), var(--orange)) left top / 1px 8px no-repeat, linear-gradient(var(--orange), var(--orange)) right bottom / 8px 1px no-repeat, linear-gradient(var(--orange), var(--orange)) right bottom / 1px 8px no-repeat; }
.node:active { cursor: grabbing; }
.node-dot { position: absolute; left: 10px; top: 22px; width: 9px; height: 9px; border: 1px solid #f4f7ff; background: var(--node-color, var(--orange)); transform: rotate(45deg); box-shadow: 0 0 5px var(--node-color), 0 0 12px color-mix(in srgb, var(--node-color) 45%, transparent); animation: node-star-breathe var(--star-breathe-duration) ease-in-out infinite alternate; } /* unslop-ignore: user requested glowing stars */
.node.root .node-dot { width: 16px; height: 16px; left: 6px; top: 18px; background: #fff7ef; border-color: #fff; box-shadow: 0 0 7px #fff, 0 0 20px var(--orange), 0 0 38px #ff884d77; } /* unslop-ignore: central spark is intentionally luminous */
@keyframes node-star-breathe { from { opacity: var(--star-opacity-min); transform: rotate(45deg) scale(var(--star-scale-min)); } to { opacity: 1; transform: rotate(45deg) scale(var(--star-scale-max)); } }
.node small { display: block; color: var(--quiet); font-family: var(--font-mono); font-size: .68rem; letter-spacing: .08em; margin-bottom: 3px; }
.node strong { display: block; font-size: .92rem; font-weight: 500; line-height: 1.25; }

.canvas-hint { position: absolute; left: 18px; bottom: 19px; color: var(--quiet); font-size: .78rem; }
.canvas-wrap[data-tool="add"] { cursor: crosshair; }
.canvas-wrap[data-tool="connect"] .node { cursor: cell; }
.legend { position: absolute; right: 18px; bottom: 16px; display: flex; gap: 16px; color: var(--muted); font-size: .75rem; }
.legend span { display: flex; align-items: center; gap: 7px; }
.legend i { width: 16px; height: 3px; background: var(--legend-color); }

.inspector { border-left: 1px solid var(--border); background: var(--panel); padding: 22px 20px 18px; display: flex; min-width: 0; flex-direction: column; gap: 20px; overflow-y: auto; z-index: 6; }
.inspector-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.eyebrow { color: var(--quiet); font-family: var(--font-mono); font-size: .69rem; letter-spacing: .08em; text-transform: uppercase; }
.eyebrow b { color: var(--orange); font-weight: 500; }
.inspector h1 { margin: 7px 0 0; font-size: 1.35rem; line-height: 1.2; font-weight: 500; }
.icon-button { display: none; width: 36px; height: 36px; border: 1px solid var(--border); background: transparent; font-size: 1.4rem; cursor: pointer; }
.field { display: grid; gap: 8px; }
.field > span, .section-title > span { color: var(--muted); font-size: .77rem; }
.field input, .field textarea { width: 100%; border: 1px solid var(--border); border-radius: 2px; outline: 0; background: #090e15; color: var(--ink); padding: 10px 11px; font-size: .88rem; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--orange); }
.field textarea { line-height: 1.55; min-height: 130px; }
.inspector-section { display: grid; gap: 11px; }
.section-title { display: flex; align-items: center; justify-content: space-between; }
.text-button { border: 0; background: transparent; color: var(--orange); cursor: pointer; padding: 4px; font-size: .75rem; }
.outgoing-list { display: grid; gap: 7px; }
.edge-row { border: 1px solid var(--border); background: #0b1119; padding: 10px; }
.edge-row strong { display: block; font-size: .78rem; font-weight: 500; margin-bottom: 8px; }
.edge-row-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.edge-row strong { min-width: 0; overflow-wrap: anywhere; }
.edge-delete { border: 0; background: transparent; color: var(--quiet); cursor: pointer; padding: 0 2px; line-height: 1; font-size: 1rem; }
.edge-delete:hover { color: var(--danger); }
.swatches { display: flex; align-items: center; gap: 7px; }
.swatch-toggle { width: 25px; height: 25px; border: 1px solid #566063; background: transparent; padding: 4px; cursor: pointer; }
.swatch-toggle::after { content: ""; display: block; width: 100%; height: 100%; background: var(--swatch); opacity: .28; }
.swatch-toggle.active { border-color: var(--swatch); }
.swatch-toggle.active::after { opacity: 1; }
.swatch-note { margin-left: auto; color: var(--quiet); font-family: var(--font-mono); font-size: .62rem; }
.delete-button { margin-top: auto; min-height: 38px; border: 1px solid #654742; background: transparent; color: var(--danger); border-radius: 2px; cursor: pointer; }
.delete-button:hover { background: #322725; }
.mobile-actions { display: none; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 22px; transform: translate(-50%, 14px); padding: 9px 13px; border: 1px solid var(--border); background: #252b2d; color: var(--ink); font-size: .78rem; opacity: 0; pointer-events: none; transition: opacity var(--toast-transition-duration) ease, transform var(--toast-transition-duration) ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto minmax(120px, 1fr) auto; padding: 0 12px; }
  .save-state { display: none; }
  .project-title input { width: 100%; }
  .workspace { display: block; }
  .toolrail { display: none; }
  .canvas-wrap { width: 100%; height: calc(100vh - var(--header-h)); }
  .inspector { position: fixed; inset: auto 0 0 0; max-height: 72vh; transform: translateY(101%); transition: transform .2s ease; border-left: 0; border-top: 1px solid var(--border); box-shadow: 0 -18px 50px #0008; }
  .inspector.open { transform: translateY(0); }
  .icon-button { display: block; }
  .mobile-actions { position: fixed; z-index: 8; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; border: 1px solid var(--border); background: #202627ee; padding: 5px; box-shadow: 0 8px 30px #0008; }
  .mobile-actions button { min-height: 42px; border: 0; border-right: 1px solid var(--border); background: transparent; padding: 0 16px; cursor: pointer; }
  .mobile-actions button:last-child { border-right: 0; color: var(--orange); }
  .legend { display: none; }
  .canvas-hint { bottom: 74px; }
  .toast { bottom: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
  .spark { stroke-dasharray: 6 22; }
}
