/* Dark by default. Red mode swaps to a red-on-black palette (no blue, green or white). */
:root {
  color-scheme: dark;
  --bg: #05070d;
  --card: #0e1424;
  --border: #33415f;
  --text: #eef2ff;
  --muted: #b4bfdc;
  --accent: #7fb2ff;
  --btn-bg: #1b2745;
  --btn-primary: #254a96;
  --focus: #ffd34d;
  --warn: #ffd34d;
  --error: #ff9a9a;
  --field: #070b16;
}

:root[data-theme="red"] {
  --bg: #000000;
  --card: #120000;
  --border: #7a1818;
  --text: #ff6a6a;
  --muted: #e04848;
  --accent: #ff4040;
  --btn-bg: #2a0000;
  --btn-primary: #5a0000;
  --focus: #ff9090;
  --warn: #ff8a8a;
  --error: #ff8a8a;
  --field: #000000;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  accent-color: var(--accent);
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--card);
  color: var(--text);
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip:focus { left: 0; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 1.4rem; }
h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
h3 { margin: 1rem 0 0.25rem; font-size: 1.05rem; }
.h2like { font-size: 1.25rem; font-weight: 700; }

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); align-items: start; }
}
.side { display: grid; gap: 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.muted { color: var(--muted); margin: 0.25rem 0 0.5rem; }
.small { font-size: 0.9rem; }
.notice { margin: 0.25rem 0 0.5rem; color: var(--warn); }
.notice:empty { display: none; }

canvas#sky-canvas {
  display: block;
  width: min(100%, 78vh);
  aspect-ratio: 1 / 1;
  margin: 0.5rem auto;
  border-radius: 8px;
  background: var(--bg);
}

.view-toggle { display: flex; gap: 0.5rem; margin: 0.5rem 0; }
.view-toggle .btn { flex: 1; }

.time-box { margin-top: 0.5rem; }
.time-readout { font-size: 1.2rem; font-weight: 700; margin: 0.25rem 0; }
.slider-label { display: block; margin: 0.5rem 0 0.25rem; }
.slider-row { display: flex; gap: 0.75rem; align-items: center; }
.slider-row input[type="range"] { flex: 1; min-height: 44px; margin: 0; }
.sky-readout { margin: 0.5rem 0 0; }

.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--btn-primary); font-weight: 700; }
.btn[aria-pressed="true"] { border-color: var(--accent); border-width: 2px; }

input[type="text"], select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 8px;
}
select option { background: var(--field); color: var(--text); }
label { display: block; margin: 0.75rem 0 0.25rem; }

.coords { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 0.75rem; }
@media (max-width: 420px) { .coords { grid-template-columns: 1fr; } }

summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.cross-text p { margin: 0.5rem 0; }
.countdown { font-size: 1.15rem; font-weight: 700; margin: 0.25rem 0 0.75rem; }
.star-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }
.finder ol { margin: 0.25rem 0; padding-left: 1.4rem; }
.finder li { margin: 0.25rem 0; }

.footer { padding: 1rem; text-align: center; color: var(--muted); font-size: 0.9rem; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.msg-error { color: var(--error); }
.msg-warn { color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* selftest page */
.banner { padding: 1rem; font-size: 1.4rem; font-weight: 700; border-radius: 10px; margin: 1rem 0; }
.banner.pass { background: #0d3d1f; color: #d6ffe3; }
.banner.fail { background: #4a0f0f; color: #ffe0e0; }
.banner.run { background: var(--card); color: var(--text); }
.tests { list-style: none; padding: 0; margin: 0; font-family: Consolas, "Courier New", monospace; }
.tests li { padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.tests .ok { color: #9dffb8; }
.tests .bad { color: #ff9a9a; font-weight: 700; }

/* ---------- audience sections ---------- */
/* html[data-section] picks the reading level. An element with data-sections="a b" shows only in those. */
html[data-section="tamariki"] [data-sections]:not([data-sections~="tamariki"]),
html[data-section="rangatahi"] [data-sections]:not([data-sections~="rangatahi"]),
html[data-section="pakeke"] [data-sections]:not([data-sections~="pakeke"]) {
  display: none !important;
}

.section-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
}
.section-switch .btn { flex: 1 1 10rem; }
.section-switch .btn[aria-pressed="true"] { background: var(--btn-primary); font-weight: 700; }

.challenge {
  margin: 0.75rem 0 0.25rem;
  padding: 0.5rem 0.75rem;
  border-left: 4px solid var(--accent);
  background: var(--field);
  border-radius: 0 8px 8px 0;
}

.tonight-moon { font-size: 1.1rem; font-weight: 700; margin: 0.25rem 0 0.5rem; }
.tonight-list { margin: 0.25rem 0; padding-left: 1.2rem; }
.tonight-list li { margin: 0.35rem 0; }

.sources { margin-top: 0.5rem; }
.sources p { margin: 0.25rem 0; }
.source-list { margin: 0.25rem 0; padding-left: 1.2rem; }
.source-list li { margin: 0.25rem 0; }
a { color: var(--accent); }
.section-switch .btn { overflow-wrap: anywhere; }

/* Tamariki: big type, big targets, few words. */
.kid-line { font-size: 1.3rem; font-weight: 700; text-align: center; margin: 0.25rem 0 0.5rem; }
.big-num { display: block; font-size: 4.5rem; line-height: 1; font-weight: 800; }
.big-label { display: block; font-size: 1.4rem; font-weight: 700; }
.big-words { display: block; font-size: 2rem; font-weight: 800; line-height: 1.2; }

.tile {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 1rem;
  margin: 0.5rem 0 1rem;
  border-radius: 14px;
  border: 4px solid var(--border);
}
.tile-q { font-size: 1.3rem; font-weight: 700; }
.tile-a { font-size: 2rem; font-weight: 800; }
/* Three states told apart by words AND border shape AND colour. */
.tile[data-state="yes"] { background: var(--tile-yes-bg); color: var(--tile-yes-text); border: 6px solid var(--tile-yes-border); }
.tile[data-state="near"] { background: var(--tile-near-bg); color: var(--tile-near-text); border: 6px dotted var(--tile-near-border); }
.tile[data-state="no"] { background: var(--card); color: var(--text); border: 6px dashed var(--tile-no-border); }

:root {
  --tile-yes-bg: #0d5a2b; --tile-yes-text: #ffffff; --tile-yes-border: #7dffb0;
  --tile-near-bg: #5c4700; --tile-near-text: #ffffff; --tile-near-border: #ffd34d;
  --tile-no-border: #ff9a9a;
}
:root[data-theme="red"] {
  --tile-yes-bg: #4a0000; --tile-yes-text: #ff9a9a; --tile-yes-border: #ff6a6a;
  --tile-near-bg: #1c0000; --tile-near-text: #ff8a8a; --tile-near-border: #ff6a6a;
  --tile-no-border: #a02020;
}

html[data-section="tamariki"] body { font-size: 1.3rem; }
html[data-section="tamariki"] h1 { font-size: 1.6rem; }
html[data-section="tamariki"] h2 { font-size: 1.8rem; }
html[data-section="tamariki"] .btn { min-height: 56px; font-size: 1.25rem; }
html[data-section="tamariki"] .time-readout { font-size: 1.6rem; }
html[data-section="tamariki"] .slider-row input[type="range"] { min-height: 56px; }
html[data-section="tamariki"] summary { min-height: 56px; }
