/* =========================================================
   The Daylight Almanac — editorial print, lit by the sky
   ========================================================= */

:root {
  --paper: #f3ede1;
  --paper-2: #ebe3d3;
  --ink: #1d1a16;
  --muted: #72695c;
  --rule: #cdc2ae;
  --accent: #b9472a;
  --moon-dark: #d9d1bf;
  --shadow: 0 30px 60px -30px rgba(40, 28, 12, 0.45);

  --serif: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --sans: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --page: min(1280px, calc(100% - 48px));
  color-scheme: light;
}

body[data-theme='night'] {
  --paper: #0c0f1f;
  --paper-2: #121631;
  --ink: #ece5d3;
  --muted: #8f8ca6;
  --rule: #2c3152;
  --accent: #f0a65c;
  --moon-dark: #1b2040;
  --shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.9);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.45s ease, color 0.45s ease;
  overflow-x: hidden;
}

body * { transition: border-color 0.45s ease, background-color 0.45s ease, color 0.45s ease, fill 0.45s ease, stroke 0.45s ease; }
body.no-trans,
body.no-trans * { transition: none !important; }

.grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 50;
  opacity: 0.28;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.38  0 0 0 0 0.28  0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
body[data-theme='night'] .grain { mix-blend-mode: screen; opacity: 0.07; }

/* ---------- masthead ---------- */
.masthead {
  width: var(--page);
  margin: 0 auto;
  padding-top: 26px;
}

.mast-rail {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  border-top: 4px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.mast-edition { color: var(--accent); text-align: center; }

.mast-title {
  margin: 22px 0 6px;
  font-family: var(--serif);
  font-weight: 380;
  font-size: clamp(46px, 9.4vw, 136px);
  line-height: 0.92;
  letter-spacing: -0.035em;
  text-align: center;
  font-variation-settings: 'opsz' 144, 'SOFT' 30;
}
.mast-title em {
  font-style: italic;
  color: var(--accent);
  font-variation-settings: 'opsz' 144, 'SOFT' 100, 'WONK' 1;
}

.mast-sub {
  margin: 0 auto 22px;
  max-width: 640px;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px 40px;
  padding: 14px 0 16px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.control label {
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.control-row { display: flex; align-items: center; gap: 8px; }

select,
input[type='number'],
input[type='date'] {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  font: 500 15px/1.2 var(--sans);
  padding: 6px 2px;
  outline: none;
}
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%231d1a16' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 4px center;
  background-size: 10px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}
body[data-theme='night'] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23ece5d3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
select::picker-icon { display: none; }
select option { background: var(--paper); color: var(--ink); }
#place { min-width: 250px; }
input[type='number'] { width: 96px; font-family: var(--mono); font-size: 14px; }
input[type='number']::-webkit-inner-spin-button { display: none; }
input[type='date'] { font-family: var(--mono); font-size: 14px; }
select:focus-visible,
input:focus-visible { border-bottom-color: var(--accent); box-shadow: 0 1px 0 var(--accent); }

.icon-btn,
.text-btn {
  display: inline-grid;
  place-items: center;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.text-btn { padding: 0 14px; font: 600 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle:first-child { fill: currentColor; stroke: none; }
.icon-btn:hover,
.text-btn:hover { border-color: var(--ink); }
.icon-btn:focus-visible,
.text-btn:focus-visible,
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.busy { animation: spin 1s linear infinite; }
.icon-btn.denied { border-color: var(--accent); color: var(--accent); }
.coords.bad { animation: shake 0.4s; }
.coords.bad input { border-bottom-color: var(--accent); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ---------- the stage ---------- */
.stage {
  position: relative;
  width: var(--page);
  height: clamp(380px, 64vh, 660px);
  margin: 30px auto 0;
  border-radius: 3px;
  overflow: hidden;
  background: #070a16;
  box-shadow: var(--shadow);
  outline: 1px solid var(--ink);
  outline-offset: 6px;
}

#sky {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}
#sky.dragging { cursor: grabbing; }

.stage-overlay {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 22px 26px 40px;
  background: linear-gradient(180deg, rgba(8, 12, 24, 0.28) 0%, rgba(8, 12, 24, 0) 100%);
  color: #fff;
  pointer-events: none;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45), 0 1px 4px rgba(0, 0, 0, 0.35);
}

.clock-time {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(54px, 8vw, 108px);
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-variation-settings: 'opsz' 144;
}
.clock-time .sec { font-size: 0.38em; opacity: 0.6; letter-spacing: 0; margin-left: 4px; }
.clock-meta {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.85;
}

.stage-right { display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }

.phase-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(10, 14, 30, 0.22);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.phase-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5), 0 0 12px currentColor; }
body[data-phase='night'] .phase-dot { background: #0b0f22; color: #6070c0; }
body[data-phase='astronomical'] .phase-dot { background: #1a2148; color: #6070c0; }
body[data-phase='nautical'] .phase-dot { background: #2e3b77; color: #7d8de0; }
body[data-phase='blue'] .phase-dot { background: #5470b4; color: #8fa8ff; }
body[data-phase='golden'] .phase-dot { background: #f2a654; color: #ffb35c; }
body[data-phase='day'] .phase-dot { background: #f7e2ab; color: #fff2c0; }

.readout { margin: 0; display: grid; gap: 6px; text-align: right; }
.readout div { display: flex; justify-content: flex-end; align-items: baseline; gap: 10px; }
.readout dt { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.6; }
.readout dd { margin: 0; font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }

.stage-hint,
.facing {
  position: absolute;
  bottom: 46px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}
.stage-hint { left: 50%; transform: translateX(-50%); transition: opacity 0.8s; white-space: nowrap; }
.stage-hint.gone { opacity: 0; }
.facing { left: 26px; }

/* ---------- scrubber ---------- */
.scrubber {
  width: var(--page);
  margin: 0 auto;
  padding: 64px 0 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 22px;
}

.play {
  width: 52px;
  height: 52px;
  margin-top: -19px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.45s ease;
}
.play:hover { transform: scale(1.06); }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play .i-pause,
body.is-playing .play .i-play { display: none; }
body.is-playing .play .i-pause { display: block; }

.track { position: relative; padding-bottom: 44px; }

.band {
  height: 14px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: background 0.4s;
}

.track input[type='range'] {
  position: absolute;
  inset: 0 0 auto 0;
  width: 100%;
  height: 14px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
.track input[type='range']::-webkit-slider-runnable-track { height: 14px; background: transparent; }
.track input[type='range']::-moz-range-track { height: 14px; background: transparent; }
.track input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--paper) 60%, transparent), 0 6px 16px rgba(0, 0, 0, 0.3);
}
.track input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--paper) 60%, transparent), 0 6px 16px rgba(0, 0, 0, 0.3);
}
.track input[type='range']:focus-visible { outline: none; }
.track input[type='range']:focus-visible::-webkit-slider-thumb { border-color: var(--accent); }

.pins { position: absolute; inset: 0 0 auto 0; height: 14px; pointer-events: none; }
.pin {
  position: absolute;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
  font-family: var(--mono);
  line-height: 1.15;
}
.pin::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1px;
  height: 10px;
  background: var(--ink);
  opacity: 0.5;
}
.pin b { font-size: 9px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.pin em { font-style: normal; font-size: 12px; font-weight: 500; }
.pin-noon b { color: var(--accent); }
.pin-moon { bottom: auto; top: calc(100% + 30px); flex-direction: column-reverse; opacity: 0.75; }
.pin-moon::after { top: auto; bottom: 100%; height: 26px; opacity: 0.25; }

.ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.scrub-side { display: flex; align-items: center; gap: 10px; margin-top: -9px; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 600 11px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on { border-color: var(--accent); color: var(--accent); }
.live.on .live-dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
#speed { font: 500 12px var(--mono); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  50% { box-shadow: 0 0 0 5px transparent; }
}

/* ---------- field note ---------- */
.note {
  width: min(920px, calc(100% - 48px));
  margin: 46px auto 64px;
  text-align: center;
}
.note-kicker {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}
.note-kicker::before,
.note-kicker::after { content: '—'; margin: 0 10px; opacity: 0.6; }
.note-text {
  margin: 0;
  min-height: 3.9em;
  font-family: var(--serif);
  font-weight: 320;
  font-style: italic;
  font-size: clamp(21px, 2.5vw, 32px);
  line-height: 1.32;
  letter-spacing: -0.01em;
  text-wrap: balance;
  font-variation-settings: 'opsz' 72, 'SOFT' 60;
}

/* ---------- columns ---------- */
.columns {
  width: var(--page);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 4px solid var(--ink);
  padding-top: 26px;
}

.col { padding: 0 28px; border-left: 1px solid var(--rule); min-width: 0; }
.col:first-child { padding-left: 0; border-left: 0; }
.col:nth-child(3) { padding-right: 0; }
.col-wide {
  grid-column: 1 / -1;
  margin-top: 40px;
  padding: 26px 0 0;
  border-left: 0;
  border-top: 1px solid var(--ink);
}

.col h2 {
  margin: 0 0 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--ink);
  font-family: var(--serif);
  font-weight: 560;
  font-size: 27px;
  letter-spacing: -0.015em;
  font-variation-settings: 'opsz' 48;
}
.col-num { font-style: italic; font-weight: 400; color: var(--accent); margin-right: 4px; }

.ledger { margin: 0; }
.ledger .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px dotted var(--rule);
}
.ledger dt { color: var(--muted); font-size: 14px; }
.ledger dd {
  margin: 0;
  text-align: right;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 400;
  line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums;
}
.ledger dd small {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.col-foot {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
}

.light-split { display: grid; gap: 14px; margin-top: 8px; }
.light-split h3 {
  margin: 6px 0 2px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
.spans { list-style: none; margin: 0; padding: 0; }
.spans li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dotted var(--rule);
  font-size: 14px;
}
.sp-label { display: inline-flex; align-items: center; color: var(--muted); }
.sp-time { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-time i { font-style: normal; margin: 0 4px; opacity: 0.5; }
.none { font-family: var(--serif); font-style: italic; color: var(--muted); }

.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 9px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); flex: none; }
body[data-theme='night'] .sw { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.sw-night { background: #0b0f22; }
.sw-astronomical { background: #1a2148; }
body[data-theme='night'] .sw-astronomical { background: #232d63; }
.sw-nautical { background: #2e3b77; }
.sw-blue { background: #5470b4; }
.sw-golden { background: #f2a654; }
.sw-day { background: #f7e2ab; }

.moon-head { display: flex; align-items: center; gap: 18px; margin: 14px 0 6px; }
.moon-svg { width: 92px; height: 92px; flex: none; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.18)); }
.moon-dark { fill: var(--moon-dark); }
.moon-rim { fill: none; stroke: var(--rule); stroke-width: 1; }
body[data-theme='night'] .moon-svg { filter: drop-shadow(0 0 22px rgba(255, 245, 210, 0.22)); }
.moon-phase { margin: 0; font-family: var(--serif); font-size: 26px; line-height: 1.1; font-weight: 480; }
.moon-sub { margin: 6px 0 0; font-family: var(--mono); font-size: 11px; color: var(--muted); line-height: 1.5; }

/* year chart */
.year-wrap { position: relative; margin-top: 16px; }
#yearChart { display: block; width: 100%; height: auto; cursor: crosshair; overflow: visible; }
.yg { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2 4; }
.ym { stroke: var(--rule); stroke-width: 1; opacity: 0.6; }
.yl { fill: var(--muted); font-family: var(--mono); font-size: 10px; }
.yf-a { stop-color: var(--accent); stop-opacity: 0.32; }
.yf-b { stop-color: var(--accent); stop-opacity: 0.02; }
.yarea { fill: url(#yFill); }
.yline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.ymarker line { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.ymarker circle { fill: var(--accent); stroke: var(--paper); stroke-width: 2.5; }
.yhover line { stroke: var(--ink); stroke-width: 1; opacity: 0.3; }
.year-tip {
  position: absolute;
  top: -8px;
  transform: translate(-50%, -100%);
  padding: 4px 9px;
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  transition: none;
}
.year-tip b { font-weight: 500; margin-right: 6px; opacity: 0.7; }

/* ---------- legend & colophon ---------- */
.legend {
  width: var(--page);
  margin: 54px auto 0;
  padding: 16px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; }

.colophon {
  width: min(860px, calc(100% - 48px));
  margin: 0 auto;
  padding: 30px 0 70px;
  text-align: center;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--muted);
}
.colophon strong { color: var(--ink); font-weight: 600; }
.keys { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; }
kbd {
  display: inline-block;
  min-width: 22px;
  margin: 0 2px;
  padding: 1px 6px;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .columns { grid-template-columns: 1fr; }
  .col,
  .col:first-child,
  .col:nth-child(3) { padding: 22px 0 6px; border-left: 0; border-top: 1px solid var(--rule); }
  .col:first-child { border-top: 0; padding-top: 0; }
  .col-wide { border-top: 1px solid var(--ink); margin-top: 22px; }
}

@media (max-width: 720px) {
  :root { --page: calc(100% - 28px); }
  .mast-rail { font-size: 9px; flex-wrap: wrap; justify-content: center; }
  .mast-edition { order: -1; width: 100%; }
  .controls { gap: 14px 22px; }
  #place { min-width: 0; width: 100%; }
  .control { width: 100%; }
  .control-row select { flex: 1; }
  .stage { height: 58vh; min-height: 360px; outline-offset: 4px; }
  .stage-overlay { flex-direction: column; padding: 16px; }
  .stage-right { align-items: flex-start; }
  .readout { text-align: left; }
  .readout div { justify-content: flex-start; }
  .facing { display: none; }
  .scrubber { grid-template-columns: auto 1fr; padding-top: 58px; gap: 16px; }
  .scrub-side { grid-column: 1 / -1; justify-content: center; margin-top: 0; }
  .pin b { display: none; }
  .pin-moon { display: none; }
  .track { padding-bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  body, body * { transition: none !important; }
  .live.on .live-dot { animation: none; }
}
