:root {
  --bg: #08090d;
  --panel: #12151c;
  --text: #e7ecf5;
  --muted: #8b95a8;
  --accent: #5aa5ff;
  --studied: #32cd70;
  --target: #ff5a8f;
  --needed: #ffc857;
  --edge: rgba(180, 190, 210, 0.45);
  --edge-active: #ffcc66;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 10, 0.92);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.boot-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-card {
  text-align: center;
  padding: 28px 36px;
  border-radius: 16px;
  border: 1px solid #2a3a55;
  background: #10141d;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.boot-card p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.boot-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 3px solid rgba(90, 168, 255, 0.2);
  border-top-color: #5aa8ff;
  border-radius: 50%;
  animation: boot-spin 0.9s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

.boot-error {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  max-width: min(560px, 92vw);
  padding: 12px 18px;
  border-radius: 12px;
  background: #3a1518;
  border: 1px solid #ff5555;
  color: #ffd0d0;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.boot-error.hidden {
  display: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: linear-gradient(180deg, #12161f 0%, #0e1118 100%);
  border-bottom: 1px solid #2a3348;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-sub {
  font-weight: 600;
  font-size: 13px;
  color: #9ec5ff;
  margin-left: 6px;
}

.topbar input[type="search"] {
  flex: 1;
  min-width: 160px;
  max-width: 440px;
  margin-left: auto;
  border: 1px solid #33415a;
  background: #0a0e16;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.topbar input[type="search"]:focus {
  outline: none;
  border-color: #5aa8ff;
  box-shadow: 0 0 0 3px rgba(90, 168, 255, 0.2);
}

.zoom-controls {
  display: flex;
  gap: 6px;
}

.zoom-controls button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  border-radius: 10px;
  border: 1px solid #2f6ba7;
  background: #1a3a5c;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.zoom-controls button:hover {
  filter: brightness(1.12);
  border-color: #4d8fd4;
}

.zoom-controls .fit-path-btn {
  background: linear-gradient(180deg, #4a2a4a 0%, #2e1a3a 100%);
  border-color: #b86dff;
  font-size: 18px;
}

.zoom-controls .fit-path-btn:hover {
  border-color: #d49bff;
  box-shadow: 0 0 12px rgba(184, 109, 255, 0.35);
}

.zoom-controls .clear-path-btn {
  background: linear-gradient(180deg, #3a2228 0%, #261418 100%);
  border-color: #c45a6a;
  font-size: 16px;
}

.zoom-controls .clear-path-btn:hover {
  border-color: #ff7a8a;
  box-shadow: 0 0 12px rgba(255, 90, 110, 0.35);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px 1fr auto;
}

.workspace-viewer {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  position: relative;
  min-height: 0;
}

.workspace-viewer .viewer-wrap {
  min-height: 0;
  height: 100%;
}

.workspace-viewer .detail-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  max-width: min(340px, 92vw);
  z-index: 20;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
}

.workspace-viewer .detail-panel.hidden {
  display: none;
}

.topbar-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.detail-path {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: #dce6f8;
}

.path-empty {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(90, 168, 255, 0.06);
  border: 1px dashed rgba(90, 168, 255, 0.25);
  color: var(--muted);
}

.path-route {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(12, 16, 24, 0.85);
}

.path-route-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 8px;
  opacity: 0.85;
}

.path-route-steps {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.path-step {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-weight: 600;
}

.path-step-target {
  background: rgba(255, 70, 70, 0.2);
  color: #ffb0a8;
  box-shadow: 0 0 0 1px rgba(255, 90, 80, 0.45);
}

.path-arrow {
  color: rgba(255, 255, 255, 0.35);
  font-size: 11px;
  margin: 0 2px;
}

.path-route-tech { border-left: 3px solid #5aa8ff; }
.path-route-tech .path-route-label { color: #7ec8ff; }
.path-route-tech .path-step { color: #b8dcff; }

.path-route-economy { border-left: 3px solid #45ff6a; }
.path-route-economy .path-route-label { color: #5dff82; }
.path-route-economy .path-step { color: #b8ffd0; }

.path-route-culture { border-left: 3px solid #ff5ad6; }
.path-route-culture .path-route-label { color: #ff7ae8; }
.path-route-culture .path-step { color: #ffc8f2; }

.path-route-atomic,
.path-route-wonders { border-left: 3px solid #ff5555; }
.path-route-atomic .path-route-label,
.path-route-wonders .path-route-label { color: #ff8888; }
.path-route-atomic .path-step,
.path-route-wonders .path-step { color: #ffc8c8; }

.path-summary {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 4px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.path-summary strong {
  color: #ffd76a;
  font-weight: 800;
}

.detail-section-path h3 {
  color: #9ec5ff;
}

.viewer-layout .node {
  cursor: pointer;
}

.viewer.viewer-path-focus {
  background-color: #040508;
}

.viewer-layout .node.dimmed {
  opacity: 0.14;
}

.viewer-layout .node.in-path {
  opacity: 1;
  filter: none;
  z-index: 4;
  border-width: 3px;
  box-shadow:
    0 0 0 2px rgba(255, 90, 70, 0.75),
    0 0 22px rgba(255, 70, 55, calc(0.25 + var(--path-step, 0.5) * 0.45));
}

.viewer-layout .node.in-path.branch-tech {
  border-color: #7ec8ff;
  box-shadow:
    0 0 0 2px rgba(90, 168, 255, 0.85),
    0 0 20px rgba(90, 168, 255, calc(0.2 + var(--path-step, 0.5) * 0.5));
}

.viewer-layout .node.in-path.branch-economy {
  border-color: #5dff82;
  box-shadow:
    0 0 0 2px rgba(69, 255, 106, 0.85),
    0 0 20px rgba(69, 255, 106, calc(0.2 + var(--path-step, 0.5) * 0.5));
}

.viewer-layout .node.in-path.branch-culture {
  border-color: #ff7ae8;
  box-shadow:
    0 0 0 2px rgba(255, 90, 214, 0.85),
    0 0 20px rgba(255, 90, 214, calc(0.2 + var(--path-step, 0.5) * 0.5));
}

.viewer-layout .node.in-path.branch-atomic,
.viewer-layout .node.in-path.branch-wonders {
  border-color: #ff7070;
  box-shadow:
    0 0 0 2px rgba(255, 85, 85, 0.9),
    0 0 24px rgba(255, 70, 70, calc(0.25 + var(--path-step, 0.5) * 0.55));
}

.viewer-layout .node.target {
  z-index: 6;
  border-width: 3px;
  border-color: #ff4444;
  opacity: 1;
  filter: none;
  box-shadow:
    0 0 0 4px rgba(255, 55, 55, 0.95),
    0 0 36px rgba(255, 60, 50, 0.65),
    0 12px 32px rgba(0, 0, 0, 0.45);
}

.viewer-layout .era-header-manual {
  pointer-events: none;
  cursor: default;
}

.tools-panel {
  padding: 14px;
  background: var(--panel);
  border-right: 1px solid #232a38;
  overflow-y: auto;
}

.tools-panel button {
  width: 100%;
  border: 1px solid #32435f;
  background: #1a3a5c;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 8px;
}

.tools-panel button.secondary {
  background: #222a38;
  border-color: #3a4a64;
}

.tools-panel button.accent {
  background: #3d2a6b;
  border-color: #9b6dff;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.mode-toggle-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.mode-toggle button {
  margin-bottom: 0;
  font-size: 12px;
  padding: 8px 6px;
}

.tools-panel button.active {
  box-shadow: 0 0 0 2px rgba(155, 109, 255, 0.55);
}

.panel-title {
  margin: 0 0 10px 0;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.editor-status {
  margin: 8px 0 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}

.panel-divider {
  border: none;
  border-top: 1px solid #2a3345;
  margin: 14px 0;
}

.dot.link-from { background: #9b6dff; }
.dot.move { background: #5ad6ff; }
.dot.era { background: #c8d0e0; }

.viewer.editor-layout {
  cursor: grab;
}

.viewer.editor-layout.move-mode .node.editor-mode {
  cursor: grab;
}

.viewer.editor-layout.link-mode .node.editor-mode {
  cursor: pointer;
}

.viewer.editor-layout .node.dragging-node {
  cursor: grabbing;
  z-index: 10;
  box-shadow: 0 0 0 2px #9b6dff, 0 16px 40px rgba(0, 0, 0, 0.55);
}

.node.link-source {
  box-shadow: 0 0 0 3px rgba(155, 109, 255, 0.75);
}

.node.editor-mode {
  cursor: pointer;
}

.legend {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot.studied { background: var(--studied); }
.dot.target { background: var(--target); }
.dot.needed { background: var(--needed); }

.viewer-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #05070b;
}

.viewer-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.55);
}

.viewer {
  touch-action: none;
}

.viewer {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  cursor: grab;
  background: #06080c;
}

.viewer.expanded-layout {
  background-color: #06080c;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.07) 1px, transparent 0);
  background-size: 28px 28px;
}

#treeImage {
  display: none;
  position: absolute;
  z-index: 0;
  pointer-events: none;
  object-fit: fill;
  object-position: center;
  filter: brightness(0.62) saturate(0.86) contrast(1.08);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 55%, rgba(0, 0, 0, 0.96) 72%, transparent 100%);
  mask-image: radial-gradient(ellipse at center, #000 55%, rgba(0, 0, 0, 0.96) 72%, transparent 100%);
  user-select: none;
}

.viewer.has-era-backdrop {
  background-color: #05070b;
  background-image:
    linear-gradient(180deg, rgba(3, 5, 9, 0.08), rgba(3, 5, 9, 0.5)),
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.045) 1px, transparent 0);
  background-size: auto, 28px 28px;
}

.viewer.has-era-backdrop .node {
  background: color-mix(in srgb, var(--branch-color, #6f86a9) 20%, rgba(6, 9, 14, 0.98));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.68);
}

.viewer.has-era-backdrop .era-header-manual {
  background: rgba(18, 22, 29, 0.92);
  text-shadow: 0 2px 4px #000;
}

.viewer.dragging {
  cursor: grabbing;
  user-select: none;
}

.stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.stage.stage-animate {
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.viewer.is-panning .node,
.viewer.is-panning .edge-path,
.viewer.is-panning .edge-merge {
  transition: none !important;
}

.viewer.is-panning .node-unlocks {
  overflow: hidden;
  pointer-events: none;
}

.era-headers {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.era-headers-editor {
  z-index: 4;
}

.era-project-title {
  position: absolute;
  top: 12px;
  right: 24px;
  padding: 4px 0;
  font-size: 13px;
  font-weight: 700;
  color: #5aa8ff;
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
}

.era-header {
  position: absolute;
  transform: translate(-50%, 0);
  padding: 10px 18px;
  border-radius: 10px;
  border: 2px solid;
  background: rgba(12, 16, 24, 0.95);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.era-header-manual {
  pointer-events: auto;
  cursor: grab;
  box-sizing: border-box;
  text-align: center;
  text-transform: none;
  letter-spacing: 0.02em;
  font-weight: 600;
  color: #f2f6ff;
  background: rgba(36, 40, 48, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 2px solid var(--era-accent, #5aa8ff);
  border-radius: 0;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  user-select: none;
  overflow: hidden;
  position: absolute;
  transform: translate(-50%, 0);
}

.era-header-label {
  display: block;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer.era-mode .era-header-manual {
  outline: 1px dashed rgba(255, 210, 120, 0.55);
  outline-offset: 2px;
}

.viewer.era-mode .era-resize-handle {
  opacity: 1;
}

.era-resize-handle {
  position: absolute;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 2;
}

.era-resize-w,
.era-resize-e {
  top: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
}

.era-resize-w {
  left: 0;
}

.era-resize-e {
  right: 0;
}

.era-resize-s {
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  cursor: ns-resize;
}

.era-header-manual:hover .era-resize-handle,
.era-header-manual.resizing-era .era-resize-handle {
  opacity: 1;
}

.era-resize-handle::after {
  content: "";
  position: absolute;
  background: rgba(255, 220, 140, 0.75);
  border-radius: 2px;
}

.era-resize-w::after,
.era-resize-e::after {
  top: 50%;
  width: 3px;
  height: 18px;
  transform: translateY(-50%);
}

.era-resize-w::after {
  left: 3px;
}

.era-resize-e::after {
  right: 3px;
}

.era-resize-s::after {
  left: 50%;
  bottom: 2px;
  width: 28px;
  height: 3px;
  transform: translateX(-50%);
}

.era-header-manual.dragging-era {
  cursor: grabbing;
  opacity: 0.92;
}

.era-header-manual.resizing-era {
  opacity: 0.95;
}

.era-column-rail {
  position: absolute;
  pointer-events: none;
  border-left: 1px solid;
  border-right: 1px solid;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0) 100%
  );
  box-sizing: border-box;
}

.era-header-span {
  text-align: center;
  box-sizing: border-box;
}

.era-bus-atomic {
  background: rgba(255, 90, 90, 0.45);
  width: 3px;
}

.era-bus {
  position: absolute;
  width: 2px;
  background: rgba(200, 210, 230, 0.25);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
}

.edges {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.edge-line,
.edge-path {
  fill: none;
  stroke: var(--edge);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.edge-bus,
.edge-cross,
.edge-split,
.edge-stack {
  stroke-dasharray: none;
  stroke-width: 4;
  opacity: 0.92;
}

.edge-inline {
  stroke-width: 3.5;
  opacity: 0.88;
}

.edge-editor {
  stroke-width: 3.5;
  opacity: 0.8;
}

.edge-editor.edge-bus,
.edge-editor.edge-cross,
.edge-editor.edge-stack {
  stroke-width: 4;
  opacity: 0.86;
}

.edge-path.edge-cross {
  stroke-width: 2.8;
  stroke-dasharray: none;
  opacity: 0.82;
}

.viewer-link-preview .edge-path {
  opacity: 0.1;
  filter: none;
}

.viewer-link-preview .edge-path.edge-outgoing-preview {
  stroke: #ffd35a !important;
  stroke-width: 5;
  opacity: 1;
  filter: drop-shadow(0 0 5px rgba(255, 211, 90, 0.75));
}

.viewer-link-preview .edge-path.edge-incoming-preview {
  stroke: #72d8ff !important;
  stroke-width: 4;
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(114, 216, 255, 0.7));
}

.node.node-source-preview {
  box-shadow: 0 0 0 3px #f4ead0, 0 0 24px rgba(244, 234, 208, 0.5);
}

.node.node-next-preview {
  box-shadow: 0 0 0 3px #ffd35a, 0 0 26px rgba(255, 211, 90, 0.65);
}

.node.node-previous-preview {
  box-shadow: 0 0 0 3px #72d8ff, 0 0 22px rgba(114, 216, 255, 0.55);
}

.edge-path.edge-cross.active {
  stroke-dasharray: none;
  stroke-width: 4.5;
  opacity: 1;
}

.edge-tech {
  stroke: #5aa8ff;
  filter: drop-shadow(0 0 3px rgba(90, 168, 255, 0.45))
    drop-shadow(0 0 8px rgba(90, 168, 255, 0.22));
}

.edge-economy {
  stroke: #45ff6a;
  filter: drop-shadow(0 0 3px rgba(69, 255, 106, 0.45))
    drop-shadow(0 0 8px rgba(69, 255, 106, 0.22));
}

.edge-maritime {
  stroke: #39d9ff;
  filter: drop-shadow(0 0 3px rgba(57, 217, 255, 0.42))
    drop-shadow(0 0 8px rgba(57, 217, 255, 0.2));
}

.edge-culture {
  stroke: #ff5ad6;
  filter: drop-shadow(0 0 3px rgba(255, 90, 214, 0.45))
    drop-shadow(0 0 8px rgba(255, 90, 214, 0.22));
}

.edge-wonders {
  stroke: #ffd34d;
  filter: drop-shadow(0 0 3px rgba(255, 211, 77, 0.45))
    drop-shadow(0 0 8px rgba(255, 211, 77, 0.22));
}

.edge-atomic,
.edge-merge {
  filter: drop-shadow(0 0 3px rgba(255, 85, 85, 0.5))
    drop-shadow(0 0 8px rgba(255, 85, 85, 0.25));
}

.edge-merge {
  stroke-width: 4;
  opacity: 0.95;
}

.branch-band-label {
  position: absolute;
  transform: translate(0, -50%) rotate(-90deg);
  transform-origin: left center;
  padding: 8px 12px;
  border-left: 3px solid;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}

.branch-band-rail {
  position: absolute;
  border-top: 1px dashed;
  pointer-events: none;
  z-index: 0;
}

.saved-branch-zone {
  position: absolute;
  border-top: 1px solid;
  border-bottom: 1px solid;
  border-radius: 18px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--branch-zone-color) 5%, transparent), transparent 42%);
  pointer-events: none;
  z-index: 0;
}

.saved-branch-label {
  position: absolute;
  width: 116px;
  padding: 7px 9px;
  border-left: 4px solid;
  border-radius: 6px;
  background: rgba(8, 10, 16, 0.9);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 4;
}

.path-edges-focus .edge-path.path-dimmed,
.path-edges-focus .edge-line.path-dimmed,
.path-edges-focus .edge-merge.path-dimmed {
  opacity: 0.07;
  stroke: #2a3344 !important;
  filter: none;
}

.edge-line.active,
.edge-path.active,
.edge-merge.active {
  stroke: #ff5544 !important;
  stroke-width: 5;
  opacity: 1;
  stroke-dasharray: none !important;
}

.path-edges-focus .edge-path.active.edge-tech,
.path-edges-focus .edge-merge.active.edge-tech {
  stroke: #6ec8ff !important;
}

.path-edges-focus .edge-path.active.edge-economy,
.path-edges-focus .edge-merge.active.edge-economy {
  stroke: #4dff78 !important;
}

.path-edges-focus .edge-path.active.edge-maritime,
.path-edges-focus .edge-merge.active.edge-maritime {
  stroke: #4de4ff !important;
}

.path-edges-focus .edge-path.active.edge-culture,
.path-edges-focus .edge-merge.active.edge-culture {
  stroke: #ff66e0 !important;
}

.path-edges-focus .edge-path.active.edge-atomic,
.path-edges-focus .edge-merge.active.edge-atomic,
.path-edges-focus .edge-path.active.edge-wonders,
.path-edges-focus .edge-merge.active.edge-wonders {
  stroke: #ff5555 !important;
}

.nodes-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 228px;
  min-height: 128px;
  height: 128px;
  max-height: 128px;
  padding: 10px 12px 8px;
  border-radius: 12px;
  border: 2px solid var(--branch-color, #6f86a9);
  background: color-mix(in srgb, var(--branch-color, #6f86a9) 22%, rgba(8, 10, 16, 0.97));
  color: #e8f0ff;
  text-align: center;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-sizing: border-box;
}

.node.locked {
  opacity: 0.32;
  filter: grayscale(0.35);
}

.node.starting-tech {
  border-color: #82d495;
  background: color-mix(in srgb, #82d495 19%, rgba(8, 10, 16, 0.97));
  box-shadow: 0 0 0 1px rgba(130, 212, 149, 0.24), 0 10px 28px rgba(0, 0, 0, 0.5);
}

.node.starting-tech::after {
  content: "ИЗУЧЕНА";
  position: absolute;
  top: -11px;
  right: 10px;
  padding: 3px 8px;
  border: 1px solid #82d495;
  border-radius: 999px;
  color: #dfffe6;
  background: #183923;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.node.locked .node-title,
.node.locked .node-unlocks {
  color: #5a6478;
}

.node-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--branch-color, #9ec5ff);
  text-align: center;
  padding-bottom: 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--branch-color, #5aa8ff) 55%, transparent);
  margin-bottom: 2px;
}

.node-unlocks {
  flex: 1;
  font-size: 11px;
  line-height: 1.42;
  color: #eef2fa;
  text-align: center;
  padding: 2px 2px 4px;
  max-height: 46px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.node-unlocks::-webkit-scrollbar {
  width: 4px;
}

.node-unlocks::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.node-costs {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 6px;
  margin-top: auto;
}

.cost-science { color: #7ec8ff; }
.cost-gold { color: #ffd76a; }

.branch-tech { --branch-color: #5aa8ff; }
.branch-maritime { --branch-color: #39d9ff; }
.branch-economy { --branch-color: #45ff6a; }
.branch-culture { --branch-color: #ff5ad6; }
.branch-atomic { --branch-color: #ff5555; }
.branch-wonders { --branch-color: #ffd34d; }

.node.wonder-shelf {
  width: 144px;
  min-height: 108px;
  height: 108px;
  max-height: 108px;
  padding: 8px 8px 6px;
  gap: 4px;
}

.node.wonder-shelf .node-title {
  font-size: 12px;
  line-height: 1.15;
  padding-bottom: 4px;
}

.node.wonder-shelf .node-unlocks {
  font-size: 9px;
  line-height: 1.25;
  max-height: 34px;
  -webkit-line-clamp: 3;
}

.node.wonder-shelf .node-costs {
  font-size: 9px;
  padding-top: 3px;
}

.node.wonder-shelf.wonder-era-start::before {
  content: attr(data-era-label);
  position: absolute;
  left: -1px;
  bottom: calc(100% + 20px);
  min-width: 144px;
  color: #f6e9c1;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-align: left;
  text-shadow: 0 2px 5px #000;
}

.node.wonder-shelf.wonder-era-start::after {
  content: "";
  position: absolute;
  left: -1px;
  bottom: calc(100% + 10px);
  width: 144px;
  height: 2px;
  background: #d7b74e;
  box-shadow: 0 0 5px rgba(215, 183, 78, 0.48);
}

.node.dimmed { opacity: 0.2; }
.node.search-hit {
  box-shadow: 0 0 0 2px rgba(126, 200, 255, 0.5), 0 12px 32px rgba(0, 0, 0, 0.45);
}
.node.studied { border-color: var(--studied); }
.node.target { border-color: var(--target); box-shadow: 0 0 0 2px rgba(255, 90, 143, 0.35); }
.node.needed { border-color: var(--needed); }
.viewer-layout .node:hover {
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(126, 200, 255, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
}

.node:hover { transform: translate(-50%, -50%) scale(1.03); }

.nodes-layer,
.edges {
  contain: layout style;
}

.detail-panel {
  width: 340px;
  max-width: 38vw;
  background: linear-gradient(180deg, #121820 0%, #0e1218 100%);
  border-left: 1px solid #2a3548;
  padding: 20px 18px 18px;
  overflow-y: auto;
  position: relative;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.4);
}

.detail-panel.hidden {
  display: none;
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: #222a38;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

.detail-era {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--target);
  margin-bottom: 6px;
}

.detail-title {
  margin: 0 28px 16px 0;
  font-size: 26px;
  line-height: 1.2;
}

.detail-section h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-costs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 10px;
}

.cost-box {
  border-radius: 12px;
  padding: 12px;
  border: 1px solid #2a3345;
  background: #0c1018;
}

.cost-box span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.cost-box strong {
  font-size: 18px;
}

.cost-box.science strong { color: #7ec8ff; }
.cost-box.gold strong { color: #ffd76a; }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid #3a4a64;
  background: linear-gradient(180deg, #1e2838 0%, #151c28 100%);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(90, 168, 255, 0.2);
}

.chip.muted-chip {
  cursor: default;
  opacity: 0.65;
}

.chip.muted-chip:hover {
  transform: none;
  box-shadow: none;
}

.chip.studied {
  border-color: var(--studied);
  opacity: 0.7;
}

.result {
  background: #0c1018;
  border: 1px solid #2a3345;
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  margin-bottom: 8px;
}

.result.muted {
  color: var(--muted);
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
}

.edge-merge { stroke-width: 3; }
.edge-vertical.edge-atomic { stroke: #ff5555; stroke-width: 4; }

@media (max-width: 1100px) {
  .workspace:not(.workspace-viewer) {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .tools-panel {
    display: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 10px;
  }

  .brand-block {
    flex: 1 1 100%;
  }

  .topbar-hint {
    font-size: 11px;
  }

  .zoom-controls button {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .topbar input[type="search"] {
    flex: 1 1 100%;
    max-width: none;
    margin-left: 0;
  }
}

.viewer.viewer-path-focus .node.target {
  border-color: #ff4444;
  box-shadow:
    0 0 0 4px rgba(255, 55, 55, 0.95),
    0 0 36px rgba(255, 60, 50, 0.65),
    0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Телефоны: меньше DOM, без blur/filter при панорамировании */
html.perf-mobile .viewer.expanded-layout {
  background-image: none;
}

html.perf-mobile .viewer-wrap::after {
  display: none;
}

html.perf-mobile .edge-tech,
html.perf-mobile .edge-economy,
html.perf-mobile .edge-culture,
html.perf-mobile .edge-wonders,
html.perf-mobile .edge-atomic,
html.perf-mobile .edge-merge {
  filter: none;
}

html.perf-mobile .edge-path,
html.perf-mobile .edge-line,
html.perf-mobile .edge-merge {
  vector-effect: unset;
  stroke-width: 2.5;
}

html.perf-mobile .edge-bus,
html.perf-mobile .edge-cross,
html.perf-mobile .edge-split,
html.perf-mobile .edge-stack {
  stroke-width: 3;
}

html.perf-mobile .node {
  width: 196px;
  min-height: 64px;
  padding: 8px 10px 6px;
  box-shadow: none;
  contain: layout paint style;
}

html.perf-mobile .node-compact .node-title {
  padding-bottom: 4px;
  margin-bottom: 0;
  font-size: 14px;
}

html.perf-mobile .node-compact .node-costs {
  border-top: none;
  padding-top: 2px;
  font-size: 11px;
}

html.perf-mobile .viewer-layout .node.in-path,
html.perf-mobile .viewer-layout .node.in-path.branch-tech,
html.perf-mobile .viewer-layout .node.in-path.branch-economy,
html.perf-mobile .viewer-layout .node.in-path.branch-culture,
html.perf-mobile .viewer-layout .node.in-path.branch-atomic,
html.perf-mobile .viewer-layout .node.in-path.branch-wonders {
  box-shadow: 0 0 0 2px rgba(255, 90, 70, 0.9);
}

html.perf-mobile .viewer-layout .node.target,
html.perf-mobile .viewer.viewer-path-focus .node.target {
  box-shadow: 0 0 0 3px rgba(255, 55, 55, 0.95);
}

html.perf-mobile .viewer-layout .node:hover {
  box-shadow: none;
}

html.perf-mobile .stage.stage-animate {
  transition: none;
}

html.perf-mobile .viewer.is-panning .node,
html.perf-mobile .viewer.is-panning .edge-path,
html.perf-mobile .viewer.is-panning .edge-merge,
html.perf-mobile .viewer.is-panning .era-header-manual {
  opacity: 1;
}

html.perf-mobile .viewer.is-panning .node.dimmed {
  opacity: 0.12;
}

html.perf-mobile .viewer.is-pinching {
  cursor: zoom-in;
}

html.perf-mobile .era-column-rail {
  display: none;
}

.topbar-link {
  color: #8db2ff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #32435f;
  background: #1a2438;
}

.topbar-link:hover {
  background: #24324a;
}

.editor-panel {
  width: 360px;
  max-width: 40vw;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.compact {
  gap: 4px;
}

.field span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid #32435f;
  background: #0c1018;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
}

.field textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.45;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.editor-actions button {
  border: 1px solid #32435f;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}

.editor-actions button.accent {
  background: #3d2a6b;
  border-color: #9b6dff;
}

.tools-panel button.danger-outline {
  background: transparent;
  border-color: #aa4444;
  color: #ff9999;
}

.tools-panel button.danger-outline:hover {
  background: #3a1a1a;
}

.editor-actions button.danger,
.tools-panel button.danger {
  background: #4a1f1f;
  border-color: #aa4444;
  color: #ffb0b0;
}

.edge-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edge-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #0c1018;
  border: 1px solid #2a3345;
  font-size: 13px;
}

.edge-list .edge-empty {
  color: var(--muted);
  justify-content: center;
}

.edge-remove {
  border: none;
  background: #3a2020;
  color: #ff8888;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.era-editor-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.era-editor-row {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #2a3345;
  background: #0c1018;
}

.file-btn {
  display: block;
  text-align: center;
  cursor: pointer;
  margin-bottom: 8px;
}

.editor-hint {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0 0 8px 0;
}

.editor-hint code {
  color: #9bc4ff;
  font-size: 10px;
}

.plan-result {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #0d1a12;
  border: 1px solid #2d5a3d;
  color: #9fdfb0;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.plan-result.hidden {
  display: none;
}

.create-node-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #3d2a6b;
  background: rgba(61, 42, 107, 0.15);
}

.create-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.create-actions button {
  width: 100%;
  border: 1px solid #32435f;
  border-radius: 8px;
  padding: 9px 10px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  margin-bottom: 0;
}

.create-actions button.accent {
  background: #3d2a6b;
  border-color: #9b6dff;
}

.create-actions button.secondary {
  background: #222a38;
  border-color: #3a4a64;
}

.viewer.placing-node {
  cursor: crosshair;
}

.viewer.placing-node .node {
  pointer-events: none;
}


.unlock-link {
  color: #4ea1f3;
  text-decoration: none;
}
.unlock-link:hover {
  color: #82c8ff;
  text-decoration: underline;
}

.chip.chip-link {
  color: #4ea1f3 !important;
  text-decoration: none;
  cursor: pointer;
}
.chip.chip-link:hover {
  color: #82c8ff !important;
  background: rgba(78, 161, 243, 0.12) !important;
  border-color: #4ea1f3 !important;
}

.cost-box.rating strong { color: #b6d2a7; }
#detailArticle { font-size: 13px; }


.detail-unlock-group {
  width: 100%;
  min-width: 0;
  margin-bottom: 4px;
}

.detail-unlock-group h4 {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.detail-unlock-group .chip {
  padding: 5px 10px;
}
