/* Jump Rush — layout, HUD and overlay chrome. */

*, *::before, *::after { box-sizing: border-box; }
/* `hidden` is only a UA rule, so any author `display` beats it. Pin it once. */
[hidden] { display: none !important; }

:root {
  --ink:        #e8ecf6;
  --ink-dim:    #97a1bd;
  --bg:         #0b0d14;
  --panel:      rgba(13, 17, 28, 0.86);
  --line:       rgba(255, 255, 255, 0.12);
  --gold:       #ffd166;
  --mint:       #06d6a0;
  --rose:       #ef476f;
  --sky:        #4cc9f0;
  --radius:     14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }

body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(120% 90% at 50% -10%, #1b2140 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
}

/* ---------------------------------------------------------------- stage --
   Fixed 900x420 field, letterboxed. `container-type: size` makes the HUD and
   overlay scale against the stage instead of the viewport, so a phone in
   portrait does not get desktop-sized chrome over a short strip of game.     */
.stage {
  position: relative;
  width: 100%;
  max-width: min(1100px, calc((100dvh - 150px) * (960 / 540)));
  aspect-ratio: 960 / 540;
  container-type: size;
  border-radius: var(--radius);
  overflow: hidden;
  background: #10131f;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 30px 70px -30px rgba(0, 0, 0, 0.9);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ------------------------------------------------------------------ hud -- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  padding: clamp(8px, 3cqh, 18px) clamp(10px, 2.4cqw, 22px) 0;
  pointer-events: none;
  font-family: var(--mono);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

/* Right padding keeps BEST clear of the sound/pause buttons above it. */
.hud__row {
  display: flex;
  align-items: baseline;
  gap: clamp(8px, 2cqw, 18px);
  padding-right: clamp(54px, 17cqh, 84px);
}
.hud__cell { display: flex; align-items: baseline; gap: 0.45em; }
.hud__cell--end { margin-left: auto; }
.hud__cell--coins { gap: 0.35em; }

.hud__label {
  font-size: clamp(8px, 2.6cqh, 12px);
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.hud__value {
  font-size: clamp(16px, 7cqh, 34px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.hud__value--sm { font-size: clamp(12px, 4.4cqh, 20px); color: var(--ink-dim); }
#hud-coins { color: var(--gold); }

.hud__coin {
  width: clamp(9px, 3.4cqh, 16px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff2c4, var(--gold) 55%, #d99b1f);
  display: inline-block;
  transform: translateY(0.1em);
}

.hud__speed {
  margin-top: clamp(4px, 1.4cqh, 9px);
  width: clamp(70px, 22cqw, 220px);
  height: clamp(3px, 1cqh, 5px);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.hud__speed i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--mint), var(--gold) 70%, var(--rose));
  transition: width 140ms linear;
}

/* ---------------------------------------------------------------- tools -- */
.stage__tools {
  position: absolute;
  top: clamp(8px, 3cqh, 18px);
  right: clamp(10px, 2.4cqw, 22px);
  display: flex;
  gap: 6px;
  z-index: 3;
}
.icon-btn {
  width: clamp(22px, 7cqh, 34px);
  height: clamp(22px, 7cqh, 34px);
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(10, 13, 22, 0.55);
  color: var(--ink-dim);
  font: 600 clamp(9px, 3cqh, 14px)/1 var(--mono);
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.icon-btn:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.3); }
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: rgba(255, 209, 102, 0.5); }

/* -------------------------------------------------------------- overlay -- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4cqh 4cqw;
  background: rgba(6, 8, 14, 0.62);
  backdrop-filter: blur(3px);
  z-index: 2;
}

/* Lift the title card so the runner is visible under it rather than behind. */
#panel-ready { margin-bottom: 13cqh; }

.panel {
  width: min(100%, 620px);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: clamp(10px, 4cqh, 26px) clamp(12px, 3cqw, 30px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  animation: rise 220ms cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

.title {
  margin: 0;
  font: 800 clamp(24px, 15cqh, 68px)/0.95 var(--sans);
  letter-spacing: -0.03em;
}
.title em {
  font-style: normal;
  color: var(--mint);
  text-shadow: 0 0 26px rgba(6, 214, 160, 0.45);
}
.title b {
  font-weight: 800;
  color: var(--gold);
  font-size: 0.52em;
  vertical-align: 0.42em;
  letter-spacing: 0.04em;
  text-shadow: 0 0 22px rgba(255, 209, 102, 0.45);
}
.panel__head {
  margin: 0 0 clamp(6px, 2cqh, 14px);
  font: 800 clamp(18px, 9cqh, 38px)/1 var(--sans);
  letter-spacing: -0.02em;
}
.tagline {
  margin: clamp(4px, 1.6cqh, 10px) 0 clamp(8px, 3cqh, 18px);
  color: var(--ink-dim);
  font-size: clamp(10px, 3.6cqh, 16px);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: clamp(7px, 2.6cqh, 13px) clamp(16px, 4cqw, 30px);
  font: 700 clamp(11px, 4cqh, 17px)/1 var(--sans);
  color: #06231a;
  background: linear-gradient(180deg, #4ef0c2, var(--mint));
  box-shadow: 0 10px 26px -12px rgba(6, 214, 160, 0.9);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--sky); outline-offset: 3px; }

.keys {
  list-style: none;
  margin: clamp(8px, 3cqh, 18px) 0 0;
  padding: 0;
  display: grid;
  gap: clamp(3px, 1.2cqh, 7px);
  color: var(--ink-dim);
  font-size: clamp(9px, 3.2cqh, 14px);
}
.hint {
  margin: clamp(6px, 2cqh, 12px) 0 0;
  color: var(--ink-dim);
  font-size: clamp(9px, 3.2cqh, 13px);
}
kbd {
  display: inline-block;
  min-width: 1.7em;
  margin-right: 0.3em;
  padding: 0.15em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: 600 0.92em/1.25 var(--mono);
}

.stats {
  display: flex;
  justify-content: center;
  gap: clamp(12px, 5cqw, 40px);
  margin: clamp(8px, 3cqh, 18px) 0 clamp(10px, 3cqh, 20px);
}
.stats div { display: grid; gap: 2px; }
.stats dt {
  font: 600 clamp(8px, 2.6cqh, 11px)/1 var(--mono);
  letter-spacing: 0.16em;
  color: var(--ink-dim);
}
.stats dd {
  margin: 0;
  font: 700 clamp(16px, 7cqh, 32px)/1 var(--mono);
  font-variant-numeric: tabular-nums;
}
#over-coins { color: var(--gold); }

.badge {
  display: inline-block;
  margin: 0 0 clamp(6px, 2cqh, 12px);
  padding: 0.3em 0.8em;
  border-radius: 999px;
  background: var(--gold);
  color: #2b1d00;
  font: 800 clamp(8px, 2.8cqh, 12px)/1 var(--mono);
  letter-spacing: 0.16em;
  animation: pop 500ms ease-out both;
}
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.12); } }

/* -------------------------------------------------------- touch controls -- */
.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 3cqh 3cqw;
  z-index: 1;
  pointer-events: none;
}
.touch__side {
  display: flex;
  gap: 2cqw;
  align-items: flex-end;
}
.touch__btn {
  pointer-events: auto;
  min-width: 15cqw;
  padding: 3.2cqh 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(12, 16, 26, 0.5);
  color: var(--ink-dim);
  font: 700 clamp(10px, 3.4cqh, 15px)/1 var(--mono);
  letter-spacing: 0.1em;
  backdrop-filter: blur(3px);
}
.touch__btn--jump {
  min-width: 21cqw;
  color: #06231a;
  background: rgba(6, 214, 160, 0.85);
  border-color: transparent;
}
.touch__btn:active { filter: brightness(1.2); }

/* ----------------------------------------------------------------- foot -- */
.foot {
  margin: 0;
  text-align: center;
  color: var(--ink-dim);
  font-size: 12.5px;
  line-height: 1.7;
}
.foot p { margin: 0; }
.foot strong { color: var(--ink); font-weight: 600; }
.foot a { color: var(--sky); }

/* The field is a fixed 900x420 landscape box, so a portrait phone letterboxes
   it down to a strip. Media queries read the viewport, which is the right box
   for a question about the device rather than about the stage. */
.rotate { display: none; }

@media (orientation: portrait) and (pointer: coarse) {
  .app { padding: 8px; gap: 10px; }
  .rotate {
    display: block;
    margin: 0;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--gold);
    font-size: 13px;
    text-align: center;
  }
}

@media (max-height: 520px) {
  .app { padding: 8px; gap: 8px; }
  .foot { display: none; }
  .stage { max-width: min(1100px, calc((100dvh - 30px) * (960 / 540))); }
}
