/* ==========================================================================
   Danfo Run — Day 06/30
   Colour has strict roles here:
     yellow  = a danfo, and only a danfo (inside the road, yellow means danger)
     orange  = the player and the readouts
     bone    = paint, text
     asphalt = everything else
   ========================================================================== */

:root {
  --asphalt: #14130F;
  --asphalt-2: #0D0C09;
  --road: #201E19;
  --danfo: #FFC400;
  --danfo-hi: #FFD84A;
  --danfo-lo: #D99A00;
  --stripe: #14120C;
  --orange: #FF6B1A;
  --orange-hi: #FF8A3D;
  --bone: #EDE7D8;
  --bone-2: rgba(237, 231, 216, 0.66);
  --bone-3: rgba(237, 231, 216, 0.34);
  --hairline: rgba(237, 231, 216, 0.14);

  --display: "Bungee", "Archivo", system-ui, sans-serif;
  --ui: "Archivo", system-ui, -apple-system, sans-serif;
  --label: "JetBrains Mono", ui-monospace, monospace;

  --r: 4px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --pad-t: max(0.75rem, env(safe-area-inset-top));
  --pad-r: max(0.9rem, env(safe-area-inset-right));
  --pad-b: max(0.9rem, env(safe-area-inset-bottom));
  --pad-l: max(0.9rem, env(safe-area-inset-left));
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--asphalt-2);
}

body {
  font-family: var(--ui);
  color: var(--bone);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------- stage --- */

.frame {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--asphalt);
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

/* ----------------------------------------------------------------- hud --- */

/* Tied to the road's own width so the readouts frame the play surface
   instead of drifting into the corners of a wide screen. */
.hud {
  position: absolute;
  top: var(--pad-t);
  left: 50%;
  transform: translateX(-50%);
  /* Mirrors the road's own width formula in script.js, including the
     height cap, so the readouts keep framing the road when a phone is
     held sideways instead of drifting out into the gutters. */
  width: min(calc(100% - var(--pad-l) - var(--pad-r)), 27.5rem, 62dvh);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
  z-index: 20;
}

.readout { display: flex; flex-direction: column; gap: 0.1rem; }
.readout--best { text-align: right; }

.readout__key {
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--bone-2);
  text-shadow: 0 0 10px rgba(13, 12, 9, 0.95);
}

.readout__val {
  font-family: var(--ui);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.75rem, 9vw, 2.75rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--bone);
  /* A danfo can pass directly behind the readouts, so they carry their own
     shade rather than relying on whatever is underneath. */
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 14px rgba(13, 12, 9, 0.95);
}

.readout--time .readout__val { color: var(--orange); }

.readout--best .readout__val {
  font-size: clamp(0.875rem, 4vw, 1.125rem);
  color: var(--bone-2);
  margin-top: 0.25rem;
}

/* gear pill — the difficulty tell */
.gear {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem 0.25rem;
  border: 1.5px solid var(--hairline);
  border-radius: var(--r);
  background: rgba(13, 12, 9, 0.72);
  transform-origin: 50% 0;
}

.gear__key {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--bone-3);
}

.gear__no {
  font-family: var(--display);
  font-size: 1rem;
  line-height: 1;
  color: var(--bone);
}

.gear.is-punched {
  animation: gearPunch 420ms var(--ease);
  border-color: var(--orange);
}
.gear.is-punched .gear__no { color: var(--orange); }

@keyframes gearPunch {
  0%   { transform: scale(1); }
  22%  { transform: scale(1.42); }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------- tap guide --- */

.tapguide {
  position: absolute;
  inset: auto 0 22% 0;
  display: flex;
  justify-content: space-between;
  padding: 0 8vw;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  transition: opacity 260ms var(--ease);
}

.tapguide.is-on { opacity: 1; animation: guidePulse 1.6s ease-in-out infinite; }

.tapguide__side {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--display);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--bone-3);
}

.tapguide__arrow {
  width: 0; height: 0;
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
}
.tapguide__arrow--l { border-right: 0.5rem solid var(--bone-3); }
.tapguide__arrow--r { border-left: 0.5rem solid var(--bone-3); }

@keyframes guidePulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

/* ------------------------------------------------------------- screens --- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(var(--pad-t) + 3.25rem) 1.25rem calc(var(--pad-b) + 2.5rem);
  transition: opacity 320ms var(--ease), visibility 320ms;
}

.screen[inert],
.screen.is-off {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.screen__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: min(100%, 26rem);
  transition: transform 420ms var(--ease);
}

.screen[inert] .screen__inner,
.screen.is-off .screen__inner { transform: translateY(2.25rem); }

.screen--start { background: linear-gradient(180deg, rgba(13,12,9,0.42) 0%, rgba(13,12,9,0.88) 46%, rgba(13,12,9,0.96) 100%); }

/* Base state is a plain scrim, carrying enough weight on its own to put the
   yellow of the road out of competition with the score. */
.screen--over { background: rgba(13, 12, 9, 0.93); }

/* Where the compositor can drain the colour out of the road instead, the
   scrim lightens and the wreck stays faintly visible behind the result. */
@supports (backdrop-filter: grayscale(0.85) blur(3px)) or
          (-webkit-backdrop-filter: grayscale(0.85) blur(3px)) {
  .screen--over {
    background: rgba(13, 12, 9, 0.74);
    backdrop-filter: grayscale(0.85) blur(3px);
    -webkit-backdrop-filter: grayscale(0.85) blur(3px);
  }
}

.screen--pause { background: rgba(13, 12, 9, 0.9); }

/* title lockup — the one place display type goes big */

.lockup {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  gap: 0.5rem;
  margin-bottom: 1.4rem;
}

.lockup__bar {
  height: 0.5rem;
  background: var(--danfo);
  box-shadow: 0 0 0 0.28rem var(--stripe);
}

.lockup__type {
  margin: 0.55rem 0;
  font-family: var(--display);
  line-height: 0.86;
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Display type is sized off the width but capped against the height, so a
   phone held sideways cannot grow the title until it pushes the button off
   the bottom of the screen. */
.lockup__top {
  font-size: min(clamp(3.5rem, 20vw, 5.5rem), 13vh);
  color: var(--danfo);
  text-shadow: 0 0.28rem 0 var(--stripe);
}

.lockup__bottom {
  font-size: min(clamp(2.25rem, 13vw, 3.5rem), 8.5vh);
  color: transparent;
  -webkit-text-stroke: 2px var(--bone);
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}

.lede {
  margin: 0 0 1.6rem;
  max-width: 22rem;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--bone-2);
  text-wrap: balance;
}

/* buttons */

.btn {
  appearance: none;
  min-height: 3.5rem;
  min-width: 11rem;
  padding: 0 2rem;
  border: 0;
  border-radius: var(--r);
  background: var(--danfo);
  color: var(--stripe);
  font-family: var(--display);
  font-size: 1.0625rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 0.3rem 0 var(--danfo-lo), 0 0.75rem 1.5rem rgba(0, 0, 0, 0.45);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background-color 120ms linear;
}

.btn:hover { background: var(--danfo-hi); }

.btn:active {
  transform: translateY(0.24rem);
  box-shadow: 0 0.06rem 0 var(--danfo-lo), 0 0.35rem 0.8rem rgba(0, 0, 0, 0.45);
}

.btn:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}

.btn--ghost {
  background: transparent;
  color: var(--bone);
  box-shadow: inset 0 0 0 2px var(--bone-3);
}
.btn--ghost:hover { background: rgba(237, 231, 216, 0.08); }
.btn--ghost:active { transform: translateY(0.12rem); box-shadow: inset 0 0 0 2px var(--bone-3); }

.bestline {
  margin: 1.1rem 0 0;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bone-2);
}
.bestline b { color: var(--bone); font-variant-numeric: tabular-nums; }

.kbd {
  margin: 1rem 0 0;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--bone-2);
}
@media (hover: none) { .kbd { display: none; } }

/* game over */

.verdict {
  margin: 0 0 0.85rem;
  font-family: var(--display);
  font-size: min(clamp(2rem, 11vw, 2.75rem), 8vh);
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--bone);
}
.verdict.is-record { color: var(--orange); }

.finalscore {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.1rem;
  margin-bottom: 1.5rem;
}

.finalscore__val {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  font-size: min(clamp(4.5rem, 26vw, 6rem), 17vh);
  line-height: 0.82;
  letter-spacing: -0.055em;
  color: var(--orange);
}

.finalscore__unit {
  font-weight: 700;
  font-size: clamp(1.25rem, 6vw, 1.5rem);
  color: var(--bone-2);
}

.tally {
  width: min(100%, 17rem);
  margin: 0 0 1.9rem;
  border-top: 1px solid var(--hairline);
}

.tally__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--hairline);
}

.tally dt {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--bone-2);
}

.tally dd {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bone);
}

.pause-word {
  margin: 0 0 1.5rem;
  font-family: var(--display);
  font-size: clamp(1.75rem, 9vw, 2.25rem);
  color: var(--bone-2);
}

/* --------------------------------------------------------- day branding --- */

.day {
  position: fixed;
  z-index: 55;
  right: var(--pad-r);
  bottom: var(--pad-b);
  margin: 0;
  font-family: var(--label);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--bone-3);
  pointer-events: none;
  user-select: none;
}

/* --------------------------------------------------------------- wide --- */

@media (min-width: 720px) and (min-height: 560px) {
  .hud { top: calc(var(--pad-t) + 0.5rem); }
  .tapguide { display: none; }
}

/* Phone held sideways. Everything on a screen has to fit without scrolling,
   so the vertical rhythm compresses and the optional lines step out. */
@media (max-height: 520px) {
  .screen {
    padding-top: calc(var(--pad-t) + 2.25rem);
    padding-bottom: calc(var(--pad-b) + 0.75rem);
  }
  .lockup { margin-bottom: 0.7rem; gap: 0.3rem; }
  .lockup__bar { height: 0.3rem; box-shadow: 0 0 0 0.16rem var(--stripe); }
  .lockup__type { margin: 0.3rem 0; }
  .lede { margin-bottom: 0.9rem; font-size: 0.875rem; }
  .verdict { margin-bottom: 0.5rem; }
  .finalscore { margin-bottom: 0.75rem; }
  .tally { margin-bottom: 1rem; }
  .tally__row { padding: 0.3rem 0; }
  .btn { min-height: 3rem; }
  .bestline, .kbd { display: none; }
}

/* --------------------------------------------------- reduced motion --- */
/* Motion is the game, so the road keeps moving. What goes is the chrome
   choreography and anything that shakes the whole viewport. */

@media (prefers-reduced-motion: reduce) {
  .screen, .screen__inner, .btn { transition-duration: 1ms; }
  .screen[inert] .screen__inner,
  .screen.is-off .screen__inner { transform: none; }
  .gear.is-punched { animation: none; }
  .tapguide.is-on { animation: none; opacity: 1; }
}
