/* To use a licensed webfont, add its url() ahead of the local() sources below.
   Stock iOS ships Helvetica Neue only up to Bold Italic, which is what the fallback resolves to. */
@font-face {
  font-family: "Walked Display";
  src: local("HelveticaNeue-BlackItalic"), local("Helvetica Neue Black Italic");
  font-weight: 900;
  font-style: italic;
}

:root {
  --font-display: "Walked Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --red: #FF2B1C;
  --land: #EBEBE8; /* map land and water; mirrored in js/style.js */
  --sea: #FAFAF9;
  --surface: #FFFFFF;
  --ink: #141413;
  --muted: #8C8C88;
  --hairline: rgba(0, 0, 0, 0.09);
  --grabber: rgba(0, 0, 0, 0.16);
  --backdrop: rgba(0, 0, 0, 0.3);
  --gutter: 16px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --fit: 6.3; /* width of the longer line in ems; refined at runtime from the real numbers */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --land: #1A1A1A;
    --sea: #0B0B0B;
    --surface: #232323;
    --ink: #F2F2F0;
    --muted: #7C7C78;
    --hairline: rgba(255, 255, 255, 0.1);
    --grabber: rgba(255, 255, 255, 0.22);
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none; /* the page itself never scrolls or zooms; the map handles its own gestures */
  background: var(--land);
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---- map ---- */

#map {
  position: absolute;
  inset: 0;
  background: var(--land);
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 400ms var(--ease-out), transform 400ms var(--ease-out);
}
#map.ready { opacity: 1; transform: none; }
#map .maplibregl-canvas { outline: none; }

.me { width: 0; height: 0; pointer-events: none; }
.me i, .me b {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}
.me i {
  box-shadow: 0 0 0 2px var(--sea);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 300ms var(--ease-out), transform 300ms var(--ease-out);
}
.me b { opacity: 0; }
.me.on i { opacity: 1; transform: none; }
.me.on b { animation: pulse 3.2s cubic-bezier(0.22, 0.61, 0.36, 1) infinite; }
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.3; }
  75%, 100% { transform: scale(4.4); opacity: 0; }
}

/* Only shown when the map under the numbers is too busy to read against. */
#scrim {
  position: absolute;
  inset: auto 0 0;
  height: calc(var(--stats-h, 150px) + max(env(safe-area-inset-bottom), var(--gutter)) + 88px);
  background: linear-gradient(to top,
    var(--sea) 0%,
    color-mix(in srgb, var(--sea) 94%, transparent) 34%,
    color-mix(in srgb, var(--sea) 62%, transparent) 64%,
    transparent 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 500ms var(--ease-out);
}
#scrim.on { opacity: 1; }

/* ---- numbers ---- */

#stats {
  /* Wide enough that the longer line spans the screen; in landscape, height is the limit instead. */
  --size: clamp(2.5rem, min(calc((100vw - 2 * var(--gutter) - env(safe-area-inset-left) - env(safe-area-inset-right)) / var(--fit)), 15vh), 6rem);
  position: absolute;
  left: max(env(safe-area-inset-left), var(--gutter));
  bottom: max(env(safe-area-inset-bottom), var(--gutter));
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--red);
  font: italic 900 var(--size) / 0.85 var(--font-display);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
  transition: transform 180ms var(--ease-out);
}
#stats.pressed { transform: scale(0.97); }
/* A held press keeps sinking a little, so a long-press feels like it is going somewhere. */
#stats.held { transform: scale(0.95); transition: transform 420ms cubic-bezier(0.4, 0, 0.6, 1); }
#stats:focus-visible { outline: 2px solid var(--red); outline-offset: 8px; border-radius: 4px; }

.slot { display: block; position: relative; white-space: nowrap; }
.v {
  display: block;
  transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out), filter 200ms var(--ease-out);
}
.v.from { transform: translateY(0.28em); opacity: 0; filter: blur(4px); }
.v.out { position: absolute; left: 0; top: 0; transform: translateY(-0.28em); opacity: 0; filter: blur(4px); }
.u { font-size: 0.4em; letter-spacing: -0.01em; margin-left: 0.2em; }

.period {
  font-size: 0.8125rem;
  line-height: 1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin: 0 0 0.85em 0.1em;
}
.period .v.from, .period .v.out { filter: blur(2px); }
.period .v.from { transform: translateY(0.5em); }
.period .v.out { transform: translateY(-0.5em); }

/* ---- shared form pieces (sheet + first launch) ---- */

.field { display: block; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.label {
  color: var(--red);
  font: italic 900 0.6875rem / 1 var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
/* What a field is doing right now, on the same line as its name. */
.status { color: var(--muted); font-size: 0.8125rem; line-height: 1; text-align: right; }
.status.bad { color: var(--red); }
.input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  caret-color: var(--red);
  font: 400 1.0625rem / 1.4 var(--font-ui);
  -webkit-user-select: text;
  user-select: text;
}
.input::placeholder { color: var(--muted); opacity: 0.7; }
.action {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--red);
  font: 400 1.0625rem / 1.4 var(--font-ui);
  cursor: pointer;
}
.action:disabled { opacity: 0.35; }
.pressable { transition: transform 160ms var(--ease-out); }
.pressable:active:not(:disabled) { transform: scale(0.97); }
.action:focus-visible, .input:focus-visible { outline: 2px solid var(--red); outline-offset: 6px; border-radius: 2px; }

/* ---- settings sheet ---- */

#sheet { position: absolute; inset: 0; z-index: 3; }
.backdrop { position: absolute; inset: 0; background: var(--backdrop); opacity: 0; }
.panel {
  position: absolute;
  inset: auto 0 0;
  max-height: 90%;
  padding: 10px max(env(safe-area-inset-right), 22px) calc(max(env(safe-area-inset-bottom), 14px) + 14px) max(env(safe-area-inset-left), 22px);
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  outline: 0;
  touch-action: none;
  will-change: transform;
}
/* Fills the gap when the sheet is pulled past its resting point. */
.panel::after { content: ""; position: absolute; inset: 100% 0 auto; height: 50vh; background: inherit; }
.grabber { width: 36px; height: 5px; margin: 0 auto 22px; border-radius: 3px; background: var(--grabber); }
.panel .field { padding: 16px 0 14px; border-top: 1px solid var(--hairline); }
.panel .field:first-of-type { border-top: 0; padding-top: 0; }
.sync { margin: 0; }
.sync div { display: flex; justify-content: space-between; gap: 16px; font-size: 1.0625rem; line-height: 1.65; }
.sync dd { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.credits { margin: 6px 0 0; color: var(--muted); font-size: 0.6875rem; line-height: 1.4; }
.credits a { color: inherit; text-decoration: none; }

/* ---- first launch ---- */

#gate {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 24vh) max(env(safe-area-inset-right), 24px) 0 max(env(safe-area-inset-left), 24px);
  background: var(--sea);
  transition: opacity 300ms var(--ease-out);
}
#gate.leaving { opacity: 0; pointer-events: none; }
#gate .field { width: 100%; }
#gate .input { padding-bottom: 14px; border-bottom: 1px solid var(--grabber); font-size: 1.375rem; }

@media (prefers-reduced-motion: reduce) {
  #map { transform: none; transition: opacity 200ms linear; }
  #stats, #stats.held, .v, .pressable, .me i, #scrim { transition: none; }
  #stats.pressed, #stats.held, .pressable:active:not(:disabled) { transform: none; opacity: 0.7; }
  .v.from, .v.out { transform: none; filter: none; }
  .me.on b { animation: none; opacity: 0.16; transform: scale(2.6); }
}
