:root {
  --rail-w: 230px;
}

/* ---------- Night mode (default, field use) ---------- */
/* Night is the default: these variables live on :root so the very first paint is
   red-on-black, before any script has run. .mode-day (below) overrides them. */
:root,
.mode-night {
  --bg: #0a0000;
  --panel-bg: #140202;
  --fg: #c23b2b;
  --fg-dim: #7a2419;
  --border: #3a0f0a;
  --input-bg: #1c0403;
  --accent: #e05a3f;
  color-scheme: dark;
}

/* ---------- Day mode (screen, non-field use) ---------- */
.mode-day {
  --bg: #f6f5f2;
  --panel-bg: #ffffff;
  --fg: #1a1a1a;
  --fg-dim: #6b6b6b;
  --border: #d8d5cf;
  --input-bg: #ffffff;
  --accent: #a8391f;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Top bar: identity, target entry, global toggles ---------- */
#topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}

#topbar h1 {
  font-size: 1rem;
  letter-spacing: 0.02em;
  margin: 0;
  flex: 0 0 auto;
}

.coord-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 2.3rem) auto minmax(0, 2.3rem) auto minmax(0, 3.6rem) auto;
  gap: 0.6rem 0.4rem;
  align-items: center;
  margin: 1.4rem 0 0.8rem;
}

.coord-prefix {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}
.coord-prefix-dec {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.coord-unit {
  font-size: 0.75rem;
  color: var(--fg-dim);
}

.coord-field {
  padding: 0.3rem 0.3rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  text-align: center;
}
/* Sized to actual content, not a generic uniform box: H/D and M need at most
   2 digits, seconds need "00.00". The widths are set by the grid columns above
   (which can shrink on a very narrow screen), so the inputs just fill their cell. */
.coord-field.coord-hm,
.coord-field.coord-sec { width: 100%; min-width: 0; margin-top: 0; }   /* margin-top 0: keeps the H/M/S letters centred on the boxes */
.coord-field.coord-sign { width: 2.6rem; }

/* Remove number-input spin buttons everywhere -- values here (coordinates,
   focal lengths, AFOV, Barlow factor) are typed, not click-incremented. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Status text: on the title row, between "Star Hop" and the designation. Always a single line
   (no wrap) in a slot that is always there, so it can come and go without moving anything. */
.status {
  flex: 1 1 0;
  min-width: 0;
  align-self: center;
  margin: 0 0.4rem;
  text-align: center;
  font-family: Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-toggles {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

label.checkbox.small {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

button.small {
  width: auto;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

/* ---------- Buttons / inputs, shared ---------- */
button {
  padding: 0.5rem;
  background: transparent;
  border: 1px solid var(--fg);
  color: var(--fg);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  cursor: pointer;
}
button.primary { border-color: var(--accent); color: var(--accent); }
/* Hover fill only where a pointer can really hover. On a touch screen the hover
   state sticks after a tap and leaves a solid bright button on a dark-adapted screen. */
@media (hover: hover) {
  button:hover { background: var(--fg); color: var(--bg); }
  button.primary:hover { background: var(--accent); color: var(--bg); }
}

label {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
  color: var(--fg);
}
label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
label.checkbox input[type="checkbox"] { margin: 0; }

input[type="number"], input[type="text"], input[type="email"], textarea, select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.35rem 0.45rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
}
/* ---------- Theme the remaining browser-default (white) form widgets ---------- */

/* Checkboxes: themed box with an accent-coloured fill when checked. */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin: 0;
  display: inline-grid;
  place-content: center;
  background: var(--input-bg);
  border: 1px solid var(--fg-dim);
  cursor: pointer;
}
input[type="checkbox"]::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  background: var(--accent);
  transform: scale(0);
}
input[type="checkbox"]:checked::after { transform: scale(1); }
input[type="checkbox"]:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* Radio buttons: same treatment, round, with an accent-coloured dot. */
input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin: 0;
  display: inline-grid;
  place-content: center;
  background: var(--input-bg);
  border: 1px solid var(--fg-dim);
  border-radius: 50%;
  cursor: pointer;
}
input[type="radio"]::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
}
input[type="radio"]:checked::after { transform: scale(1); }
input[type="radio"]:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* Open dropdown list: themed rows. (The highlighted row's colour is chosen by
   the OS/browser and can't be reliably overridden on a native <select>.) */
select option {
  background: var(--input-bg);
  color: var(--fg);
}

/* Browser autofill paints inputs light blue/white. Paint over it with the
   theme colours instead (inset shadow + text-fill is the standard workaround). */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fg);
  caret-color: var(--fg);
  box-shadow: 0 0 0 1000px var(--input-bg) inset;
  transition: background-color 9999s ease-in-out 0s;
}
input:autofill {
  color: var(--fg);
  box-shadow: 0 0 0 1000px var(--input-bg) inset;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- Tooltips (see initTooltips in common.js) ---------- */
.tip {
  position: fixed;
  z-index: 300;
  max-width: 18rem;
  padding: 0.4rem 0.6rem;
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--fg-dim);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: none;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
.tip[hidden] { display: none; }
label.checkbox[hidden] { display: none; }

/* ---------- Themed dropdowns (see enhanceSelect in common.js) ---------- */
.tsel { position: relative; width: 100%; margin-top: 0.25rem; }
.tsel.coord-sign { width: 2.6rem; }
.search-row .tsel { width: auto; flex: 0 0 auto; margin: 0; }
select.tsel-native { display: none; }

.tsel-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 0.4rem;
  width: 100%;
  padding: 0.35rem 0.45rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  letter-spacing: 0;
  text-align: left;
}
.tsel-btn:hover { background: var(--input-bg); color: var(--fg); border-color: var(--fg-dim); }
.tsel-btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.tsel.coord-sign .tsel-btn { padding: 0.3rem 0.3rem; font-size: 0.82rem; }
.tsel.coord-sign .tsel-label { text-align: center; }
.tsel-label { grid-area: 1 / 1; visibility: hidden; white-space: nowrap; }
.tsel-label.sel { visibility: visible; }
.tsel-chev {
  grid-area: 1 / 2;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-dim);
}

.tsel-list {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 60;
  min-width: 100%;
  width: max-content;
  max-width: 85vw;
  max-height: 16rem;
  overflow-y: auto;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--input-bg);
  border: 1px solid var(--fg-dim);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}
.tsel-list[hidden] { display: none; }
.tsel-list.align-right { left: auto; right: 0; }
.tsel-list li {
  padding: 0.6rem 0.75rem;   /* roomy enough for a finger */
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  color: var(--fg);
  white-space: nowrap;
  cursor: pointer;
}
.tsel-list li[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.tsel-list li.active,
.tsel-list li:hover { background: var(--fg); color: var(--bg); }

/* ---------- Main 3-zone layout ---------- */
#layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.rail {
  flex: 0 0 var(--rail-w);
  background: var(--panel-bg);
  padding: 0.9rem;
  overflow-y: auto;
}
#rail-left { border-right: 1px solid var(--border); }
#rail-right { border-left: 1px solid var(--border); }

.group {
  border-top: 1px solid var(--border);
  padding-top: 1.1rem;
  margin-top: 1.1rem;
}
.group:first-child { border-top: none; margin-top: 0; }

.group h2 {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin: 0 0 0.7rem;
  display: flex;
  justify-content: space-between;
}

#chart-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  min-width: 0;
  min-height: 0;
}

#chart-wrap {
  position: relative;
  overflow: hidden;
  width: min(96vh, 100%);
  max-height: 100%;
  aspect-ratio: 1 / 1;
  /* The frame is an outline drawn inside the box, not a border on the canvas:
     a border would shrink the canvas's drawing area relative to the survey
     image behind it, and the stars would no longer line up with it. */
  outline: 1px solid var(--border);
  outline-offset: -1px;
}

#dss-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}

#chart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.print-only { display: none; }
#print-chart-wrap { display: none; }
#print-dss-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Photographic-negative style for print: dark stars/nebulosity on a white
     background, matching the black-on-white star chart and saving ink. */
  filter: invert(1);
}
#print-chart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 5;
}
.spinner-stars {
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  z-index: 6;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Viewport-centred spinner for long operations on the setup page
   (e.g. the SIMBAD search). Same look as the chart-page spinners. */
.spinner-page {
  position: fixed;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  z-index: 100;
}
.spinner[hidden] { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 1.2rem 1.4rem;
  max-width: 22rem;
  text-align: center;
}
.modal p {
  font-size: 0.9rem;
  margin: 0 0 1rem;
  color: var(--fg);
}
.modal button { width: 100%; }

/* ---------- Narrow screens: rails become horizontal bars above/below the viewport ---------- */
@media (max-width: 860px) {
  #layout { flex-direction: column; }
  .rail {
    flex: 0 0 auto;
    width: 100%;
    max-height: 34vh;
  }
  #rail-left { border-right: none; border-bottom: 1px solid var(--border); }
  #rail-right { border-left: none; border-top: 1px solid var(--border); }
  #topbar { gap: 0.5rem; }
}

/* ---------- Print ---------- */
@media print {
  :root { color-scheme: light; }
  #topbar, .rail { display: none; }
  #app, #layout, #chart-area { display: block; padding: 0; }
  #chart-wrap { display: none; }
  #print-chart-wrap {
    display: block;
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 7in;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
  }
  body { background: #fff; color: #000; }
  .tip { display: none; }
  .print-only {
    display: block;
    text-align: center;
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
  }
  .ph-title { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
  .ph-pos { font-family: Consolas, monospace; font-size: 0.9rem; margin: 0.1rem 0 0.5rem; }
  .ph-equipment {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.1rem 0.9rem;
    max-width: 7in;
    margin: 0 auto 0.4rem;
    text-align: left;
    font-size: 0.8rem;
  }
  .ph-equipment dt { font-weight: 700; }
  .ph-equipment dd { margin: 0; }
  .ph-chart { font-size: 0.78rem; margin-bottom: 0.4rem; }
  #print-footer { font-size: 0.72rem; margin: 0.5rem 0 0; color: #333; }
}

/* ---------- Setup page (index.html) ---------- */
#setup-page {
  max-width: 32rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}
.setup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.setup-header label.checkbox.small { white-space: nowrap; margin-top: 0.3rem; }
#setup-page h1 {
  margin: 0 0 0.2rem;
  font-size: 1.4rem;
}
#setup-page .subtitle {
  color: var(--fg-dim);
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}
.page-intro {
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 0 0 1rem;
}
/* Each section is its own panel, so Target and Optics read as two clear steps. */
.setup-section {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 1.5rem 1.35rem 1.6rem;
  margin-top: 2.25rem;
}
.setup-section h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.8rem;
}
.section-intro {
  font-size: 0.85rem;
  line-height: 1.6;
  margin: 0 0 1.6rem;
}
.setup-section h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg);
  margin: 2rem 0 0.8rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
.section-intro + h3 { margin-top: 0; }
#setup-page .hint {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--fg-dim);
  margin: 0.7rem 0 0;
}
#setup-page .hint:empty { display: none; }
/* Instructions that belong ABOVE a control, so the soft keyboard doesn't cover them. */
#setup-page .hint.hint-above { margin: 0 0 0.9rem; }
/* Messages that must not be missed: a coordinate is out of range, saving failed. Red only, so size and weight carry it. */
#setup-page .hint.warn {
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.35;
  padding-left: 0.7rem;
  border-left: 3px solid var(--accent);
}

/* ---------- Contact form ---------- */
.contact-field { margin: 0 0 1rem; }
.field-label { display: block; font-size: 0.85rem; color: var(--fg); }
.field-note { display: block; font-size: 0.78rem; line-height: 1.5; color: var(--fg-dim); margin-top: 0.25rem; }
.contact-form textarea { min-height: 9rem; resize: vertical; line-height: 1.45; }
.contact-form input::placeholder, .contact-form textarea::placeholder { color: var(--fg-dim); font-style: italic; opacity: 1; }
#setup-page .hint.emphasis { color: var(--accent); font-weight: 700; }
#setup-page .hint.notice { color: var(--accent); font-size: 1rem; font-weight: 700; }
.contact-check { margin-top: 0.6rem; }
#setup-page .hint a { color: var(--accent); }   /* never the browser's blue link colour */
.contact-form #fill-status + .contact-field { margin-top: 1.2rem; }
.contact-form #btn-fill-link { margin-bottom: 0.4rem; }
/* The honeypot: off-screen, not display:none, so simple robots still fill it in. People never reach it. */
.contact-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 480px) {
  .contact-form input, .contact-form textarea, .contact-form select { font-size: 16px; }   /* stops phones zooming in on focus */
}

.search-row {
  display: flex;
  gap: 0.5rem;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
/* Names are short (8-10 characters), so the input takes whatever the type
   dropdown and Search button leave over. */
.search-row input { margin: 0; flex: 1 1 5rem; min-width: 0; }
.search-row select { width: auto; flex: 0 0 auto; margin: 0; }
.search-row button,
.search-row button.secondary { width: auto; flex: 0 0 auto; margin-top: 0; }

.object-results {
  list-style: none;
  margin: 0.4rem 0 1rem;
  padding: 0;
  border: 1px solid var(--border);
  max-height: 14rem;
  overflow-y: auto;
}
.object-results li {
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.object-results li:last-child { border-bottom: none; }
.object-results li:hover { background: var(--input-bg); }
.obj-alt, .obj-type {
  color: var(--fg-dim);
  font-size: 0.78rem;
}
.obj-type { float: right; }

/* One row of the Optics form (telescope, eyepiece, Barlow, image enhancer): boxes, then a remove button.
   Only the column widths differ between the four. */
.gear-row {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}
.gear-row input, .gear-row select, .gear-row .tsel { margin: 0; }
.gear-row .remove-btn {
  width: auto;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}
.gear-row-telescope { grid-template-columns: 1fr 4.5em 5.5em 2em; }
.gear-row-eyepiece { grid-template-columns: 1fr 4.5em 4.5em 2em; }
.gear-row-barlow { grid-template-columns: 1fr 4.5em 2em; }
.gear-row-enhancer {
  margin-top: 0;
  align-items: center;
  /* minmax(0, ...) lets the label wrap on a very narrow screen instead of pushing the row wider than its card */
  grid-template-columns: minmax(0, 1fr) 4.5em 4.5em 2em;
}
.gear-row-enhancer label.checkbox { margin: 0; font-size: 0.82rem; }

button.secondary { width: auto; font-size: 0.8rem; padding: 0.4rem 0.7rem; margin-top: 0.3rem; }
button.large { width: 100%; padding: 0.8rem; font-size: 0.95rem; margin-top: 2.25rem; }

/* ---------- StarHop: read-only target display + eyepiece selection ---------- */
.target-display {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-family: Consolas, monospace;
  font-size: 0.82rem;
}
.target-name {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  max-width: 24rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.target-name:empty { display: none; }
.target-display a {
  color: var(--accent);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.78rem;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.eyepiece-select-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
}
.eyepiece-select-row input { margin: 0; }
.eyepiece-tfov-inline {
  margin-left: auto;
  color: var(--fg-dim);
  font-family: Consolas, monospace;
  font-size: 0.75rem;
}
.barlow-header {
  font-size: 0.7rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.6rem 0 0.3rem;
}
.rail .hint {
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--fg-dim);
  margin: 0.6rem 0 0;
}
.rail .hint a { color: var(--accent); }

/* ---------- Support / tip button (see js/support.js) ---------- */
.support-slot:empty { display: none; }
.support-text {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--fg-dim);
  margin: 0 0 0.6rem;
}
.footer-support-btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-family: inherit;
  text-decoration: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
}
.footer-support-btn:hover, .footer-support-btn:focus-visible { background: var(--accent); color: var(--bg); }
.support-slot-setup {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
}
@media print { .support-slot { display: none; } }
/* ---------- Setup page: collapsible blocks (About, Optics) ---------- */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }

.fold-chev {
  flex: 0 0 auto;
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--accent);
  transition: transform 0.15s;
}
details[open] > summary .fold-chev { transform: rotate(90deg); }

.about { margin: 0 0 0.5rem; }
.about > summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.75rem;          /* comfortable finger target */
  color: var(--accent);
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}
.about-body { padding: 0.1rem 0 0.4rem; }
.about-body .page-intro:last-child { margin-bottom: 0; }

/* Optics card: heading + one-line gear summary + Edit/Done, all tappable. */
details.setup-section > summary {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 1rem;
}
details.setup-section > summary h2 { grid-column: 1; margin: 0; }
details.setup-section[open] > summary { margin-bottom: 0.8rem; }
.optics-summary {
  grid-column: 1;
  grid-row: 2;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--fg-dim);
}
.optics-summary:empty,
details[open] .optics-summary { display: none; }
.summary-action {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--accent);
  font-size: 0.8rem;
}
.summary-action .act::before { content: 'Edit'; }
details[open] .summary-action .act::before { content: 'Done'; }

/* ---------- Setup page: phones ---------- */
@media (max-width: 480px) {
  #setup-page { padding: 1rem 0.9rem 2.5rem; }
  #setup-page .subtitle { margin-bottom: 0.6rem; }
  .setup-section { padding: 1.1rem 1rem 1.2rem; margin-top: 1rem; }
  .setup-section h2 { margin-bottom: 0.6rem; }
  .search-row input,
  .search-row button,
  .search-row .tsel-btn { min-height: 2.6rem; }
  .search-row input { font-size: 1rem; }      /* 16px also stops iOS zooming in on focus */
  .search-row .tsel-btn { height: 100%; }
  .coord-grid { margin: 1rem 0 0.2rem; column-gap: 0.35rem; }
  .coord-field { padding: 0.45rem 0.2rem; }
  button.large { margin-top: 1.25rem; }
  .support-slot-setup { margin-top: 1.75rem; }
}

/* ---------- Setup page: very small phones (<= 350px) ---------- */
/* Everything stays on one line down to here; below it the search box gets its own line. */
@media (max-width: 350px) {
  .search-row { flex-wrap: wrap; }
  .search-row input { flex-basis: 100%; }
}

/* ---------- Wider screens: pack the coordinate fields instead of spreading them across the card ---------- */
@media (min-width: 481px) {
  .coord-grid { justify-content: start; }
}

/* ---------- Chart page: the object name sits across from the title ---------- */
.title-row {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  min-width: 0;
}
.title-row .target-name { min-width: 0; flex: 0 1 auto; }   /* the designation keeps its room; the status gives way first */
/* Desktop: a fixed slot, so the designation does not slide sideways when a message comes and goes. */
@media (min-width: 861px) { .title-row .status { flex: 0 0 13rem; text-align: left; } }
@media (max-width: 860px) {
  .title-row { flex: 1 1 100%; justify-content: space-between; }
  .title-row .target-name { max-width: none; font-size: 1.15rem; text-align: right; }
}

/* ---------- Privacy page + footer link ---------- */
/* Plain HTML on purpose (not built by support.js): it must survive a stale or cached script. */
.site-links { margin: 1rem 0 0; font-size: 0.8rem; text-align: center; }
.site-links a { color: var(--fg); text-decoration: none; border-bottom: 1px dotted var(--fg); padding: 0.3rem 0; }
.site-links a:hover, .site-links a:focus-visible { color: var(--accent); border-bottom-color: var(--accent); }

.back-link {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  white-space: nowrap;
  margin-top: 0.4rem;
}
.privacy-hero {
  border-left: 3px solid var(--accent);
  margin-top: 1.5rem;
}
.privacy-hero .statement { font-size: 1.2rem; }
.statement {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--fg);
}
.setup-section .detail { margin: 0; font-size: 0.85rem; line-height: 1.6; }
.setup-section .detail + .detail { margin-top: 0.7rem; }
.setup-section .detail a { color: var(--accent); }
.privacy-foot { margin: 1.75rem 0 0; font-size: 0.78rem; color: var(--fg-dim); text-align: center; }

/* ---------- Focus rings: red, never the browser's default white/blue (night vision) ---------- */
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="email"]:focus, textarea:focus { border-color: var(--accent); }
textarea:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* ---------- Search placeholder must read as a hint, not as a typed value ---------- */
#object-search-input::placeholder { color: var(--fg-dim); font-style: italic; opacity: 1; }

/* ---------- Setup link: import banner + copy fallback ---------- */
.import-banner {
  background: var(--panel-bg);
  border: 1px solid var(--accent);
  padding: 0.9rem 1rem;
  margin: 0 0 1rem;
}
.import-banner[hidden] { display: none; }
.import-banner p { margin: 0 0 0.8rem; font-size: 0.88rem; line-height: 1.5; }
.import-actions { display: flex; gap: 0.5rem; }
.import-actions button { width: auto; margin: 0; padding: 0.45rem 0.9rem; }
.import-actions button[hidden] { display: none; }
.copy-fallback { margin-top: 0.6rem; }
.copy-fallback[hidden] { display: none; }

/* =====================================================================
   Chart page
   ===================================================================== */

/* Centre the tip button / text in the side panels (all screen sizes). */
.rail .support-slot { text-align: center; }

.coords { display: flex; gap: 0.9rem; white-space: nowrap; }   /* RA and Dec never split across lines */
.gear-toggle { display: none; }                                   /* phones only, see below */
/* Barlow / enhancer block sits under the eyepieces on desktop, with no divider of its own. */
.rail .group-accessories { border-top: 0; padding-top: 0; margin-top: 0.8rem; }

/* ---------------------------------------------------------------------
   Phones and small tablets (<= 860px)

   No scrolling panels inside the page. The side panels dissolve
   (display: contents) so every control block becomes a direct child of
   #layout, and `order` stacks them in the order they are used:

     eyepiece chips -> telescope & accessories bar -> CHART ->
     field radius -> rotation -> limiting magnitude -> tip / privacy

   Desktop keeps its three columns; none of this applies there.
   --------------------------------------------------------------------- */
@media (max-width: 860px) {
  #topbar { padding: 0.5rem 0.9rem; }

  /* Header = three rows: title + object name / RA + Dec (large, one line) /
     New target + Daytime + Overlay + Print (one line). The two wrapper
     elements dissolve so those four controls become siblings in one row. */
  #topbar { justify-content: space-between; align-items: center; gap: 0.35rem 0.6rem; }
  .target-display, .topbar-toggles { display: contents; }
  .title-row { order: 0; }
  .coords { order: 1; flex: 1 1 100%; gap: 0.7rem; font-size: clamp(0.62rem, 4vw, 1rem); }
  #change-target-link { order: 2; }
  .topbar-toggles > * { order: 3; }
  #topbar label.checkbox.small, #change-target-link { font-size: 0.78rem; }
  #topbar button.small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

  .rail { display: contents; }
  #layout { flex-direction: column; }
  #rail-left .group-eyepiece   { order: 1; }
  .gear-toggle                 { order: 2; }
  #rail-left .group-telescope  { order: 3; }
  #rail-left .group-accessories { order: 4; }
  #chart-area                  { order: 5; flex: 0 0 auto; }
  #rail-left .group-radius     { order: 6; }
  #rail-right .group-rotation  { order: 7; }
  #rail-right .group-magnitude { order: 8; }
  #rail-right .support-slot    { order: 9; }
  #rail-right .site-links    { order: 10; }

  /* Each block is a full-width strip. */
  .rail .group, .gear-toggle {
    margin: 0;
    padding: 0.65rem 0.9rem;
    border: 0;
    border-top: 1px solid var(--border);
    background: var(--panel-bg);
  }
  .rail .group:first-child { border-top: 1px solid var(--border); }
  .rail .group.group-accessories { border-top: 0; padding-top: 0; }
  .rail .group h2 { margin: 0 0 0.45rem; }
  .rail .hint { margin: 0.35rem 0 0; }
  .rail .site-links { margin: 0; padding: 0 0.9rem 1rem; background: var(--panel-bg); }

  /* Telescope / Barlow / enhancer: folded behind a bar that always shows what is selected. */
  #layout:not(.gear-open) .gear-item { display: none; }
  .gear-toggle {
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 0.8rem;
    align-items: center;
    width: 100%;
    text-align: left;
    border-radius: 0;
    letter-spacing: 0;
    font-size: 0.82rem;
    color: var(--fg);
  }
  .gear-toggle:hover { background: var(--panel-bg); color: var(--fg); }
  .gear-title { grid-column: 1; color: var(--accent); font-weight: 600; }
  .gear-summary { grid-column: 1; grid-row: 2; margin-top: 0.15rem; font-size: 0.74rem; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .barlow-combined { display: none; }
  .gear-toggle .fold-chev { grid-column: 2; grid-row: 1 / span 2; }
  .gear-toggle[aria-expanded="true"] .fold-chev { transform: rotate(90deg); }

  /* Eyepieces, telescopes and Barlows as tappable chips that wrap onto as many lines as needed. */
  #telescope-select-list, #eyepiece-select-list, #barlow-select-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  #telescope-select-list .hint, #eyepiece-select-list .hint { flex: 1 0 100%; margin: 0; }
  .rail .eyepiece-select-row {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.45rem;
    align-items: center;
    margin: 0;
    padding: 0.35rem 0.7rem;
    min-height: 2.75rem;          /* finger-sized */
    line-height: 1.15;
    border: 1px solid var(--border);
    background: var(--input-bg);
  }
  .rail .eyepiece-select-row input { grid-row: 1 / span 2; }
  .rail .eyepiece-tfov-inline { grid-column: 2; margin-left: 0; font-size: 0.7rem; }
  .rail .eyepiece-select-row:has(input:checked) { border-color: var(--accent); }

  /* Eyepieces and Barlows: compact one-line chips. (The field size is for the chart's
     benefit, not the observer's, so it is not shown on the chip.) Barlows keep their factor. */
  #eyepiece-select-list .eyepiece-select-row,
  #barlow-select-list .eyepiece-select-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2.5rem;
    padding: 0.3rem 0.7rem;
    font-size: 0.95rem;
  }
  #eyepiece-select-list .eyepiece-tfov-inline,
  #barlow-select-list .eyepiece-tfov-inline { display: none; }   /* names only, no numbers */
  .barlow-header { display: none; }   /* the heading already says "Eyepieces and Barlows" */
  /* Eyepieces, then Barlows, as ONE run of boxes. */
  .chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .chip-list > #eyepiece-select-list, .chip-list > #barlow-select-list { display: contents; }

  /* Where :has() is supported the radio/checkbox dot is dropped: the chip itself lights up
     when selected. (Older browsers keep the dot, so nothing is ever unreadable.) */
  @supports selector(:has(*)) {
    .rail .eyepiece-select-row { position: relative; }
    .rail .eyepiece-select-row input[type="radio"],
    .rail .eyepiece-select-row input[type="checkbox"] {
      position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
    }
    .rail .eyepiece-select-row:has(input:checked) {
      color: var(--accent);
      box-shadow: inset 0 0 0 1px var(--accent);
    }
    .rail .eyepiece-select-row:has(input:focus-visible) { outline: 1px solid var(--accent); outline-offset: 2px; }
  }
  .group-accessories label.checkbox { margin: 0.6rem 0 0; }
}

/* Very small phones: shave the header controls so New target / Daytime / Overlay / Print still fit one row. */
@media (max-width: 350px) {
  #topbar { column-gap: 0.4rem; padding-left: 0.7rem; padding-right: 0.7rem; }
  #topbar label.checkbox.small, #change-target-link { font-size: 0.7rem; }
  #topbar label.checkbox.small { gap: 0.2rem; }
  #topbar button.small { padding: 0.28rem 0.45rem; font-size: 0.7rem; }
}

/* Android paints a cyan flash over whatever you tap. Make it a dim red instead (night vision). */
html { -webkit-tap-highlight-color: rgba(194, 59, 43, 0.25); }

/* ---------- Print: nothing but the chart page (kept LAST; !important beats the phone layout) ---------- */
@media print {
  #topbar, .rail, .gear-toggle, .site-links, .support-slot, .import-banner { display: none !important; }
  #layout { display: block !important; }
}