:root {
  color-scheme: dark;
  --bg: #05070d;
  --panel: #0d1220;
  --panel-2: #161d33;
  --ink: #e6ecff;
  --muted: #9aa4c7;
  --accent: #7cc4ff;
  --accent-2: #ffb974;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
}

body {
  height: 100vh;
  width: 100vw;
}

#app {
  display: grid;
  height: 100vh;
  width: 100vw;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "stage panel";
  gap: 0;
}

.topbar {
  grid-area: header;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0a0f1e 0%, #05070d 100%);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar .subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.stage {
  grid-area: stage;
  position: relative;
  background: radial-gradient(
    ellipse at center,
    #0a1428 0%,
    #04060c 70%,
    #000 100%
  );
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

#sim-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

#sim-canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(6, 9, 20, 0.7);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  min-width: 160px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.hud-label {
  color: var(--muted);
}

.hud-value {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink);
}

.panel {
  grid-area: panel;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.primary-controls {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  min-height: 40px;
  min-width: 44px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button:hover {
  background: #1c2545;
  border-color: rgba(255, 255, 255, 0.18);
}

button:active {
  background: #232d55;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#play-pause {
  background: var(--accent);
  color: #05070d;
  border-color: transparent;
  font-weight: 600;
}
#play-pause:hover {
  background: #9dd6ff;
}

#add-comet {
  background: var(--accent-2);
  color: #201406;
  border-color: transparent;
  font-weight: 600;
}
#add-comet:hover {
  background: #ffcc95;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #1c2545;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #05070d;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #05070d;
}

input[type="range"]:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.help {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  font-size: 12px;
  color: var(--muted);
}
.help h2 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.help ul {
  padding-left: 16px;
  margin: 0 0 8px;
}
.help li {
  margin-bottom: 2px;
}
.help kbd {
  background: #1c2545;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}
.seed-line {
  margin: 6px 0 0;
}

/* Mobile / narrow layout (e.g. 375x812) */
@media (max-width: 720px) {
  html,
  body {
    overflow: auto;
  }
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(320px, 55vh) auto;
    grid-template-areas:
      "header"
      "stage"
      "panel";
    height: auto;
    min-height: 100vh;
  }
  .panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
  }
  .topbar h1 {
    font-size: 16px;
  }
}
