* { box-sizing: border-box; }

/* ----------------------------------------------------------------- themes
   The chart SVG is recolored by the Rust renderer; these variables restyle the
   rest of the page. `data-theme` is set on <html> before first paint (see the
   inline script in index.html) so there is never a white flash at night. */

:root,
html[data-theme="light"] {
  color-scheme: light;
  --page-bg: #e9e9ec;
  --card-bg: #fff;
  --chart-bg: #fff;
  --text: #222;
  --text-2: #444;
  --muted: #666;
  --faint: #777;
  --heading: #1b2a49;
  --border: #d0d0d6;
  --field-bg: #fff;
  --field-border: #bbb;
  --hover: #f1f1f4;
  --primary-bg: #1b2a49;
  --primary-hover: #2b3f6b;
  --primary-text: #fff;
  --warning: #9a4b00;
  --shadow: rgba(0, 0, 0, .25);
  --top-inset: env(safe-area-inset-top);
}

/* Installed to the home screen, iOS draws the page under the status bar and puts a blurred band
   over it. The safe-area inset should describe that band, but iOS doesn't always report it, so
   in the installed app never reserve less than a typical notch / Dynamic Island height. */
@media (display-mode: standalone) {
  :root, html[data-theme] { --top-inset: max(env(safe-area-inset-top), 3.25rem); }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #05070a;
  --card-bg: #0d1117;
  --chart-bg: #0d1117;
  --text: #d7dbe1;
  --text-2: #b4bbc6;
  --muted: #99a0ab;
  --faint: #8a919c;
  --heading: #aebbd6;
  --border: #232a33;
  --field-bg: #0d1117;
  --field-border: #3a424d;
  --hover: #161c24;
  --primary-bg: #2b3f6b;
  --primary-hover: #365187;
  --primary-text: #fff;
  --warning: #e0a050;
  --shadow: rgba(0, 0, 0, .8);
}

/* Red on black keeps your eyes dark-adapted. No blue or green light anywhere. */
html[data-theme="night"] {
  color-scheme: dark;
  accent-color: #c0392b;
  --page-bg: #000;
  --card-bg: #000;
  --chart-bg: #000;
  --text: #ff5a48;
  --text-2: #e04a3a;
  --muted: #b03020;
  --faint: #a02a1c;
  --heading: #ff5a48;
  --border: #4a1510;
  --field-bg: #000;
  --field-border: #6f2219;
  --hover: #1c0805;
  --primary-bg: #5a1810;
  --primary-hover: #74201a;
  --primary-text: #ff6a58;
  --warning: #ff7a5a;
  --shadow: rgba(0, 0, 0, 0);
}

body {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 22rem;
  grid-template-areas: "stage controls";
  min-height: 100vh;
  font: 16px/1.4 system-ui, sans-serif;
  color: var(--text);
  background: var(--page-bg);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- stage */

#stage {
  grid-area: stage;
  position: relative;
  padding: calc(3.5rem + var(--top-inset)) 1.5rem 1.5rem; /* room for the theme button */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
#chart {
  width: min(100%, 820px);
  /* Reserve the chart's space before it is drawn so nothing jumps when it appears (layout shift).
     US Letter is the default on wide screens; phones use the square screen layout. */
  aspect-ratio: 8.5 / 11;
  background: var(--chart-bg);
  box-shadow: 0 2px 12px var(--shadow);
}
/* Once the SVG is in, its own proportions take over. */
#chart:has(svg) { aspect-ratio: auto; }
#chart svg { display: block; width: 100%; height: auto; }

#theme-btn {
  position: absolute;
  top: calc(.5rem + var(--top-inset));
  right: .5rem;
  z-index: 1;
  min-height: 44px;
  padding: .4rem .8rem;
  border-radius: 999px;
  font-size: .85rem;
}

/* Header and summary card only accompany the phone/screen layout; the paper
   layouts draw their own title, how-to text and legend inside the SVG. */
#summary { display: none; width: min(100%, 640px); }
body.layout-screen #chart { width: min(100%, 640px); aspect-ratio: 1; }
body.layout-screen #chart:has(svg) { aspect-ratio: auto; }
body.layout-screen #summary { display: block; }
body.layout-screen #object-page, body.layout-screen #solar-page { width: min(100%, 640px); }

/* The page title (the <h1>) stays in the document on every layout. On paper layouts the chart
   draws its own title, so the masthead is only hidden visually: still read by search engines and
   screen readers, which tend to ignore display:none text. */
#masthead {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
body.layout-screen #masthead {
  position: static;
  width: min(100%, 640px);
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}

#masthead { text-align: center; color: var(--heading); }
#masthead h1 { margin: 0; font: bold 1.9rem Georgia, 'DejaVu Serif', serif; }
#subtitle { margin: .15rem 0 0; color: var(--text-2); font-size: .95rem; text-wrap: balance; }

#summary {
  background: var(--card-bg);
  border-radius: 8px;
  padding: .75rem 1rem;
  box-shadow: 0 1px 6px var(--shadow);
}
html[data-theme="night"] #summary { border: 1px solid var(--border); }
#summary h2 { margin: 0 0 .25rem; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#summary p { margin: .3rem 0; }
#summary .how { font-size: .85rem; color: var(--muted); }

/* Optional object list: a card after the chart (and the solar system) on screen, and the last page when printing. */
#object-page {
  width: min(100%, 820px); /* same as the chart, which is narrower on the screen layout (below) */
  box-sizing: border-box;
  background: var(--card-bg);
  border-radius: 8px;
  padding: .75rem 1rem;
  box-shadow: 0 1px 6px var(--shadow);
}
html[data-theme="night"] #object-page { border: 1px solid var(--border); }
#object-page h2 { margin: 0; font: bold 1.3rem Georgia, 'DejaVu Serif', serif; color: var(--heading); }
#object-page .when { margin: .1rem 0 .5rem; font-size: .9rem; color: var(--text-2); }
#object-page h3 { margin: .9rem 0 .25rem; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#object-page ul { margin: 0; padding: 0; list-style: none; }
#object-page li { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; break-inside: avoid; }
#object-page li span:last-child { flex: none; color: var(--text-2); text-align: right; }
#object-page .note { margin: .75rem 0 0; font-size: .8rem; color: var(--muted); }

/* The solar system diagram. It draws its own title, so the card is just the picture. */
#solar-page {
  width: min(100%, 820px);
  box-sizing: border-box;
  background: var(--card-bg);
  border-radius: 8px;
  padding: .5rem;
  box-shadow: 0 1px 6px var(--shadow);
}
html[data-theme="night"] #solar-page { border: 1px solid var(--border); }
#solar-page svg { display: block; width: 100%; height: auto; }

#default-note { margin: 0; max-width: 640px; text-align: center; font-size: .85rem; font-style: italic; color: var(--muted); }
#warning { color: var(--warning); font-size: .9rem; max-width: 640px; margin: 0; }
#warning:empty { display: none; }
.noscript { max-width: 640px; text-align: center; color: var(--warning); }

/* Two-sentence description under the chart: gives the page readable text of its own. */
.intro { width: min(100%, 640px); margin: .5rem 0 0; text-align: center; font-size: .95rem; color: var(--text-2); }

/* Link from the chart page to the About / FAQ page. */
.site-links { width: min(100%, 640px); text-align: center; font-size: .9rem; padding-bottom: 1rem; }
.site-links a, .doc-main a { color: var(--muted); }
.site-links a:hover, .doc-main a:hover { color: var(--text); }

/* ---------------------------------------------------------- About page
   A plain reading page (about/index.html). It shares the themes above. */
body.doc { display: block; min-height: 100vh; }
.doc-main {
  max-width: 42rem;
  margin: 0 auto;
  padding: calc(1rem + var(--top-inset)) 1.25rem 3rem;
  color: var(--text-2);
  line-height: 1.6;
}
.doc-main h1 { margin: 1rem 0 .1rem; font: bold 2rem Georgia, 'DejaVu Serif', serif; color: var(--heading); }
.doc-main .lead { margin: 0 0 1rem; font-size: 1.15rem; color: var(--muted); }
.doc-main h2 { margin: 2rem 0 .5rem; font-size: 1.3rem; color: var(--heading); }
.doc-main h3 { margin: 1.4rem 0 .2rem; font-size: 1.05rem; color: var(--text); }
.doc-main p { margin: .4rem 0; }
.back-link { padding: .5rem 0; }
.back-link.bottom { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.doc-main .back-link a { display: inline-block; padding: .6rem 0; min-height: 44px; font-weight: 600; color: var(--text); }

/* ------------------------------------------------------------- controls */

#controls {
  grid-area: controls;
  padding: 1.25rem;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
details > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  padding: .55rem 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "\25B8"; display: inline-block; width: 1.2rem; }
details[open] > summary::before { content: "\25BE"; }
form { display: grid; gap: .75rem; padding-bottom: .5rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
label { display: grid; gap: .2rem; font-weight: 600; font-size: .85rem; }
label small { font-weight: 400; color: var(--faint); }
label.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-size: .95rem; cursor: pointer; }
label.check input { flex: none; width: 1.25rem; height: 1.25rem; min-height: 0; padding: 0; margin: 0; accent-color: var(--primary-bg); }
input, select, button {
  font: inherit;
  color: var(--text);
  padding: .55rem .6rem;
  min-height: 44px;
  border: 1px solid var(--field-border);
  border-radius: 6px;
  background: var(--field-bg);
  min-width: 0;
}
/* Fields sit inside labels that are .85rem, which `inherit` would pass down. iOS Safari zooms the
   page when it focuses a field under 16px, so set it explicitly. */
input, select { font-size: 16px; }
/* City search: a list under the Place name box. */
.place-field { position: relative; }
#place-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: 6px;
  box-shadow: 0 4px 14px var(--shadow);
}
#place-results li {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: .4rem .6rem;
  font-size: .95rem;
  cursor: pointer;
}
#place-results li + li { border-top: 1px solid var(--border); }
#place-results li:hover, #place-results li[aria-selected="true"] { background: var(--hover); }
.toggles-below { display: none; width: min(100%, 640px); justify-content: center; flex-wrap: wrap; column-gap: 1.5rem; }
button { cursor: pointer; touch-action: manipulation; }
button:hover { background: var(--hover); }
button.primary { background: var(--primary-bg); color: var(--primary-text); border-color: var(--primary-bg); font-weight: 600; }
button.primary:hover { background: var(--primary-hover); }
[hidden] { display: none !important; }
/* The top copy of "Sky right now" is for phones; the sidebar copy is used everywhere else. */
.now-here-top { display: none; width: min(100%, 640px); }
/* Like "Sky right now": the copy under the chart is for phones, the one by the time fields for the rest. */
.animate-btn { font-weight: 600; }
.animate-below { display: none; width: min(100%, 640px); }
.animate-btn[aria-pressed="true"] { background: var(--primary-bg); color: var(--primary-text); border-color: var(--primary-bg); }
#install { display: grid; gap: .5rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.actions .wide { grid-column: 1 / -1; }
.hint { font-size: .8rem; color: var(--muted); margin: .25rem 0; }
.credits a { color: inherit; }

/* ---------------------------------------------------------------- phones */

@media (max-width: 800px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas: "stage" "controls";
    align-content: start;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #stage { padding: calc(.75rem + var(--top-inset)) .5rem 0; }
  .now-here-top { display: block; }
  .now-here-side { display: none; }
  .animate-below:not([hidden]) { display: block; }
  .animate-side { display: none; }
  .toggles-below { display: flex; }
  label.check.names-side, label.check.deep-sky-side { display: none; }
  #chart { box-shadow: none; }
  body.layout-screen #chart, body.layout-screen #object-page, body.layout-screen #solar-page { width: 100%; }
  /* Icon-only theme button on phones, and keep the title clear of it. */
  #theme-btn { width: 44px; padding: 0; font-size: 1.1rem; }
  #theme-btn .theme-name { display: none; }
  body.layout-screen #masthead { padding: 0 3rem; }
  #controls {
    position: static;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--border);
    padding: 1rem .75rem calc(1rem + env(safe-area-inset-bottom));
    margin-top: .75rem;
  }
}

/* ----------------------------------------------------------------- print
   Printing is always black on white: the page re-renders the chart with the
   light theme (see main.js) and these rules hide everything else. */

@media print {
  html, body { background: #fff !important; display: block; min-height: 0; }
  #controls, #masthead, #summary, #warning, #default-note, #theme-btn, .animate-btn, .toggles-below, .now-here-top, .intro, .site-links, .noscript { display: none !important; }
    /* The object list starts a new page. The page margin is 0, so it brings its own, and it is black on
       white whatever theme is on screen. */
    #object-page:not([hidden]) {
      display: block;
      width: auto !important;
      border-radius: 0;
      box-shadow: none;
      border: 0 !important;
      background: #fff;
      padding: .55in .7in;
      break-before: page;
      page-break-before: always;
    }
    /* The solar system diagram gets its own page, before the object list: white, with the same
       margins as the object list. */
    #solar-page:not([hidden]) {
      display: block;
      width: auto !important;
      border-radius: 0;
      box-shadow: none;
      border: 0 !important;
      background: #fff;
      padding: .55in .7in;
      break-before: page;
      page-break-before: always;
    }
    #solar-page svg { max-height: 8in; }
    #object-page, #object-page * { color: #000 !important; border-color: #bbb !important; }
    #object-page ul { column-count: 2; column-gap: .4in; }
    #object-page li { font-size: 9pt; padding: .12rem 0; }
    #object-page h3 { margin-top: .6rem; }
  #stage { padding: 0; display: block; }
  #chart { width: 100% !important; box-shadow: none; background: #fff; }
  /* Never taller than one page (the 1% keeps rounding from pushing a sliver onto page 2). The SVG
     scales to fit inside its box, so this only ever shrinks the chart a hair. */
  #chart svg { width: 100%; height: auto; max-height: 99vh; page-break-inside: avoid; }
  /* Without the object list the printout is exactly one page: cut off anything that would spill
     onto a blank second page. */
  body:not(.has-object-list):not(.has-solar-page) { height: 99vh; overflow: hidden; }
}
