/*
 * Visual system for the `daylight` mini-site: one full-screen map.
 * The theme follows the sun at the reader's place (see js/theme.js). Land is
 * always black → white by day length; only the frame around it changes.
 */

:root,
:root[data-theme="dark"] {
  --bg: #0b1620;
  --ocean: #15283a;
  --ink: #e6edf3;
  --mute: #8da0b1;
  --rule: rgba(230, 237, 243, 0.14);
  --panel: rgba(11, 22, 32, 0.74);
  --panel-border: rgba(230, 237, 243, 0.1);
  --coast: rgba(255, 255, 255, 0.2);
  --rim: rgba(230, 237, 243, 0.22);
  --parallel: rgba(240, 180, 76, 0.55);
  --accent: #f0b44c;
  --accent-ink: #0b1620;
  --label-halo: rgba(11, 22, 32, 0.85);
  color-scheme: dark;
}

:root[data-theme="light"] {
  /* Frame and ocean stay well below white so white land never melts into them. */
  --bg: #cdd6dd;
  --ocean: #8497a7;
  --ink: #121c24;
  --mute: #46586a;
  --rule: rgba(18, 28, 36, 0.14);
  --panel: rgba(205, 214, 221, 0.8);
  --panel-border: rgba(18, 28, 36, 0.12);
  --coast: rgba(0, 0, 0, 0.28);
  --rim: rgba(18, 28, 36, 0.3);
  --parallel: rgba(122, 64, 0, 0.6);
  --accent: #9a5a06;
  --accent-ink: #f4f1ea;
  --label-halo: rgba(205, 214, 221, 0.88);
  color-scheme: light;
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  /* DM Sans is variable in optical size: left on auto, every font size gets a
     differently drawn cut and neighbouring lines look like different fonts. */
  font-optical-sizing: none;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background-color 900ms ease, color 900ms ease;
}

button,
input {
  font: inherit;
  color: inherit;
}

.app {
  position: relative;
  height: 100svh;
  width: 100vw;
  overflow: hidden;
}

.map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

/* Easter egg: polar lights, a low-resolution layer screened over the map. */
.aurora {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  mix-blend-mode: screen;
}

.map.is-dragging {
  cursor: grabbing;
}

/* ------------------------------------------------------------ top bar --- */

.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  pointer-events: none;
  z-index: 5;
}

.topbar > * {
  pointer-events: auto;
}

.site-logo img {
  height: 32px;
  width: auto;
  opacity: 0.9;
  display: block;
}

:root[data-theme="dark"] .site-logo img {
  filter: invert(1) hue-rotate(180deg);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--accent);
}

/* The icon shows what you get, not what you have. */
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun {
  display: none;
}

.site-lang {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 600;
}

.site-lang a {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--mute);
  text-decoration: none;
}

.site-lang a.is-active {
  background: var(--ink);
  color: var(--bg);
}

/* -------------------------------------------------------------- intro --- */

.intro {
  position: absolute;
  top: 64px;
  left: 24px;
  max-width: 29rem;
  pointer-events: none;
  z-index: 4;
}

.title {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 4.4vw, 3.6rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
}

.lead {
  margin: 14px 0 0;
  font-size: clamp(16px, 1.3vw, 18px);
  line-height: 1.45;
  color: var(--mute);
  text-shadow: 0 0 12px var(--bg);
}

.sun-hint {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 12px 0 0;
  font-size: 14px;
  min-height: 3.9em;
}

.sun-hint-source {
  color: var(--mute);
}

.sun-hint-state {
  font-weight: 500;
  color: var(--accent);
}

.sun-hint-length {
  color: var(--ink);
}

/* The intro ignores the pointer (the map is under it); the button must not. */
.sun-hint-action {
  pointer-events: auto;
  margin-left: 0.5em;
  padding: 1px 9px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  vertical-align: 1px;
}

.sun-hint-action:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.sun-hint-action:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ------------------------------------------------------------- legend --- */

/* Bottom left, level with the controls; above them when the panel spans the width. */
.legend {
  position: absolute;
  left: 24px;
  bottom: 32px;
  width: 220px;
  z-index: 4;
  pointer-events: none;
}

.legend-title {
  margin: 0 0 10px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--mute);
}

/* A horizontal bar under the title, hours underneath. */
.legend-body {
  width: 100%;
}

.legend-ramp {
  width: 100%;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--rule);
}

.legend-ticks {
  position: relative;
  height: 14px;
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--mute);
  line-height: 1;
}

/* Each hour label is centred on its point of the bar; the ends stay inside. */
.legend-ticks li {
  position: absolute;
  top: 0;
  white-space: nowrap;
  transform: translateX(-50%);
}

.legend-ticks li:nth-child(1) { left: 0; transform: none; }
.legend-ticks li:nth-child(2) { left: 25%; }
.legend-ticks li:nth-child(3) { left: 50%; }
.legend-ticks li:nth-child(4) { left: 75%; }
.legend-ticks li:nth-child(5) { left: 100%; transform: translateX(-100%); }

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

.controls {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(10px);
  z-index: 6;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.controls-row--secondary {
  margin-top: 10px;
  justify-content: space-between;
  gap: 10px;
}

.play-button {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.play-button .icon-pause,
.play-button.is-playing .icon-play {
  display: none;
}

.play-button.is-playing .icon-pause {
  display: block;
}

.slider-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  padding-bottom: 14px;
}

.day-slider {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.month-ticks {
  position: absolute;
  inset: auto 0 0 0;
  height: 12px;
  list-style: none;
  margin: 0;
  padding: 0 8px;
  font-size: 10px;
  color: var(--mute);
}

.month-ticks li {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.date-label {
  flex: none;
  min-width: 7.5em;
  text-align: right;
  font-weight: 600;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips button,
.view-toggle button {
  border: 1px solid var(--panel-border);
  background: transparent;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--mute);
  cursor: pointer;
  white-space: nowrap;
}

.chips button:hover,
.view-toggle button:hover {
  color: var(--ink);
}

.chips button.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.view-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

/* Globe spin on/off: filled with the accent while spinning. */
.spin-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: transparent;
  color: var(--mute);
  cursor: pointer;
}

.spin-button:hover {
  color: var(--ink);
}

.spin-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.spin-button[hidden] {
  display: none;
}

/* What the button does, above it (the panel sits at the bottom). */
.spin-button {
  position: relative;
}

.spin-button::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  right: -8px;
  width: max-content;
  max-width: 15rem;
  padding: 6px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 150ms ease;
}

.spin-button:hover::after,
.spin-button:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

.view-toggle {
  display: flex;
  flex: none;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
}

.view-toggle button {
  border: 0;
}

.view-toggle button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* Above the timeline panel, left-aligned; shown only around an equinox. */
.date-note {
  position: absolute;
  left: 4px;
  bottom: 100%;
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.3;
  color: var(--ink);
  text-shadow: 0 0 8px var(--bg), 0 0 3px var(--bg);
  pointer-events: none;
}

.date-note[hidden] {
  display: none;
}

/* ------------------------------------------------------------ tooltip --- */

.tooltip {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  transform: translate(12px, -50%);
}

/* Parallels carry a sentence, not a number: let it wrap. */
.tooltip--note {
  white-space: normal;
  max-width: 16rem;
}

.tooltip strong {
  display: block;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- byline --- */

.byline {
  position: absolute;
  right: 20px;
  bottom: 4px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  color: var(--mute);
}

.byline-name {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  text-underline-offset: 0.15em;
}

.byline-name:hover,
.byline-method:hover {
  color: var(--accent);
  text-decoration: underline;
}

.byline-tg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  color: var(--mute);
}

.byline-tg:hover {
  color: var(--accent);
}

.byline-method {
  padding: 0;
  border: 0;
  background: none;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  text-underline-offset: 0.15em;
}

/* ---------------------------------------------------------- methodology --- */

.method-dialog {
  width: min(40rem, calc(100vw - 32px));
  max-height: min(92svh, 46rem);
  /* Scrolls if the screen is short, but without the system scrollbar. */
  overflow-y: auto;
  scrollbar-width: none;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.method-dialog::-webkit-scrollbar {
  display: none;
}

.method-dialog::backdrop {
  background: rgba(5, 10, 15, 0.55);
  backdrop-filter: blur(2px);
}

.method-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  background: var(--bg);
}

.method-title {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.75rem;
  font-weight: 700;
}

.method-body {
  padding: 0 20px 22px;
  font-size: 15px;
  line-height: 1.55;
}

.method-body h3 {
  margin: 18px 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--mute);
}

.method-body p {
  margin: 0 0 10px;
}

.method-body a {
  color: var(--accent);
}

.noscript {
  position: absolute;
  inset: 40% 0 auto;
  text-align: center;
}

/* ------------------------------------------------------------- mobile --- */

@media (max-width: 720px) {
  .topbar {
    padding: 10px 14px;
  }

  .site-logo img {
    height: 26px;
  }

  .intro {
    top: 52px;
    left: 16px;
    right: 16px;
    max-width: none;
  }

  .lead {
    font-size: 14px;
  }

  /* No room on the left under the title: a compact scale in the top corner. */
  /* In the strip above the timeline, right side; the equinox note takes the left. */
  .legend {
    left: auto;
    right: 16px;
    bottom: calc(32px + var(--controls-h, 120px) + 8px);
    width: 150px;
  }

  .legend-ramp {
    height: 8px;
  }

  .legend-ticks {
    margin-top: 4px;
    height: 12px;
    font-size: 11px;
  }

  .date-note {
    max-width: calc(100% - 166px);
    font-size: 12px;
  }

  .legend-title {
    display: none;
  }


  /* Room under the panel for the byline, which sits at the very bottom. */
  .controls {
    bottom: 32px;
    padding: 10px 12px;
  }

  .controls-row {
    gap: 10px;
  }

  .date-label {
    min-width: 5.5em;
    font-size: 14px;
  }

  /* All five dates on one line, globe/map tools on the line below, left-aligned. */
  .controls-row--secondary {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .chips {
    flex-wrap: nowrap;
    width: 100%;
    gap: 4px;
  }

  .chips button {
    padding: 3px 7px;
    font-size: 11px;
  }

  .view-tools {
    margin-left: 0;
  }

  .byline {
    left: 16px;
    right: 16px;
    bottom: max(4px, env(safe-area-inset-bottom));
    justify-content: center;
    font-size: 12px;
  }
}

@media (min-width: 721px) and (max-width: 1180px) {
  /* The controls reach the left edge here: lift the scale above them. */
  .legend {
    bottom: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }
}

.theme-instant body {
  transition: none;
}

@media (max-width: 520px) {
  .month-ticks li:nth-child(even) {
    display: none;
  }
}
