/* ===== Runner Lab — Treadmill Route MVP ===== */

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

:root {
  --bg: #0a0c10;
  --bg-2: #12161d;
  --ink: #f4f6f8;
  --ink-dim: #8a94a2;
  --route: #0a84ff;
  --route-glow: rgba(10, 132, 255, 0.55);
  --danger: #ff453a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  /* safe zone: keep HUD elements this far off the screen edges */
  --safe-x: 80px;
  --safe-y: 20px;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  /* kill iOS double-tap-to-zoom so rapid taps on the pace buttons register */
  touch-action: manipulation;
}

/* ---------- orientation gate ---------- */
.rotate-hint {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  font-size: 15px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  text-transform: uppercase;
  z-index: 100;
}
.rotate-icon { font-size: 44px; color: var(--ink); }

@media (orientation: portrait) {
  #app { display: none; }
  .rotate-hint { display: flex; }
}

/* ---------- back to site ---------- */
.back-link {
  position: fixed;
  top: var(--safe-y);
  left: var(--safe-x);
  z-index: 60;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }
/* out of the way once the run HUD is on screen */
body:has(#screen-run.is-active) .back-link,
body:has(#screen-finish.is-active) .back-link { display: none; }

/* ---------- screens ---------- */
#app {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 100% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%);
}
.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.screen.is-active { display: flex; }

/* ---------- shared CTA ---------- */
.cta {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #0a0c10;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 14px 40px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.cta:active { transform: scale(0.96); }

/* ================= SETUP ================= */
.setup-grid {
  display: flex;
  align-items: center;
  gap: min(8vw, 72px);
  width: min(780px, calc(100vw - 2 * var(--safe-x)));
}

.setup-track {
  flex: 0 0 auto;
  width: min(210px, 34vw);
  text-align: center;
}
#setup-svg {
  width: 100%;
  height: auto;
  overflow: visible;
  cursor: pointer;
  touch-action: none;
}
#setup-path {
  stroke: rgba(255, 255, 255, 0.22);
  stroke-width: 10;
}
#setup-pin circle { fill: #fff; stroke: #0a0c10; stroke-width: 1.5; }
#setup-dir { fill: var(--route); }
.track-hint {
  margin-top: 14px;
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.setup-card {
  flex: 1 1 auto;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: center;
}
.setup-row { display: flex; flex-direction: column; gap: 8px; }
.setup-row > label {
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
}
.setup-row > b {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.setup-row > b small { font-size: 17px; color: var(--ink-dim); margin-left: 4px; }

.pace-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}
.pace-control button {
  appearance: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.pace-control button:active { background: rgba(255, 255, 255, 0.12); }
.pace-control > b { font-size: 40px; font-weight: 700; min-width: 150px; }

#start-btn { align-self: center; margin-top: 6px; }

/* ================= RUN ================= */
#screen-run { overflow: hidden; }

/* perspective runway */
.runway {
  position: absolute;
  inset: 0;
  overflow: hidden;
  perspective: 300px;
  perspective-origin: 50% 38%;
}
.runway-floor {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: -10%;
  height: 150%;
  transform: rotateX(80deg);
  transform-origin: 50% 100%;
}
.runway-lines {
  position: absolute;
  inset: -50% -25%;
  background-image:
    /* bright centre route line */
    linear-gradient(
      to right,
      transparent calc(50% - 10px),
      var(--route) calc(50% - 10px),
      var(--route) calc(50% + 10px),
      transparent calc(50% + 10px)
    ),
    /* horizontal track rungs */
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.22) 0 6px,
      transparent 6px 60px
    );
  /* rungs span at most ~40% of the screen at the near edge, tapering
     narrower with perspective */
  --rung-max: 40vw;
  background-size: 100% 100%, var(--rung-max) 66px;
  background-position: 0 0, center var(--flow, 0px);
  background-repeat: no-repeat, repeat-y;
  filter: drop-shadow(0 0 14px var(--route-glow));
}
.runway-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    var(--bg) 6%,
    rgba(10, 12, 16, 0.55) 30%,
    transparent 62%
  );
  pointer-events: none;
}
.chevron {
  position: absolute;
  left: 50%;
  bottom: 15%;
  width: 0;
  height: 0;
  border-left: 26px solid transparent;
  border-right: 26px solid transparent;
  border-bottom: 40px solid #fff;
  transform: translateX(-50%);
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.35));
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob {
  50% { transform: translateX(-50%) translateY(-5px); }
}

/* HUD blocks */
.hud { position: absolute; z-index: 5; }
.hud-tl { top: var(--safe-y); left: var(--safe-x); }
.pace-big { font-size: 44px; font-weight: 700; line-height: 1; }
.pace-big small { font-size: 15px; color: var(--ink-dim); margin-left: 5px; }
.elapsed {
  margin-top: 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.hud-tr { top: var(--safe-y); right: var(--safe-x); display: flex; gap: 12px; }
.badge {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: baseline;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.badge b { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.badge i { font-size: 12px; font-style: normal; color: var(--ink-dim); margin-left: 2px; }
.badge label {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.badge-prog { border-color: var(--route); }

.hud-card {
  top: var(--safe-y);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px 10px 16px;
  background: rgba(18, 22, 29, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}
.card-arrow { font-size: 22px; color: var(--route); transform: translateY(-1px); }
.card-body { display: flex; flex-direction: column; line-height: 1.15; }
.card-body b { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-body small { font-size: 10px; letter-spacing: 0.16em; color: var(--ink-dim); }

/* minimap */
.minimap { bottom: var(--safe-y); left: var(--safe-x); width: 116px; }
#mini-svg { width: 100%; height: auto; display: block; overflow: visible; }
#mini-bg { stroke: rgba(255, 255, 255, 0.18); stroke-width: 9; }
#mini-trail { filter: drop-shadow(0 0 4px var(--route-glow)); }
#mini-trail line {
  stroke: var(--route);
  stroke-width: 9;
  stroke-linecap: round;
}
#mini-start { fill: #fff; opacity: 0.45; }
#mini-marker { fill: #fff; stroke: #0a0c10; stroke-width: 1.5; }
.minimap-dist {
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}
.minimap-dist b {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* pause */
.pause-btn {
  position: absolute;
  z-index: 5;
  bottom: var(--safe-y);
  right: var(--safe-x);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 22, 29, 0.8);
  color: var(--ink);
  font-size: 18px;
  letter-spacing: 2px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.pause-btn:active { background: rgba(255, 255, 255, 0.1); }

.paused-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: rgba(6, 8, 11, 0.72);
  backdrop-filter: blur(3px);
}
.paused-overlay.is-open { display: flex; }
.paused-text {
  font-size: 14px;
  letter-spacing: 0.4em;
  color: var(--ink-dim);
}

/* ================= FINISH ================= */
.finish-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.finish-card h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.14em;
}
.finish-time {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.finish-pace { font-size: 17px; color: var(--ink-dim); }
.finish-laps {
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--ink-dim);
}
#finish-btn { margin-top: 22px; }
