* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Share Tech Mono', 'Courier New', monospace;
}

html, body {
  height: 100%;
  width: 100%;
}

body {
  background-color: #0b1118;
  color: #d7e3f4;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.small-header {
  flex-shrink: 0;
}

.game-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.game-container {
  background-color: #0b1118;
  border-radius: 12px;
  box-shadow: none;
  padding: 10px;
  width: 100%;
  height: 100%;
  text-align: center;
  border: none;
  display: flex;
  flex-direction: column;
  position: relative;
}

.game-info {
  margin: 0 auto 10px auto;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  width: 100%;
  max-width: 700px;
}

h1 {
  color: #8a96a8;
  margin-bottom: 0;
  font-size: 1.2rem;
}

.timer-section {
  text-align: right;
}

.timer {
  font-size: 1.2rem;
  font-weight: bold;
  color: #88f0b0;
  margin-bottom: 0;
}

.timer.rescued {
  color: #4CAF50;
}

.best-score {
  font-size: 0.8rem;
  color: #6a7a8a;
  margin-top: 2px;
}

.sound-toggle {
  width: 36px;
  height: 36px;
  padding: 7px;
  align-self: flex-start;
  color: rgba(80, 255, 140, 0.5);
  background: linear-gradient(180deg, #14222e 0%, #0c1620 100%);
  border: 1px solid rgba(80, 255, 140, 0.16);
  border-radius: 8px;
  cursor: pointer;
}

.sound-toggle:hover {
  background: linear-gradient(180deg, #1a2d3a 0%, #102030 100%);
}

.sound-toggle svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sound-toggle .icon-sound-off,
.sound-toggle.is-muted .icon-sound-on {
  display: none;
}

.sound-toggle.is-muted .icon-sound-off {
  display: block;
}

.sound-toggle.is-muted {
  color: #6a7a8a;
}

.rescued-label {
  color: #4CAF50;
  margin-right: 8px;
  font-size: 1rem;
  display: inline;
}

/* Fires once, the moment rescue lands at 120s. The run does NOT stop there —
   the player keeps dodging for a best time — so this can't sit over the radar
   or eat drags: it announces itself, says the run continues, and clears. */
.rescued-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}

.rescued-banner.show {
  animation: rescuedBanner 3.4s ease-out both;
}

.rescued-banner-title {
  font-size: clamp(1.8rem, 9vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7dffae;
  text-shadow: 0 0 18px rgba(80, 255, 140, 0.65),
               0 2px 6px rgba(0, 0, 0, 0.85);
}

.rescued-banner-sub {
  margin-top: 6px;
  font-size: clamp(0.8rem, 3.6vw, 1rem);
  letter-spacing: 0.08em;
  color: #b8f5cf;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
}

@keyframes rescuedBanner {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.82);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  76% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -58%) scale(1);
  }
}

.instructions {
  color: #b8c4d4;
  margin-bottom: 15px;
}

.game-area {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.controls {
  margin-top: 20px;
}

.red-text {
  color: #ff4d4d;
}

.green-text {
  color: #4caf50;
}

button {
  background-color: #2ea043;
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 10px 2px;
  cursor: pointer;
  border-radius: 5px;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #25913b;
}

.control-info {
  color: #9fb0c2;
  font-size: 0.9em;
  margin-bottom: 10px;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 10;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: transparent;
  align-items: center;
  justify-content: center;
}

.modal-content {
  position: relative;
  background-color: rgba(9, 18, 14, 0.92);
  margin: auto;
  padding: 25px 16px;
  border-radius: 10px;
  border: 1px solid rgba(80, 255, 140, 0.35);
  box-shadow: 0 0 45px rgba(80, 255, 140, 0.14),
              0 24px 60px rgba(0, 0, 0, 0.65),
              inset 0 0 30px rgba(80, 255, 140, 0.05);
  width: 80%;
  /* Wide enough for the longest story line ("You're stranded..." at 1.05rem
     monospace ≈ 445px) to stay on one line */
  max-width: 500px;
  text-align: left;
  color: #d9e5f5;

  .start-btn {
    display: block;
    width: 100%;
    padding: 16px 32px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Chakra Petch', 'Share Tech Mono', monospace;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 20px;
    background: linear-gradient(180deg, #38c25a 0%, #22903e 100%);
    border: 1px solid rgba(150, 255, 190, 0.5);
    box-shadow: 0 0 18px rgba(80, 255, 140, 0.35),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: btnPulse 2.2s ease-in-out infinite;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }

  .start-btn:hover {
    transform: translateY(-2px);
    background: linear-gradient(180deg, #43d968 0%, #28a548 100%);
    box-shadow: 0 0 32px rgba(80, 255, 140, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: none;
  }

  .start-btn:active {
    transform: translateY(0);
  }

  .story-section {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(80, 255, 140, 0.2);
    margin-bottom: 15px;

    h1 {
      font-family: 'Chakra Petch', 'Share Tech Mono', monospace;
      /* Fluid size + em-based tracking so the title stays on one line
         down to ~320px screens */
      font-size: clamp(1.2rem, 7vw, 2rem);
      white-space: nowrap;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.16em;
      color: #eafff2;
      text-shadow: 0 0 12px rgba(80, 255, 140, 0.65),
                   0 0 34px rgba(80, 255, 140, 0.3);
      margin-bottom: 16px;
      animation: titleFlicker 4s linear infinite;
    }

    .story-text {
      font-size: 1.05rem;
      color: #88f0b0;
      margin: 8px 0;
      line-height: 1.4;
      /* When the screen is too narrow to avoid wrapping, split into even
         lines rather than orphaning the last word */
      text-wrap: balance;

      .eta {
        color: #eafff2;
        text-shadow: 0 0 10px rgba(80, 255, 140, 0.7);
      }
    }
  }

  .instructions {
    padding: 10px 0px;

    h3 {
      font-family: 'Chakra Petch', 'Share Tech Mono', monospace;
      font-size: 0.85rem;
      color: #6fdd96;
      margin-bottom: 12px;
      text-transform: uppercase;
      letter-spacing: 3px;
    }

    p {
      display: flex;
      align-items: baseline;
      gap: 8px;
      margin: 10px 0px;
      font-size: 0.95rem;
      color: #b8c4d4;
    }
  }
}

/* Welcome panel: scanline overlay + entrance choreography */
.welcome-panel {
  overflow: hidden;
  animation: panelIn 0.55s cubic-bezier(0.18, 0.9, 0.3, 1.15) both;
}

.welcome-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: repeating-linear-gradient(0deg,
    rgba(180, 255, 210, 0.03) 0px, rgba(180, 255, 210, 0.03) 1px,
    transparent 1px, transparent 3px);
}

.welcome-panel > * {
  animation: riseIn 0.5s ease both;
}

.welcome-panel .story-section { animation-delay: 0.25s; }
.welcome-panel .instructions { animation-delay: 0.4s; }
.welcome-panel .start-btn { animation: riseIn 0.5s ease 0.55s both, btnPulse 2.2s ease-in-out 1.05s infinite; }
.welcome-panel .start-btn:hover { animation: none; }

/* Mini radar emblem with rotating sweep */
.radar-emblem {
  position: relative;
  width: 92px;
  height: 92px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 1px solid rgba(80, 255, 140, 0.45);
  background: radial-gradient(circle,
    rgba(80, 255, 140, 0.1) 0%,
    rgba(80, 255, 140, 0.03) 55%,
    transparent 72%);
  box-shadow: 0 0 26px rgba(80, 255, 140, 0.2),
              inset 0 0 18px rgba(80, 255, 140, 0.1);
}

.radar-emblem::before,
.radar-emblem::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(80, 255, 140, 0.22);
}

.radar-emblem::before { inset: 15px; }
.radar-emblem::after { inset: 31px; }

.radar-sweep {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg,
    rgba(80, 255, 140, 0.55) 0deg,
    rgba(80, 255, 140, 0.12) 55deg,
    transparent 80deg);
  animation: radarSpin 3s linear infinite;
}

.radar-blip {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #50ff8c;
  box-shadow: 0 0 8px rgba(80, 255, 140, 0.9);
  animation: blipPing 3s ease-out infinite;
}

.blip-1 { top: 24%; left: 62%; }
.blip-2 { top: 60%; left: 28%; animation-delay: 1.5s; }

/* Legend dots in the instructions */
.threat-dot {
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  align-self: center;
}

.sweep-dot {
  background: #50ff8c;
  box-shadow: 0 0 8px rgba(80, 255, 140, 0.7);
}

.red-dot {
  background: #ff4d4d;
  box-shadow: 0 0 8px rgba(255, 77, 77, 0.7);
  animation: beaconBlink 1.6s ease-in-out infinite;
}

.green-dot {
  background: #4caf50;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.7);
  animation: beaconBlink 1.6s ease-in-out 0.8s infinite;
}

@keyframes panelIn {
  from { opacity: 0; transform: scale(0.92) translateY(18px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes radarSpin {
  to { transform: rotate(360deg); }
}

@keyframes beaconBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@keyframes blipPing {
  0%, 55% { opacity: 0; transform: scale(0.6); }
  60% { opacity: 1; transform: scale(1.4); }
  75% { opacity: 0.8; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.8); }
}

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 14px rgba(80, 255, 140, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  50% { box-shadow: 0 0 30px rgba(80, 255, 140, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
}

@keyframes titleFlicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.75; }
  94% { opacity: 1; }
  96% { opacity: 0.85; }
  97% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .welcome-panel,
  .welcome-panel > *,
  .welcome-panel .start-btn,
  .radar-sweep,
  .radar-blip,
  .red-dot,
  .green-dot,
  .story-section h1 {
    animation: none !important;
  }
}

#gameOverMessage {
  margin-bottom: 15px;
  color: #e6f4ff;
}

#gameOverReason {
  margin-bottom: 20px;
  color: #b8c4d4;
}

/* On-screen arrow keys (pointer devices only — see the touch rule below) */
.key-controls {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  gap: 10px;
  z-index: 2;
  /* Only the key caps themselves should catch taps, not the strip between them */
  pointer-events: none;
}

.key-controls .key-cap {
  pointer-events: auto;
}

.key-cap {
  width: 64px;
  height: 64px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  color: rgba(80, 255, 140, 0.32);
  background: linear-gradient(180deg, #14222e 0%, #0c1620 100%);
  border: 1px solid rgba(80, 255, 140, 0.16);
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.45),
              inset 0 1px 0 rgba(120, 255, 170, 0.15);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.06s ease, background-color 0.15s ease;
}

.key-cap:hover {
  background: linear-gradient(180deg, #1a2d3a 0%, #102030 100%);
}

.key-cap:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45),
              inset 0 1px 0 rgba(120, 255, 170, 0.15);
}

/* Touch devices rotate the radar by dragging it, so the key caps are dead
   weight there — they just cover the canvas. Keyboard/mouse users keep them. */
@media (hover: none) and (pointer: coarse) {
  .key-controls {
    display: none;
  }
}

/* For mobile devices */
@media (max-width: 600px) {
  .game-container {
    padding: 10px;
  }

  button {
    padding: 8px 16px;
    font-size: 14px;
  }

  /* Slightly smaller key caps so they cover less of the canvas */
  .key-cap {
    width: 56px;
    height: 56px;
    font-size: 24px;
  }
}
