:root {
  --panel: rgba(10, 14, 24, 0.72);
  --edge: rgba(140, 170, 220, 0.16);
  --ink: #e8edf7;
  --dim: #8f9db8;
  --accent: #7fb2ff;
  --warm: #ffd9a0;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------- collapsible panels -------------------------- */
.panelHead {
  display: none;                 /* desktop keeps panels always open */
  width: 100%;
  align-items: center;
  gap: 7px;
  padding: 9px 11px;
  background: none;
  border: 0;
  font: 600 11.5px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: left;
  cursor: pointer;
}
.panelHead .chev { transition: transform 0.2s; font-size: 10px; }
.collapsed .panelHead { color: var(--ink); }
.collapsed .panelHead .chev { transform: rotate(-90deg); }
/* NB: hiding a collapsed body is deliberately NOT declared here. On desktop
   the headers are hidden, so a panel left collapsed by a narrow viewport
   would have no way to reopen and its content would be unreachable. The
   rule lives in the touch block, where a header exists to undo it. */

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#sky.dragging { cursor: grabbing; }

#radar {
  position: fixed;
  right: 14px;
  bottom: 96px;
  width: 132px;
  height: 132px;
  z-index: 9;                 /* below the panels, never floating over them */
  cursor: crosshair;
  border-radius: 50%;
  background: rgba(8, 12, 20, 0.62);
  border: 1px solid var(--edge);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.28s;
}
body.clean #radar { opacity: 0; pointer-events: none; }

button.wide { width: 100%; }

/* what you just tapped */
#idCard {
  position: fixed;
  z-index: 28;
  width: 200px;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.86);
  border: 1px solid rgba(140, 170, 220, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.18s, transform 0.18s;
}
#idCard.show { opacity: 1; transform: translateY(0); }
#idCard b { display: block; font-size: 13px; font-weight: 600; color: #f0f5ff; }
#idCard span { display: block; margin-top: 2px; font-size: 11px; color: var(--dim); }
#idCard span:first-of-type { color: #a8c4ee; }
body.clean #idCard, body.titleMode #idCard { opacity: 0; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
  background: #000;
  z-index: 50;
  transition: opacity 0.5s;
}
#loading.gone { opacity: 0; pointer-events: none; }
/* Start-up died. Say why, and stop swallowing taps - an opaque overlay at
   z-index 50 sits above every escape hatch in the app. */
#loading.failed {
  background: rgba(0, 0, 0, 0.86);
  color: #ff9d7a;
  pointer-events: none;
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 13px;
  padding: 24px;
  text-align: center;
}

/* ------------------------------- title -------------------------------- */
/* Sits over the live scene: Earth keeps spinning and cycling phase behind
   it, so the menu is the simulation rather than a picture of one. Only the
   text and buttons take pointer events. */
#title {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: clamp(14px, 5vh, 46px) 18px calc(clamp(14px, 5vh, 46px) + env(safe-area-inset-bottom));
  pointer-events: none;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 30%, rgba(0, 0, 0, 0.55) 78%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.65) 0%, transparent 26%, transparent 68%, rgba(0, 0, 0, 0.75) 100%);
  transition: opacity 0.55s ease;
}
#title.gone { opacity: 0; pointer-events: none; }
body.titleMode #topbar,
body.titleMode #left,
body.titleMode #right,
body.titleMode #transport,
body.titleMode #radar,
body.titleMode #hint { opacity: 0; pointer-events: none; }

.bigTitle {
  margin: 0;
  font-weight: 300;
  font-size: clamp(23px, 5.6vh, 52px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f2f6ff;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.8);
}
.tagline {
  margin: clamp(5px, 1.4vh, 13px) 0 0;
  font-size: clamp(10.5px, 1.7vh, 14px);
  letter-spacing: 0.04em;
  color: rgba(198, 214, 240, 0.82);
  max-width: 34em;
}
.titleBottom { display: flex; gap: 11px; align-items: center; flex-wrap: wrap; justify-content: center; }
#title button, #infoPanel button { pointer-events: auto; }

button.enter {
  width: auto;
  padding: clamp(8px, 1.6vh, 13px) clamp(26px, 5vw, 46px);
  border-radius: 999px;
  font-size: clamp(12px, 1.8vh, 14px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(127, 178, 255, 0.17);
  border-color: rgba(127, 178, 255, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
button.enter:hover { background: rgba(127, 178, 255, 0.3); }
button.info {
  width: auto;
  padding: clamp(8px, 1.6vh, 13px) clamp(16px, 3vw, 24px);
  border-radius: 999px;
  font-size: clamp(11px, 1.6vh, 13px);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#infoPanel {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(3, 5, 10, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
}
#infoPanel.open { display: grid; }
.infoInner {
  max-width: 620px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 4px 4px 8px;
}
.infoInner h2 {
  color: var(--accent);
  margin: 18px 0 7px;
  font-size: 10px;
}
.infoInner h2:first-child { margin-top: 0; }
.infoInner p, .infoInner li { font-size: 13px; line-height: 1.55; color: #d7e0f2; margin: 0 0 9px; }
.infoInner ul { padding-left: 18px; margin: 0 0 9px; }
.infoInner b { color: #fff; font-weight: 600; }
.infoInner button { margin-top: 14px; }

/* ------------------------------- panels -------------------------------- */
.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  z-index: 10;
  transition: opacity 0.28s, transform 0.28s;
}
body.clean .panel, body.clean #hint { opacity: 0; pointer-events: none; transform: translateY(-6px); }
body.clean #topbar { transform: translateY(-16px); }

/* The only way back out of clean mode by pointer. Deliberately not inside any
   panel, since clean mode fades those to zero opacity and a child cannot
   escape a transparent parent. */
#showUI {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 30;
  width: auto;
  padding: 9px 12px;
  border-radius: 11px;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  background: rgba(10, 14, 24, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.28s;
}
body.clean #showUI { opacity: 0.5; pointer-events: auto; }
body.clean #showUI:hover, body.clean #showUI:active { opacity: 1; }
body.titleMode #showUI { opacity: 0; pointer-events: none; }

#topbar {
  top: 14px; left: 14px; right: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
}
.brand { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.brand .dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, #f2f2ee 0 38%, #b9bcc0 55%, #6d7176 100%);
  box-shadow: 0 0 18px rgba(200, 215, 255, 0.35);
  flex: none;
}
h1 { font-size: 14px; margin: 0; font-weight: 600; letter-spacing: 0.01em; }
.brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--dim); }

.clock { text-align: right; }
.clockMain { font: 600 15px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.clockSub { font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--dim); }

#left  { top: 76px; left: 14px;  width: 244px; padding: 4px 14px 14px; }
#right { top: 76px; right: 14px; width: 244px; padding: 4px 14px 14px; }
#left, #right {
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 170, 220, 0.35) transparent;
}

h2 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--dim);
  margin: 15px 0 8px;
  font-weight: 600;
}

.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 2.5px 0;
  font-size: 12px;
}
.kv span { color: var(--dim); }
.kv b { font: 500 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.hint {
  color: var(--dim);
  font-size: 11px;
  line-height: 1.4;
  margin: 9px 0 0;
}

/* ------------------------------- inputs -------------------------------- */
select, input[type=number], input[type=datetime-local], button {
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 9px;
  padding: 7px 9px;
  width: 100%;
  outline: none;
}
input[type=datetime-local] { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
select:focus, input:focus { border-color: var(--accent); }
select option { background: #0c1220; }

.row2 { display: flex; gap: 8px; margin-top: 8px; }
.row2 label { flex: 1; font-size: 10.5px; color: var(--dim); }
.row2 input { margin-top: 3px; }

.btnRow { display: flex; gap: 7px; margin-top: 8px; }
button {
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:active { background: rgba(255, 255, 255, 0.18); }
button.on { background: rgba(127, 178, 255, 0.22); border-color: rgba(127, 178, 255, 0.5); }

.ghost {
  width: auto;
  padding: 5px 9px;
  background: transparent;
  color: var(--dim);
  flex: none;
}

.slider { display: block; margin-top: 12px; font-size: 11px; color: var(--dim); }
.slider b { color: var(--ink); font-weight: 500; }
input[type=range] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
  background: transparent;
}
.check { display: flex; align-items: center; gap: 7px; margin-top: 11px; font-size: 11.5px; color: var(--dim); }
.check input { accent-color: var(--accent); }

/* ------------------------------ day bar -------------------------------- */
.daybar {
  position: relative;
  height: 9px;
  border-radius: 5px;
  overflow: hidden;
  margin: 4px 0 9px;
  border: 1px solid var(--edge);
}
.daybar .fill {
  position: absolute; inset: 0;
  background: linear-gradient(90deg,
    #05070d 0%, #05070d 20%, #6b6255 25%, #d8d2c4 33%,
    #f2eee4 50%, #d8d2c4 67%, #6b6255 75%, #05070d 80%, #05070d 100%);
}
.daybar i {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent);
  transform: translateX(-1px);
}

/* ----------------------------- transport ------------------------------- */
/* Centred with auto margins rather than left:50% + translateX. With only
   `left` set, the available width is the space from the 50% mark to the
   right edge - half the viewport - so on a phone the speed chips wrapped
   onto a second row and ate a third of the screen. */
#transport {
  bottom: 14px;
  left: 0;
  right: 0;
  margin-inline: auto;
  width: max-content;
  max-width: calc(100vw - 28px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 12px;
}
.tRow { display: flex; align-items: center; gap: 7px; }
.chips { justify-content: center; flex-wrap: wrap; }
#transport .chips button {
  width: auto;
  height: 26px;
  padding: 0 11px;
  font-size: 11.5px;
  letter-spacing: 0.01em;
  border-radius: 13px;
}
body.clean #transport { transform: translateY(10px); }
#transport button {
  width: 38px; height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  flex: none;
}
#transport button.primary {
  width: 46px;
  background: rgba(127, 178, 255, 0.2);
  border-color: rgba(127, 178, 255, 0.45);
}
.speedBox { padding: 0 10px; min-width: 168px; }
.speedBox b { display: block; font: 600 12.5px ui-monospace, Menlo, Consolas, monospace; }
.speedBox span { display: block; font-size: 10.5px; color: var(--dim); }

#hint {
  position: fixed;
  bottom: 62px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  color: rgba(160, 175, 200, 0.55);
  font-size: 11px;
  z-index: 9;
  pointer-events: none;
  transition: opacity 0.3s;
}

/* ======================================================================
   TOUCH / PHONE
   Landscape on a phone gives roughly 850x390 css px, so vertical space is
   the scarce resource: panels collapse to a single tappable strip and the
   sky keeps the rest. Zoom moves from a slider to a pinch gesture.
   ====================================================================== */
@media (pointer: coarse), (max-width: 820px), (max-height: 560px) {
  :root { --radius: 12px; }

  .desktopOnly { display: none !important; }
  #hint { display: none; }

  .panelHead { display: flex; }
  .collapsed .panelBody { display: none; }
  .panelBody {
    padding: 0 12px 12px;
    max-height: min(58vh, 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #topbar {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    padding: 6px 10px;
    gap: 10px;
  }
  .brand .dot { width: 20px; height: 20px; }
  h1 { font-size: 12px; }
  .brand p { font-size: 10px; }
  .clockMain { font-size: 12.5px; }
  .clockSub { display: none; }

  /* Panels hang from the top edge, collapsed by default; the bottom strip
     belongs to the transport and the sky map, which must never collide. */
  #left, #right {
    top: calc(var(--topbarH, 47px) + 16px + env(safe-area-inset-top));
    bottom: auto;
    width: 232px;
    max-height: none;
    padding: 0;
    overflow: visible;
  }
  #left { left: max(8px, env(safe-area-inset-left)); }
  #right { right: max(8px, env(safe-area-inset-right)); }
  #left.collapsed, #right.collapsed { width: auto; }
  /* only one panel opens at a time, and the other tab steps out of the way
     so the two can never stack into each other */
  body.panelOpen .collapsible.collapsed { display: none; }

  h2 { margin: 12px 0 6px; font-size: 9.5px; }
  .kv { font-size: 11.5px; padding: 2px 0; }
  .kv b { font-size: 11.5px; }
  .hint { font-size: 10.5px; }

  /* fingers need bigger targets than a mouse does */
  select, input[type=number], input[type=datetime-local], button { padding: 9px 10px; }
  input[type=range] { height: 26px; }

  #radar {
    width: 96px; height: 96px;
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(var(--transportH, 72px) + 20px + env(safe-area-inset-bottom));
  }
  /* the radar sits above the panels in stacking order, so on a small
     screen it hides rather than floating over open panel content */
  body.panelOpen #radar { opacity: 0; pointer-events: none; }

  #transport {
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 6px 8px;
    gap: 6px;
    max-width: calc(100vw - 16px);
  }
  .tRow { gap: 5px; }
  #transport button { width: 34px; height: 32px; font-size: 12px; }
  #transport button.primary { width: 42px; }
  #transport .chips button { height: 28px; padding: 0 10px; font-size: 11px; }
  .speedBox { min-width: 0; padding: 0 6px; }
  .speedBox span { display: none; }
  .speedBox b { font-size: 11.5px; }
}

/* very short viewports: phone in landscape */
@media (max-height: 440px) {
  #topbar { padding: 5px 9px; }
  .brand p { display: none; }
  .panelBody { max-height: 44vh; }
  #radar { width: 82px; height: 82px; }
  #transport { padding: 5px 7px; gap: 5px; }
  #transport button { height: 30px; width: 32px; }
  #transport button.primary { width: 40px; }
  #transport .chips button { height: 25px; font-size: 10.5px; padding: 0 8px; }
}

/* portrait phone: panels span the width instead of floating narrow */
@media (pointer: coarse) and (orientation: portrait) {
  #left, #right { width: auto; }
  #left { left: 8px; right: 8px; }
  /* stacked under the left tab when both are collapsed; when either opens
     the other tab is hidden, so they cannot collide */
  #right {
    left: 8px; right: 8px;
    top: calc(var(--topbarH, 47px) + 62px + env(safe-area-inset-top));
  }
  #left.collapsed, #right.collapsed { width: auto; }
}

/* installed as an app: no browser chrome to lean on */
@media (display-mode: standalone) {
  #hint { display: none; }
}
