:root {
  --bg: #000000;
  --bg2: #000000;
  --ink: #e9eefc;
  --muted: rgba(233, 238, 252, 0.72);
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(0, 0, 0, 0.35);

  --start: #48d18d;
  --end: #ff5b6b;
  --wall: #0a0f1d;
  --visited: #47a6ff;
  --path: #ffd24a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: #000;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 15, 29, 0.55);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand .title {
  font-weight: 800;
  letter-spacing: 0.3px;
}
.brand .subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.navMore { display: none; }

.modeControls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modeControls .core,
.modeControls .adv {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stageMode { width: 100%; }

button {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 650;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
button:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.14); }
button:active { transform: translateY(0px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary { background: rgba(255, 255, 255, 0.06); }

.sep {
  width: 1px;
  height: 26px;
  background: var(--border);
  margin: 0 4px;
}

.slider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.slider input[type="range"] { width: 150px; }

.select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.select select {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(10, 15, 29, 0.4);
  color: var(--ink);
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 700;
}

.main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.stage {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 18px 50px var(--shadow);
  align-self: start;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 13px;
}

.hidden { display: none !important; }

.stageInner { width: 100%; }
.stageInner.quad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
  align-items: start;
  align-content: start;
}
.tile {
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  position: relative;
  align-self: start;
}
.tileTitle {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 15, 29, 0.55);
  backdrop-filter: blur(8px);
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 12px;
  color: rgba(233, 238, 252, 0.92);
  z-index: 1;
}
.tile canvas { width: 100%; height: auto; display: block; }

canvas {
  width: 100%;
  height: auto;
  display: block;
}

.hint { display: none; }

.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  color: var(--ink);
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
}

.panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panelCard {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 14px 34px var(--shadow);
}

.panelTitle {
  font-weight: 800;
  letter-spacing: 0.2px;
  margin-bottom: 10px;
}

.stats { display: grid; gap: 8px; }
.statRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}
.statKey { color: var(--muted); font-size: 12px; }
.statVal { font-weight: 800; }

.legend { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.legendRow { display: flex; align-items: center; gap: 10px; }
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.1);
}
.swatch.start { background: var(--start); }
.swatch.end { background: var(--end); }
.swatch.wall { background: var(--wall); }
.swatch.weight { background: rgba(255, 210, 74, 0.28); }
.swatch.frontier { background: rgba(71, 166, 255, 0.24); }
.swatch.visited { background: rgba(71, 166, 255, 0.75); }
.swatch.path { background: rgba(255, 210, 74, 0.92); }

.notes {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.paint { display: grid; gap: 10px; }
.paintRow { display: flex; gap: 10px; flex-wrap: wrap; }
.paintHint { color: var(--muted); font-size: 13px; line-height: 1.35; }

.playback { display: grid; gap: 10px; }
.playbackHint { color: var(--muted); font-size: 13px; line-height: 1.35; }
.slider.wide { width: 100%; justify-content: space-between; }
.slider.wide input[type="range"] { width: 200px; }

.movement { display: grid; gap: 10px; }

.scoreboard {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}
.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}
.scoreboard th, .scoreboard td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 4px;
  text-align: left;
  white-space: nowrap;
}
.scoreboard th { color: rgba(233, 238, 252, 0.85); font-weight: 800; }
.scoreboard td { color: var(--muted); }

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

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 12px;
  }

  .brand .subtitle { display: none; }
  .brand .title { font-size: 16px; }

  .controls {
    justify-content: flex-start;
    gap: 6px;
  }

  .navMore {
    display: inline-flex;
    margin-left: auto;
  }

  .sep { display: none; }

  /* Collapse advanced controls on mobile; toggle via body.nav-expanded */
  .modeControls .adv { display: none; width: 100%; }
  body.nav-expanded .modeControls .adv { display: flex; }

  .modeControls .core { width: 100%; }

  .select, .slider { flex: 1 1 180px; }
  button { flex: 0 0 auto; }
}
