:root {
  color-scheme: dark;
  --ink: #171a2b;
  --paper: #fff9ec;
  --blue: #3a8df5;
  --red: #ef4656;
  --mint: #71ddb0;
  --yellow: #ffd166;
  --muted: #9597aa;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ink);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button, a { color: inherit; font: inherit; }
button { border: 0; }

.game-shell {
  width: 100%;
  height: 100%;
  height: 100svh;
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 30%, #282b43 0, #171a2b 48%, #11131f 100%);
}

.hud {
  z-index: 5;
  width: min(100%, 980px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto auto minmax(120px, auto) 1fr;
  align-items: center;
  gap: clamp(14px, 4vw, 42px);
  padding: max(9px, env(safe-area-inset-top)) 16px 7px;
}
.wordmark {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--paper);
  text-decoration: none;
  font-size: .78rem;
  font-weight: 950;
  letter-spacing: .17em;
}
.wordmark i { width: 15px; height: 15px; border-radius: 50%; background: var(--blue); box-shadow: 13px 0 0 var(--red); }
.hud-stat { display: grid; justify-items: center; min-width: 55px; }
.hud small { color: var(--muted); font-size: .5rem; font-weight: 900; letter-spacing: .18em; }
.hud strong { font-size: 1rem; font-weight: 950; font-variant-numeric: tabular-nums; }
.hud strong::after { content: "s"; margin-left: 2px; color: #737588; font-size: .65em; }
.hud-status { min-width: 108px; display: grid; justify-items: start; gap: 3px; color: #777a91; font-size: .47rem; font-weight: 900; letter-spacing: .1em; }
.hud-status span.ready { color: var(--mint); }
.hud-status span.charged { color: var(--yellow); }
.icon-button {
  justify-self: end;
  width: 35px;
  height: 35px;
  border: 1px solid #ffffff24;
  border-radius: 50%;
  background: #ffffff0d;
  color: #dadbe5;
  font-weight: 900;
  cursor: pointer;
}

.stage {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 14px max(14px, env(safe-area-inset-bottom));
}
#game {
  display: block;
  width: min(calc(100vw - 28px), calc(100svh - 82px), 760px);
  height: min(calc(100vw - 28px), calc(100svh - 82px), 760px);
  max-width: 100%;
  max-height: 100%;
  border: 1px solid #ffffff22;
  border-radius: 20px;
  background: #ede8d8;
  box-shadow: 0 20px 60px #0007, inset 0 0 0 5px #ffffff14;
  touch-action: none;
}

.touch-controls { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #121522d9;
  backdrop-filter: blur(10px);
  transition: opacity 220ms ease, visibility 220ms ease;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.card { width: min(100%, 470px); text-align: center; }
.eyebrow { margin: 0 0 15px; color: var(--mint); font-size: .57rem; font-weight: 950; letter-spacing: .26em; }
.card h1 { margin: 0; font-size: clamp(4.8rem, 20vw, 8rem); font-weight: 1000; line-height: .76; letter-spacing: -.09em; }
.card h1 span { color: var(--red); }
.message { margin: 30px 0 0; color: #b2b3c2; font-size: .96rem; line-height: 1.55; }
.message b { color: var(--paper); }
.results {
  width: min(100%, 330px);
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid #ffffff1c;
  border-radius: 14px;
}
.results[hidden] { display: none; }
.results div { display: grid; gap: 5px; padding: 13px 8px; }
.results div + div { border-left: 1px solid #ffffff1c; }
.results small { color: #828497; font-size: .47rem; font-weight: 900; letter-spacing: .13em; }
.results strong { font-size: 1.08rem; font-variant-numeric: tabular-nums; }
.play-button {
  width: min(100%, 330px);
  height: 56px;
  margin-top: 26px;
  padding: 0 8px 0 23px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 99px;
  background: var(--paper);
  color: var(--ink);
  font-size: .72rem;
  font-weight: 950;
  letter-spacing: .16em;
  cursor: pointer;
  box-shadow: 0 14px 38px #0005;
}
.play-button i { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--red); color: white; font-size: 1.25rem; font-style: normal; }
.controls { margin: 20px 0 0; color: #686a7e; font-size: .49rem; font-weight: 850; letter-spacing: .07em; }
kbd { padding: 2px 5px; border: 1px solid #ffffff1b; border-radius: 4px; font: inherit; }

.pause-card {
  position: fixed;
  inset: 0;
  z-index: 12;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: #121522dc;
  backdrop-filter: blur(10px);
}
.pause-card:not([hidden]) { display: grid; }
.pause-card small { color: var(--mint); font-size: .54rem; font-weight: 950; letter-spacing: .24em; }
.pause-card strong { font-size: clamp(1.5rem, 6vw, 2.5rem); letter-spacing: -.04em; }
.pause-card div { display: flex; gap: 9px; margin-top: 16px; }
.pause-card button { padding: 12px 22px; border-radius: 99px; background: var(--paper); color: var(--ink); font-size: .59rem; font-weight: 950; letter-spacing: .12em; cursor: pointer; }
.pause-card button + button { background: #33374e; color: var(--paper); }

@media (pointer: coarse), (max-width: 760px) {
  .game-shell { grid-template-rows: 58px minmax(0, 1fr) 142px; }
  .hud { gap: 9px; grid-template-columns: 1fr auto auto 1fr; padding-inline: 12px; }
  .wordmark span, .hud-status { display: none; }
  .controls { display: none; }
  .icon-button { grid-column: 4; }
  .stage { padding: 0 8px 6px; }
  #game {
    width: min(calc(100vw - 16px), calc(100svh - 206px));
    height: min(calc(100vw - 16px), calc(100svh - 206px));
    border-radius: 15px;
  }
  .touch-controls {
    display: flex;
    min-height: 0;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 5px max(20px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    touch-action: none;
  }
  .joystick { position: relative; width: 116px; height: 116px; border-radius: 50%; touch-action: none; }
  .joystick-rings { position: absolute; inset: 3px; border: 2px solid #ffffff21; border-radius: 50%; background: #ffffff0a; box-shadow: inset 0 0 30px #0003; }
  .joystick-rings::before, .joystick-rings::after { content: ""; position: absolute; background: #ffffff12; }
  .joystick-rings::before { left: 50%; top: 12px; bottom: 12px; width: 1px; }
  .joystick-rings::after { top: 50%; left: 12px; right: 12px; height: 1px; }
  .joystick-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; translate: -50% -50%; border-radius: 50%; background: var(--blue); border: 3px solid #b9d9ff; box-shadow: 0 7px 18px #0005; }
  .touch-actions { display: flex; align-items: center; gap: 11px; }
  .action-button { width: 75px; height: 75px; display: grid; place-content: center; gap: 2px; border-radius: 50%; background: #30344b; border: 2px solid #ffffff20; color: var(--paper); font-size: .58rem; font-weight: 950; letter-spacing: .06em; touch-action: none; }
  .action-button span { color: #8b8ea2; font-size: .42rem; }
  .sprint-button.active { background: var(--blue); transform: scale(.96); }
  .pulse-button { background: #66541e; color: var(--yellow); }
  .pulse-button:disabled { opacity: .34; filter: grayscale(1); }
  .pulse-button.charged { box-shadow: 0 0 24px #ffd16655; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .game-shell { grid-template-rows: 48px minmax(0, 1fr); }
  .hud { padding-block: 5px; }
  .touch-controls { position: fixed; inset: 52px 0 0; padding: 0 18px; pointer-events: none; }
  .joystick, .touch-actions { pointer-events: auto; }
  #game { width: min(calc(100vw - 250px), calc(100svh - 58px)); height: min(calc(100vw - 250px), calc(100svh - 58px)); }
}

@media (max-width: 380px) {
  .best { display: none; }
  .hud { grid-template-columns: 1fr auto 1fr; }
  .icon-button { grid-column: 3; }
  .joystick { width: 105px; height: 105px; }
  .action-button { width: 68px; height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; }
}
