:root {
  --frame-border: #33203f;
  --panel-bg: #100a18;
  --text-main: #f7f1c8;
  --text-dim: #c5c0b4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Courier New", Courier, monospace;
  background: radial-gradient(circle at 30% 15%, #49396a 0%, #140f21 48%, #09070f 100%);
  color: var(--text-main);
}

.page {
  width: min(96vw, 900px);
}

.game-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 4px solid var(--frame-border);
  border-radius: 10px;
  overflow: hidden;
  background: #09050d;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  top: 0.7rem;
  right: 0.8rem;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.7rem;
  padding: 0.35rem 0.6rem;
  border: 2px solid rgba(255, 255, 255, 0.32);
  background: rgba(16, 10, 24, 0.75);
  font-size: clamp(0.75rem, 1.8vw, 1rem);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: calc(100% - 1rem);
  pointer-events: none;
}

.hud.score-pulse {
  animation: score-pulse 0.22s ease-in-out infinite alternate;
}

.time-hud {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 13;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #fff4c0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
  max-width: calc(100% - 1rem);
  font-size: clamp(0.95rem, 5vw, 2.7rem);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.time-hud.hidden {
  display: none;
}

.time-hud #time-effect-countdown {
  line-height: 1;
}

.time-hud #time-effect-icon {
  display: block;
  width: clamp(1.2rem, 3.8vw, 2.2rem);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#high-score {
  color: var(--text-dim);
}

.message {
  padding: 0.35rem 0.6rem;
  border: 2px solid rgba(255, 255, 255, 0.32);
  background: rgba(16, 10, 24, 0.75);
  color: var(--text-main);
  font-size: clamp(0.72rem, 1.7vw, 0.95rem);
  letter-spacing: 0.03em;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
  max-width: calc(100% - 1rem);
  pointer-events: none;
}

.overlay-stack {
  position: absolute;
  left: 50%;
  top: max(12%, calc(var(--hud-clearance, 0px) + 0.55rem));
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: min(calc(100% - 1rem), 30rem);
  pointer-events: none;
}

.overlay-stack .message {
  position: static;
  transform: none;
  width: 100%;
  max-width: 100%;
}

.start-instruction {
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translateX(-50%);
  width: fit-content;
  max-width: calc(100% - 1.4rem);
  padding: 0.25rem 0.45rem;
}

.start-instruction-list {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.start-instruction-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.2rem;
  line-height: 1.15;
}

.start-instruction-number {
  color: var(--text-dim);
}

.start-instruction-icon {
  display: block;
  flex: 0 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.agent-icon {
  width: clamp(0.72rem, 2.5vw, 1rem);
  height: auto;
}

.time-icon {
  width: clamp(0.65rem, 2.2vw, 0.85rem);
  height: auto;
}

@media (max-width: 480px) {
  .start-instruction {
    top: 54%;
    font-size: clamp(0.62rem, 2.8vw, 0.78rem);
  }

  .start-instruction-list {
    gap: 0.3rem;
  }
}

.final-score {
  font-size: clamp(0.95rem, 2.3vw, 1.25rem);
}

@keyframes score-pulse {
  from {
    opacity: 1;
    box-shadow: 0 0 0 rgba(247, 241, 200, 0);
  }

  to {
    opacity: 0.55;
    box-shadow: 0 0 12px rgba(247, 241, 200, 0.45);
  }
}

.hidden {
  display: none !important;
}
