*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0e0e18;
  --panel: #161622;
  --border: #2a2a3e;
  --text: #e8e8f0;
  --muted: #9090a8;
  --accent: #0078ff;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.header h1 a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.15em;
}

.header h1 a:hover {
  color: var(--accent);
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.subtitle a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.15em;
}

.subtitle a:hover {
  color: var(--accent);
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 0;
  min-height: 0;
  height: calc(100vh - 72px);
}

.canvas-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0.5rem 0.75rem;
  height: 100%;
}

#sim-canvas {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #141428;
  cursor: crosshair;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.swatch.target { background: #ff6400; }
.swatch.obstacle { background: #0078ff; }
.swatch.robot { background: #fff; }
.swatch.path { background: #00c800; width: 16px; height: 3px; border-radius: 1px; }
.swatch.trail { background: #464646; }

.controls {
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.controls h2 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.control {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.25rem 0.5rem;
  margin-bottom: 0.9rem;
  font-size: 0.85rem;
}

.control-label {
  grid-column: 1 / -1;
}

.control-label em {
  color: var(--muted);
  font-style: normal;
}

.control input[type="range"] {
  grid-column: 1;
  width: 100%;
  accent-color: var(--accent);
}

.control output {
  grid-column: 2;
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-size: 0.8rem;
}

.buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}

.buttons button {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #1e1e30;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.buttons button:hover {
  background: #282840;
  border-color: var(--accent);
}

.buttons button.toggle-btn.active {
  background: #1a3050;
  border-color: var(--accent);
  color: #7ec8ff;
}

.stats {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stats strong {
  color: var(--text);
  font-weight: 500;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .controls {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  #sim-canvas {
    max-height: 60vh;
  }
}
