:root {
  --ink: #eef2ff;
  --soft: #b6c1e2;
  --dim: #8592bb;
  --panel: rgba(9, 16, 38, 0.8);
  --panel-hover: rgba(18, 30, 66, 0.95);
  --line: rgba(160, 182, 255, 0.2);
  --gold: #ffd27a;
  --gold-deep: #b98a2e;
  --gap: 2vh;
  --r: 2vh;
  --tb-h: 0px;
  --body: clamp(15px, min(2.1vh, 3.9vw), 26px);
  --small: clamp(13px, min(1.75vh, 3.4vw), 21px);
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); }
body { background: #03060f; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--ink);
}

/* ---------- The sky ---------- */
#sky {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
#sky:active { cursor: grabbing; }

/* ---------- Top: toolbar and place ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1vh;
  padding: var(--gap);
  padding-top: max(var(--gap), env(safe-area-inset-top));
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; flex-wrap: wrap; gap: 0.6vh; max-width: 60vw; }
#toolbar button {
  width: clamp(40px, min(6vh, 7.5vw), 64px); height: clamp(40px, min(6vh, 7.5vw), 64px);
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: clamp(20px, min(3vh, 3.75vw), 32px);
  color: var(--ink);
  display: grid; place-items: center;
  backdrop-filter: blur(4px);
}
#toolbar button:hover { background: var(--panel-hover); }
#toolbar button[aria-pressed='false'] { color: var(--dim); }
#toolbar button[aria-pressed='false'] svg { opacity: 0.55; }
body[data-view='dome'] .i-dome, body[data-view='horizon'] .i-horizon { display: none; }

#place {
  display: flex; align-items: center; gap: 1.2vh;
  background: var(--panel);
  border-radius: var(--r);
  padding: 0.8vh 0.8vh 0.8vh 2vh;
  font-weight: 800;
  font-size: clamp(17px, min(3vh, 4.2vw), 36px);
  line-height: 1.1;
  backdrop-filter: blur(4px);
  min-width: 0;
}
#place-name {
  border: none; background: none; padding: 0.1em 0 0;
  font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
#place-change {
  flex: none;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0.3em 0.9em 0.15em;
  font-size: var(--small); font-weight: 700;
  color: var(--soft);
}
#place-change:hover { color: var(--ink); border-color: var(--gold); }

/* ---------- Panels: Tonight and the object card ---------- */
.sheet {
  position: fixed;
  z-index: 11;
  background: var(--panel);
  border-radius: var(--r);
  padding: 1.6vh 2.2vh 1.8vh;
  font-size: var(--body);
  line-height: 1.35;
  overflow-y: auto;
  overscroll-behavior: contain;
  backdrop-filter: blur(6px);
  box-shadow: 0 1vh 4vh rgba(0, 0, 0, 0.35);
}
.sheet.more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 4em), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 4em), transparent);
}
.sheet h2 { margin: 0 2.4em 0.6vh 0; font-size: 1.45em; line-height: 1.1; font-weight: 800; }
.sheet h2 small { display: block; font-size: 0.62em; font-weight: 600; color: var(--soft); }
.sheet h3 {
  margin: 1.4vh 0 0.4vh;
  font-size: 0.8em; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--gold);
}
.sheet ul { margin: 0; padding: 0; list-style: none; }
.sheet li { position: relative; padding-left: 1em; margin: 0.35em 0; }
.sheet li::before { content: ''; position: absolute; left: 0.1em; top: 0.6em; width: 0.38em; height: 0.38em; border-radius: 50%; background: var(--soft); opacity: 0.6; }
.close {
  position: absolute; top: 1vh; right: 1vh;
  width: clamp(36px, 5vh, 56px); height: clamp(36px, 5vh, 56px);
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--soft);
  font-size: clamp(22px, 3.4vh, 38px); line-height: 1;
  display: grid; place-items: center;
}
.close:hover { background: rgba(255, 255, 255, 0.18); color: var(--ink); }

#tn-sun { display: flex; flex-wrap: wrap; gap: 0.2em 1.1em; margin: 0.6vh 0 1vh; color: var(--soft); }
#tn-sun b { color: var(--ink); white-space: nowrap; }
#tn-sun .note { flex-basis: 100%; margin: 0; color: var(--gold); }
#tn-moon {
  display: flex; align-items: center; gap: 1.4vh;
  padding: 0.8vh 1vh;
  margin: 0 -1vh;
  border-radius: 1.4vh;
  cursor: pointer;
}
#tn-moon:hover { background: rgba(255, 255, 255, 0.06); }
.phase { flex: none; width: clamp(40px, 6.5vh, 76px); height: clamp(40px, 6.5vh, 76px); }
#tn-planets li.link { cursor: pointer; border-radius: 0.5em; }
#tn-planets li.link:hover { color: var(--gold); }

#card { z-index: 12; }
#card-head { display: flex; align-items: center; gap: 1.6vh; margin-right: 2.4em; }
#card-head h2 { margin: 0; font-size: 1.7em; }
#card-kind { margin: 0.2vh 0 0; color: var(--gold); font-weight: 700; }
#card-art .phase { width: clamp(52px, 9vh, 100px); height: clamp(52px, 9vh, 100px); }
#card-lines { margin-top: 1vh; }
#card-lines li:first-child { font-weight: 700; }

/* ---------- The time bar ---------- */
#timebar {
  position: fixed;
  z-index: 10;
  background: var(--panel);
  border-radius: var(--r);
  padding: 1.4vh 2vh 1.6vh;
  backdrop-filter: blur(6px);
  font-size: var(--body);
  user-select: none; -webkit-user-select: none;
}
.tb-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 1.4vh; }
#clock { display: flex; align-items: baseline; gap: 1vh; }
#time {
  font-weight: 800;
  font-size: clamp(30px, min(5.6vh, 9vw), 68px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
#live {
  align-self: center;
  padding: 0.25em 0.7em 0.1em;
  border-radius: 999px;
  background: #e5484d; color: #fff;
  font-size: var(--small); font-weight: 800; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.06em;
}
#timebar.daytime #time { color: var(--soft); }
#datebox { display: flex; align-items: center; gap: 0.4vh; color: var(--soft); font-weight: 700; white-space: nowrap; }
#datebox button {
  width: clamp(34px, 4.4vh, 52px); height: clamp(34px, 4.4vh, 52px);
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.5em; line-height: 1; font-weight: 800;
  display: grid; place-items: center;
  padding-bottom: 0.15em;
}
#datebox button:hover { background: rgba(255, 255, 255, 0.18); }

#slider-wrap { position: relative; margin: 1.2vh 0 0; padding-bottom: 2.9em; }
#slider-wrap.two-rows { padding-bottom: 4.1em; }
#slider {
  --thumb: clamp(26px, 3.8vh, 44px);
  --track: linear-gradient(90deg, #0e1434, #0e1434);
  -webkit-appearance: none; appearance: none;
  display: block;
  width: 100%; height: var(--thumb);
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
#slider::-webkit-slider-runnable-track { height: calc(var(--thumb) * 0.5); border-radius: 999px; background: var(--track); box-shadow: inset 0 0 0 1px var(--line); }
#slider::-moz-range-track { height: calc(var(--thumb) * 0.5); border-radius: 999px; background: var(--track); box-shadow: inset 0 0 0 1px var(--line); }
#slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb); height: var(--thumb);
  margin-top: calc(var(--thumb) * -0.25);
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff8e6;
  box-shadow: 0 0 0 4px rgba(255, 210, 122, 0.25), 0 2px 8px rgba(0, 0, 0, 0.5);
}
#slider::-moz-range-thumb {
  width: var(--thumb); height: var(--thumb);
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff8e6;
  box-shadow: 0 0 0 4px rgba(255, 210, 122, 0.25), 0 2px 8px rgba(0, 0, 0, 0.5);
}
#marks { position: absolute; left: 0; right: 0; top: clamp(26px, 3.8vh, 44px); height: 2.7em; }
.mark {
  position: absolute; top: 0;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  border: none; background: none; padding: 0;
  color: var(--soft);
  font-size: var(--small); line-height: 1.15; font-weight: 700;
  white-space: nowrap;
}
.mark i { display: block; width: 2px; height: 0.6em; margin-bottom: 0.15em; background: currentColor; opacity: 0.7; }
.mark.low { padding-top: 1.25em; }
.mark.low i { height: 1.85em; }
.mark:hover { color: var(--gold); }
.mark.quiet span { visibility: hidden; }
.mark.dark { color: #a9b8ff; }
.mark.midnight { color: var(--dim); }

.tb-buttons { display: flex; flex-direction: column; gap: 0.8vh; }
.transport, .jumps { display: flex; gap: 0.8vh; }
.jumps button { flex: 1 1 auto; padding-left: 0.5em; padding-right: 0.5em; }
.tb-buttons button {
  height: clamp(42px, 5.6vh, 64px);
  min-width: clamp(42px, 5.6vh, 64px);
  border: 2px solid var(--line);
  border-radius: 1.4vh;
  background: rgba(255, 255, 255, 0.06);
  font-size: var(--body); font-weight: 800; line-height: 1;
  white-space: nowrap;
  padding: 0.15em 0.8em 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
}
.tb-buttons button:hover { background: rgba(255, 255, 255, 0.14); }
.tb-buttons button:active { transform: translateY(1px); }
#step-back, #step-fwd { padding: 0; width: clamp(48px, 7vh, 80px); flex: none; }
#step-back svg, #step-fwd svg { width: 1.3em; height: 1.3em; }
#play {
  flex: 1 1 auto;
  background: var(--gold); color: #2b1d00; border-color: var(--gold);
  box-shadow: 0 0.4vh 0 var(--gold-deep);
}
#play:hover { background: #ffdc94; }
#play i { width: 0; height: 0; border-style: solid; border-width: 0.5em 0 0.5em 0.85em; border-color: transparent transparent transparent currentColor; margin-top: -0.1em; }
#play.playing i { width: 0.75em; height: 0.95em; border: none; border-left: 0.25em solid; border-right: 0.25em solid; }
#speed { color: var(--soft); font-variant-numeric: tabular-nums; }
#now[aria-pressed='true'] { border-color: #e5484d; color: #ffd5d6; }

/* ---------- Message after a key press ---------- */
#toast {
  position: fixed; left: 50%; top: 9vh;
  transform: translateX(-50%);
  z-index: 15;
  background: var(--panel);
  border-radius: 999px;
  padding: 0.6vh 2.4vh 0.4vh;
  font-size: var(--body); font-weight: 700;
  pointer-events: none;
  max-width: 90vw; text-align: center;
}
#toast.show { animation: toast 1.8s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; } 8% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Menu ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(3, 6, 18, 0.55), rgba(2, 4, 12, 0.88));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(940px, 94vw);
  background: rgba(13, 22, 50, 0.97);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--gold); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: var(--soft); }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.panel h3 { margin: 0 0 6px; font-size: 16px; color: var(--soft); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cards.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 0; }
.cards button {
  border: 3px solid rgba(160, 182, 255, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s;
}
.cards.row button { padding: 6px 14px 4px; }
.cards button:hover { transform: translateY(-2px); border-color: rgba(160, 182, 255, 0.45); }
.cards button[aria-pressed='true'] { border-color: var(--gold); background: rgba(255, 210, 122, 0.13); }
.cards b { display: block; font-size: 22px; line-height: 1.1; }
.cards.row b { font-size: 18px; }
.cards span { display: block; font-size: 15px; color: var(--soft); line-height: 1.3; }
.show-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px 22px; margin-bottom: 4px; }

#place-section { margin-bottom: 18px; }
#place-now { margin: 0 0 8px; font-size: 19px; }
#place-now span { color: var(--soft); font-size: 15px; margin-left: 6px; white-space: nowrap; }
.search-row { display: flex; flex-wrap: wrap; gap: 10px; }
#place-search {
  flex: 1 1 260px;
  min-width: 0;
  height: 48px;
  border: 3px solid rgba(160, 182, 255, 0.3);
  border-radius: 14px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.95);
  color: #14203d;
  font-size: 19px; font-weight: 700;
  outline: none;
}
#place-search:focus { border-color: var(--gold); }
#locate {
  height: 48px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  padding: 0 16px;
  font-size: 17px; font-weight: 700;
}
#locate:hover { border-color: var(--gold); }
#place-results { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#place-results button {
  border: 2px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  padding: 5px 14px 3px;
  font-size: 17px;
}
#place-results button:hover { border-color: var(--gold); }
#place-results span { color: var(--soft); font-size: 14px; }
.quiet-note { margin: 8px 0 0; font-size: 15px; color: var(--soft); }
.quiet-note:empty { display: none; }
.quiet-note a { color: inherit; }
.help + .quiet-note { margin-top: 14px; font-size: 13px; }

.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.buttons button {
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px; font-weight: 800;
}
.buttons button.primary { background: var(--gold); color: #2b1d00; font-size: 22px; padding: 12px 34px; box-shadow: 0 6px 0 var(--gold-deep); }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--gold-deep); }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #7fd89a; }
.help { margin-top: 16px; font-size: 15px; color: var(--soft); }
.help summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.help ul { padding-left: 20px; line-height: 1.5; }
.help li { margin: 4px 0; }

/* ---------- Layout: a wide board or laptop ----------
   The dome is a circle 94% of the screen height across, in the middle.
   The panels go in the strips either side of it. */
@media (min-aspect-ratio: 8/5) and (min-width: 900px) {
  :root { --side: max(250px, min(560px, calc((100vw - 94vh) / 2 - 6vh))); }
  #timebar { left: var(--gap); bottom: var(--gap); width: var(--side); }
  #tonight {
    right: var(--gap); top: calc(var(--gap) + clamp(44px, 6.6vh, 70px) + 1.4vh);
    width: var(--side);
    max-height: calc(100vh - 2 * var(--gap) - clamp(44px, 6.6vh, 70px) - 1.4vh);
  }
  #card { right: var(--gap); bottom: var(--gap); width: var(--side); max-height: 52vh; }
  /* the side strips are narrow, so keep the lines close together */
  #tonight { line-height: 1.25; padding-top: 1.3vh; padding-bottom: 1.4vh; }
  #tonight li { margin: 0.2em 0; }
  #tonight h3 { margin-top: 1.1vh; }
  #tn-sun { margin: 0.4vh 0 0.6vh; }
  #tn-moon { padding: 0.5vh 1vh; }
  body:has(#card:not([hidden])) #tonight { max-height: calc(100vh - 52vh - 3 * var(--gap) - clamp(44px, 6.6vh, 70px) - 1.4vh); }
  #place { max-width: var(--side); }
  #toolbar { max-width: 40vw; }
  /* In the horizon view the bar can run along the bottom */
  body[data-view='horizon'] #timebar { width: min(var(--side), 40vw); }
}

/* ---------- Layout: narrower screens ----------
   The time bar runs along the bottom and the cards sit above it. */
@media (max-aspect-ratio: 7999/5000), (max-width: 899px) {
  #timebar {
    left: 50%; bottom: var(--gap);
    transform: translateX(-50%);
    width: min(980px, calc(100vw - 2 * var(--gap)));
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 2vh;
    align-items: center;
  }
  .tb-top { flex-direction: column; align-items: flex-start; }
  #slider-wrap { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
  .tb-buttons { grid-column: 1 / -1; margin-top: 0.6vh; flex-direction: row; }
  .transport { flex: 1.3 1 0; }
  .jumps { flex: 1 1 0; }
  #tonight {
    right: var(--gap); top: calc(var(--gap) + clamp(44px, 6.6vh, 70px) + 1.4vh);
    width: min(440px, 44vw);
    max-height: calc(100vh - var(--tb-h) - 4 * var(--gap) - clamp(44px, 6.6vh, 70px));
  }
  #card {
    right: var(--gap); bottom: calc(var(--tb-h) + 2 * var(--gap));
    width: min(480px, calc(100vw - 2 * var(--gap)));
    max-height: calc(100vh - var(--tb-h) - 4 * var(--gap) - clamp(44px, 6.6vh, 70px));
  }
  /* The sky sits in the space above the time bar, so the bar doesn't
     cover the southern edge of the dome (phones held sideways, 4:3 boards) */
  #sky { height: calc(100% - var(--tb-h) - 2 * var(--gap)); }
}

/* ---------- Phones ---------- */
@media (max-width: 700px) {
  :root { --gap: 8px; --r: 16px; --body: 15px; --small: 12.5px; }
  #hud-top { padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  #toolbar { gap: 5px; flex-wrap: nowrap; max-width: none; }
  #toolbar button { width: 40px; height: 40px; font-size: 19px; border-radius: 11px; flex: none; }
  #toolbar [data-action='milkyway'], #toolbar [data-action='fullscreen'] { display: none; }
  #place { font-size: 16px; padding: 0 12px; height: 40px; border-radius: 11px; }
  #place-change { display: none; }
  /* The dome sits in the space above the time bar */
  #sky { height: calc(100% - var(--tb-h)); }
  #timebar {
    left: 0; right: 0; bottom: 0; transform: none;
    width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 10px 14px max(12px, env(safe-area-inset-bottom));
    display: block;
  }
  .tb-top { flex-direction: row; align-items: center; }
  #time { font-size: 32px; }
  #slider-wrap { margin-top: 6px; padding-bottom: 2.9em; }
  #slider { --thumb: 30px; }
  .tb-buttons { gap: 6px; margin-top: 2px; flex-direction: column; }
  .transport, .jumps { gap: 6px; }
  .tb-buttons button { height: 46px; min-width: 46px; border-radius: 12px; padding: 0.15em 0.6em 0; font-size: 15px; }
  #step-back, #step-fwd { width: 64px; }
  .sheet { padding: 14px 16px 16px; }
  #tonight, #card {
    left: 0; right: 0; top: auto; bottom: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 18px 18px 0 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background: rgba(9, 16, 38, 0.95);
    z-index: 13;
  }
  .close { top: 8px; right: 8px; width: 44px; height: 44px; }
  .panel { padding: 18px 18px 16px; border-radius: 20px; }
  .logo { font-size: 36px; }
  .tagline { font-size: 16px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .cards b { font-size: 18px; }
  .cards span { font-size: 13.5px; }
  .show-grid { grid-template-columns: 1fr; }
  #setup { padding: 8px; }
}

@media (max-height: 560px) {
  .panel { padding: 16px 22px; }
  .logo { font-size: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast.show { animation: none; }
  .cards button { transition: none; }
}
