:root {
  --bg: #fff;
  --fg: #000;
  --sans: "Inter Tight", system-ui, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --line: #d9d9d9;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --fg: #fff; --line: #333; }
}
* { box-sizing: border-box; margin: 0; }
html { scroll-snap-type: y proximity; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}
section {
  min-height: 100vh;
  min-height: 100svh;
  padding: 16px;
  display: grid;
  align-content: center;
  scroll-snap-align: start;
}
.num {
  font-size: clamp(96px, 22vw, 320px);
  font-weight: 600;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.num.mono {
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: -0.06em;
}
.lede {
  font-size: clamp(18px, 2.4vw, 28px);
  margin-top: 0.6em;
}
.note {
  margin-top: clamp(48px, 6vw, 96px);
  font-size: clamp(16px, 1.8vw, 22px);
  opacity: 0.55;
  max-width: 40ch;
  min-height: 1.4em;
}
.serif { font-family: var(--serif); font-style: italic; font-size: clamp(20px, 2.2vw, 30px); }
.mono.note { font-family: var(--mono); font-size: clamp(13px, 1.3vw, 16px); }
a { color: inherit; }
button {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.6em;
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  color: inherit;
  padding: 0;
  margin-left: 1em;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0.55;
}
button:hover { opacity: 1; }
button[hidden] { display: none; }

/* split-flap clock */
.flap {
  --h: clamp(96px, 20vw, 300px);
  --w: calc(var(--h) * 0.68);
  display: flex;
  align-items: center;
  gap: calc(var(--h) * 0.06);
  height: var(--h);
  perspective: calc(var(--h) * 4);
  margin-top: clamp(24px, 4vw, 56px);
}
.card {
  position: relative;
  width: var(--w);
  height: var(--h);
  font-weight: 600;
  font-size: calc(var(--h) * 0.86);
  line-height: var(--h);
  letter-spacing: -0.04em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--bg);
}
.card > span {
  position: absolute;
  left: 0; width: 100%; height: 50%;
  overflow: hidden;
  background: var(--fg);
  backface-visibility: hidden;
}
.card .t, .card .ft { top: 0; border-radius: 6px 6px 0 0; }
.card .b, .card .fb { bottom: 0; border-radius: 0 0 6px 6px; }
.card .b > i, .card .fb > i { position: absolute; left: 0; width: 100%; bottom: 0; font-style: normal; }
.card .t > i, .card .ft > i { position: absolute; left: 0; width: 100%; top: 0; font-style: normal; }
.card .t, .card .ft { border-bottom: 1px solid var(--bg); box-sizing: border-box; }
.card .ft, .card .fb { display: none; }
.card.flip .ft { display: block; transform-origin: bottom; animation: ft .28s ease-in forwards; }
.card.flip .fb { display: block; transform-origin: top; transform: rotateX(90deg); animation: fb .28s ease-out .28s forwards; }
@keyframes ft { to { transform: rotateX(-90deg); } }
@keyframes fb { to { transform: rotateX(0); } }
.colon {
  font-weight: 600;
  font-size: calc(var(--h) * 0.6);
  line-height: 1;
  padding: 0 calc(var(--h) * 0.02);
}
@media (prefers-reduced-motion: reduce) {
  .card.flip .ft, .card.flip .fb { display: none; }
}
.unit { font-size: 0.35em; letter-spacing: 0; margin-left: 0.15em; }

/* per-slide layers */
section { position: relative; overflow: hidden; }
section > .num, section > .lede, section > .note, section > .flap { position: relative; z-index: 1; }
.layer { position: absolute; inset: 0; pointer-events: none; }

/* wikipedia: titles drifting in and out */
.wiki-title {
  position: absolute;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(18px, 2vw, 28px);
  max-width: 28ch;
  opacity: 0;
  animation: wiki-fade var(--life) ease-in-out forwards;
  transform-origin: left center;
}
@keyframes wiki-fade {
  0%   { opacity: 0;   transform: scale(0.92); }
  15%  { opacity: 0.6; transform: scale(1); }
  85%  { opacity: 0.6; transform: scale(1.04); }
  100% { opacity: 0;   transform: scale(1.08); }
}

/* aircraft: one dot per plane, relative to the visitor */
.plane {
  position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  color: var(--fg);
  transition: transform 14s linear, opacity 1s;
}
.you {
  position: absolute; left: 50%; top: 50%;
  width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; border: 1px solid var(--fg); opacity: 0.4;
}

@media (prefers-reduced-motion: reduce) {
  .wiki-title { animation-duration: 0s; opacity: 0.6; }
  .plane { transition: none; }
}
.plane svg { display: block; width: 100%; height: 100%; }

/* keyline between slides: strongest at viewport centre */
section + section::before {
  content: "";
  position: absolute;
  left: 16px; right: 16px; top: 0;
  height: 1px;
  background: var(--fg);
  opacity: var(--k, 0);
  transform: scaleY(calc(1 + 2 * var(--k, 0)));
  transform-origin: top;
}

/* ISS ground track */
.track { inset: 12vh 16px; }
.track svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.track path { fill: none; stroke: var(--fg); stroke-width: 0.5; vector-effect: non-scaling-stroke; }
.track .future { opacity: 0.45; stroke-width: 1; stroke-dasharray: 3 4; }
.track .past { opacity: 0.55; stroke-width: 1; }
.track .iss-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--fg); }
.track .iss-dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--fg);
  animation: ping 2.4s ease-out infinite;
}
@keyframes ping { 0% { transform: scale(1); opacity: 0.7; } 100% { transform: scale(5); opacity: 0; } }
.track .you { transition: none; }

/* earthquakes: last 24h, radius by magnitude, new ones pulse */
.quake {
  position: absolute;
  width: var(--r); height: var(--r);
  margin: calc(var(--r) / -2) 0 0 calc(var(--r) / -2);
  border-radius: 50%;
  border: 1px solid var(--fg);
  opacity: 0.35;
}
.quake.new { background: var(--fg); opacity: 1; }
.quake.new::after {
  content: ""; position: absolute; inset: -1px; border-radius: 50%;
  border: 1px solid var(--fg);
  animation: ring 2.4s ease-out infinite;
}
@keyframes ring { to { transform: scale(4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .quake.new::after { animation: none; } }

/* receipt */
.receipt {
  font-family: var(--mono);
  font-size: clamp(15px, 1.6vw, 20px);
  display: grid;
  grid-template-columns: 1fr max-content;
  max-width: 40ch;
  column-gap: 1.5ch;
  row-gap: 0.5em;
  align-items: center;
}
.receipt dt { display: flex; align-items: center; gap: 1.5ch; opacity: 0.55; }
.receipt dt::after { content: ""; flex: 1; border-top: 1px dashed currentColor; opacity: 0.5; }
.receipt dd { text-align: right; font-variant-numeric: tabular-nums; }
.sign {
  margin-top: clamp(48px, 6vw, 96px);
  font-size: clamp(18px, 2.4vw, 28px);
  line-height: 1.4;
}
.sign a { text-decoration: none; border-bottom: 1px solid currentColor; }

/* small flip cards in the receipt */
.flap.small { --h: clamp(22px, 2.2vw, 30px); margin: 0; justify-content: flex-end; }
.flap.small .card > span { border-radius: 3px 3px 0 0; }
.flap.small .card .b, .flap.small .card .fb { border-radius: 0 0 3px 3px; }
.flap.small .colon { font-size: calc(var(--h) * 0.7); }
.receipt dd { display: flex; justify-content: flex-end; align-items: center; }

/* floating widget */
.widget {
  position: fixed; right: 16px; bottom: 16px; z-index: 10;
  display: flex; gap: 4px;
}
.widget button {
  width: 40px; height: 40px; padding: 10px; margin: 0; border: 0; opacity: 1;
  display: grid; place-items: center;
  background: var(--bg); color: var(--fg);
}
.widget button svg { width: 20px; height: 20px; }
.widget button { opacity: 0.6; border-radius: 6px; }
.widget button:hover, .widget button[aria-pressed="true"] { opacity: 1; }
.widget button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }

/* about dialog */
.about {
  position: fixed; right: 16px; bottom: 60px; left: auto; top: auto; margin: 0;
  max-width: 34ch; padding: 20px 22px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--fg);
  font-size: 16px; line-height: 1.45;
}
.about::backdrop { background: transparent; }
.about p + p { margin-top: 1em; font-family: var(--mono); font-size: 13px; }
.about a { text-decoration: none; border-bottom: 1px solid currentColor; }

/* grid view: desktop only */
@media (min-width: 768px) {
  body.grid { height: 100vh; height: 100svh; overflow: hidden; }
  body.grid html, body.grid { scroll-snap-type: none; }
  body.grid main {
    display: grid; height: 100%; gap: 1px; background: var(--line);
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-template-areas:
      "arrive wiki  iss   iss"
      "air    sky   sky   quake"
      "air    sky   sky   me";
  }
  body.grid section { min-height: 0; height: 100%; padding: 12px; background: var(--bg); scroll-snap-align: none; }
  body.grid section::before { display: none; }
  body.grid #arrive { grid-area: arrive; } body.grid #wiki { grid-area: wiki; }
  body.grid #iss { grid-area: iss; }       body.grid #air { grid-area: air; }
  body.grid #quake { grid-area: quake; }   body.grid #sky { grid-area: sky; }
  body.grid #me { grid-area: me; padding-bottom: 56px; }
  body.grid .num { font-size: clamp(36px, 6vw, 110px); }
  body.grid .lede { font-size: clamp(13px, 1.2vw, 18px); margin-top: 0.4em; }
  body.grid .note { margin-top: 1.2em; font-size: 12px; }
  body.grid .flap { --h: clamp(40px, 5vw, 90px); margin-top: 12px; }
  body.grid .flap.small { --h: 18px; margin: 0; }
  body.grid .track { inset: 8% 12px; }
  body.grid .wiki-title { font-size: 14px; max-width: 22ch; }
  body.grid .receipt { display: none; }
  body.grid .sign { margin-top: 0; font-size: clamp(14px, 1.3vw, 18px); }
  body.grid .plane { width: 12px; height: 12px; margin: -6px 0 0 -6px; }
}
@media (max-width: 767px) { .widget, .about { display: none; } }
