/* Shibuya Midnight — layout for a phone held either way.
 *
 * The rule for both orientations: the road fills the screen, the numbers sit in the corners
 * a thumb is not using, and the steering zones are wherever the thumbs already are. Nothing
 * is hidden in portrait and nothing is stretched in landscape; the two are designed, not
 * one designed and one survived.
 */

:root {
  --ink: #eef2ff;
  --ink-dim: #97a2c4;
  --neon: #ff3d6e;
  --neon-2: #14e0ff;
  --panel: rgba(9, 11, 22, 0.55);
  --panel-edge: rgba(140, 170, 255, 0.18);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #05060c;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  height: 100dvh;                 /* the phone's real height, with the bars showing */
  overflow: hidden;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------------------------------------------------------------- touch zones */
#touch { position: absolute; inset: 0; display: flex; touch-action: none; }

.zone {
  flex: 1;
  position: relative;
  touch-action: none;
  transition: background 120ms ease;
}

.zone::after {
  content: "";
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 42px;
  height: 42px;
  opacity: 0.35;
  border-top: 3px solid var(--neon-2);
  border-right: 3px solid var(--neon-2);
  transition: opacity 120ms ease;
}

.zone.left::after { left: max(22px, env(safe-area-inset-left)); transform: rotate(-135deg); }
.zone.right::after { right: max(22px, env(safe-area-inset-right)); transform: rotate(45deg); }

.zone.active { background: radial-gradient(120% 60% at 50% 100%, rgba(20, 224, 255, 0.12), transparent 70%); }
.zone.active::after { opacity: 0.95; }

/* ------------------------------------------------------------------------ HUD */
#hud {
  position: absolute;
  inset: 0;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
  display: grid;
  gap: 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  padding: 7px 11px;
}

.times { display: flex; gap: 14px; align-items: baseline; }
.times div { display: flex; flex-direction: column; gap: 1px; }
.times label {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  text-transform: uppercase;
}
.times span { font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums; }
#best-time.flash { color: #ffd166; text-shadow: 0 0 14px rgba(255, 209, 102, 0.8); }

.lap {
  font-size: 13px;
  letter-spacing: 0.16em;
  font-weight: 600;
  text-shadow: 0 0 12px rgba(20, 224, 255, 0.5);
}

.speedo {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 14px 8px;
}
.speedo span {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(255, 61, 110, 0.55);
}
.speedo small { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.1em; }

#minimap {
  width: clamp(132px, 25vw, 205px);
  height: auto;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

/* The way out, and the way to stop: both small, both out of a thumb's way. */
.home, .pause-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
  padding: 7px 11px;
  line-height: 1;
}
.home span { font-size: 14px; color: var(--neon-2); text-shadow: 0 0 10px rgba(20, 224, 255, 0.6); }
.pause-btn {
  font-family: var(--mono);
  cursor: pointer;
  color: var(--ink);
  justify-self: end;
}
.pause-btn:active { transform: scale(0.96); }

/* --------------------------------------------------------------- boost tank */
.tank {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
}
.tank-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.tank-track {
  display: block;
  width: clamp(64px, 16vw, 118px);
  height: 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(140, 170, 255, 0.18);
}
#fuel-fill {
  display: block;
  height: 100%;
  width: 45%;
  border-radius: 6px;
  background: linear-gradient(90deg, #1e7fd0, var(--neon-2));
  box-shadow: 0 0 12px rgba(70, 216, 255, 0.7);
  transition: width 140ms linear;
}
.tank.low #fuel-fill { background: linear-gradient(90deg, #b0233d, #ff6a6a); box-shadow: 0 0 12px rgba(255, 90, 90, 0.6); }
.tank.ready { animation: tankReady 1.1s ease-in-out infinite; }
@keyframes tankReady {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(140, 170, 255, 0.18); }
  50% { box-shadow: inset 0 0 0 1px rgba(70, 216, 255, 0.85), 0 0 18px rgba(70, 216, 255, 0.35); }
}
.tank-coins {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--neon-2);
  font-variant-numeric: tabular-nums;
}
.tank-coins b { color: var(--ink); }

/* ------------------------------------------------------------ action buttons */
/* Landscape phones have 330-580 px of height and six lines of instructions to show: the card
   has to get its start button on screen without asking for a scroll. */
@media (orientation: landscape) and (max-height: 700px) {
  .card { padding: 13px 20px; max-width: min(700px, 94vw); }
  .card h1 { font-size: 25px; margin: 0 0 2px; }
  .card .subtitle { font-size: 9.5px; margin-bottom: 7px; }
  /* Two columns made it worse: these rows are a label plus a paragraph, and squeezing each into
     half the card just wraps the text further. Drop the two lines that least matter on a phone
     instead — the keyboard hints, and the throttle advice — and keep the card one column. */
  .card .how { font-size: 11.5px; line-height: 1.3; gap: 3px; }
  .card .how b { flex: 0 0 46px; }
  .card .how > div:nth-child(2),
  .card .how > div:nth-child(6) { display: none; }
  .courses { margin: 7px 0 2px; }
  .course-btn { padding: 5px 9px; font-size: 11px; }
  .course-blurb { font-size: 10.5px; margin-top: 4px; }
  .card .bestline { margin-top: 7px; }
  .card .buttons { margin-top: 9px; }
}

/* One bar, centred at the bottom, both orientations — where a thumb reaches on a phone and
   where a cursor expects it on a desktop. */
.controls {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 999px;
  background: rgba(8, 10, 18, 0.62);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--panel-edge);
}
.control-split {
  display: block;
  width: 1px;
  height: 26px;
  margin: 0 3px;
  background: rgba(255, 255, 255, 0.16);
}
.action-btn {
  pointer-events: auto;
  width: clamp(52px, 13vw, 68px);
  height: clamp(52px, 13vw, 68px);
  /* A button carries 16 px of padding a side by default: in a 43 px circle that leaves 11 px
     of content and the label hangs out past the rim. Centre it and give the padding back. */
  padding: 0;
  display: grid;
  place-items: center;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, box-shadow 120ms ease;
  touch-action: none;
}
.action-btn:active, .action-btn.active { transform: scale(0.94); }
.action-btn.steer {
  width: clamp(56px, 14vw, 82px);
  border-radius: 15px;
  font-size: 11px;
  letter-spacing: 0.04em;
}
.action-btn.brake { box-shadow: 0 0 0 1px rgba(255, 90, 90, 0.25); }
.action-btn.reverse { font-size: 10px; }
.action-btn.boost { border-color: rgba(70, 216, 255, 0.4); color: #d5f4ff; }
.action-btn.boost.active {
  background: linear-gradient(180deg, rgba(70, 216, 255, 0.4), rgba(30, 127, 208, 0.55));
  box-shadow: 0 0 26px rgba(70, 216, 255, 0.75);
  transform: scale(1.04);
}
.action-btn.brake.active { background: rgba(255, 90, 90, 0.3); box-shadow: 0 0 22px rgba(255, 90, 90, 0.6); }

/* ------------------------------------------------------------ boost streaks */
.streaks {
  position: absolute;
  inset: -10%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 46px, rgba(140, 225, 255, 0.13) 46px 48px),
    radial-gradient(120% 70% at 50% 50%, transparent 45%, rgba(20, 120, 200, 0.22) 100%);
  transform-origin: 50% 50%;
  transition: opacity 160ms ease;
}
.boosting .streaks { opacity: 1; animation: rush 340ms linear infinite; }
@keyframes rush { from { transform: scale(1.34); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .boosting .streaks { animation: none; } }

/* The lights. Without this the race simply starts, which reads as a bug. */
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(90px, 26vh, 190px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 0 40px rgba(255, 61, 110, 0.85), 0 0 90px rgba(20, 224, 255, 0.5);
  animation: tick 900ms ease-out;
}
.countdown[hidden] { display: none; }
.countdown.go { color: #7dffb0; text-shadow: 0 0 50px rgba(125, 255, 176, 0.9); }
@keyframes tick {
  0% { opacity: 0; transform: scale(1.5); }
  25% { opacity: 1; transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

.combo {
  justify-self: start;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.12em;
  color: #ffd166;
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.75);
  animation: pulse 320ms ease;
}
.combo[hidden] { display: none; }
.score { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }

@keyframes pulse { from { transform: scale(1.25); } to { transform: scale(1); } }

/* ------------------------------------------------------------------- overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(10, 12, 26, 0.72), rgba(3, 4, 9, 0.92));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
  animation: fade 260ms ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: min(430px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 20px 20px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(18, 21, 40, 0.92), rgba(8, 10, 20, 0.94));
  border: 1px solid var(--panel-edge);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 60px rgba(255, 61, 110, 0.08);
  text-align: center;
}

.title {
  margin: 0 0 2px;
  font-size: clamp(28px, 9vw, 42px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 0.98;
  background: linear-gradient(92deg, var(--neon) 8%, #ffb347 46%, var(--neon-2) 92%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  margin: 6px 0 16px;
  color: var(--ink-dim);
  font-size: 13px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.how { margin: 0 0 18px; display: grid; gap: 9px; text-align: left; }
.how div { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; line-height: 1.4; }
.how b { flex: 0 0 auto; color: var(--neon-2); font-weight: 600; }

.bestline {
  display: flex;
  justify-content: space-around;
  gap: 10px;
  margin: 0 0 16px;
  padding: 11px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-edge);
}
.bestline div { display: flex; flex-direction: column; gap: 2px; }
.bestline label { font-size: 9px; letter-spacing: 0.18em; color: var(--ink-dim); text-transform: uppercase; }
.bestline span { font-family: var(--mono); font-size: 17px; }

.buttons { display: grid; gap: 9px; }
button {
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  cursor: pointer;
  transition: transform 90ms ease, background 140ms ease;
}
button:active { transform: scale(0.98); }
button.primary {
  background: linear-gradient(96deg, var(--neon), #ff7a3d);
  border-color: transparent;
  color: #12030a;
  box-shadow: 0 10px 34px rgba(255, 61, 110, 0.35);
}
.row { display: flex; gap: 9px; }
.row button { flex: 1; }

.record {
  margin: 12px 0 0;
  color: #ffd166;
  font-weight: 700;
  letter-spacing: 0.16em;
  font-size: 12px;
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.7);
}
.record[hidden] { display: none; }

.stats { display: grid; gap: 8px; margin: 16px 0; }
.stats div { display: flex; justify-content: space-between; font-size: 14px; }
.stats label { color: var(--ink-dim); }
.stats span { font-family: var(--mono); }

/* A bright sweep across the screen when a lap goes in. */
#flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
}
#flash.go { animation: sweep 620ms ease-out; }
@keyframes sweep {
  0% { opacity: 0; transform: translateX(-30%); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateX(30%); }
}

/* ------------------------------------------------------------------ landscape */
/* Wide: everything in the corners, the HUD out of the way of a low, fast view. */
@media (orientation: landscape) {
  #hud {
    grid-template-columns: auto auto 1fr auto;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "home  lap   times  pause"
      "combo .     .      map"
      "tank  speed .      .";
    padding-bottom: 78px;              /* the control bar overlays this strip */
  }
  .tank { grid-area: tank; justify-self: start; align-self: end; }
  .home { grid-area: home; }
  .lap { grid-area: lap; justify-self: start; }
  .times { grid-area: times; justify-self: center; }
  #minimap { grid-area: map; justify-self: end; align-self: end; width: clamp(142px, 25vh, 214px);
             height: clamp(142px, 25vh, 214px); }
  .pause-btn { grid-area: pause; }
  .combo { grid-area: combo; }
  .speedo { grid-area: speed; justify-self: start; align-self: end; }
  .speedo span { font-size: clamp(38px, 8vh, 60px); }
}

/* ------------------------------------------------------------------- portrait */
/* Tall: the view is a letterbox of road down the middle, so the numbers move to the top
   corners and the thumbs get the whole bottom third to themselves. */
@media (orientation: portrait) {
  #hud {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto 1fr auto auto;
    /* The times get the full width: three timings in a two-column slot wrap onto a second
       line, and a stopwatch that wraps is worse than no stopwatch. */
    grid-template-areas:
      "home  lap   pause"
      "times times times"
      "combo .     map"
      "tank  .     ."
      "speed .     .";
    padding-bottom: 84px;              /* and here */
  }
  .tank { grid-area: tank; justify-self: start; align-self: end; }
  .times { gap: 18px; }
  .times span { font-size: 15px; white-space: nowrap; }
  .home { grid-area: home; }
  .lap { grid-area: lap; justify-self: start; }
  .times { grid-area: times; justify-self: start; }
  .pause-btn { grid-area: pause; }
  #minimap { grid-area: map; justify-self: end; width: clamp(120px, 34vw, 182px);
             height: clamp(120px, 34vw, 182px); }
  .combo { grid-area: combo; }
  .speedo { grid-area: speed; justify-self: start; align-self: end; }
  .speedo span { font-size: clamp(40px, 14vw, 64px); }

  /* The band the thumbs live in, at the bottom of the screen. The road above it stays
     clear, which is the whole trick of playing a driving game on a tall phone. */
  #touch { align-items: flex-end; }
  .zone { height: 38%; }
  /* High enough to clear the speedo, which owns the bottom-left corner. */
  .zone::after { bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  #flash.go { animation: none; }
  .combo { animation: none; }
  .overlay { animation: none; }
}


/* -------------------------------------------------------------- narrow phones */
/* Grid items default to min-width:auto, so one wide child — the three timing columns — can
   push the whole HUD wider than the phone and shove the Boost button off the edge. */
#hud > * { min-width: 0; }

@media (max-width: 470px) {
  .times div span { font-size: 16px; letter-spacing: 0.02em; }
  /* Three buttons across a 390 px phone leaves about 43 px each: the labels have to shrink
     with them or "Brake" is clipped by its own circle. */
  .action-btn { font-size: 8.5px; letter-spacing: 0.01em; }
  .times label { font-size: 8px; letter-spacing: 0.12em; }
  .times { gap: 10px; padding: 7px 10px; }
  .action-btn { width: clamp(42px, 11vw, 58px); height: clamp(42px, 11vw, 58px); font-size: 9.5px; }
  .controls { gap: 6px; }
  .tank-track { width: clamp(50px, 13vw, 88px); }
  .tank { gap: 6px; padding: 6px 9px; }
}


/* ---------------------------------------------------------------- course picker */
.courses { margin: 10px 0 4px; }
.courses label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 5px;
}
.course-row { display: flex; flex-wrap: wrap; gap: 6px; }
.course-btn {
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.course-btn:hover { background: rgba(255, 255, 255, 0.11); }
.course-btn.active {
  border-color: var(--neon-2);
  background: rgba(20, 224, 255, 0.14);
  box-shadow: 0 0 16px rgba(20, 224, 255, 0.28);
}
.course-blurb {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-dim);
}
