/* Layout: the chart is the page, with a light wind drifting across it. One small tool
   floats at its centre, inside a chronometer ring that counts the 30-second TOTP window.
   The page opens with a show: the title is dug out of the land a letter at a time, lines
   up across the middle and goes off in a flash. Only then does the tool appear, on that spot.
   A loupe follows the cursor. */
:root{
  color-scheme: dark;
  --ink: #040404;                       /* chart paper */
  --void: #000;                         /* tool face */
  --white: #fff;
  --fg: #ededed;
  --fg-2: rgba(255,255,255,.62);
  --fg-3: rgba(255,255,255,.4);
  --fg-4: rgba(255,255,255,.22);
  --rule: rgba(255,255,255,.17);
  --display: "Martian Mono", "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --lens: 176px;                        /* loupe diameter, read by the renderer */
  --ease: cubic-bezier(.2,.75,.2,1);
}

*,*::before,*::after{ box-sizing: border-box; }
html,body{ height: 100%; }
body{
  margin: 0; background: var(--ink); color: var(--fg);
  font: 400 12px/1.5 var(--mono);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::selection{ background: var(--white); color: var(--void); }
.sr{ position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden]{ display: none !important; }

/* ── Chart ─────────────────────────────────────────────── */
#chart,#wind{ position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; opacity: 0; transition: opacity .8s ease; }
#wind{ pointer-events: none; transition: opacity 3.2s ease .5s; }
#chart.on,#wind.on{ opacity: 1; }
#dig,#surge,#blast{ position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
#dig{ z-index: 0; }
#surge{ z-index: 1; mix-blend-mode: color-dodge; }      /* the shock front: it lights up whatever of the chart it crosses */
#blast{ z-index: 6; }                                   /* the flash itself, over everything */
#safe{ position: fixed; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px); }

/* traffic on the chart: vessels under way and lights on the capes */
#live{ position: fixed; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity 1.4s ease .3s; }
#live.on{ opacity: 1; }
#live i{ position: absolute; left: 0; top: 0; width: 0; height: 0; will-change: transform; }
.light::after{
  content: ""; position: absolute; left: -13px; top: -13px; width: 26px; height: 26px;
  border: 1px solid var(--white); border-radius: 50%; opacity: 0;
  animation: ping 5.6s cubic-bezier(.2,.6,.3,1) infinite; animation-delay: var(--d, 0s);
}
@keyframes ping{ 0%{ transform: scale(.12); opacity: .8; } 50%,100%{ transform: scale(1); opacity: 0; } }
.ship::before{ content: ""; position: absolute; left: -2.5px; top: -2.5px; width: 5px; height: 5px; background: var(--white); transform: rotate(45deg); }
.ship::after{ content: ""; position: absolute; right: 4px; top: -.5px; width: 18px; height: 1px; background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,.55)); }

/* ── Loupe ─────────────────────────────────────────────── */
.loupe{
  position: fixed; left: 0; top: 0; z-index: 4; width: var(--lens); height: var(--lens);
  margin: calc(var(--lens) / -2) 0 0 calc(var(--lens) / -2);
  pointer-events: none; opacity: 0; transition: opacity .16s; will-change: transform, opacity;
}
.loupe.on{ opacity: 1; }
.loupe canvas{
  display: block; width: 100%; height: 100%; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,.8), 0 0 0 5px rgba(0,0,0,.5), 0 0 0 6px rgba(255,255,255,.12), 0 22px 60px rgba(0,0,0,.85);
  transform: scale(.84); transition: transform .26s var(--ease);
}
.loupe.on canvas{ transform: none; }
.loupe p{
  position: absolute; left: 50%; top: calc(100% + 14px); transform: translateX(-50%); margin: 0;
  display: grid; justify-items: center; white-space: nowrap;
  font: 500 9.5px/1.65 var(--mono); letter-spacing: .13em; text-transform: uppercase;
  color: var(--fg-3); font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #000, 0 0 6px #000, 0 0 10px #000;
}
.loupe p b{ font-weight: 500; color: var(--fg); }
.lensing .stage{ cursor: none; }

/* ── Marginalia ────────────────────────────────────────── */
.mark{
  position: fixed; z-index: 3; margin: 0; pointer-events: none;
  right: calc(env(safe-area-inset-right,0px) + 18px); bottom: calc(env(safe-area-inset-bottom,0px) + 13px);
  font: 500 9.5px/1.6 var(--mono); letter-spacing: .14em; text-transform: uppercase;
  color: var(--fg-3); font-variant-numeric: tabular-nums; white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 6px #000;
}
.mark b{ font-weight: 500; color: var(--fg-2); }

/* ── Stage ─────────────────────────────────────────────── */
.stage{
  position: relative; min-height: 100%;
  display: grid; place-items: center;
  padding-block: 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  overflow: hidden;
}
.station{ position: relative; width: min(100%, 264px); }
/* the tool and its ring sit out the opening, then condense out of the glare (see Opening, in the script) */
.tool,.dial{ opacity: 0; visibility: hidden; }
.tool{ filter: blur(12px) brightness(1.7); }
.open .tool,.open .dial{ opacity: 1; visibility: visible; transition: opacity .8s ease, filter 1s var(--ease); }
.open .tool{ filter: none; }

/* chronometer ring */
.dial{ position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 2; pointer-events: none; }
.dial svg{ position: absolute; overflow: visible; display: block; }
.ring{ fill: none; stroke: rgba(255,255,255,.2); }
.tk{ stroke: rgba(255,255,255,.26); }
.tk-1{ stroke: rgba(255,255,255,.5); }
.tk-5{ stroke: rgba(255,255,255,.95); }
.num,.engr{ paint-order: stroke; stroke: var(--ink); stroke-width: 3.5px; stroke-linejoin: round; text-anchor: middle; }
.num{ font: 500 9px var(--mono); letter-spacing: .08em; fill: rgba(255,255,255,.62); dominant-baseline: central; }
.engr{ font: 500 7.5px var(--mono); letter-spacing: .24em; fill: rgba(255,255,255,.4); }
.arc{ fill: none; stroke: rgba(255,255,255,.5); stroke-width: 1.5; transition: stroke .4s; }
.idx{ fill: rgba(255,255,255,.6); transition: fill .4s; }
.station[data-state="live"] .arc{ stroke: var(--white); }
.station[data-state="live"] .idx{ fill: var(--white); }

/* ── Tool ──────────────────────────────────────────────── */
.tool{
  position: relative; z-index: 5; display: block; padding: 14px 14px 0; cursor: default;
  background: var(--void);
  box-shadow: 0 0 0 1px rgba(255,255,255,.1), 0 24px 70px rgba(0,0,0,.9), 0 0 120px rgba(0,0,0,.6);
}
.cap{ font: 500 9.5px/1.2 var(--mono); letter-spacing: .17em; text-transform: uppercase; }
.row{ display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.row label{ color: var(--fg-2); }

.entry{ display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 6px; align-items: start; margin-top: 9px; }
.entry textarea{
  display: block; width: 100%; height: 40px; min-height: 40px; margin: 0;
  padding: 9px 11px; resize: none; overflow: hidden; cursor: text;
  background: rgba(255,255,255,.04); border: 1px solid var(--rule); border-radius: 0;
  color: var(--white); caret-color: var(--white);
  font: 400 13px/20px var(--mono); letter-spacing: .03em; text-transform: uppercase;
  outline: 0; -webkit-appearance: none; appearance: none;
  transition: border-color .15s, background-color .15s;
}
.entry textarea::placeholder{ color: rgba(255,255,255,.2); }
.entry textarea:hover{ border-color: rgba(255,255,255,.32); }
.entry textarea:focus{ border-color: var(--white); background: rgba(255,255,255,.06); }
.station[data-state="invalid"] .entry textarea{ border-style: dashed; border-color: rgba(255,255,255,.8); }

.go{
  width: 40px; height: 40px; padding: 0; display: grid; place-items: center;
  background: var(--white); color: var(--void); border: 1px solid var(--white); border-radius: 0;
  cursor: pointer; -webkit-appearance: none; appearance: none;
  transition: background-color .12s, color .12s, border-color .2s;
}
.go svg{ display: block; }
.go:active:not(:disabled){ transform: translateY(1px); }
.go:focus-visible{ outline: 1px solid var(--white); outline-offset: 3px; }
.go:disabled{ background: transparent; color: var(--fg-4); border-color: var(--rule); cursor: not-allowed; }
.station.copied .go{ background: var(--void); color: var(--white); }
@media (hover: hover){ .go:hover:not(:disabled){ background: var(--void); color: var(--white); } }

.meta{ margin: 7px 0 0; min-height: 16px; font: 400 10.5px/16px var(--mono); color: rgba(255,255,255,.5); }
.meta .err{ display: inline-block; margin-right: 7px; padding: 0 4px 0 5px; background: var(--white); color: var(--void); font-weight: 600; font-size: 9px; line-height: 13px; letter-spacing: .14em; text-transform: uppercase; vertical-align: 1px; }
.station[data-state="invalid"] .meta{ color: var(--fg); }

.readout{ display: flex; align-items: baseline; justify-content: space-between; margin-top: 9px; padding-bottom: 11px; }
.code{
  display: block; margin: 0; white-space: nowrap;
  font: 300 27px/1.2 var(--display); letter-spacing: .01em;
  color: var(--fg-4); font-variant-numeric: tabular-nums; transition: color .35s;
}
.code.on{ color: var(--white); cursor: copy; }
.grp{ display: inline-block; }
.grp + .grp{ margin-left: .4em; }
.cell{ position: relative; display: inline-block; height: 1.2em; overflow: hidden; vertical-align: top; }
.cell > span{ display: inline-block; }
.cell > span.in{ position: absolute; left: 0; top: 100%; }
.cell.roll > span{ animation: roll .5s var(--ease) both; animation-delay: calc(var(--i) * 32ms); }
@keyframes roll{ to{ transform: translateY(-1.2em); } }

.ttl{ color: var(--fg-3); font-variant-numeric: tabular-nums; transition: color .3s; }
.ttl b{ display: inline-block; font-weight: 500; padding: 1px 3px; margin-right: 2px; }
.station[data-state="live"] .ttl{ color: var(--fg); }
.station[data-state="live"].hurry .ttl b{ background: var(--white); color: var(--void); }

.fuse{ position: relative; height: 2px; margin: 0 -14px; background: rgba(255,255,255,.08); overflow: hidden; }
.fuse i{ position: absolute; inset: 0; background: var(--fg-3); transform-origin: 0 50%; transition: background-color .4s; }
.station[data-state="live"] .fuse i{ background: var(--white); }
.station[data-state="live"].hurry .fuse i{ animation: hurry 1s steps(2, jump-none) infinite; }
@keyframes hurry{ to{ opacity: .25; } }

/* ── Touch and small screens ───────────────────────────── */
@media (pointer: coarse){
  .station{ width: min(100%, 304px); }
  .entry{ grid-template-columns: minmax(0, 1fr) 44px; }
  .entry textarea{ height: 44px; min-height: 44px; padding: 10px 11px; font-size: 16px; line-height: 22px; letter-spacing: .02em; }
  .go{ width: 44px; height: 44px; }
}
@media (max-height: 420px){ .mark{ display: none; } .stage{ padding-block: 20px; } }
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{ animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
