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

:root {
  --bg-deep: #080e1c;
  --bg-panel: #0f172a;
  --bg-card: #1e293b;
  --border-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --accent-sky: #38bdf8;
  --btn-blue: #0369a1;
  --btn-coral: #c2410c;
  --btn-emerald: #15803d;
  --btn-slate: #1e293b;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "DejaVu Sans", sans-serif;
  line-height: 1.35;
}

.top-header {
  max-width: 1004px;
  margin: 0 auto;
  padding: 6px 12px 4px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.top-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #f8fafc;
}

.badge {
  background: #0f172a;
  border: 1px solid #0369a1;
  color: #7dd3fc;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.lede {
  margin: 3px 0 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

kbd, code {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 0 4px;
  font-family: "DejaVu Sans Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  color: #f8fafc;
}

.action-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

button {
  appearance: none;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 0.73rem;
  font-weight: 600;
  font-family: inherit;
  color: #ffffff;
  background: var(--btn-slate);
  cursor: pointer;
  transition: filter 0.12s ease, border-color 0.12s ease;
}

button:hover {
  filter: brightness(1.12);
  border-color: #7dd3fc;
}

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.btn-primary {
  background: var(--btn-blue);
  border-color: #38bdf8;
  color: #ffffff;
}

.btn-accent {
  background: var(--btn-coral);
  border-color: #fdba74;
  color: #ffffff;
}

.btn-emerald {
  background: var(--btn-emerald);
  border-color: #86efac;
  color: #ffffff;
}

.btn-slate {
  background: #1e293b;
  border-color: #475569;
  color: #f8fafc;
}

.workbench-grid {
  max-width: 1004px;
  margin: 0 auto;
  padding: 4px 12px 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 298px;
  gap: 10px;
  align-items: start;
  isolation: isolate;
}

.stage-column, .control-sidebar {
  min-width: 0;
}

.canvas-frame {
  position: relative;
  background: #0b1120;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px;
  z-index: 1;
}

#orbitCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 396px;
  aspect-ratio: 640 / 396;
  border-radius: 6px;
  background: #070c18;
  touch-action: none;
  cursor: crosshair;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}

.hud-pill {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-right {
  border-color: #0369a1;
  color: #7dd3fc;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 5px 8px;
  min-width: 0;
}

.metric-label {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

.metric-value {
  font-size: 0.80rem;
  font-weight: 700;
  color: #f8fafc;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-sidebar {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hidden {
  display: none !important;
}

.panel-heading {
  margin: 0;
  font-size: 0.80rem;
  font-weight: 700;
  color: #7dd3fc;
}

.btn-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.btn-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.mode-btn, .brush-btn {
  padding: 5px 4px;
  font-size: 0.72rem;
  text-align: center;
  white-space: nowrap;
}

.mode-btn.active, .brush-btn.active {
  background: var(--btn-blue);
  border-color: #7dd3fc;
  color: #ffffff;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  color: #e2e8f0;
  margin-top: 2px;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #38bdf8;
}

.course-desc {
  margin: 4px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.rules-list {
  margin: 0;
  padding-left: 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-banner {
  background: #111827;
  border: 1px solid #334155;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 0.74rem;
  color: #e2e8f0;
}

.site-footer {
  max-width: 1004px;
  margin: 2px auto 10px;
  padding: 4px 12px;
  font-size: 0.72rem;
  color: #cbd5e1;
  text-align: center;
}

.site-footer a {
  color: #7dd3fc;
  text-decoration: underline;
  font-weight: 600;
}

@media (max-width: 760px) {
  .top-header {
    padding: 4px 8px 3px;
  }
  .top-header h1 {
    font-size: 0.95rem;
  }
  .badge {
    font-size: 0.64rem;
    padding: 1px 6px;
  }
  .lede {
    font-size: 0.69rem;
    margin: 2px 0 4px;
    line-height: 1.25;
  }
  .action-strip {
    gap: 3px;
  }
  .action-strip button {
    font-size: 0.65rem;
    padding: 3px 5px;
  }
  .workbench-grid {
    grid-template-columns: minmax(0, 1fr);
    padding: 3px 8px 8px;
    gap: 8px;
  }
  .canvas-frame {
    padding: 4px;
  }
  .hud-pill {
    font-size: 0.65rem;
    padding: 2px 6px;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
