/* Night-ride UI: high contrast, huge hit targets, readable at a glance on a
   handlebar mount while moving. */

:root {
  --bg: #08080c;
  --panel: #13131b;
  --line: #262633;
  --text: #f2f2f7;
  --dim: #8c8ca0;
  --lime: #c8ff2e;
  --magenta: #ff2e93;
  --amber: #ffb52e;

  --gap: 1rem;
  --radius: 1rem;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 1.25rem) 1.25rem
           calc(env(safe-area-inset-bottom) + 1.25rem);
}

/* Only the section matching the current screen is shown. */
section { display: none; flex: 1; flex-direction: column; }
#app[data-screen="join"]        section[data-for="join"],
#app[data-screen="unscheduled"] section[data-for="unscheduled"],
#app[data-screen="wait"]        section[data-for="wait"],
#app[data-screen="playing"]     section[data-for="playing"],
#app[data-screen="paused"]      section[data-for="paused"],
#app[data-screen="ended"]       section[data-for="ended"] { display: flex; }

/* The tune panel is opened on demand, not shown by default: the countdown and
   the timer are what a rider needs at a glance. */
#tune { margin-top: var(--gap); }

h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--lime);
}

.ride { margin: 0.15rem 0 0; color: var(--dim); font-size: 0.95rem; }

.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
}

.label {
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}

.huge {
  font-size: clamp(3.5rem, 22vw, 7rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
button:active { transform: scale(0.97); }

.primary {
  width: 100%;
  padding: 1.5rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #0a0a00;
  background: var(--lime);
  border: none;
}

.warn {
  padding: 0.9rem 1rem;
  border: 1px solid color-mix(in oklab, var(--amber) 45%, transparent);
  border-radius: 0.75rem;
  background: color-mix(in oklab, var(--amber) 10%, transparent);
  color: var(--amber);
  font-size: 0.9rem;
}

/* --- nudge --- */

.nudge-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.nudge-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--magenta);
}

.nudge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.nudge-grid button {
  padding: 1.1rem 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.presets { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.presets button { flex: 1; padding: 0.7rem 0.4rem; font-size: 0.8rem; color: var(--dim); }

/* Anything hidden stays hidden, whatever display it is otherwise given. */
[hidden] { display: none !important; }

/* --- status --- */

.bar {
  height: 6px;
  margin-top: 0.75rem;
  overflow: hidden;
  background: var(--line);
  border-radius: 999px;
}
.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--lime);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.hint { color: var(--dim); font-size: 0.85rem; text-align: center; }

/* Autoplay lapsed while the page sat in a pocket. */
#gesture {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
}
#gesture.shown { display: flex; }

/* ?debug=1 — the only way to tell a stall from a seek thrash on a phone. */
#debug {
  margin: var(--gap) 0 0;
  padding: 0.75rem;
  overflow-x: auto;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  color: var(--lime);
  font: 400 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* --- guidance --- */

.steps {
  margin: 0.5rem 0 0;
  padding: 0;
  max-width: 20rem;
  list-style: none;
  counter-reset: step;
  text-align: left;
}
.steps li {
  position: relative;
  margin-bottom: 0.7rem;
  padding-left: 2rem;
  color: var(--dim);
  counter-increment: step;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--lime);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Four beats of the bar. Pulsed from JS against the rider's own nudge, so the
   dot lights when their speaker should click, not when ours does. */
.beats {
  display: flex;
  gap: 0.85rem;
  margin: 1.5rem 0 0.9rem;
}
.beat {
  width: 0.9rem;
  height: 0.9rem;
  background: var(--lime);
  border-radius: 50%;
  opacity: 0.25;
  will-change: transform, opacity;
}
.beat.down {
  width: 1.3rem;
  height: 1.3rem;
  margin-top: -0.2rem;
  background: var(--magenta);
}

.calibrate {
  max-width: 20rem;
  margin: 0;
  color: var(--dim);
  font-size: 0.9rem;
}
.calibrate strong { color: var(--text); }

.nudge-help {
  margin: 0 0 0.6rem;
  color: var(--dim);
  font-size: 0.8rem;
}
.nudge-help strong { color: var(--magenta); }

.nudge-grid button small {
  display: block;
  margin-top: 0.15rem;
  color: var(--dim);
  font-size: 0.7rem;
  font-weight: 400;
}

/* Secondary to the timer and the pause button, which is what a rider reaches
   for. Present, findable, not competing. */
.ghost {
  align-self: center;
  margin-top: var(--gap);
  padding: 0.8rem 1.4rem;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 0.9rem;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 0.3em;
}
.ghost[aria-expanded="true"] { color: var(--text); }

/* --- sync state --- */

.sync {
  margin: 0.6rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.sync[data-state="ok"] { color: var(--lime); }
.sync[data-state="working"] { color: var(--amber); }
.sync[data-state="off"] { color: var(--magenta); }
.sync[data-state="idle"] { color: var(--dim); }

.sync-detail {
  margin: 0.35rem 0 0;
  color: var(--dim);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* Marks the moment the mix takes over from the countdown. */
#burst {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
}
#burst span {
  width: 7rem;
  height: 7rem;
  border: 3px solid var(--lime);
  border-radius: 50%;
}
#burst.go { animation: burst 900ms cubic-bezier(0.2, 0.7, 0.3, 1); }
@keyframes burst {
  0%   { opacity: 1;    transform: scale(0.25); }
  60%  { opacity: 0.35; }
  100% { opacity: 0;    transform: scale(3.4); }
}

/* The last few seconds of the countdown tick visibly. */
#countdown.tick { animation: tick 420ms ease-out; }
@keyframes tick {
  0%   { transform: scale(1.06); color: var(--lime); }
  100% { transform: scale(1); }
}

#app[data-screen="playing"] .huge { animation: arrive 700ms ease-out; }
@keyframes arrive {
  0%   { opacity: 0; transform: scale(0.92); }
  100% { opacity: 1; transform: scale(1); }
}

.glyph {
  width: 3rem;
  height: 3rem;
  margin: 0.4rem 0;
  fill: none;
  stroke: var(--dim);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
