:root {
  color-scheme: dark;
  --navy: #071426;
  --navy-glass: rgba(6, 20, 39, 0.78);
  --navy-soft: rgba(8, 27, 49, 0.58);
  --cyan: #43e8ff;
  --cyan-bright: #b8f8ff;
  --coral: #ff5f68;
  --yellow: #ffd166;
  --white: #f5fbff;
  --muted: #a8bed0;
  --line: rgba(133, 224, 255, 0.24);
  --shadow: 0 14px 45px rgba(0, 8, 24, 0.38);
  --safe-top: max(14px, env(safe-area-inset-top));
  --safe-right: max(16px, env(safe-area-inset-right));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --safe-left: max(16px, env(safe-area-inset-left));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  color: var(--white);
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button {
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 4px;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.hidden {
  display: none !important;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, #70d9f1 0%, #c8f4f3 48%, #158c94 100%);
}

#game canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  outline: none;
}

/* Fine cinematic texture without hiding the live scene. */
#game::before,
#game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

#game::before {
  background:
    radial-gradient(circle at 50% 45%, transparent 43%, rgba(3, 13, 28, 0.13) 74%, rgba(3, 11, 25, 0.43) 115%),
    linear-gradient(180deg, rgba(255, 245, 197, 0.05), transparent 24%);
}

#game::after {
  opacity: 0.12;
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.045) 0,
    rgba(255, 255, 255, 0.045) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: soft-light;
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.025em;
}

#hud button,
#hud a {
  pointer-events: auto;
}

#score,
#distance,
#combo,
#armor {
  position: absolute;
  text-shadow: 0 2px 14px rgba(0, 8, 22, 0.8);
}

#score {
  top: calc(var(--safe-top) + 8px);
  left: var(--safe-left);
  max-width: 40vw;
  padding: 11px 17px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--navy-glass), rgba(8, 33, 54, 0.48));
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.08);
  color: var(--white);
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 900;
  line-height: 1;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#score::before {
  content: "SCORE";
  display: block;
  margin-bottom: 5px;
  color: var(--cyan);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.2em;
}

#distance {
  top: calc(var(--safe-top) + 9px);
  left: 50%;
  min-width: 142px;
  padding: 10px 18px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: var(--navy-soft);
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.08);
  text-align: center;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 900;
  line-height: 1.1;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#combo {
  top: calc(var(--safe-top) + 91px);
  left: var(--safe-left);
  color: var(--yellow);
  font-size: clamp(17px, 2.7vw, 25px);
  font-style: italic;
  font-weight: 950;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.45));
}

#combo::before {
  content: "COMBO  ";
  color: rgba(255, 255, 255, 0.78);
  font-size: 9px;
  font-style: normal;
  letter-spacing: 0.18em;
  vertical-align: middle;
}

#armor {
  top: calc(var(--safe-top) + 68px);
  right: var(--safe-right);
  display: flex;
  min-height: 30px;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.armorPip {
  display: inline-block;
  width: 23px;
  height: 15px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 5px 9px 5px 9px;
  transform: skewX(-13deg);
  background: linear-gradient(135deg, #e8fdff, var(--cyan) 45%, #0ca4d0);
  box-shadow:
    0 0 13px rgba(67, 232, 255, 0.65),
    inset 0 1px 2px rgba(255, 255, 255, 0.8);
  transition: opacity 180ms ease, filter 180ms ease, transform 180ms ease;
}

.armorPip.off {
  opacity: 0.25;
  border-color: rgba(255, 255, 255, 0.22);
  background: #263649;
  box-shadow: none;
  filter: saturate(0);
  transform: skewX(-13deg) scale(0.88);
}

#hud *:has(> #progressFill) {
  position: absolute;
  top: calc(var(--safe-top) + 63px);
  left: 50%;
  width: min(190px, 38vw);
  height: 5px;
  overflow: hidden;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(3, 14, 30, 0.68);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}

#progressFill {
  width: 0%;
  height: 100%;
  min-height: 5px;
  border-radius: inherit;
  background: linear-gradient(90deg, #16b9dc, var(--cyan-bright), var(--yellow));
  box-shadow: 0 0 12px rgba(67, 232, 255, 0.9);
  transition: width 120ms linear;
}

#hud *:has(> #boostFill) {
  position: absolute;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 126px);
  width: clamp(112px, 15vw, 175px);
  height: 15px;
  overflow: hidden;
  border: 2px solid rgba(198, 248, 255, 0.55);
  border-radius: 999px;
  background: rgba(4, 18, 35, 0.8);
  box-shadow: 0 5px 20px rgba(0, 8, 24, 0.38);
}

#boostFill {
  width: 100%;
  height: 100%;
  min-height: 8px;
  border-radius: inherit;
  background: linear-gradient(90deg, #087fae, var(--cyan) 65%, #eaffff);
  box-shadow: 0 0 16px rgba(67, 232, 255, 0.8);
  transition: width 100ms linear;
}

/* Top controls */
#muteBtn,
#pauseBtn {
  position: absolute;
  z-index: 32;
  top: var(--safe-top);
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(177, 231, 255, 0.3);
  border-radius: 14px;
  background: var(--navy-glass);
  box-shadow: 0 8px 24px rgba(0, 10, 27, 0.28), inset 0 1px rgba(255, 255, 255, 0.1);
  color: var(--white);
  font-size: 20px;
  line-height: 1;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

#muteBtn {
  right: var(--safe-right);
}

#pauseBtn {
  right: calc(var(--safe-right) + 58px);
}

#muteBtn:hover,
#pauseBtn:hover {
  border-color: var(--cyan);
  background: rgba(11, 46, 69, 0.9);
}

#muteBtn:active,
#pauseBtn:active {
  transform: scale(0.92);
}

/* Full-screen overlays */
#titleScreen,
#pauseScreen,
#endScreen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    calc(var(--safe-top) + 58px)
    var(--safe-right)
    calc(var(--safe-bottom) + 24px)
    var(--safe-left);
  text-align: center;
}

#titleScreen {
  z-index: 25;
  align-items: flex-start;
  justify-content: center;
  padding-left: max(6vw, var(--safe-left));
  text-align: left;
  background:
    linear-gradient(90deg, rgba(3, 14, 31, 0.92) 0%, rgba(4, 18, 36, 0.69) 37%, rgba(4, 20, 37, 0.09) 72%, transparent 100%),
    linear-gradient(0deg, rgba(3, 14, 28, 0.38), transparent 45%);
}

#pauseScreen,
#endScreen {
  z-index: 40;
  background:
    radial-gradient(circle at 50% 42%, rgba(11, 49, 72, 0.48), rgba(3, 13, 29, 0.83) 75%),
    linear-gradient(180deg, rgba(3, 15, 31, 0.3), rgba(3, 13, 29, 0.76));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

#titleScreen h1,
#titleScreen .logo,
#pauseScreen h1,
#pauseScreen h2,
#endTitle {
  margin: 0;
  color: var(--white);
  font-weight: 950;
  font-style: italic;
  letter-spacing: -0.055em;
  line-height: 0.9;
  text-transform: uppercase;
  text-shadow:
    0 4px 0 rgba(5, 54, 77, 0.65),
    0 10px 35px rgba(0, 7, 20, 0.55);
}

#titleScreen h1,
#titleScreen .logo {
  max-width: min(650px, 90vw);
  font-size: clamp(54px, 9.2vw, 118px);
  transform: skewX(-5deg);
}

#titleScreen h1 em,
#titleScreen .logo em,
#titleScreen h1 span,
#titleScreen .logo span {
  color: var(--cyan);
  font-style: inherit;
}

#titleScreen p {
  max-width: 490px;
  margin: 22px 0;
  color: #d8eaf3;
  font-size: clamp(13px, 1.8vw, 17px);
  font-weight: 650;
  line-height: 1.65;
  letter-spacing: 0.025em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

#titleScreen p strong {
  color: var(--yellow);
}

#pauseScreen h1,
#pauseScreen h2,
#endTitle {
  margin-bottom: 24px;
  font-size: clamp(43px, 8vw, 84px);
}

#endTitle {
  color: var(--cyan-bright);
}

#endStats {
  width: min(430px, 92vw);
  margin: 0 0 24px;
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(10, 35, 57, 0.88), rgba(4, 18, 35, 0.76));
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.09);
  color: #dceef7;
  font-size: clamp(15px, 2vw, 19px);
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
  white-space: pre-line;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#endStats strong,
#endStats b {
  color: var(--yellow);
  font-weight: 900;
}

#startBtn,
#resumeBtn,
#restartPauseBtn,
#restartBtn,
#shareBtn {
  position: relative;
  min-height: 54px;
  padding: 14px 28px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 8, 22, 0.34), inset 0 1px rgba(255, 255, 255, 0.28);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
  pointer-events: auto;
}

#startBtn,
#resumeBtn,
#restartBtn {
  overflow: hidden;
  background: linear-gradient(115deg, #13badc, var(--cyan) 55%, #a7f7ff);
  color: #042135;
  box-shadow:
    0 10px 35px rgba(25, 211, 240, 0.26),
    inset 0 1px rgba(255, 255, 255, 0.65);
}

#startBtn {
  min-width: min(280px, 84vw);
  min-height: 62px;
  margin-top: 5px;
  font-size: 17px;
  font-style: italic;
  animation: startGlow 2.4s ease-in-out infinite;
}

#startBtn::after {
  content: "";
  position: absolute;
  top: -70%;
  left: -35%;
  width: 24%;
  height: 240%;
  transform: rotate(24deg);
  background: rgba(255, 255, 255, 0.5);
  animation: buttonShine 3.4s ease-in-out infinite;
}

#restartPauseBtn,
#shareBtn {
  background: rgba(10, 31, 52, 0.86);
  color: var(--white);
}

#shareBtn {
  border-color: rgba(255, 209, 102, 0.5);
  color: var(--yellow);
}

#startBtn:hover,
#resumeBtn:hover,
#restartPauseBtn:hover,
#restartBtn:hover,
#shareBtn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 14px 38px rgba(0, 8, 22, 0.42), 0 0 22px rgba(67, 232, 255, 0.15);
}

#startBtn:active,
#resumeBtn:active,
#restartPauseBtn:active,
#restartBtn:active,
#shareBtn:active {
  transform: translateY(1px) scale(0.98);
}

#resumeBtn,
#restartPauseBtn,
#restartBtn,
#shareBtn {
  width: min(290px, 86vw);
  margin: 6px;
}

/* Large, separated touch controls */
#leftBtn,
#rightBtn,
#boostBtn {
  position: absolute;
  z-index: 20;
  bottom: var(--safe-bottom);
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1px solid rgba(188, 239, 255, 0.43);
  background: linear-gradient(145deg, rgba(11, 39, 62, 0.82), rgba(4, 19, 36, 0.75));
  box-shadow:
    0 10px 30px rgba(0, 7, 20, 0.32),
    inset 0 1px rgba(255, 255, 255, 0.14);
  color: var(--cyan-bright);
  font-size: 31px;
  line-height: 1;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  pointer-events: auto;
  touch-action: none;
  transition: transform 80ms ease, background 80ms ease, box-shadow 80ms ease;
}

#leftBtn,
#rightBtn {
  border-radius: 24px;
}

#leftBtn {
  left: var(--safe-left);
}

#rightBtn {
  left: calc(var(--safe-left) + 88px);
}

#boostBtn {
  right: var(--safe-right);
  width: 94px;
  border-color: rgba(67, 232, 255, 0.72);
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(9, 110, 142, 0.9), rgba(4, 40, 65, 0.88));
  color: #e9fdff;
  font-size: 13px;
  font-style: italic;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px var(--cyan);
}

#leftBtn:active,
#rightBtn:active,
#boostBtn:active {
  transform: scale(0.92);
  background: linear-gradient(145deg, rgba(33, 188, 216, 0.94), rgba(4, 78, 105, 0.94));
  box-shadow: 0 0 28px rgba(67, 232, 255, 0.5), inset 0 2px 8px rgba(0, 20, 37, 0.35);
}

/* Event feedback */
#toast {
  position: absolute;
  z-index: 50;
  top: 30%;
  left: 50%;
  max-width: 85vw;
  padding: 9px 18px;
  transform: translate(-50%, 16px) scale(0.85);
  opacity: 0;
  border: 1px solid rgba(157, 244, 255, 0.45);
  border-radius: 999px;
  background: rgba(4, 24, 43, 0.78);
  box-shadow: 0 8px 30px rgba(0, 10, 26, 0.35), 0 0 20px rgba(67, 232, 255, 0.16);
  color: var(--cyan-bright);
  font-size: clamp(19px, 4vw, 32px);
  font-style: italic;
  font-weight: 950;
  letter-spacing: -0.02em;
  text-align: center;
  text-shadow: 0 0 14px rgba(67, 232, 255, 0.55);
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#toast.show {
  animation: toastPop 900ms cubic-bezier(0.2, 0.85, 0.25, 1) both;
}

#flash {
  position: absolute;
  inset: 0;
  z-index: 45;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 55%, rgba(255, 112, 102, 0.15), rgba(255, 57, 73, 0.64)),
    var(--coral);
  mix-blend-mode: screen;
  pointer-events: none;
}

#flash.active {
  animation: crashFlash 430ms ease-out both;
}

@keyframes startGlow {
  0%,
  100% {
    box-shadow: 0 10px 35px rgba(25, 211, 240, 0.22), inset 0 1px rgba(255, 255, 255, 0.65);
  }
  50% {
    box-shadow: 0 12px 42px rgba(25, 211, 240, 0.48), inset 0 1px rgba(255, 255, 255, 0.8);
  }
}

@keyframes buttonShine {
  0%,
  45% {
    left: -35%;
  }
  70%,
  100% {
    left: 125%;
  }
}

@keyframes toastPop {
  0% {
    opacity: 0;
    transform: translate(-50%, 18px) scale(0.75);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.08);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -8px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -28px) scale(0.96);
  }
}

@keyframes crashFlash {
  0% {
    opacity: 0.85;
  }
  30% {
    opacity: 0.42;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 600px) {
  #titleScreen {
    align-items: center;
    justify-content: flex-end;
    padding: calc(var(--safe-top) + 62px) 22px calc(var(--safe-bottom) + 28px);
    text-align: center;
    background:
      linear-gradient(0deg, rgba(3, 14, 31, 0.94) 0%, rgba(3, 16, 33, 0.65) 43%, rgba(4, 20, 37, 0.06) 78%, transparent 100%);
  }

  #titleScreen h1,
  #titleScreen .logo {
    font-size: clamp(48px, 15.5vw, 72px);
  }

  #titleScreen p {
    margin: 16px auto;
    font-size: 13px;
    line-height: 1.55;
  }

  #score {
    max-width: 31vw;
    padding: 9px 11px;
    border-radius: 12px;
    font-size: 19px;
  }

  #score::before {
    font-size: 8px;
  }

  #distance {
    top: calc(var(--safe-top) + 65px);
    min-width: 132px;
    padding: 8px 13px 12px;
    font-size: 14px;
  }

  #hud *:has(> #progressFill) {
    top: calc(var(--safe-top) + 111px);
    width: 145px;
  }

  #combo {
    top: calc(var(--safe-top) + 124px);
    font-size: 18px;
  }

  #armor {
    top: calc(var(--safe-top) + 59px);
    gap: 5px;
  }

  .armorPip {
    width: 19px;
    height: 13px;
  }

  #hud *:has(> #boostFill) {
    right: calc(var(--safe-right) + 2px);
    bottom: calc(var(--safe-bottom) + 101px);
    width: 92px;
    height: 12px;
  }

  #leftBtn,
  #rightBtn {
    width: 70px;
    height: 70px;
    border-radius: 22px;
  }

  #rightBtn {
    left: calc(var(--safe-left) + 80px);
  }

  #boostBtn {
    width: 86px;
    height: 76px;
    border-radius: 38px;
  }

  #endStats {
    padding: 15px 20px;
  }
}

@media (max-height: 650px) {
  #titleScreen p {
    margin: 10px 0;
    line-height: 1.4;
  }

  #titleScreen h1,
  #titleScreen .logo {
    font-size: clamp(43px, 11vh, 72px);
  }

  #pauseScreen h1,
  #pauseScreen h2,
  #endTitle {
    margin-bottom: 12px;
    font-size: clamp(38px, 10vh, 62px);
  }

  #endStats {
    margin-bottom: 10px;
    padding-block: 10px;
    line-height: 1.55;
  }

  #resumeBtn,
  #restartPauseBtn,
  #restartBtn,
  #shareBtn {
    min-height: 46px;
    margin: 4px;
    padding-block: 10px;
  }
}

@media (min-width: 900px) {
  #leftBtn,
  #rightBtn,
  #boostBtn {
    opacity: 0.78;
  }

  #leftBtn:hover,
  #rightBtn:hover,
  #boostBtn:hover {
    opacity: 1;
    border-color: var(--cyan);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  #startBtn,
  #startBtn::after {
    animation: none;
  }

  #toast.show {
    animation-duration: 500ms;
  }
}
