:root {
  --bg: #0b0e1a;
  --panel: #121830;
  --panel-2: #0e1426;
  --text: #d6dcf5;
  --dim: #8a93b8;
  --red: #ff3b30;
  --accent: #ffd60a;
  --earth: #3a86ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 70% -10%, #1a2350 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
}

header {
  padding: 44px 32px 28px;
  max-width: 1280px;
  margin: 0 auto;
  border-bottom: 1px solid #1a2040;
}

h1 { margin: 0 0 10px; font-size: 34px; letter-spacing: .3px; color: #eef1ff; }
h2 { font-size: 20px; margin: 0 0 10px; color: #e0e5f7; letter-spacing: .2px; }
.tagline { color: #9aa3c7; max-width: 760px; margin: 0 0 20px; }

.preamble { max-width: 760px; margin: 0 0 22px; color: #c2cae8; }
.preamble p { margin: 0; }

.preamble-figure {
  float: right;
  width: min(400px, 45%);
  margin: 4px 0 14px 22px;
  background: var(--panel);
  border: 1px solid #232c52;
  border-radius: 14px;
  padding: 10px;
}
.preamble-figure img { width: 100%; border-radius: 8px; display: block; }
.preamble-figure figcaption {
  font-size: 12px; color: #aeb8e0; padding: 8px 2px 0; line-height: 1.4;
}

/* On narrow screens, stop floating and let it stack full-width */
@media (max-width: 640px) {
  .preamble-figure { float: none; width: 100%; margin: 0 0 16px; }
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips span {
  background: var(--panel); border: 1px solid #232c52; border-radius: 999px;
  padding: 4px 12px; font-size: 13px; color: #aeb8e0;
}
.chips b { color: var(--accent); font-weight: 600; }

main {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px;
  max-width: 1280px; margin: 24px auto 0; padding: 0 32px;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; padding: 0 16px; } }

#canvas-wrap { position: relative; }
#sky {
  width: 100%; aspect-ratio: 1; display: block; border-radius: 14px;
  background: #070a14; border: 1px solid #1c2447;
}
#hud {
  position: absolute; top: 14px; left: 16px; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#hud-date { font-size: 20px; font-weight: 600; }
#hud-offset { color: #9aa3c7; font-size: 13px; }
#hud-status { font-size: 13px; font-weight: 700; }
#hud-status.hit { color: var(--accent); }
#hud-status.miss { color: #6b749c; }

#controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid #232c52; border-radius: 12px;
  padding: 12px 16px; margin-top: 14px;
}
#controls label { font-size: 13px; color: #9aa3c7; display: flex; gap: 6px; align-items: center; }
#play {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--red); color: #fff; font-size: 16px; flex: none;
}
#play:hover { filter: brightness(1.15); }
select {
  background: var(--panel-2); color: var(--text); border: 1px solid #2a3464;
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
  max-width: 100%;
}
#scrub { flex: 1; min-width: 140px; accent-color: var(--red); }
#scrub-label { font-size: 13px; color: #9aa3c7; min-width: 42px; }

#crossings {
  background: var(--panel); border: 1px solid #232c52; border-radius: 14px;
  padding: 16px; max-height: 720px; display: flex; flex-direction: column;
}
#crossings h2 { font-size: 16px; margin: 0 0 4px; }
#crossings .hint { font-size: 12px; color: #7c86ad; margin: 2px 0 12px; }
#crossing-count { color: var(--accent); font-size: 14px; }
#crossing-list { overflow-y: auto; flex: 1; }
#load-future {
  margin-top: 10px; padding: 9px; border-radius: 8px;
  border: 1px dashed #2a3464; background: var(--panel-2);
  color: #9aa3c7; cursor: pointer; font-size: 13px;
}
#load-future:hover { color: var(--text); border-color: #4a5b9e; }
#load-future:disabled { cursor: wait; opacity: .6; }
.year-head {
  font-size: 12px; font-weight: 700; color: #7c86ad; letter-spacing: 1px;
  margin: 10px 0 4px; border-bottom: 1px solid #1e2750; padding-bottom: 2px;
}
.crossing {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; color: var(--text); cursor: pointer;
  padding: 5px 6px; border-radius: 8px; font-size: 13px; text-align: left;
  font-variant-numeric: tabular-nums;
}
.crossing:hover { background: #1a2347; }
.crossing.active { background: #2a1a1a; outline: 1px solid var(--red); }
.crossing .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.crossing .when { flex: 1; }
.crossing .meta { color: #7c86ad; font-size: 12px; }

#about {
  max-width: 1280px;
  margin: 48px auto 64px;
  padding: 0 32px;
  color: #aeb8e0;
}
#about p { max-width: 820px; line-height: 1.75; }

#about > h2 {
  color: #e0e5f7;
  font-size: 22px;
  margin-top: 48px;
  padding-top: 40px;
  border-top: 1px solid #1a2040;
}
#about > h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 780px), 1fr));
  gap: 20px;
  margin-top: 20px;
}
.gallery figure {
  margin: 0;
  background: var(--panel);
  border: 1px solid #232c52;
  border-radius: 14px;
  padding: 12px;
}
.gallery img { width: 100%; border-radius: 8px; display: block; }
.gallery figcaption { font-size: 13px; color: #aeb8e0; padding: 10px 4px 2px; line-height: 1.45; }
.gallery .wide { grid-column: 1 / -1; max-width: 800px; }

.month-tiles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 14px; max-width: 900px; }
.month-tiles img {
  width: 64px; height: 64px; display: block;
  background: #070a14; border: 1px solid #1c2447; border-radius: 5px;
}

table.periods {
  border-collapse: collapse; margin: 16px 0; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
table.periods th, table.periods td {
  text-align: left; padding: 6px 18px 6px 0; border-bottom: 1px solid #1e2750;
}
table.periods th { color: #7c86ad; font-size: 12px; letter-spacing: 1px;
  text-transform: uppercase; font-weight: 600; }
table.periods td:first-child { color: var(--text); font-weight: 600; }

#fold-ui {
  background: var(--panel); border: 1px solid #232c52; border-radius: 14px;
  padding: 16px; margin-top: 16px;
}
#fold-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
#fold-presets button {
  background: var(--panel-2); border: 1px solid #2a3464; border-radius: 999px;
  color: #9aa3c7; font-size: 12px; padding: 4px 12px; cursor: pointer;
}
#fold-presets button:hover { color: var(--text); border-color: #4a5b9e; }
#fold-presets button.active {
  color: var(--accent); border-color: var(--accent); background: #1a1a0e;
}
#fold-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
#fold-controls label { font-size: 13px; color: #9aa3c7; display: flex; gap: 6px; align-items: center; min-width: 0; }
#fold-channel { flex: 1; min-width: 0; }
#fold-period { flex: 1; min-width: 160px; accent-color: var(--red); }
#fold-readout {
  font-size: 13px; color: var(--accent); min-width: 190px;
  font-variant-numeric: tabular-nums;
}
#fold-canvas {
  width: 100%; display: block; border-radius: 8px;
  background: #070a14; border: 1px solid #1c2447;
}
.fold-axes { font-size: 12px; color: #7c86ad; margin: 8px 2px 0; }

.footer { font-size: 13px; color: #7c86ad; margin-top: 36px; line-height: 1.7; }
a { color: #7fb3ff; text-decoration: none; }
a:hover { color: #a8ceff; text-decoration: underline; }

@media (max-width: 820px) {
  header { padding: 28px 16px 20px; }
  h1 { font-size: 26px; }
  #about { padding: 0 16px; margin-top: 32px; }
  .month-tiles img { width: 54px; height: 54px; }

  /* period-folding explorer: stack the controls so nothing is forced
     wider than the phone's viewport */
  #fold-controls { gap: 10px; }
  #fold-controls label { width: 100%; }
  #fold-period { flex: 1 1 100%; min-width: 0; }
  #fold-readout { width: 100%; min-width: 0; }

  /* the period table is wider than a narrow phone — let it scroll
     on its own instead of forcing the whole page sideways */
  table.periods { display: block; overflow-x: auto; max-width: 100%; }
}

/* never let a stray wide element create a horizontal scroll / zoomed-out
   page on small screens */
body { overflow-x: hidden; }
