:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --bar-bg: #f3f5f8;
  --ink: #101828;
  --ink-soft: #2c3647;
  --muted: #556175;
  --rule: #cfd6e0;
  --link: #1f4fa8;
  --accent: #8f5100;
  --accent-bg: #f6e3c2;
  --accent-ink: #5a3300;
  --callout-bg: #fbf1df;
  --c-dark: #27305e;
  --c-twi: #6f84b8;
  --c-bright: #c7d3ea;
  --c-moon: #ecd9a0;
  --k-dark: #27305e;
  --k-moon: #d2b35a;
  --moon-lit: #f4ecd0;
  --moon-dark: #27303f;
  --moon-edge: #27303f;
  --p-saturn: #9a6f12;
  --p-neptune: #2a54b8;
  --p-uranus: #12808a;
  --p-jupiter: #8a4b1f;
  --p-mars: #b0321f;
  --sky-top: #03060f;
  --sky-bot: #17294b;
  --pine: #06100d;
  --star: #dfe6f5;
  --limit: #f2b441;
  --saturn-c: #e8cf8f;
  --hero-ink: #eef2f7;
  --hero-muted: #aeb9ca;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --wide: 68rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b121e;
    --bar-bg: #0b121e;
    --ink: #e4e9f1;
    --ink-soft: #c3ccda;
    --muted: #97a3b6;
    --rule: #27344b;
    --link: #93b6ff;
    --accent: #f2b441;
    --accent-bg: #3a2a0c;
    --accent-ink: #ffd78a;
    --callout-bg: #19180f;
    --c-dark: #1f2b72;
    --c-twi: #4f67a8;
    --c-bright: #a9bce0;
    --c-moon: #5e5024;
    --k-dark: #8e9cf0;
    --k-moon: #e3cf8e;
    --moon-lit: #efe6c8;
    --moon-dark: #1d2638;
    --moon-edge: #3d4a63;
    --p-saturn: #e0b44f;
    --p-neptune: #7ea0ff;
    --p-uranus: #5fd0d8;
    --p-jupiter: #e39a62;
    --p-mars: #ff7a5c;
    --pine: #040907;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b121e;
  --bar-bg: #0b121e;
  --ink: #e4e9f1;
  --ink-soft: #c3ccda;
  --muted: #97a3b6;
  --rule: #27344b;
  --link: #93b6ff;
  --accent: #f2b441;
  --accent-bg: #3a2a0c;
  --accent-ink: #ffd78a;
  --callout-bg: #19180f;
  --c-dark: #1f2b72;
  --c-twi: #4f67a8;
  --c-bright: #a9bce0;
  --c-moon: #5e5024;
  --k-dark: #8e9cf0;
  --k-moon: #e3cf8e;
  --moon-lit: #efe6c8;
  --moon-dark: #1d2638;
  --moon-edge: #3d4a63;
  --p-saturn: #e0b44f;
  --p-neptune: #7ea0ff;
  --p-uranus: #5fd0d8;
  --p-jupiter: #e39a62;
  --p-mars: #ff7a5c;
  --pine: #040907;
}

/* Red light mode: everything drops to dim red on black to protect dark adaptation */
body.night {
  color-scheme: dark;
  --bg: #000;
  --bar-bg: #000;
  --ink: #e04a36;
  --ink-soft: #d0402e;
  --muted: #b8382a;
  --rule: #3a0f0b;
  --link: #ff5a40;
  --accent: #ff5a40;
  --accent-bg: #3a0c07;
  --accent-ink: #ff7a60;
  --callout-bg: #140403;
  --c-dark: #2a0806;
  --c-twi: #5a120c;
  --c-bright: #8a1c12;
  --c-moon: #4a100a;
  --k-dark: #7a1a12;
  --k-moon: #e04a36;
  --moon-lit: #c43a2a;
  --moon-dark: #1c0504;
  --moon-edge: #4a120c;
  --p-saturn: #e04a36;
  --p-neptune: #e04a36;
  --p-uranus: #e04a36;
  --p-jupiter: #e04a36;
  --p-mars: #e04a36;
  --sky-top: #000;
  --sky-bot: #1a0302;
  --pine: #000;
  --star: #a8301f;
  --limit: #ff5a40;
  --saturn-c: #c43a2a;
  --hero-ink: #e04a36;
  --hero-muted: #b8382a;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.55;
  overflow-x: hidden;
}

a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

h1, h2, h3 { font-family: var(--serif); line-height: 1.15; font-weight: 600; }

.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Hero ---------- */
.hero {
  overflow: hidden;
  background: var(--pine);
  color: var(--hero-ink);
}
.hero-sky {
  display: block;
  width: 100%;
  height: max(200px, min(25vw, 380px));
}
.hero-stars circle { fill: var(--star); }
.hero-stars circle:nth-child(3n) { opacity: 0.6; }
.hero-stars circle:nth-child(7n) { opacity: 0.35; }
.hero-trees polygon { fill: var(--pine); }
.tree-limit {
  stroke: var(--limit);
  stroke-width: 1.6;
  stroke-dasharray: 9 7;
}
.tree-limit-label {
  fill: var(--limit);
  font-family: var(--sans);
  font-size: 15px;
  letter-spacing: 0.02em;
}
.hero-saturn .ring { fill: none; stroke: var(--saturn-c); stroke-width: 2; }
.hero-saturn .globe { fill: var(--saturn-c); }

.hero-text {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2.5rem;
}
.hero h1 {
  font-size: clamp(2.2rem, 5.5vw, 3.9rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
  color: var(--hero-ink);
}
.lede {
  margin: 0;
  max-width: 44rem;
  font-size: 1.15rem;
  color: var(--hero-muted);
}

/* ---------- Controls bar ---------- */
.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem max(1.25rem, calc((100% - var(--wide)) / 2 + 1.25rem));
}
.next-card {
  flex: 1 1 16rem;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.next-kicker {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}
#next-link {
  min-width: 0;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#next-link:hover { text-decoration: underline; }

.filters {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters button,
.night-toggle {
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}
.filters button:hover,
.night-toggle:hover { border-color: var(--muted); }
.filters button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.night-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.night-toggle::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: #c62a1a;
  box-shadow: 0 0 0 2px rgba(198, 42, 26, 0.25);
}
.night-toggle[aria-pressed="true"] {
  border-color: var(--ink);
}

@media (max-width: 640px) {
  .controls { gap: 0.45rem 0.6rem; padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .next-card { flex-basis: 100%; }
  .filters { flex: 1 1 0; min-width: 0; }
  .night-toggle { font-size: 0; padding: 0.45rem 0.55rem; gap: 0; }
  .night-toggle::before { width: 0.9rem; height: 0.9rem; }
}

/* ---------- Main layout ---------- */
main {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.overview { padding-top: 2.5rem; }
.overview h2,
.reference h2 {
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  margin: 0 0 0.6rem;
}
.intro { max-width: 46rem; margin: 0 0 1rem; color: var(--ink-soft); }

.rules {
  display: grid;
  gap: 0 2.5rem;
  margin-top: 1.5rem;
  font-size: 0.97rem;
  color: var(--ink-soft);
}
.rules p { margin: 0 0 1rem; }
.rules strong { color: var(--ink); }
@media (min-width: 800px) {
  .rules { grid-template-columns: 1fr 1fr; }
}

/* ---------- Season chart ---------- */
.chart-wrap {
  position: relative;
  overflow-x: auto;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem 0 0.6rem;
  margin: 0.5rem 0 0.75rem;
}
table.season {
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.season th,
.season td {
  padding: 0;
  min-width: 1.75rem;
  height: 1.75rem;
  text-align: center;
  vertical-align: middle;
}
.season th[scope="row"],
.season .corner {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg);
  text-align: left;
  white-space: nowrap;
  padding: 0 0.8rem 0 0.25rem;
  font-weight: 700;
  font-size: 0.85rem;
}
.season .corner {
  vertical-align: bottom;
  color: var(--muted);
  font-weight: 400;
}
.season .mon {
  text-align: left;
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0 0.3rem;
  border-left: 1px solid var(--rule);
  height: auto;
}
.season thead a {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 0.15rem 0;
}
.season thead a:hover { color: var(--ink); text-decoration: underline; }

.season td.sky { border: 1px solid var(--bg); }
.sky-dark { background: var(--c-dark); }
.sky-twilight { background: var(--c-twi); }
.sky-bright { background: var(--c-bright); }

.season td.moon { border: 1px solid var(--bg); }
.moon-up { background: var(--c-moon); }
.mini-moon { display: block; margin: auto; }

.r-saturn { --pc: var(--p-saturn); }
.r-neptune { --pc: var(--p-neptune); }
.r-uranus { --pc: var(--p-uranus); }
.r-jupiter { --pc: var(--p-jupiter); }
.r-mars { --pc: var(--p-mars); }
.r-saturn th, .r-neptune th, .r-uranus th, .r-jupiter th, .r-mars th { color: var(--pc); }

.dot {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  vertical-align: middle;
}
.pl-early .dot { background: var(--pc); }
.pl-late .dot { border: 2px solid var(--pc); }
.pl-none .dot {
  width: 0.35rem;
  height: 0.35rem;
  background: var(--rule);
}

.season .r-ev td { height: 2rem; }
.ev a {
  display: block;
  color: var(--accent);
  text-decoration: none;
  font-size: 1.05rem;
  line-height: 2rem;
}
.ev a:hover { transform: scale(1.2); }
@media (prefers-reduced-motion: reduce) {
  .ev a:hover { transform: none; }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.legend span { white-space: nowrap; }
.lg {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.4rem;
  vertical-align: -0.1rem;
}
.lg-early { border-radius: 50%; background: var(--ink); }
.lg-late { border-radius: 50%; border: 2px solid var(--ink); }
.lg-dark { background: var(--c-dark); }
.lg-twi { background: var(--c-twi); }
.lg-bright { background: var(--c-bright); }
.lg-moon { background: var(--c-moon); }
.lg-star { color: var(--accent); margin-right: 0.4rem; font-weight: 400; }

/* ---------- Weeks ---------- */
.month { margin-top: 3.25rem; }
.month-title {
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  margin: 0 0 0.25rem;
  letter-spacing: -0.01em;
}
.month-title .yr { color: var(--muted); font-weight: 500; }

.week {
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  gap: 0 2.25rem;
  padding: 1.75rem 0 1.5rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: var(--bar-h, 5rem);
}

.when p { margin: 0; }
.when .date {
  font-family: var(--serif);
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1.1;
}
.when .date::before {
  content: "Tue ";
  font-size: 0.55em;
  font-weight: 500;
  color: var(--muted);
  vertical-align: 0.35em;
}
.moon-glyph { display: block; margin: 0.6rem 0 0.5rem; }
.moon-glyph .dark,
.mini-moon .dark { fill: var(--moon-dark); stroke: var(--moon-edge); stroke-width: 1; }
.moon-glyph .lit,
.mini-moon .lit { fill: var(--moon-lit); }

.when .kind {
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.when .kind::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  flex: none;
}
.kind-dark .kind::before { background: var(--k-dark); }
.kind-moon .kind::before { background: var(--k-moon); }
.kind-mixed .kind::before { background: linear-gradient(90deg, var(--k-moon) 50%, var(--k-dark) 50%); }
.when .moonline,
.when .darkline {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}
.when .darkline { margin-top: 0.4rem; font-weight: 700; }

.body h3 {
  font-size: clamp(1.3rem, 2.6vw, 1.6rem);
  margin: 0 0 0.6rem;
}
.week[data-event] .body h3::before {
  content: "✦";
  color: var(--accent);
  font-weight: 400;
  margin-right: 0.45rem;
}
.next-flag {
  display: none;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-bg);
  color: var(--accent-ink);
  border-radius: 3px;
  padding: 0.15rem 0.5rem;
  margin: 0 0 0.6rem;
}
.week.is-next .next-flag { display: inline-block; }

.callout {
  margin: 0.4rem 0 1rem;
  padding: 0.75rem 1rem;
  background: var(--callout-bg);
  border-left: 3px solid var(--accent);
}
.planets,
.jup { margin: 0.5rem 0; color: var(--ink-soft); }
.pl-label,
.jup-label { font-weight: 700; color: var(--ink); }

.body h4 {
  margin: 1.2rem 0 0.35rem;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.targets,
.eye {
  list-style: none;
  margin: 0;
  padding: 0;
}
.targets li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--rule);
}
.targets li:last-child { border-bottom: 0; }
.obj { font-weight: 700; }
.alt {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  max-width: 13rem;
  padding-top: 0.12rem;
}
.note {
  grid-column: 1 / -1;
  color: var(--ink-soft);
  font-size: 0.97rem;
}

.eye li {
  position: relative;
  padding: 0.2rem 0 0.2rem 1.2rem;
  color: var(--ink-soft);
}
.eye li::before {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 0.72em;
  width: 0.45rem;
  height: 0.45rem;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}

@media (max-width: 700px) {
  .week { grid-template-columns: minmax(0, 1fr); padding-top: 1.4rem; }
  .when {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.9rem;
    align-items: center;
    margin-bottom: 0.9rem;
  }
  .when .date { grid-column: 1; grid-row: 1; }
  .when .moon-glyph { grid-column: 1; grid-row: 2 / span 1; margin: 0.3rem 0 0; }
  .when .kind { grid-column: 2; grid-row: 1; margin: 0; justify-self: end; }
  .when .moonline { grid-column: 2; grid-row: 2; }
  .when .darkline { grid-column: 1 / -1; grid-row: 3; }
  .alt { max-width: 9rem; }
}

/* ---------- Reference ---------- */
.reference { margin-top: 3.5rem; }
.table-wrap { overflow-x: auto; }
.planets-table {
  width: 100%;
  min-width: 40rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.planets-table th,
.planets-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.65rem 0.75rem 0.65rem 0;
  border-bottom: 1px solid var(--rule);
}
.planets-table thead th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}
.planets-table tbody th {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
}
.planets-table td:nth-child(2),
.planets-table td:nth-child(3) { white-space: nowrap; }
.planets-table td:last-child { color: var(--ink-soft); }
@media (max-width: 900px) {
  .planets-table td:nth-child(2),
  .planets-table td:nth-child(3) { white-space: normal; min-width: 8rem; }
}

.two-col {
  display: grid;
  gap: 2.5rem 3rem;
}
@media (min-width: 820px) {
  .two-col { grid-template-columns: 1fr 1fr; }
}
.extras,
.tools {
  list-style: none;
  margin: 0;
  padding: 0;
}
.extras li,
.tools li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
}
.x-date {
  display: block;
  font-weight: 700;
  color: var(--ink);
}
.tools a { font-weight: 700; }
.tools span { display: block; font-size: 0.95rem; }

.notes p { max-width: 48rem; color: var(--ink-soft); }

.foot {
  border-top: 1px solid var(--rule);
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1.5rem 1.25rem 2.5rem;
}
.foot p { margin: 0; }

/* ---------- Print: a clean handout ---------- */
@media print {
  :root, body, body.night {
    --bg: #fff; --ink: #000; --ink-soft: #222; --muted: #555; --rule: #bbb;
    --link: #000; --accent: #7a4500; --callout-bg: #f4f4f4;
    --c-dark: #333; --c-twi: #999; --c-bright: #ddd; --c-moon: #eee;
    --k-dark: #333; --k-moon: #bbb;
    --moon-lit: #fff; --moon-dark: #444; --moon-edge: #444;
    --p-saturn: #000; --p-neptune: #000; --p-uranus: #000; --p-jupiter: #000; --p-mars: #000;
  }
  .controls, .hero-sky { display: none; }
  .hero { background: none; color: #000; }
  .hero h1, .lede { color: #000; }
  .chart-wrap { overflow: visible; }
  .week { break-inside: avoid; }
  .month-title { break-after: avoid; }
  a { text-decoration: none; }
}
.hero-trees rect { fill: var(--pine); }
.filters .short { display: none; }
@media (max-width: 640px) {
  .filters .long { display: none; }
  .filters .short { display: inline; }
  .filters button { padding: 0.4rem 0.6rem; }
}
body.night .filters button[aria-pressed="true"] {
  background: var(--accent-bg);
  color: var(--ink);
  border-color: var(--ink);
}
body.night .moon-glyph .lit,
body.night .mini-moon .lit { fill: #8e2a1c; }

/* ---------- "Next session only" note ---------- */
.filter-note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.6rem;
  margin: 0 0 -0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--callout-bg);
  border-left: 3px solid var(--accent);
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.link-btn {
  font: inherit;
  font-weight: 700;
  color: var(--link);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.link-btn:hover { text-decoration-thickness: 2px; }
@media print { .filter-note { display: none; } }
