:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #02030a;
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

#app,
#canvas-wrap,
#canvas-wrap canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#canvas-wrap canvas {
  display: block;
  outline: none;
}

#hud {
  position: fixed;
  z-index: 10;
  top: calc(10px + var(--safe-top));
  left: calc(14px + var(--safe-left));
  right: calc(14px + var(--safe-right));
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.28);
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.hud-center {
  align-items: center;
}

.hud-right {
  align-items: flex-end;
}

.hud-label {
  color: #ff6464;
  font-size: clamp(10px, 1.45vw, 14px);
  font-weight: 700;
  letter-spacing: 0.12em;
}

#score,
#high-score,
#level {
  font-size: clamp(18px, 2.6vw, 28px);
  line-height: 1;
  letter-spacing: 0.08em;
}

#status-panel {
  position: fixed;
  z-index: 12;
  left: 50%;
  top: 50%;
  width: min(88vw, 520px);
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

#status-panel.hidden {
  opacity: 0;
  transform: translate(-50%, -46%);
}

#status-title {
  color: #ffe600;
  font-size: clamp(26px, 5vw, 54px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow:
    0 0 8px rgba(255, 230, 0, 0.8),
    0 0 26px rgba(255, 178, 0, 0.5),
    3px 3px 0 #9c2a00;
}

#status-subtitle {
  margin-top: 8px;
  color: #fff;
  font-size: clamp(12px, 2vw, 18px);
  font-weight: 700;
  line-height: 1.5;
  text-shadow: 0 0 9px #000, 0 2px 2px #000;
}

#bonus-toast {
  position: fixed;
  z-index: 13;
  left: 50%;
  top: 43%;
  min-height: 1em;
  transform: translate(-50%, -50%) scale(0.8);
  color: #7ffcff;
  font-size: clamp(20px, 4vw, 38px);
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 12px currentColor, 2px 2px 0 #00154a;
}

#bonus-toast.show {
  animation: bonus-pop 700ms ease-out both;
}

@keyframes bonus-pop {
  0% { opacity: 0; transform: translate(-50%, -35%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -62%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -85%) scale(0.9); }
}

#lives {
  position: fixed;
  z-index: 10;
  left: calc(16px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  gap: 7px;
  pointer-events: none;
}

.life-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffe600;
  box-shadow: 0 0 9px rgba(255, 230, 0, 0.9);
  clip-path: polygon(0 0, 100% 0, 52% 50%, 100% 100%, 0 100%);
}

#top-actions {
  position: fixed;
  z-index: 14;
  top: calc(72px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  max-width: min(92vw, 560px);
}

#top-actions button {
  min-height: 34px;
  border: 1px solid rgba(95, 174, 255, 0.65);
  border-radius: 999px;
  padding: 7px 12px;
  color: #eaf6ff;
  background: rgba(3, 13, 38, 0.72);
  box-shadow: inset 0 0 14px rgba(0, 92, 255, 0.13), 0 0 12px rgba(0, 95, 255, 0.12);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

#top-actions button:hover,
#top-actions button:focus-visible {
  border-color: #75d8ff;
  background: rgba(7, 35, 86, 0.9);
  outline: none;
}

#top-actions button:active {
  transform: translateY(1px) scale(0.98);
}

#touch-controls {
  position: fixed;
  z-index: 15;
  right: calc(18px + var(--safe-right));
  bottom: calc(18px + var(--safe-bottom));
  width: 142px;
  height: 142px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
}

.dir {
  border: 1px solid rgba(91, 190, 255, 0.7);
  border-radius: 14px;
  color: #fff;
  background: rgba(4, 20, 52, 0.62);
  box-shadow: inset 0 0 16px rgba(0, 111, 255, 0.18), 0 0 12px rgba(0, 111, 255, 0.1);
  backdrop-filter: blur(6px);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dir:active,
.dir.pressed {
  background: rgba(0, 96, 210, 0.78);
  transform: scale(0.94);
}

.dir.up { grid-column: 2; grid-row: 1; }
.dir.left { grid-column: 1; grid-row: 2; }
.dir.down { grid-column: 2; grid-row: 3; }
.dir.right { grid-column: 3; grid-row: 2; }

#help {
  position: fixed;
  z-index: 9;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  color: rgba(215, 230, 255, 0.68);
  font-size: 11px;
  pointer-events: none;
  white-space: nowrap;
}

noscript {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: #02030a;
  color: #fff;
}

@media (hover: hover) and (pointer: fine) and (min-width: 850px) {
  #touch-controls {
    opacity: 0.34;
    transition: opacity 160ms ease;
  }

  #touch-controls:hover,
  #touch-controls:focus-within {
    opacity: 1;
  }
}

@media (max-width: 760px) {
  #top-actions {
    top: calc(62px + var(--safe-top));
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    justify-content: center;
  }

  #top-actions button {
    min-height: 31px;
    padding: 5px 9px;
    font-size: 11px;
  }

  #touch-controls {
    right: calc(12px + var(--safe-right));
    bottom: calc(12px + var(--safe-bottom));
    width: 126px;
    height: 126px;
  }

  #lives {
    bottom: calc(22px + var(--safe-bottom));
  }

  #help {
    display: none;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  #top-actions {
    top: calc(52px + var(--safe-top));
  }

  #touch-controls {
    width: 112px;
    height: 112px;
  }
}
