:root {
  --bg-a: #081b2f;
  --bg-b: #13395f;
  --bg-c: #1b6a8f;
  --accent: #47e6ff;
  --danger: #ff5470;
  --text: #eef9ff;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  background-color: var(--bg-a);
  background: radial-gradient(circle at 20% 20%, var(--bg-c), var(--bg-a) 55%),
    linear-gradient(145deg, var(--bg-b), var(--bg-a));
}

body {
  position: fixed;
  inset: 0;
}

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--app-height, 100dvh);
  isolation: isolate;
  background: radial-gradient(circle at 20% 20%, var(--bg-c), var(--bg-a) 55%),
    linear-gradient(145deg, var(--bg-b), var(--bg-a));
}

#app.playing canvas {
  cursor: none;
}

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

.loading-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 30;
  background: radial-gradient(circle at 20% 20%, rgba(28, 88, 128, 0.52), rgba(8, 27, 47, 0.92) 56%),
    linear-gradient(145deg, rgba(19, 57, 95, 0.9), rgba(8, 27, 47, 0.95));
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.loading-screen.visible {
  opacity: 1;
  pointer-events: auto;
}

.loading-card {
  width: min(86vw, 420px);
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid rgba(131, 233, 255, 0.5);
  background: linear-gradient(165deg, rgba(9, 38, 64, 0.92), rgba(10, 28, 49, 0.9));
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.4), 0 0 20px rgba(71, 230, 255, 0.16);
  text-align: center;
}

.loading-card h2 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.1rem, 3.8vw, 1.4rem);
}

.loading-card p {
  margin: 0;
  opacity: 0.9;
  font-size: 0.92rem;
}

.loading-bar {
  margin-top: 0.72rem;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(129, 211, 245, 0.2);
}

.loading-bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(105, 214, 255, 0.7), rgba(129, 244, 255, 0.98), rgba(105, 214, 255, 0.7));
  background-size: 200% 100%;
  animation: loading-shimmer 1.1s linear infinite;
}

@keyframes loading-shimmer {
  from {
    background-position: 0% 0%;
  }
  to {
    background-position: 200% 0%;
  }
}

.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.38rem;
  padding: 0 0.55rem;
  pointer-events: none;
  z-index: 5;
  transition: opacity 220ms ease;
}

.hud-block {
  min-width: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid rgba(124, 236, 255, 0.5);
  border-radius: 12px;
  text-align: center;
  backdrop-filter: blur(6px);
  background: rgba(8, 31, 49, 0.48);
  box-shadow: 0 0 18px rgba(71, 230, 255, 0.2);
}

.hud-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
}

.hud-value {
  font-size: 1.2rem;
  font-weight: 800;
}

.hud-value.combo {
  color: #fff4a3;
  text-shadow: 0 0 10px rgba(255, 247, 187, 0.8);
}

.lives-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 1.5rem;
}

.hud.hidden {
  opacity: 0;
}

.score-popups {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 7;
}

.combo-popups {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 12;
}

.boss-popups {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 13;
}

.perf-hud {
  position: absolute;
  right: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  max-width: min(88vw, 360px);
  padding: 0.42rem 0.52rem;
  border-radius: 10px;
  border: 1px solid rgba(144, 233, 255, 0.45);
  background: rgba(7, 24, 41, 0.76);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.38);
  color: #dbf7ff;
  font: 600 11px/1.35 "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-line;
  letter-spacing: 0.01em;
  z-index: 40;
  pointer-events: none;
}

.score-popup {
  position: absolute;
  left: 0;
  top: 0;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  font-size: clamp(1rem, 3.5vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #ffb86a;
  text-shadow: 0 0 10px rgba(255, 186, 106, 0.8), 0 2px 3px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translate3d(0, 0, 0) scale(0.66);
  animation: score-pop var(--dur, 620ms) cubic-bezier(0.22, 0.85, 0.22, 1) forwards;
  will-change: transform, opacity;
}

.score-popup-med {
  font-size: clamp(0.86rem, 3vw, 1.06rem);
  color: #ffc892;
  text-shadow: 0 0 9px rgba(255, 191, 122, 0.72), 0 1px 2px rgba(0, 0, 0, 0.4);
}

@keyframes score-pop {
  0% {
    opacity: 0;
    transform: translate3d(var(--drift-x, 0px), 0, 0) scale(0.66);
  }
  14% {
    opacity: 1;
  }
  66% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift-x, 0px), calc(var(--rise, 32px) * -1), 0) scale(1.08);
  }
}

.combo-popup {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.62);
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  font-size: clamp(0.94rem, 4.2vw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #ffed95;
  padding: 0.14rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 229, 148, 0.48);
  background: linear-gradient(180deg, rgba(78, 46, 11, 0.5), rgba(50, 28, 8, 0.45));
  -webkit-text-stroke: 1px rgba(57, 42, 2, 0.72);
  text-shadow: 0 0 10px rgba(255, 212, 95, 0.68), 0 2px 5px rgba(0, 0, 0, 0.46);
  box-shadow: 0 0 12px rgba(255, 207, 94, 0.22), inset 0 1px 0 rgba(255, 246, 207, 0.22);
  opacity: 0;
  animation: combo-burst 760ms cubic-bezier(0.16, 0.85, 0.23, 1) forwards;
  will-change: transform, opacity;
}

@keyframes combo-burst {
  0% {
    opacity: 0;
    transform: translate(calc(-50% + var(--drift-x, 0px)), -50%) scale(0.62);
  }
  18% {
    opacity: 1;
    transform: translate(calc(-50% + var(--drift-x, 0px)), -50%) scale(1.17);
  }
  68% {
    opacity: 1;
    transform: translate(calc(-50% + var(--drift-x, 0px)), -50%) scale(1.02);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--drift-x, 0px)), calc(-50% - 34px)) scale(0.95);
  }
}

.boss-arrival-popup {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.74);
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  font-size: clamp(1rem, 4.2vw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #fff6c3;
  padding: 0.2rem 0.56rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 232, 155, 0.62);
  background: linear-gradient(180deg, rgba(84, 52, 14, 0.62), rgba(54, 32, 9, 0.58));
  -webkit-text-stroke: 1px rgba(43, 31, 4, 0.75);
  text-shadow: 0 0 12px rgba(255, 220, 122, 0.86), 0 2px 6px rgba(0, 0, 0, 0.44);
  box-shadow: 0 0 16px rgba(255, 205, 86, 0.3), inset 0 1px 0 rgba(255, 247, 210, 0.26);
  opacity: 0;
  animation: boss-arrival-burst 1050ms cubic-bezier(0.18, 0.82, 0.24, 1) forwards;
  will-change: transform, opacity;
}

@keyframes boss-arrival-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.74);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  68% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 16px)) scale(0.96);
  }
}

.life-heart {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  line-height: 1;
  transform: translateY(-0.5px);
  user-select: none;
  background: url("./assets/images/menu/heart.webp") center / contain no-repeat;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.42));
}

.life-heart.on {
  opacity: 1;
}

.life-heart.off {
  opacity: 0.35;
  filter: grayscale(0.6) brightness(0.9);
}

.panel {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(88vw, 420px);
  height: max-content;
  padding: 1.5rem 1.15rem;
  border-radius: 18px;
  border: 1px solid rgba(101, 232, 255, 0.45);
  background: linear-gradient(165deg, rgba(9, 38, 64, 0.95), rgba(11, 21, 44, 0.92));
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45), 0 0 20px rgba(71, 230, 255, 0.16);
  text-align: center;
  transform: translateY(22px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 260ms ease, opacity 260ms ease;
  z-index: 9;
}

.panel.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

#startScreen.panel {
  width: min(94vw, 760px);
  max-height: calc(var(--app-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px);
  padding: clamp(1.25rem, 2.4vh, 1.9rem) clamp(0.95rem, 2.3vw, 1.6rem);
  overflow-y: auto;
}

.start-top-best {
  position: absolute;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  transform: translateX(-50%);
  width: min(72%, 230px);
  padding: 0.42rem 0.7rem 0.5rem;
  border-radius: 12px;
  border: 1px solid rgba(129, 233, 255, 0.54);
  background: linear-gradient(165deg, rgba(10, 48, 78, 0.8), rgba(8, 27, 47, 0.86));
  box-shadow: inset 0 1px 0 rgba(222, 248, 255, 0.2), 0 0 18px rgba(71, 230, 255, 0.22);
  text-align: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

#app.show-start-best .start-top-best {
  opacity: 1;
}

.start-best-label {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.82;
}

.start-best-value {
  display: block;
  margin-top: 0.1rem;
  font-size: clamp(1.25rem, 4.2vw, 1.8rem);
  line-height: 1;
  color: #eaf9ff;
  text-shadow: 0 0 10px rgba(104, 226, 255, 0.52);
}

.start-legend {
  margin: 0.7rem 0 0.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.52rem;
}

#startScreen .start-legend {
  margin: 0.9rem 0 0.65rem;
  gap: 0.72rem;
}

.legend-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-radius: 11px;
  border: 1px solid rgba(139, 224, 255, 0.33);
  background: linear-gradient(170deg, rgba(18, 49, 74, 0.72), rgba(10, 32, 53, 0.75));
}

#startScreen .legend-item {
  min-height: 98px;
  gap: 0.66rem;
  padding: 0.58rem 0.66rem;
  border-radius: 14px;
}

.legend-item.danger {
  border-color: rgba(255, 135, 171, 0.4);
  background: linear-gradient(170deg, rgba(65, 27, 49, 0.56), rgba(35, 18, 35, 0.7));
}

.legend-item p {
  margin: 0;
  line-height: 1.2;
  font-size: 0.72rem;
  opacity: 0.96;
}

#startScreen .legend-item p {
  line-height: 1.23;
  font-size: clamp(0.92rem, 2vw, 1rem);
}

.legend-item strong {
  font-size: 0.78rem;
}

#startScreen .legend-item strong {
  display: block;
  margin-bottom: 0.1rem;
  font-size: clamp(1.28rem, 2.4vw, 1.42rem);
}

.legend-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: inline-block;
  position: relative;
}

#startScreen .legend-icon {
  width: 40px;
  height: 40px;
}

.icon-pill {
  width: 36px;
  height: 36px;
  margin-top: 0;
  background: url("./assets/images/pills/vitamin.webp") center / contain no-repeat;
  filter: drop-shadow(0 2px 3px rgba(6, 23, 38, 0.55));
}

#startScreen .icon-pill {
  width: 44px;
  height: 44px;
}

.icon-pack {
  width: 36px;
  height: 36px;
  background: url("./assets/images/packs/ibuprofen.webp") center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(6, 23, 38, 0.58));
}

#startScreen .icon-pack {
  width: 44px;
  height: 44px;
}

.icon-virus {
  width: 36px;
  height: 36px;
  background: url("./assets/images/hazards/virus.webp") center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(6, 23, 38, 0.58));
}

#startScreen .icon-virus {
  width: 44px;
  height: 44px;
}

.icon-syringe {
  width: 36px;
  height: 36px;
  background: url("./assets/images/hazards/syringe.webp") center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(6, 23, 38, 0.58));
}

#startScreen .icon-syringe {
  width: 44px;
  height: 44px;
}

h1,
h2 {
  margin: 0.2rem 0 0.45rem;
  font-size: clamp(1.75rem, 5.2vw, 2.4rem);
  letter-spacing: 0.03em;
}

#startScreen h1 {
  margin: 0.05rem 0 0.58rem;
  font-size: clamp(2rem, 6.4vw, 3.35rem);
}

#startScreen > p {
  margin: 0.48rem auto 0.7rem;
  max-width: 90%;
  font-size: clamp(1rem, 2.4vw, 1.24rem);
}

p {
  margin: 0.4rem 0;
}

.hint {
  opacity: 0.85;
  font-size: 0.92rem;
}

#startScreen .hint {
  margin-top: 0.7rem;
  font-size: clamp(0.98rem, 2.2vw, 1.12rem);
}

.cta {
  margin-top: 1rem;
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  color: #05273b;
  background: linear-gradient(120deg, #89f4ff, #4dc5ff);
  box-shadow: 0 8px 22px rgba(77, 197, 255, 0.4);
}

#startScreen .cta {
  margin-top: 1.15rem;
  min-width: 172px;
  padding: 0.82rem 1.45rem;
  font-size: 1.18rem;
}

.cta:active {
  transform: translateY(1px) scale(0.99);
}

@media (max-width: 390px) {
  #startScreen.panel {
    width: min(95vw, 430px);
    padding: 1rem 0.72rem 1.08rem;
  }

  .hud {
    gap: 0.3rem;
    padding: 0 0.42rem;
  }

  .hud-block {
    padding: 0.3rem 0.3rem;
  }

  .hud-label {
    font-size: 0.58rem;
  }

  .hud-value {
    font-size: 1.06rem;
  }

  .start-legend {
    grid-template-columns: 1fr 1fr;
    gap: 0.48rem;
  }

  #startScreen h1 {
    margin: 0.02rem 0 0.4rem;
    font-size: clamp(1.58rem, 8vw, 1.96rem);
  }

  #startScreen > p {
    margin: 0.34rem auto 0.52rem;
    max-width: 96%;
    font-size: clamp(0.92rem, 4.1vw, 1rem);
    line-height: 1.18;
  }

  #startScreen .legend-item {
    min-height: 82px;
    padding: 0.42rem 0.44rem;
    gap: 0.44rem;
    border-radius: 12px;
  }

  #startScreen .legend-item strong {
    margin-bottom: 0.02rem;
    font-size: clamp(0.94rem, 5vw, 1.06rem);
  }

  #startScreen .legend-item p {
    font-size: clamp(0.78rem, 3.35vw, 0.9rem);
    line-height: 1.12;
  }

  #startScreen .legend-icon,
  #startScreen .icon-pill,
  #startScreen .icon-pack,
  #startScreen .icon-virus,
  #startScreen .icon-syringe {
    width: 32px;
    height: 32px;
  }

  #startScreen .hint {
    margin-top: 0.52rem;
    font-size: clamp(0.88rem, 3.7vw, 0.96rem);
  }

  #startScreen .cta {
    margin-top: 0.74rem;
    min-width: 148px;
    padding: 0.68rem 1.2rem;
    font-size: 1.04rem;
  }
}
