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

html, body {
  width: 100%;
  height: 100%;
  background: #06060f;
  overflow: hidden;
  font-family: 'Courier New', Courier, monospace;
  color: rgba(190, 220, 255, 0.9);
  user-select: none;
}

/* ── Canvas ─────────────────────────────────────────────────── */

#sim-canvas {
  display: block;
  position: fixed;
  inset: 0;
  cursor: default;
}

/* ── HUD ─────────────────────────────────────────────────────── */

#hud {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 10;
  font-size: 13px;
  line-height: 1.9;
  color: rgba(150, 210, 255, 0.88);
  text-shadow: 0 0 10px rgba(80, 160, 255, 0.5);
  pointer-events: none;
  letter-spacing: 0.04em;
}

/* ── Go-to-date popup ────────────────────────────────────────── */

#goto-popup {
  display: none;
  position: fixed;
  bottom: 52px;
  left: 16px;
  background: rgba(4, 8, 24, 0.92);
  border: 1px solid rgba(80, 130, 220, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 6px;
  padding: 8px 10px;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  z-index: 20;
}
#goto-popup.open { display: flex; }

#goto-date {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(190, 220, 255, 0.9);
  border-radius: 3px;
  padding: 2px 5px;
  font-family: inherit;
  font-size: 12px;
  color-scheme: dark;
}

/* ── Control panel ───────────────────────────────────────────── */

#controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(4, 8, 24, 0.82);
  border-top: 1px solid rgba(80, 130, 255, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 9px 14px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ctrl-group + .ctrl-group {
  border-left: 1px solid rgba(80, 130, 255, 0.15);
  padding-left: 12px;
}

.ctrl-label {
  color: rgba(120, 170, 220, 0.65);
  font-size: 11px;
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */

button.ctrl-btn {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  border-radius: 4px;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

button.ctrl-btn:hover {
  background: rgba(40, 80, 160, 0.85);
  border-color: rgba(120, 180, 255, 0.5);
}

button.ctrl-btn.active {
  background: rgba(50, 110, 200, 0.85);
  border-color: rgba(140, 200, 255, 0.7);
  color: #fff;
}

#btn-play {
  font-size: 15px;
  padding: 3px 12px;
  min-width: 38px;
  text-align: center;
}

/* ── Select ──────────────────────────────────────────────────── */

#follow-select {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  border-radius: 4px;
  outline: none;
}

#follow-select:hover,
#follow-select:focus {
  border-color: rgba(120, 180, 255, 0.5);
}

/* ── Speed preset row ───────────────────────────────────────── */

#speed-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* ── Orbital elements panel ──────────────────────────────────── */

#orbit-panel {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 10;
  background: rgba(4, 8, 24, 0.72);
  border: 1px solid rgba(80, 130, 255, 0.18);
  border-radius: 6px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 12px 10px;
  font-size: 12px;
  min-width: 160px;
  pointer-events: auto;
}

#orbit-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

#orbit-table {
  border-collapse: collapse;
  width: 100%;
  color: rgba(150, 210, 255, 0.88);
}

#orbit-table td {
  padding: 1px 0;
  line-height: 1.7;
}

#orbit-table td:first-child {
  color: rgba(120, 170, 220, 0.65);
  width: 20px;
}

#orbit-table td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

#orbit-select {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 2px 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  border-radius: 4px;
  outline: none;
  flex: 1;
}

#orbit-select:hover,
#orbit-select:focus {
  border-color: rgba(120, 180, 255, 0.5);
}

/* ── Phase panel ─────────────────────────────────────────────── */

#phase-panel {
  position: fixed;
  top: 185px;
  right: 16px;
  z-index: 10;
  background: rgba(4, 8, 24, 0.72);
  border: 1px solid rgba(80, 130, 255, 0.18);
  border-radius: 6px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  pointer-events: none;
}

.phase-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 0;
}

.phase-cell + .phase-cell {
  border-top: 1px solid rgba(80, 130, 255, 0.12);
}

.phase-canvas {
  display: block;
}

.phase-name {
  font-size: 10px;
  color: rgba(120, 170, 220, 0.7);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ── Sky view panel ────────────────────────────────────────── */

#sky-panel {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 70px;
  z-index: 8;
}

#sky-panel.open { display: block; }

#sky-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#sky-controls {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 9;
}

#sky-location {
  display: flex;
  align-items: center;
  gap: 6px;
}

#sky-location-select {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  border-radius: 4px;
  outline: none;
}

#sky-location-select:hover,
#sky-location-select:focus {
  border-color: rgba(120, 180, 255, 0.5);
}

#sky-options {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#sky-options label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(150, 195, 240, 0.7);
  cursor: pointer;
}

#sky-options input[type="checkbox"] {
  accent-color: rgba(80, 150, 255, 0.8);
  cursor: pointer;
}

#sky-sync-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

#sky-sync-select {
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 2px 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  border-radius: 4px;
  outline: none;
}

#sky-sync-select:hover,
#sky-sync-select:focus {
  border-color: rgba(120, 180, 255, 0.5);
}

/* ── Doc links (styled as buttons) ──────────────────────────── */

#doc-links a.ctrl-btn {
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
  font-size: 12px;
  background: rgba(20, 45, 100, 0.75);
  border: 1px solid rgba(80, 130, 220, 0.3);
  color: rgba(180, 215, 255, 0.88);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

#doc-links a.ctrl-btn:hover {
  background: rgba(40, 80, 160, 0.85);
  border-color: rgba(120, 180, 255, 0.5);
}

/* ── Keyboard hint ───────────────────────────────────────────── */

#key-hint {
  margin-left: auto;
  color: rgba(100, 140, 190, 0.45);
  font-size: 11px;
  white-space: nowrap;
}

/* ── Mobile responsive ─────────────────────────────────────── */

@media (max-width: 600px) {

  /* HUD: compact */
  #hud {
    font-size: 11px;
    top: 8px;
    left: 10px;
    line-height: 1.6;
  }

  /* Orbit panel: compact top-right */
  #orbit-panel {
    top: 8px;
    right: 8px;
    font-size: 11px;
    min-width: auto;
    padding: 6px 10px 8px;
    background: rgba(4, 8, 24, 0.85);
  }

  #orbit-panel-header {
    margin-bottom: 4px;
    gap: 6px;
  }

  #orbit-table td {
    line-height: 1.4;
    padding: 0;
  }

  /* Phase panel: horizontal row above controls, scrollable */
  #phase-panel {
    position: fixed;
    top: auto;
    bottom: 42px;
    left: 0;
    right: 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 8px;
    gap: 4px;
    border-radius: 0;
    border: none;
    border-top: 1px solid rgba(80, 130, 255, 0.18);
    background: rgba(4, 8, 24, 0.88);
    -webkit-overflow-scrolling: touch;
    z-index: 9;
  }

  .phase-cell {
    flex-shrink: 0;
    padding: 1px 4px;
  }

  .phase-cell + .phase-cell {
    border-top: none;
    border-left: 1px solid rgba(80, 130, 255, 0.12);
  }

  .phase-name {
    font-size: 9px;
  }

  /* Controls: single row, horizontally scrollable */
  #controls {
    padding: 6px 8px;
    gap: 6px;
    font-size: 11px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ctrl-group + .ctrl-group {
    padding-left: 6px;
  }

  .ctrl-group {
    gap: 3px;
    flex-shrink: 0;
  }

  button.ctrl-btn {
    padding: 3px 7px;
    font-size: 11px;
  }

  #btn-play {
    font-size: 14px;
    padding: 2px 10px;
    min-width: 32px;
  }

  #follow-select, #orbit-select {
    font-size: 11px;
    padding: 2px 6px;
  }

  #key-hint {
    display: none;
  }

  .ctrl-label {
    font-size: 10px;
  }

  #goto-popup {
    bottom: 44px;
    left: 8px;
    font-size: 11px;
  }

  #sky-panel {
    bottom: 42px;
  }

  #doc-links {
    display: none;
  }
}

/* ── Tablet / landscape phone ─────────────────────────────── */

@media (max-width: 900px) and (min-width: 601px) {

  /* Phase panel: smaller canvases, tighter spacing */
  #phase-panel {
    padding: 6px 6px 4px;
    gap: 0;
  }

  .phase-cell {
    padding: 2px 0;
  }

  #key-hint {
    display: none;
  }

  #controls {
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .ctrl-group {
    flex-shrink: 0;
  }
}

/* ── Landscape phone (short viewport) ─────────────────────── */

@media (max-height: 500px) {

  /* Phase panel: horizontal bar above controls */
  #phase-panel {
    position: fixed;
    top: auto;
    bottom: 38px;
    left: 0;
    right: 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 3px 8px;
    gap: 4px;
    border-radius: 0;
    border: none;
    border-top: 1px solid rgba(80, 130, 255, 0.18);
    background: rgba(4, 8, 24, 0.88);
    -webkit-overflow-scrolling: touch;
    z-index: 9;
  }

  .phase-cell {
    flex-shrink: 0;
    padding: 1px 4px;
  }

  .phase-cell + .phase-cell {
    border-top: none;
    border-left: 1px solid rgba(80, 130, 255, 0.12);
  }

  .phase-name {
    font-size: 9px;
  }

  /* Compact controls */
  #controls {
    padding: 5px 8px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .ctrl-group {
    flex-shrink: 0;
  }

  #key-hint {
    display: none;
  }

  button.ctrl-btn {
    padding: 2px 7px;
    font-size: 11px;
  }

  #btn-play {
    font-size: 13px;
    padding: 2px 8px;
    min-width: 30px;
  }

  /* Orbit panel compact */
  #orbit-panel {
    font-size: 11px;
    padding: 5px 10px 6px;
  }

  #orbit-table td {
    line-height: 1.3;
    padding: 0;
  }

  #sky-panel {
    bottom: 38px;
  }

  #doc-links {
    display: none;
  }
}
