:root {
  color-scheme: dark;
  --bg-top: #09111f;
  --bg-bottom: #04070d;
  --panel: rgba(9, 17, 31, 0.86);
  --panel-border: rgba(148, 163, 184, 0.18);
  --text: #edf2ff;
  --muted: #8fa1c5;
  --accent: #7ae7ff;
  --accent-strong: #33d0ff;
  --warning: #ff8f70;
  --danger: #ff5d73;
  --ok: #9bf0ae;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Yu Gothic UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(51, 208, 255, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(122, 231, 255, 0.15), transparent 25%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.45) 0 1px, transparent 1px);
  background-size: 140px 140px;
  opacity: 0.2;
}

.app-shell {
  position: relative;
  padding: 28px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.3rem, 4vw, 4.5rem);
  line-height: 0.95;
}

.subtitle {
  margin-bottom: 0;
  max-width: 640px;
  color: var(--muted);
}

.hero-stats {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.stat-card,
.card,
.overlay-card {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.stat-card {
  min-width: 120px;
  padding: 14px 16px;
  border-radius: 18px;
}

.stat-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-card strong {
  font-size: 1.7rem;
}

.restart-button {
  border: 0;
  border-radius: 18px;
  padding: 0 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #04101b;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.restart-button:hover,
.restart-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(51, 208, 255, 0.28);
}

.restart-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.language-button {
  align-self: stretch;
  min-width: 112px;
  padding: 8px 16px 10px;
  border: 1px solid rgba(122, 231, 255, 0.38);
  background: linear-gradient(145deg, rgba(122, 231, 255, 0.08), rgba(51, 208, 255, 0.18));
  color: var(--text);
  line-height: 1.05;
}

.language-button::before {
  content: "Language";
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.language-button:hover,
.language-button:focus-visible {
  box-shadow: 0 10px 24px rgba(122, 231, 255, 0.2);
}

.reset-button {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.3), rgba(100, 116, 139, 0.4));
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.9fr);
  gap: 18px;
}

.left-column {
  display: grid;
  gap: 18px;
}

.card {
  border-radius: 24px;
}

.map-panel {
  padding: 20px;
}

.objective-inline {
  width: 100%;
  margin-bottom: 0;
}

.rules-inline {
  width: 100%;
  margin-bottom: 0;
}

.rules-inline .compact-list {
  display: grid;
  gap: 8px;
  line-height: 1.5;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.panel-header p,
.info-card p,
.compact-list,
.node-detail {
  color: var(--muted);
}

.event-badge {
  align-self: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(155, 240, 174, 0.12);
  border: 1px solid rgba(155, 240, 174, 0.2);
  color: var(--ok);
  font-size: 0.9rem;
}

.event-badge.warning {
  color: var(--warning);
  background: rgba(255, 143, 112, 0.12);
  border-color: rgba(255, 143, 112, 0.22);
}

.map-wrap {
  position: relative;
  aspect-ratio: 1000 / 640;
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(122, 231, 255, 0.08), transparent 35%),
    linear-gradient(180deg, rgba(7, 13, 24, 0.8), rgba(4, 7, 13, 0.95));
  border: 1px solid rgba(122, 231, 255, 0.1);
}

#routeLayer,
.node-layer {
  position: absolute;
  inset: 0;
}

#routeLayer {
  z-index: 0;
}

.node-layer {
  z-index: 1;
  pointer-events: none;
}

.route-line {
  stroke: rgba(122, 231, 255, 0.24);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke 40ms linear, opacity 120ms ease, filter 120ms ease;
  pointer-events: none;
}

.route-hit {
  stroke: rgba(255, 255, 255, 0.001);
  stroke-width: 32;
  stroke-linecap: round;
  cursor: pointer;
  transition: stroke 120ms ease;
  outline: none;
}

.route-hit:hover {
  stroke: rgba(255, 255, 255, 0.001);
}

.route-hit:focus,
.route-hit:focus-visible {
  stroke: rgba(255, 255, 255, 0.001);
  outline: none;
}

.route-line.active {
  stroke: rgba(122, 231, 255, 0.95);
  filter: drop-shadow(0 0 8px rgba(122, 231, 255, 0.42));
}

.route-line.flow-forward,
.route-line.flow-reverse {
  stroke-dasharray: 10 10;
}

.route-line.flow-forward {
  animation: route-flow-forward 2s linear infinite;
}

.route-line.flow-reverse {
  animation: route-flow-reverse 2s linear infinite;
}

.route-line.flow-paused {
  animation-play-state: paused;
}

.route-line.blocked {
  stroke: rgba(255, 93, 115, 0.95);
  stroke-dasharray: 14 14;
  animation: none;
}

@keyframes route-flow-forward {
  from {
    stroke-dashoffset: 0;
  }

  to {
    stroke-dashoffset: -20;
  }
}

@keyframes route-flow-reverse {
  from {
    stroke-dashoffset: 0;
  }

  to {
    stroke-dashoffset: 20;
  }
}

.route-hit:hover~.route-line {
  stroke: rgba(122, 231, 255, 0.24);
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.24));
}

.route-hit:hover~.route-line.active {
  stroke: rgba(122, 231, 255, 0.95);
  filter: drop-shadow(0 0 8px rgba(122, 231, 255, 0.42));
}

.route-hit:hover~.route-line.blocked {
  stroke: rgba(255, 93, 115, 0.95);
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.2));
}

.route-label {
  fill: rgba(237, 242, 255, 0.8);
  font-size: 18px;
  text-anchor: middle;
  transition: fill 120ms ease, font-size 120ms ease;
  pointer-events: none;
}

.route-label.active {
  fill: rgba(237, 242, 255, 1);
  font-size: 20px;
}

.node {
  position: absolute;
  pointer-events: none;
  width: 126px;
  min-height: 104px;
  transform: translate(-50%, -50%);
  border-radius: 24px;
  border: 1px solid rgba(122, 231, 255, 0.18);
  background: rgba(8, 15, 27, 0.9);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.node.critical {
  border-color: rgba(255, 143, 112, 0.3);
}

.node.support {
  border-color: rgba(155, 240, 174, 0.3);
}

.node.offline {
  border-color: rgba(255, 93, 115, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 93, 115, 0.18);
}

.node.alert {
  border-color: rgba(255, 143, 112, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 143, 112, 0.18), 0 12px 30px rgba(255, 143, 112, 0.14);
}

.node.energy-low {
  animation: energy-low-pulse 1.2s ease-in-out infinite;
}

.node h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.node small {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
}

.resource-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
}

.energy-value {
  transition: color 240ms ease, text-shadow 240ms ease;
}

.energy-value.trend-up {
  color: var(--ok);
  text-shadow: 0 0 8px rgba(155, 240, 174, 0.24);
}

.energy-value.trend-down {
  color: var(--warning);
  text-shadow: 0 0 8px rgba(255, 143, 112, 0.24);
}

.energy-bar {
  margin-top: 7px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.energy-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ffb082, var(--accent-strong));
  transition: width 700ms cubic-bezier(0.25, 0.46, 0.45, 0.94), filter 240ms ease;
}

.energy-bar.trend-up span {
  filter: drop-shadow(0 0 4px rgba(155, 240, 174, 0.45));
}

.energy-bar.trend-down span {
  filter: drop-shadow(0 0 4px rgba(255, 143, 112, 0.45));
}

.value-positive {
  color: var(--ok);
}

.value-negative {
  color: var(--danger);
}

.resource-row+.resource-row {
  margin-top: 6px;
}

.integrity-row {
  margin-top: 8px;
}

.integrity-bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.integrity-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--warning), var(--ok));
}

@keyframes energy-low-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(255, 143, 112, 0.18), 0 10px 24px rgba(255, 143, 112, 0.12);
  }

  50% {
    box-shadow: 0 0 0 1px rgba(255, 143, 112, 0.38), 0 14px 34px rgba(255, 143, 112, 0.25);
  }
}

.side-panel {
  display: grid;
  gap: 18px;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  max-height: calc(100vh - 220px);
  overflow: hidden;
}

.info-card {
  padding: 18px;
}

.event-log-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.event-log-card h2 {
  margin-bottom: 10px;
}

.compact-list {
  padding-left: 18px;
  margin-bottom: 0;
}

.node-detail {
  line-height: 1.6;
}

.hint-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.hint-header h2 {
  margin-bottom: 0;
}

.hint-toggle-button {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 4px 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.hint-toggle-button:hover,
.hint-toggle-button:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.advisor-list.hidden {
  display: none;
}

.advisor-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.advisor-item {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  line-height: 1.5;
}

.advisor-item strong {
  color: var(--text);
}

.log {
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.log-entry {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.92rem;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 4, 8, 0.72);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 28px;
}

@media (prefers-reduced-motion: reduce) {
  .node.energy-low {
    animation: none;
  }

  .route-line.flow-forward,
  .route-line.flow-reverse {
    animation: none;
  }

  .energy-bar span,
  .energy-value {
    transition: none;
  }
}

@media (max-width: 960px) {
  .app-shell {
    padding: 18px;
  }

  .hero,
  .hero-stats {
    flex-direction: column;
    align-items: stretch;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-rows: auto auto;
    max-height: none;
    overflow: visible;
  }

  .objective-inline {
    width: 100%;
  }

  .node {
    width: 112px;
    min-height: 98px;
  }
}

@media (max-height: 820px) {
  .node {
    width: 112px;
    min-height: 92px;
    padding: 10px;
  }

  .node h3 {
    margin-bottom: 6px;
    font-size: 0.88rem;
  }

  .node small {
    margin-bottom: 6px;
    font-size: 0.72rem;
  }

  .resource-row {
    font-size: 0.76rem;
  }

  .node[data-node-id="relay"] {
    transform: translate(-50%, -55%);
  }
}