:root {
  color-scheme: dark;
  --bg: #0a0e12;
  --surface: #141b22;
  --surface-2: #10161d;
  --line: #2a3644;
  --text: #c9d6e0;
  --muted: #6b7d8f;
  --amber: #e8a13c;
  --cyan: #3fd0c9;
  --danger: #e46f5d;
  --ok: #77d08b;
  --wall: #d5e2ed;
  --configspace: rgba(228, 111, 93, .35);
  --focus: 0 0 0 3px rgba(63, 208, 201, .28), 0 0 0 1px var(--cyan) inset;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --display: "Space Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  background:
    linear-gradient(rgba(42, 54, 68, .16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 54, 68, .13) 1px, transparent 1px),
    radial-gradient(circle at 30% 0%, rgba(63, 208, 201, .08), transparent 34rem),
    var(--bg);
  background-size: 44px 44px, 44px 44px, auto, auto;
}

a { color: var(--cyan); }

button, input, select { font: inherit; }
button, select, input[type="range"] { outline: none; }
button:focus-visible, select:focus-visible, input:focus-visible { box-shadow: var(--focus); }

.page {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 22px;
}

header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: end;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--amber);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1 {
  margin: 8px 0 10px;
  max-width: 980px;
  font-family: var(--display);
  font-size: clamp(2rem, 4.6vw, 4.6rem);
  line-height: .96;
}

.intro {
  max-width: 860px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(.9rem, 1.2vw, 1.05rem);
  line-height: 1.6;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 8px;
  min-width: 300px;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(20, 27, 34, .72);
  padding: 10px 12px;
  min-height: 60px;
}

.chip span {
  display: block;
  color: var(--muted);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.chip strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
  padding-top: 16px;
}

.stage { min-width: 0; }

.canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface-2);
  min-height: 420px;
  overflow: hidden;
}

#sim {
  display: block;
  height: auto;
  max-width: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.canvas-help {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  padding: 12px 2px 0;
  color: var(--muted);
  font-size: .76rem;
}

.legend-item { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }

.swatch { width: 12px; height: 12px; border: 1px solid var(--line); background: var(--muted); }
.swatch.wall { background: var(--wall); }
.swatch.configspace { background: var(--configspace); }
.swatch.frontier { background: var(--cyan); }
.swatch.path { background: var(--amber); }

.readout {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(20, 27, 34, .6);
  color: var(--text);
  font-size: .82rem;
  min-height: 20px;
}

aside {
  border: 1px solid var(--line);
  background: rgba(20, 27, 34, .92);
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.panel-section { padding: 14px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }

.section-title {
  margin: 0 0 12px;
  color: var(--text);
  font-size: .76rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #101820;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease, transform .16s ease;
}

button:hover { border-color: rgba(63, 208, 201, .7); background: #14212a; }
button:active { transform: translateY(1px); }

button[aria-pressed="true"], button.primary, button[data-active="true"] {
  border-color: rgba(232, 161, 60, .82);
  color: #ffe2b5;
  background: rgba(232, 161, 60, .13);
}

button.tool.start[aria-pressed="true"] {
  border-color: rgba(119, 208, 139, .8);
  color: #d8f5e1;
  background: rgba(119, 208, 139, .14);
}

button.tool.goal[aria-pressed="true"] {
  border-color: rgba(228, 111, 93, .8);
  color: #ffd9d0;
  background: rgba(228, 111, 93, .14);
}

.icon-button { min-width: 0; padding: 0; font-size: 1rem; }

.micro-hint { margin: 6px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

.field { display: grid; gap: 8px; margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }

label, .field-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.value { color: var(--cyan); font-weight: 500; }

input[type="range"] { width: 100%; accent-color: var(--cyan); }

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: #101820;
  padding: 0 10px;
}

.desc-text {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.55;
  min-height: 3.1em;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: .8rem;
}

.switch { position: relative; width: 48px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; opacity: 0; }
.switch span { position: absolute; inset: 0; border: 1px solid var(--line); background: #0d1319; }
.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--muted);
  transition: transform .18s ease, background .18s ease;
}
.switch input:checked + span::after { transform: translateX(22px); background: var(--cyan); }
.switch input:focus-visible + span { box-shadow: var(--focus); }

.compare-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 14, .82);
  padding: 24px;
}

.compare-overlay[hidden] { display: none; }

.compare-box {
  width: min(720px, 100%);
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--cyan);
  background: var(--surface);
  padding: 16px;
}

.compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compare-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
}

.compare-hint { margin: 6px 0 12px; color: var(--muted); font-size: .78rem; }

.compare-table-wrap { overflow-x: auto; }

.compare-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.compare-table th, .compare-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.compare-table th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: .68rem; letter-spacing: .06em; }
.compare-table tbody tr { cursor: pointer; }
.compare-table tbody tr:hover { background: rgba(63, 208, 201, .08); }
.compare-table td.success { color: var(--ok); }
.compare-table td.failure { color: var(--danger); }

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  color: var(--muted);
  font-size: .78rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
  }
}

@media (max-width: 860px) {
  .page { width: min(100% - 22px, 760px); padding-top: 18px; }
  header { grid-template-columns: 1fr; }
  .status-strip { min-width: 0; }
  main { grid-template-columns: 1fr; }
  aside { position: static; max-height: none; }
}

@media (max-width: 520px) {
  .status-strip, .button-grid { grid-template-columns: 1fr; }
}
