* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a1018;
  --panel: #0e1a2b;
  --panel-2: #10243a;
  --grid: rgba(110, 180, 210, 0.06);
  --grid-strong: rgba(110, 180, 210, 0.11);
  --ink: #8fd4e6;
  --ink-dim: #5e8aa3;
  --paper: #cfe3ee;
  --muted: #93afc1;
  --brass: #d9a441;
  --brass-dim: #9c7728;
  --spark: #ffe27a;
  --charge: #7fe6ff;
  --hot: #ffd166;
  --line: rgba(120, 180, 210, 0.18);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--paper);
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.1rem;
  background: linear-gradient(180deg, #0e1a2b, #0a131f);
  border-bottom: 1px solid var(--line);
}

.title-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.title {
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--paper);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.title .cog { color: var(--brass); display: inline-block; animation: slowspin 9s linear infinite; }
.subtitle {
  font-size: clamp(0.62rem, 1.3vw, 0.8rem);
  color: var(--ink-dim);
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.controls button {
  font-family: inherit;
  font-size: 0.74rem;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.controls button:hover { background: #173451; border-color: var(--ink-dim); }
.controls button:active { transform: translateY(1px); }
.tour-count {
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 3.4rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Layout ── */
main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.stage {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(var(--grid-strong) 1px, transparent 1px) 0 0 / 140px 140px,
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px) 0 0 / 140px 140px,
    radial-gradient(ellipse at 50% 40%, #0f1d30, #080e16 80%);
}

#blueprint { width: 100%; height: 100%; display: block; }

/* ── Side panel ── */
.panel {
  flex: 0 0 clamp(260px, 30%, 400px);
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  flex: 0 0 auto;
  padding: 0.9rem 1.1rem 0.7rem;
  border-bottom: 1px solid var(--line);
}
.panel-kicker {
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 0.3rem;
}
.panel-title {
  font-size: 1.18rem;
  font-weight: 600;
  color: var(--paper);
  line-height: 1.15;
}
.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.9rem 1.1rem 1.4rem;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--muted);
}
.panel-body p { margin-bottom: 0.85rem; }
.panel-body strong { color: var(--paper); font-weight: 600; }
.panel-body em { color: var(--charge); font-style: normal; }

.specs { list-style: none; margin: 0.4rem 0 1rem; }
.specs li {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.32rem 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.78rem;
}
.specs .k { color: var(--ink-dim); }
.specs .v { color: var(--paper); text-align: right; font-variant-numeric: tabular-nums; }

.hint {
  font-size: 0.74rem;
  color: var(--ink-dim);
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
  margin-top: 0.4rem;
}
.flow-tag {
  display: inline-block;
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--ink);
  border-radius: 4px;
  padding: 2px 7px;
  margin-bottom: 0.7rem;
}
.flow-tag.power { background: var(--brass); }
.flow-tag.logi { background: #6fd0a0; }
.flow-tag.tribo { background: var(--charge); }

/* ── SVG component styling ── */
.comp { cursor: pointer; }
.comp .hit { fill: transparent; }
.comp-outline {
  fill: none;
  stroke: var(--hot);
  stroke-width: 1.4;
  stroke-dasharray: 5 4;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
.comp:hover .comp-outline { opacity: 0.4; }
.comp.selected .comp-outline {
  opacity: 1;
  filter: drop-shadow(0 0 5px var(--hot));
}
.comp.selected .ink { stroke: var(--hot); }
.comp.dimmed { opacity: 0.32; }

.ink { stroke: var(--ink); fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.ink-thin { stroke: var(--ink-dim); fill: none; stroke-width: 1; }
.fillp { fill: #0c1726; }
.fillp2 { fill: #112a40; }
.brass { stroke: var(--brass); fill: none; stroke-width: 1.6; }
.brass-f { fill: var(--brass); opacity: 0.85; }
.lbl {
  fill: var(--paper);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  text-anchor: middle;
  font-weight: 500;
}
.lbl-sm { fill: var(--ink-dim); font-size: 10px; text-anchor: middle; font-family: 'Space Grotesk', sans-serif; }
.section-lbl {
  fill: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.18em;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
}
.divider { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 6; }
.frame { fill: none; stroke: var(--line); stroke-width: 1.4; }
.cable { stroke: var(--brass-dim); stroke-width: 2; fill: none; opacity: 0.7; }

/* ── Animations ── */
@keyframes slowspin { to { transform: rotate(360deg); } }

.belt-move { stroke-dasharray: 7 7; animation: beltflow 0.8s linear infinite; }
.belt-move.rev { animation-direction: reverse; }
@keyframes beltflow { to { stroke-dashoffset: -14; } }

.spark { opacity: 0; }
.spark.go { animation: sparkle 0.5s steps(1) infinite; }
@keyframes sparkle { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

.charge-flow { stroke-dasharray: 3 9; animation: chargeflow 0.6s linear infinite; }
@keyframes chargeflow { to { stroke-dashoffset: -12; } }

.stage.paused .belt-move,
.stage.paused .spark.go,
.stage.paused .charge-flow {
  animation-play-state: paused;
}

@media (max-width: 720px) {
  main { flex-direction: column; }
  .panel { flex: 0 0 42%; border-left: none; border-top: 1px solid var(--line); }
  .subtitle { display: none; }
}
