@import url("https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700&family=Inter:wght@500;600;700;800&display=swap");

:root {
  color-scheme: dark;
  --ink: #f5f7ff;
  --muted: #9399b8;
  --cyan: #55efff;
  --blue: #476cff;
  --violet: #9f5cff;
  --pink: #ff4d9d;
  --gold: #ffc83d;
  --panel: rgba(10, 13, 39, 0.86);
  --border: rgba(161, 174, 255, 0.2);
  --display: "Chakra Petch", "Arial Narrow", sans-serif;
  --body: "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -20%, #243082 0, rgba(18, 23, 68, 0.55) 32%, transparent 58%),
    linear-gradient(160deg, #090b23 0%, #050615 50%, #090716 100%);
  color: var(--ink);
  font-family: var(--body);
  overscroll-behavior: none;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.11'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.ambient {
  position: fixed;
  width: 32vw;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
  pointer-events: none;
}

.ambient--one {
  top: 16%;
  left: -12%;
  background: #3f6cff;
}

.ambient--two {
  right: -10%;
  bottom: 0;
  background: #bf3dff;
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 32px, 1120px);
  margin: 0 auto;
  padding: 20px 0 18px;
}

.topbar,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  height: 54px;
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: #fff;
  font: 600 14px/1 var(--display);
  letter-spacing: 0.15em;
  text-decoration: none;
}

.brand strong {
  color: var(--cyan);
}

.brand__mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(85, 239, 255, 0.4);
  border-radius: 8px;
  background: rgba(47, 70, 140, 0.25);
  box-shadow: inset 0 0 18px rgba(85, 239, 255, 0.1), 0 0 18px rgba(85, 239, 255, 0.08);
}

.brand__mark svg {
  width: 23px;
  fill: var(--cyan);
  filter: drop-shadow(0 0 5px rgba(85, 239, 255, 0.75));
}

.brand__mark .brand__flame {
  fill: var(--pink);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  cursor: pointer;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(12, 16, 44, 0.64);
  color: #cdd3f4;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button:hover {
  color: var(--cyan);
  border-color: rgba(85, 239, 255, 0.5);
  transform: translateY(-1px);
}

.icon-button svg {
  width: 18px;
  fill: currentColor;
}

.sound-off,
.icon-button[aria-pressed="true"] .sound-on {
  display: none;
}

.icon-button[aria-pressed="true"] .sound-off {
  display: block;
}

.game-frame {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(157, 171, 255, 0.24);
  border-radius: 24px;
  background: #07091c;
  box-shadow:
    0 34px 80px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(64, 84, 178, 0.08),
    inset 0 0 80px rgba(50, 61, 148, 0.08);
  aspect-ratio: 16 / 9;
  isolation: isolate;
}

.game-frame::after {
  position: absolute;
  z-index: 15;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  content: "";
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 22px 25px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 260ms ease, transform 260ms ease;
}

.hud.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.hud__group {
  display: flex;
  align-items: center;
}

.hud__group--score {
  flex-direction: column;
  align-items: flex-start;
}

.hud__label,
.hud__center span {
  color: #8f96ba;
  font: 700 9px/1 var(--display);
  letter-spacing: 0.2em;
}

#scoreValue {
  margin-top: 4px;
  color: #fff;
  font: 700 23px/1 var(--display);
  letter-spacing: 0.08em;
  text-shadow: 0 0 15px rgba(85, 239, 255, 0.25);
}

.hud__center {
  display: flex;
  width: 114px;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding-top: 2px;
}

.wave-meter {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(152, 162, 211, 0.18);
}

.wave-meter i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  box-shadow: 0 0 8px var(--cyan);
  transition: width 100ms linear;
}

.hud__group--health {
  justify-self: end;
  gap: 6px;
}

.heart {
  width: 20px;
  overflow: visible;
  fill: var(--pink);
  filter: drop-shadow(0 0 5px rgba(255, 77, 157, 0.65));
  transition: opacity 180ms ease, transform 180ms ease, filter 180ms ease;
}

.heart.is-empty {
  opacity: 0.2;
  filter: grayscale(1);
  transform: scale(0.84);
}

.toast {
  position: absolute;
  z-index: 11;
  top: 29%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 24px;
  border-right: 1px solid rgba(85, 239, 255, 0.7);
  border-left: 1px solid rgba(85, 239, 255, 0.7);
  background: linear-gradient(90deg, transparent, rgba(37, 50, 124, 0.55), transparent);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 15px) scale(0.92);
}

.toast.is-visible {
  animation: toast-in 1.8s ease both;
}

.toast span {
  color: var(--cyan);
  font: 700 9px/1 var(--display);
  letter-spacing: 0.28em;
}

.toast strong {
  margin-top: 3px;
  font: 700 25px/1 var(--display);
  letter-spacing: 0.08em;
}

@keyframes toast-in {
  0% { opacity: 0; transform: translate(-50%, 15px) scale(0.92); }
  15%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(1.03); }
}

.screen {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: flex;
  visibility: hidden;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 48%, rgba(52, 69, 171, 0.2), transparent 34%),
    linear-gradient(180deg, rgba(7, 9, 28, 0.18), rgba(7, 9, 28, 0.48));
  opacity: 0;
  text-align: center;
  transition: opacity 320ms ease, visibility 320ms;
}

.screen--visible {
  visibility: visible;
  opacity: 1;
}

.screen__glow {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background: rgba(59, 83, 255, 0.12);
  filter: blur(35px);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--cyan);
  font: 700 9px/1 var(--display);
  letter-spacing: 0.34em;
}

.eyebrow span {
  width: 34px;
  height: 1px;
  background: linear-gradient(90deg, transparent, currentColor);
}

.eyebrow span:last-child {
  background: linear-gradient(90deg, currentColor, transparent);
}

h1,
h2 {
  margin: 10px 0 6px;
  color: #fff;
  font-family: var(--display);
  font-style: italic;
  font-weight: 700;
  line-height: 0.77;
  letter-spacing: -0.055em;
  text-shadow: 0 7px 30px rgba(0, 0, 0, 0.5);
}

h1 {
  font-size: clamp(58px, 7.5vw, 98px);
}

h1 em,
h2 em {
  color: transparent;
  font-style: inherit;
  -webkit-text-stroke: 2px var(--cyan);
  filter: drop-shadow(0 0 10px rgba(85, 239, 255, 0.25));
}

.screen__copy,
.game-over > p {
  margin: 20px 0 22px;
  color: #aeb4d0;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
}

.primary-button {
  display: inline-flex;
  min-width: 170px;
  height: 47px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border: 1px solid rgba(128, 246, 255, 0.7);
  border-radius: 8px;
  background: linear-gradient(135deg, #3266ff, #713dff 70%, #8b3bdf);
  color: #fff;
  font: 700 12px/1 var(--display);
  letter-spacing: 0.14em;
  box-shadow: 0 9px 28px rgba(72, 75, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.24);
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.primary-button:hover {
  filter: brightness(1.13);
  box-shadow: 0 12px 34px rgba(72, 75, 255, 0.48), 0 0 0 3px rgba(85, 239, 255, 0.08);
  transform: translateY(-2px);
}

.primary-button:active {
  transform: translateY(1px) scale(0.98);
}

.primary-button:focus-visible,
.icon-button:focus-visible,
.mobile-controls button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.primary-button svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.best-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 15px;
}

.best-score span {
  color: #777e9f;
  font: 700 8px/1 var(--display);
  letter-spacing: 0.16em;
}

.best-score strong {
  color: var(--gold);
  font: 700 15px/1 var(--display);
  letter-spacing: 0.06em;
}

.controls-hint {
  position: absolute;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 15px;
  color: #6f7595;
  font: 600 8px/1 var(--display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.controls-hint span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

kbd {
  display: inline-grid;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  place-items: center;
  border: 1px solid rgba(156, 165, 211, 0.28);
  border-bottom-color: rgba(156, 165, 211, 0.48);
  border-radius: 4px;
  background: rgba(128, 140, 196, 0.09);
  color: #c4cae7;
  font: 600 9px/1 var(--body);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.controls-hint__divider {
  width: 1px;
  height: 15px;
  background: rgba(151, 160, 206, 0.22);
}

.game-over {
  background: radial-gradient(circle at 50% 36%, rgba(151, 47, 106, 0.15), transparent 28%), rgba(7, 9, 28, 0.55);
  backdrop-filter: blur(4px);
}

.game-over__icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 10px;
  place-items: center;
  border: 1px solid rgba(255, 77, 157, 0.35);
  border-radius: 50%;
  background: rgba(255, 77, 157, 0.08);
  box-shadow: 0 0 30px rgba(255, 77, 157, 0.12);
}

.game-over__icon svg {
  width: 28px;
  fill: none;
  stroke: var(--pink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.game-over .eyebrow {
  color: var(--pink);
}

h2 {
  font-size: clamp(45px, 6vw, 72px);
  line-height: 0.9;
}

h2 em {
  -webkit-text-stroke-color: var(--pink);
}

.game-over > p {
  margin: 12px 0 15px;
}

.result-card {
  display: grid;
  width: min(340px, 85%);
  grid-template-columns: 1fr 1px 1fr;
  align-items: center;
  padding: 14px 8px;
  border: 1px solid rgba(152, 165, 230, 0.18);
  border-radius: 12px;
  background: rgba(20, 24, 60, 0.58);
}

.result-card div {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.result-card span {
  color: #777f9f;
  font: 700 8px/1 var(--display);
  letter-spacing: 0.2em;
}

.result-card strong {
  color: #fff;
  font: 700 24px/1 var(--display);
  letter-spacing: 0.08em;
}

.result-card div:last-child strong {
  color: var(--gold);
}

.result-card > i {
  height: 28px;
  background: rgba(157, 167, 214, 0.17);
}

.new-best {
  visibility: hidden;
  min-height: 26px;
  padding-top: 9px;
  color: var(--gold);
  font: 700 9px/1 var(--display);
  letter-spacing: 0.12em;
}

.new-best.is-visible {
  visibility: visible;
  animation: best-pulse 1.3s ease-in-out infinite alternate;
}

@keyframes best-pulse {
  to { text-shadow: 0 0 12px rgba(255, 200, 61, 0.75); transform: scale(1.035); }
}

.game-over .primary-button {
  margin-top: 5px;
}

.mobile-controls {
  position: absolute;
  z-index: 11;
  right: 16px;
  bottom: 16px;
  left: 16px;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.mobile-controls button {
  display: grid;
  width: 72px;
  height: 60px;
  cursor: pointer;
  place-items: center;
  border: 1px solid rgba(113, 234, 255, 0.32);
  border-radius: 17px;
  background: rgba(15, 22, 63, 0.65);
  color: rgba(222, 249, 255, 0.86);
  box-shadow: inset 0 0 18px rgba(76, 96, 255, 0.12);
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(7px);
}

.mobile-controls button.is-active {
  border-color: var(--cyan);
  background: rgba(56, 75, 170, 0.7);
  color: #fff;
  transform: scale(0.95);
}

.mobile-controls svg {
  width: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

footer {
  height: 45px;
  padding: 0 4px;
  color: #575e7e;
  font: 600 8px/1 var(--display);
  letter-spacing: 0.14em;
}

footer b {
  color: var(--gold);
}

.footer__status {
  display: flex;
  align-items: center;
  gap: 7px;
}

.footer__status i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #54efb1;
  box-shadow: 0 0 8px #54efb1;
}

@media (pointer: coarse), (max-width: 700px) {
  .mobile-controls.is-visible {
    display: flex;
  }

  .controls-hint__divider,
  .controls-hint span:first-child,
  footer {
    display: none;
  }

  .controls-hint {
    bottom: 17px;
  }

  .game-shell {
    width: min(100% - 18px, 1120px);
    padding-top: 7px;
  }

  .topbar {
    height: 48px;
  }

  .game-frame {
    min-height: min(720px, calc(100svh - 65px));
    aspect-ratio: auto;
    border-radius: 20px;
  }

  .hud {
    padding: 18px 16px;
  }

  .screen {
    padding-bottom: 85px;
  }

  .screen .controls-hint {
    bottom: 30px;
  }
}

@media (max-width: 480px) {
  .brand {
    font-size: 12px;
  }

  .hud__center {
    width: 82px;
  }

  .heart {
    width: 17px;
  }

  #scoreValue {
    font-size: 19px;
  }

  h1 {
    font-size: clamp(55px, 19vw, 76px);
  }

  .screen__copy {
    margin-top: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
