/* --------------------------------------------------------------------------
   Jet Rush HUD — comic panels, ink borders, cream paper.
   Game UI rule: readability over decoration. Big values, low clutter.
   -------------------------------------------------------------------------- */

@font-face {
  font-family: 'Bangers';
  src: url('./fonts/Bangers-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #101820;
  --paper: #f7f1e1;
  --paper-dim: #e8dfc8;
  --accent: #ffd23f;
  --red: #ef4444;
  --teal: #19c2c8;
  --purple: #9b6dff;
  --green: #4ade80;
  --yellow: #f2c230;
  --ink-soft: rgba(16, 24, 32, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #cfe9f2;
  color: var(--ink);
  font-family: 'Arial Black', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--sky, #e4f1e8);
  transition: opacity 0.55s ease;
}

body[data-ready="1"] #loading {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  width: min(360px, 80vw);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 15px 18px 17px;
  transform: rotate(-0.8deg);
}

.loading-kicker {
  font-size: 9px;
  letter-spacing: 0.24em;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 5px;
}

.loading-title {
  font-family: 'Bangers', 'Arial Black', 'Microsoft YaHei', sans-serif;
  font-size: 38px;
  line-height: 1;
  margin: 7px 0 8px;
  letter-spacing: 0.04em;
}

.loading-bar {
  height: 9px;
  border: 2px solid var(--ink);
  background: var(--paper);
  overflow: hidden;
}

.loading-bar i {
  display: block;
  width: 38%;
  height: 100%;
  background: var(--accent);
  animation: loadingSweep 1.15s ease-in-out infinite;
}

@keyframes loadingSweep {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(310%); }
}

.loading-sub {
  margin-top: 7px;
  font-family: 'Arial Black', 'Microsoft YaHei', sans-serif;
  font-size: 8px;
  letter-spacing: 0.18em;
  color: rgba(16, 24, 32, 0.58);
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  user-select: none;
}

.hidden {
  display: none !important;
}

.panel {
  position: absolute;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 1px;
  box-shadow: 4px 4px 0 var(--ink);
}

.panel-title {
  font-family: 'Arial Black', 'Microsoft YaHei', sans-serif;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.2em;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--ink);
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- ranking */
.rank {
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  width: 224px;
  padding: 8px 10px 7px;
  transform: rotate(-0.45deg);
}

#rankRows {
  margin-top: 3px;
}

.rank-row {
  display: grid;
  grid-template-columns: 19px 12px 1fr auto;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 2px;
  border-bottom: 1px solid var(--ink-soft);
}

.rank-row:last-child {
  border-bottom: 0;
}

.rank-row.you {
  background: var(--accent);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.rank-row .pos {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 20px;
  line-height: 1;
  text-align: center;
}

.rank-row .chip {
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--ink);
  background: var(--teal);
}

.rank-row .name {
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.rank-row .gap {
  font-family: 'Consolas', 'Bahnschrift', monospace;
  font-size: 10px;
  font-weight: 700;
}

/* ------------------------------------------------------------------- map */
.map {
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  width: 214px;
  padding: 8px 7px 5px;
  transform: rotate(0.35deg);
}

#minimap {
  display: block;
  width: 198px;
  height: 146px;
  margin: 1px auto 0;
}

.sound-btn {
  display: block;
  width: 198px;
  margin: 4px auto 1px;
  padding: 3px 0 2px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.12em;
  cursor: pointer;
  pointer-events: auto;
}

.sound-btn:hover {
  background: #1d2c3d;
}

.sound-btn.off {
  background: var(--paper-dim);
  color: var(--ink-soft);
}

.sound-btn:active {
  transform: translateY(1px);
}

/* ------------------------------------------------------------------- lap */
.lap {
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: calc(16px + env(safe-area-inset-left));
  width: 218px;
  padding: 7px 11px 8px;
  transform: rotate(0.4deg);
}

.lap-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0 2px;
  border-bottom: 1px dashed var(--ink-soft);
}

.lap-row:last-child {
  border-bottom: 0;
}

.lap-row .label {
  font-size: 8.5px;
  letter-spacing: 0.16em;
  white-space: nowrap;
}

.lap-row .value {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 25px;
  line-height: 0.95;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lap-row .value.big {
  font-size: 30px;
}

.lap-row.best .value.small {
  font-size: 19px;
}

/* ----------------------------------------------------------------- speed */
.speed {
  bottom: calc(16px + env(safe-area-inset-bottom));
  right: calc(16px + env(safe-area-inset-right));
  width: 252px;
  padding: 5px 7px 3px;
  transform: rotate(-0.3deg);
}

#gauge {
  display: block;
  width: 236px;
  height: 136px;
}

#driftTag {
  position: absolute;
  top: 8px;
  left: 14px;
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--accent);
  border: 2px solid var(--ink);
  padding: 1px 6px;
  transform: rotate(-3deg);
  box-shadow: 2px 2px 0 var(--ink);
  animation: driftPulse 0.35s steps(2) infinite;
}

@keyframes driftPulse {
  50% {
    background: #fff3b0;
  }
}

/* ---------------------------------------------------------------- lights */
.lights {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) rotate(-0.8deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--ink);
  border: 2.5px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(10, 18, 28, 0.35);
  padding: 7px 15px 5px;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.lights.away {
  opacity: 0;
  transform: translateX(-50%) translateY(-12px) rotate(-0.8deg);
}

.lamp-row {
  display: flex;
  gap: 10px;
}

.lamp-row i {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  background: #351515;
}

.lights.red .lamp-row i.on {
  background: #ff3d33;
  box-shadow: 0 0 12px #ff3d33;
}

.lights.green .lamp-row i {
  background: #3ddc84;
  border-color: #0b2c1a;
  box-shadow: 0 0 14px #3ddc84;
}

#countNum {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 42px;
  line-height: 0.92;
  color: var(--paper);
  letter-spacing: 0.04em;
}

.lamp-tip {
  font-family: 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(247, 241, 225, 0.72);
  margin-top: 1px;
  white-space: nowrap;
}

.lights.green #countNum {
  color: #3ddc84;
}

/* ----------------------------------------------------------------- toast */
#toast {
  position: absolute;
  left: 50%;
  /* Keep transient feedback out of the driving line: the boat sits around
     mid-screen, so the toast lives just under the start-light band. */
  top: 17.5%;
  width: max-content;
  max-width: 80vw;
  transform: translate(-50%, -50%) rotate(-2deg) scale(0.86);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  padding: 5px 16px 6px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.14s ease, transform 0.16s cubic-bezier(0.2, 1.6, 0.4, 1);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(-2deg) scale(1);
}

#toast.good {
  background: var(--accent);
}

#toast.bad {
  background: var(--red);
  color: var(--paper);
}

#toastTitle {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 26px;
  line-height: 0.9;
  letter-spacing: 0.035em;
}

#toastSub {
  margin-top: 2px;
  font-size: 9px;
  letter-spacing: 0.1em;
  font-weight: 800;
}

/* --------------------------------------------------------------- warning */
#warning {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%) rotate(1.2deg);
  background: var(--red);
  color: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  padding: 5px 18px 6px;
  font-size: 20px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  animation: warnPulse 0.5s steps(2) infinite;
}

@keyframes warnPulse {
  50% {
    background: #b91c1c;
  }
}

/* ------------------------------------------------------------------ hint */
#nextCue {
  position: absolute;
  left: 50%;
  bottom: calc(47px + env(safe-area-inset-bottom));
  transform: translateX(-50%) rotate(-0.4deg);
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(16, 24, 32, 0.55);
  padding: 3px 11px 4px 8px;
  font-family: 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#cueArrow {
  display: inline-block;
  color: var(--accent);
  font-size: 19px;
  line-height: 1;
  transform-origin: 50% 52%;
  transition: transform 0.1s linear;
}

.cue-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.cue-copy b {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--accent);
}

#cueDist {
  color: rgba(247, 241, 225, 0.76);
  font-variant-numeric: tabular-nums;
}

#hint {
  position: absolute;
  bottom: calc(15px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(247, 241, 225, 0.94);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(16, 24, 32, 0.7);
  padding: 4px 12px;
  font-family: 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.02em;
  opacity: 1;
  transition: opacity 1s ease;
}

#hint b {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 13px;
  letter-spacing: 0.06em;
}

#hint.fade {
  opacity: 0;
}

/* ---------------------------------------------------------------- finish */
#finish {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 15, 25, 0.60);
  pointer-events: auto;
}

.finish-card {
  width: min(470px, 88vw);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 10px 10px 0 var(--ink);
  padding: 16px 22px 18px;
  transform: rotate(-0.6deg);
}

.finish-kicker {
  font-size: 9px;
  letter-spacing: 0.24em;
}

.finish-title {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 74px;
  line-height: 0.88;
  margin: 2px 0 0;
}

.finish-sub {
  font-size: 11px;
  font-weight: 800;
  margin: 2px 0 10px;
  letter-spacing: 0.03em;
}

.finish-row {
  display: grid;
  grid-template-columns: 26px 14px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 4px 2px;
  border-bottom: 1px solid var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
}

.finish-row.you {
  background: var(--accent);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.finish-row .pos {
  font-family: 'Bangers', 'Arial Black', sans-serif;
  font-size: 18px;
  text-align: center;
}

.finish-row .chip {
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--ink);
}

.finish-row .fname {
  letter-spacing: 0.06em;
}

.finish-row .ft {
  font-family: 'Consolas', monospace;
  font-size: 10px;
}

#restartBtn {
  margin-top: 13px;
  width: 100%;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  font-family: 'Arial Black', 'Microsoft YaHei', sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

#restartBtn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

/* --------------------------------------------------------- small screens */
@media (max-width: 1080px) {
  .rank {
    width: 190px;
  }
  .map {
    width: 178px;
  }
  #minimap {
    width: 164px;
    height: 122px;
  }
  .sound-btn {
    width: 164px;
    font-size: 10px;
  }
  .lap {
    width: 192px;
  }
  .speed {
    width: 218px;
  }
  #gauge {
    width: 204px;
    height: 118px;
  }
  #hint {
    font-size: 9.5px;
  }
}

/* Phone portrait: the desktop HUD panels are wider than the viewport when
   combined. Keep both top panels, shrink the gauge, and lift NEXT above the
   bottom row; the keyboard hint is pointless on a phone. */
@media (max-width: 720px) {
  .rank {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    width: 156px;
    padding: 6px 7px 5px;
  }
  .panel-title {
    font-size: 8px;
    letter-spacing: 0.16em;
  }
  .rank-row {
    grid-template-columns: 16px 10px 1fr auto;
    gap: 4px;
    height: 22px;
  }
  .rank-row .pos {
    font-size: 17px;
  }
  .rank-row .chip {
    width: 9px;
    height: 9px;
  }
  .rank-row .name {
    font-size: 9px;
    letter-spacing: 0.04em;
  }
  .rank-row .gap {
    font-size: 8.5px;
  }
  .map {
    top: calc(8px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
    width: 150px;
    padding: 6px 5px 4px;
  }
  #minimap {
    width: 138px;
    height: 102px;
  }
  .sound-btn {
    width: 138px;
    font-size: 9px;
    padding: 3px 0 2px;
  }
  .lap {
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: calc(8px + env(safe-area-inset-left));
    width: 148px;
    padding: 5px 7px 6px;
  }
  .lap-row .label {
    font-size: 7.5px;
    letter-spacing: 0.12em;
  }
  .lap-row .value {
    font-size: 21px;
  }
  .lap-row .value.big {
    font-size: 25px;
  }
  .lap-row.best .value.small {
    font-size: 16px;
  }
  .speed {
    bottom: calc(8px + env(safe-area-inset-bottom));
    right: calc(8px + env(safe-area-inset-right));
    width: 190px;
    padding: 3px 4px 2px;
  }
  #gauge {
    width: 180px;
    height: 104px;
  }
  #nextCue {
    bottom: calc(126px + env(safe-area-inset-bottom));
    font-size: 9px;
    padding: 3px 8px 4px 6px;
  }
  #hint {
    display: none;
  }
  #warning {
    max-width: 90vw;
    white-space: normal;
    text-align: center;
    font-size: 14px;
    padding: 4px 10px 5px;
  }
  #toast {
    top: 24%;
    max-width: 88vw;
  }
  #toastTitle {
    font-size: 22px;
  }
}

@media (max-height: 640px) {
  #hint {
    display: none;
  }
  .map {
    display: none;
  }
}
