:root {
  --bg: #03050e;
  --ink: #eaf7ff;
  --muted: #8ba0b8;
  --dim: #546a82;
  --cyan: #5ce1ff;
  --blue: #3b8cff;
  --pink: #ff4f9a;
  --gold: #ffcf6b;
  --danger: #ff5b5b;
  --glass: rgba(8, 14, 28, 0.72);
  --line: rgba(130, 213, 255, 0.2);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(ellipse 70% 50% at 18% -8%, rgba(105, 61, 200, 0.28), transparent 62%),
    radial-gradient(ellipse 65% 50% at 92% 108%, rgba(0, 136, 176, 0.26), transparent 60%),
    radial-gradient(ellipse 80% 70% at 50% 50%, rgba(12, 22, 48, 0.7), transparent 75%),
    #03050e;
}

button { font: inherit; color: inherit; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.vignette,
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.vignette {
  background:
    radial-gradient(ellipse 82% 78% at 50% 48%, transparent 48%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.32), transparent 18%, transparent 80%, rgba(0, 0, 0, 0.42));
}

.scanlines {
  opacity: 0.09;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.55) 0px,
    rgba(255, 255, 255, 0.55) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  z-index: 6;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding:
    calc(10px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    0
    calc(12px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

body.in-game .hud,
body.game-over .hud {
  opacity: 1;
  transform: none;
}

.hud-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding-top: 4px;
}

.hud-right { align-items: flex-start; flex-direction: row; justify-content: flex-end; gap: 6px; }

.hud-label {
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.22em;
  color: var(--dim);
}

.hud-value {
  font: 700 clamp(14px, 3.8vw, 20px)/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 0 0 14px rgba(92, 225, 255, 0.45);
  font-variant-numeric: tabular-nums;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 3px;
}

.hud-wave {
  font: 700 9px/1 var(--mono);
  letter-spacing: 0.24em;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(92, 225, 255, 0.6);
  white-space: nowrap;
}

.lives {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 10px;
}

.life {
  display: block;
  width: 11px;
  height: 9px;
  background: linear-gradient(180deg, #d9fbff, var(--cyan) 55%, #1c8dff);
  clip-path: polygon(50% 0, 100% 100%, 50% 76%, 0 100%);
  filter: drop-shadow(0 0 4px rgba(92, 225, 255, 0.7));
  transition: opacity 0.2s, transform 0.2s;
}

.life.lost { opacity: 0.15; transform: scale(0.7); filter: none; }

.hud-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.icon-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(126, 194, 255, 0.18);
  background: rgba(7, 16, 32, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--muted);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.1s;
}

.icon-btn:hover { color: var(--ink); border-color: rgba(126, 194, 255, 0.45); }
.icon-btn:active { transform: scale(0.92); }

.icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg path:first-child { fill: currentColor; stroke: none; }
.icon-btn .ico-off { display: none; }
.icon-btn.muted { color: #5d6b7d; }
.icon-btn.muted .ico-on { display: none; }
.icon-btn.muted .ico-off { display: block; }

#pauseBtn { display: none; }
body.in-game #pauseBtn { display: inline-grid; }
#pauseBtn svg path { fill: none; stroke: currentColor; stroke-width: 2; }

/* ---------- Boss bar ---------- */

.boss-hud {
  position: absolute;
  z-index: 5;
  top: calc(72px + env(safe-area-inset-top, 0px));
  left: 50%;
  width: min(74%, 400px);
  transform: translate(-50%, -8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

body.boss .boss-hud { opacity: 1; transform: translate(-50%, 0); }

.boss-top {
  display: flex;
  justify-content: space-between;
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.2em;
  color: #ff9bbd;
  margin-bottom: 5px;
  text-shadow: 0 0 10px rgba(255, 79, 154, 0.6);
}

.boss-track {
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 79, 154, 0.14);
  overflow: hidden;
  border: 1px solid rgba(255, 79, 154, 0.26);
}

.boss-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff3d7f, #ff8a53);
  box-shadow: 0 0 12px rgba(255, 79, 154, 0.8);
  transition: width 0.15s linear;
}

/* ---------- Banner ---------- */

.banner {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 26%;
  width: min(86%, 460px);
  transform: translate(-50%, 10px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.banner.show { opacity: 1; transform: translate(-50%, 0); }

.banner-title {
  font: 900 clamp(22px, 7vw, 38px)/1 var(--font);
  letter-spacing: 0.18em;
  color: var(--ink);
  text-shadow:
    0 0 24px rgba(92, 225, 255, 0.55),
    0 0 60px rgba(92, 225, 255, 0.25);
}

.banner-sub {
  margin-top: 8px;
  font: 700 9px/1.4 var(--mono);
  letter-spacing: 0.22em;
  color: var(--cyan);
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding:
    calc(18px + env(safe-area-inset-top, 0px))
    clamp(18px, 6vw, 40px)
    calc(18px + env(safe-area-inset-bottom, 0px));
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.menu-overlay {
  justify-content: space-between;
  touch-action: pan-y;
  align-items: center;
  background:
    linear-gradient(180deg, rgba(3, 5, 14, 0.62) 0%, rgba(3, 5, 14, 0.06) 42%, rgba(3, 5, 14, 0.86) 100%);
  overflow-y: auto;
  overflow-x: hidden;
}

.menu-top {
  width: 100%;
  max-width: 620px;
  margin: auto auto 0;
  padding-top: clamp(24px, 7vh, 70px);
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 700 9px/1 var(--mono);
  letter-spacing: 0.32em;
  color: var(--muted);
  text-transform: uppercase;
}

.blink-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 10px var(--pink);
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.logo {
  margin: 14px 0 0;
  font: 900 clamp(44px, 14.5vw, 104px)/0.8 var(--font);
  letter-spacing: 0.035em;
  text-transform: uppercase;
  font-style: italic;
}

.logo span {
  display: block;
  background: linear-gradient(180deg, #ffffff 0%, #c9f4ff 28%, #5ce1ff 62%, #2b78ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter:
    drop-shadow(0 0 18px rgba(92, 225, 255, 0.3))
    drop-shadow(0 5px 0 rgba(13, 44, 96, 0.55));
}

.logo span + span {
  margin-top: 0.02em;
  background: linear-gradient(180deg, #fff2d6 0%, #ffcf6b 38%, #ff4f9a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter:
    drop-shadow(0 0 20px rgba(255, 79, 154, 0.28))
    drop-shadow(0 5px 0 rgba(66, 8, 48, 0.6));
}

.tagline {
  margin: 18px auto 0;
  max-width: 320px;
  font: 500 clamp(11px, 3.2vw, 13px)/1.55 var(--font);
  letter-spacing: 0.06em;
  color: var(--muted);
}

.menu-bottom {
  width: 100%;
  max-width: 400px;
  margin: auto auto 0;
  padding-top: clamp(22px, 5vh, 46px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.best-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px;
  border-top: 1px solid rgba(130, 213, 255, 0.13);
  border-bottom: 1px solid rgba(130, 213, 255, 0.13);
}

.best-label {
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.24em;
  color: var(--dim);
}

.best-value {
  font: 700 18px/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 207, 107, 0.35);
  font-variant-numeric: tabular-nums;
}

.btn {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 22px;
  border-radius: 14px;
  border: 0;
  font: 800 13px/1 var(--font);
  letter-spacing: 0.16em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
  overflow: hidden;
}

.btn:active { transform: scale(0.975); }

.btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.btn.primary {
  color: #03121c;
  background: linear-gradient(120deg, #b5f8ff 0%, #5ce1ff 38%, #3b8cff 72%, #9a6cff 100%);
  box-shadow:
    0 8px 30px rgba(59, 140, 255, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.18) inset,
    0 -3px 0 rgba(9, 42, 96, 0.35) inset;
}

.btn.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.55) 48%, transparent 62%);
  transform: translateX(-120%);
  transition: transform 0.6s ease;
}

.btn.primary:hover::after { transform: translateX(120%); }

.btn.primary svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn.ghost {
  min-height: 48px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(162, 210, 255, 0.16);
  color: var(--muted);
  font-size: 11px;
}

.btn.ghost:hover { color: var(--ink); border-color: rgba(162, 210, 255, 0.34); }

.hint {
  margin: 2px 0 0;
  text-align: center;
  font: 500 10px/1.6 var(--mono);
  letter-spacing: 0.04em;
  color: var(--dim);
}

.hint-desktop { display: block; }
.hint-touch { display: none; }

.meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 2px;
  font: 700 7px/1 var(--mono);
  letter-spacing: 0.16em;
  color: #42566d;
  flex-wrap: wrap;
}

.meta-row .dot { color: var(--pink); opacity: 0.6; font-size: 5px; }

.menu-sound {
  position: absolute;
  z-index: 3;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  width: 40px;
  height: 40px;
  opacity: 0.72;
}

/* ---------- Modals ---------- */

.center-overlay {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% 45%, rgba(19, 37, 78, 0.4), transparent 75%),
    rgba(2, 4, 12, 0.68);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.modal {
  width: 100%;
  max-width: 370px;
  padding: 30px 24px 24px;
  border-radius: 24px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(19, 32, 60, 0.78), rgba(6, 11, 24, 0.9));
  border: 1px solid rgba(126, 200, 255, 0.2);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 1px 0 rgba(255, 255, 255, 0.08) inset;
  animation: modal-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.modal-kicker {
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.3em;
  color: var(--pink);
  margin-bottom: 10px;
}

.modal h2 {
  margin: 0 0 8px;
  font: 900 clamp(26px, 8vw, 34px)/1.05 var(--font);
  letter-spacing: 0.02em;
}

.modal-text {
  margin: 0 0 22px;
  font-size: 12px;
  color: var(--muted);
}

.modal .btn { width: 100%; }
.modal .btn + .btn { margin-top: 9px; }

.record-badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid rgba(255, 207, 107, 0.45);
  background: rgba(255, 207, 107, 0.1);
  font: 700 8px/1 var(--mono);
  letter-spacing: 0.2em;
  color: var(--gold);
  box-shadow: 0 0 20px rgba(255, 207, 107, 0.15);
}

.record-badge.hidden { display: none; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 20px 0 22px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(126, 200, 255, 0.12);
}

.result-grid > div {
  background: rgba(5, 11, 24, 0.92);
  padding: 14px 8px;
}

.result-grid span {
  display: block;
  margin-bottom: 6px;
  font: 700 7px/1 var(--mono);
  letter-spacing: 0.22em;
  color: var(--dim);
}

.result-grid strong {
  font: 700 22px/1 var(--mono);
  color: var(--cyan);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.gameover .modal-kicker { color: var(--danger); }

.safe-probe {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: env(safe-area-inset-bottom, 0px);
  visibility: hidden;
  pointer-events: none;
}

/* ---------- Responsive ---------- */

@media (pointer: coarse), (hover: none) {
  .hint-desktop { display: none; }
  .hint-touch { display: block; }
  #game { cursor: default; }
}

@media (max-height: 700px) {
  .menu-top { padding-top: 8px; }
  .tagline { margin-top: 12px; }
  .menu-bottom { padding-top: 16px; gap: 9px; }
  .best-row { padding: 7px 2px; }
  .hint { display: none; }
  .meta-row { display: none; }
}

@media (max-height: 700px) and (pointer: fine) {
  .hint-desktop { display: block; font-size: 9px; line-height: 1.45; }
}

@media (max-height: 700px) and (pointer: coarse), (max-height: 700px) and (hover: none) {
  .hint-touch { display: block; font-size: 9px; line-height: 1.45; }
}

@media (max-height: 540px) {
  .logo { font-size: clamp(34px, 10vh, 52px); }
  .tagline { display: none; }
  .menu-bottom { padding-top: 12px; gap: 8px; }
  .btn { min-height: 46px; }
  .hint { display: none; }
  .meta-row { display: none; }
  .hud { padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
  .hud-label { font-size: 7px; }
  .hud-value { font-size: 13px; }
  .hud-wave { font-size: 8px; }
  .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
  .boss-hud { top: calc(46px + env(safe-area-inset-top, 0px)); }
}

@media (min-width: 760px) and (min-height: 700px) {
  .tagline { font-size: 14px; }
  .menu-bottom { padding-top: 40px; }
}

@media (max-height: 540px) {
  .modal {
    max-width: 340px;
    padding: 20px 18px 16px;
    border-radius: 19px;
  }
  .modal h2 { font-size: 24px; margin-bottom: 6px; }
  .modal-kicker { margin-bottom: 6px; }
  .modal-text { display: none; }
  .result-grid { margin: 12px 0 14px; }
  .result-grid > div { padding: 9px 6px; }
  .result-grid strong { font-size: 18px; }
  .modal .btn { min-height: 44px; }
  .modal .btn + .btn { margin-top: 7px; }
}

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