@import url("https://fonts.googleapis.com/css2?family=Orbitron:wght@700;800&display=swap");

html,
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #000;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* —— Title screen (fits 16:9 game card) —— */
#title_screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 16px);
  padding: clamp(8px, 2vh, 20px) clamp(12px, 3vw, 28px);
  box-sizing: border-box;
  background: #000;
  background-image:
    radial-gradient(ellipse 80% 55% at 50% 35%, rgba(180, 20, 20, 0.22), transparent 70%),
    linear-gradient(180deg, #050505 0%, #000 100%);
}

#title_logo {
  display: block;
  width: auto;
  height: clamp(72px, 22vh, 160px);
  max-width: min(420px, 55vw);
  object-fit: contain;
  flex-shrink: 0;
  animation: titleIn 0.7s ease-out both;
}

.title-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.6vh, 14px);
  width: min(560px, 92%);
  flex-shrink: 1;
  min-height: 0;
}

.controls-card {
  width: 100%;
  max-height: min(42vh, 260px);
  background: rgba(15, 18, 28, 0.88);
  border: 1px solid rgba(220, 38, 38, 0.45);
  border-radius: 10px;
  padding: clamp(8px, 1.4vh, 14px) clamp(12px, 2vw, 20px);
  box-sizing: border-box;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55), inset 0 0 12px rgba(220, 38, 38, 0.08);
  text-align: center;
  overflow: hidden;
  flex-shrink: 1;
  animation: titleIn 0.7s ease-out 0.1s both;
}

.controls-card h3 {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(10px, 1.6vh, 13px);
  font-weight: 800;
  color: #ff4d4d;
  letter-spacing: 0.14em;
  margin: 0 0 clamp(6px, 1vh, 10px) 0;
  text-transform: uppercase;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.2vw, 14px);
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.6vh, 5px);
  background: rgba(0, 0, 0, 0.4);
  padding: clamp(6px, 1vh, 10px) clamp(8px, 1.2vw, 12px);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: clamp(10px, 1.5vh, 12px);
  line-height: 1.35;
  color: #d1d5db;
  text-align: left;
}

.player-label {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(9px, 1.3vh, 11px);
  font-weight: 700;
  color: #f87171;
  letter-spacing: 0.1em;
  margin-bottom: 1px;
  border-bottom: 1px solid rgba(248, 113, 113, 0.2);
  padding-bottom: 3px;
}

.key-badge {
  display: inline-block;
  background: #262626;
  color: #ffffff;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(9px, 1.35vh, 11px);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #404040;
  box-shadow: 0 1px 0 #171717;
  margin: 0 1px;
  line-height: 1.4;
}

#play_btn {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  min-width: clamp(140px, 22vw, 180px);
  padding: clamp(10px, 1.8vh, 14px) clamp(28px, 5vw, 48px);
  border: 2px solid #ff2a2a;
  background: linear-gradient(180deg, #d41818 0%, #8b0000 100%);
  color: #fff;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(14px, 2.4vh, 20px);
  font-weight: 800;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 8px 22px rgba(180, 0, 0, 0.35);
  animation: playPulse 1.8s ease-in-out infinite, titleIn 0.7s ease-out 0.18s both;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

#play_btn:hover {
  transform: scale(1.04);
  background: linear-gradient(180deg, #ff3030 0%, #b00000 100%);
  box-shadow: 0 0 22px rgba(255, 40, 40, 0.45);
  animation: titleIn 0.7s ease-out 0.18s both;
}

#play_btn:active {
  transform: scale(0.98);
}

#play_btn:disabled {
  opacity: 0.55;
  cursor: wait;
  animation: none;
}

/* Wide landscape: logo left, controls + play right */
@media (min-aspect-ratio: 1.4/1) and (min-height: 360px) {
  #title_screen {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: clamp(16px, 3vw, 36px);
    padding: clamp(12px, 3vh, 28px) clamp(16px, 4vw, 40px);
  }

  #title_logo {
    height: clamp(100px, 36vh, 220px);
    max-width: min(38vw, 400px);
  }

  .title-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(10px, 2vh, 16px);
    width: min(520px, 52vw);
    max-width: min(520px, 52vw);
  }

  .controls-card {
    width: 100%;
    max-height: none;
  }
}

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

@keyframes playPulse {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 8px 22px rgba(180, 0, 0, 0.35);
  }
  50% {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12), 0 8px 30px rgba(255, 40, 40, 0.55);
  }
}

canvas {
  display: none;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#error_message {
  position: absolute;
  top: 0;
  right: 0;
  height: 40px;
  width: 300px;
  background-color: brown;
  color: white;
  padding: 10px;
  transition: all ease-in-out 1s;
  border-radius: 10px;
  z-index: 100;
}

#success_message {
  position: absolute;
  z-index: 100;
  top: 0;
  right: 0;
  height: 40px;
  width: 300px;
  background-color: green;
  color: white;
  padding: 10px;
  transition: all ease-in-out 1s;
  border-radius: 10px;
}

#pause_btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 20;
  padding: 8px 14px;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  font-family: Arial, Helvetica, sans-serif;
  cursor: pointer;
  border-radius: 8px;
}

#pause_btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#pause_overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
}

#pause_overlay.hidden {
  display: none !important;
}

.pause_panel {
  text-align: center;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
}

.pause_panel h1 {
  font-size: clamp(28px, 6vh, 48px);
  margin: 0 0 12px;
}

.pause_panel p {
  margin: 0 0 20px;
  opacity: 0.85;
}

#resume_btn {
  padding: 10px 24px;
  border: 2px solid #fff;
  background: #c62828;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
}

#resume_btn:hover {
  background: #e53935;
}

#game_win {
  width: 100%;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  background-color: black;
  color: white;
  font-size: clamp(22px, 4vh, 40px);
  text-align: center;
  display: none;
  align-items: center;
  justify-content: center;
  padding-top: 0;
}

#game_over {
  z-index: 40;
  width: 100%;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.92);
}

#game_over.hidden {
  display: none !important;
}

.game_over_panel {
  text-align: center;
  font-family: "Orbitron", Arial, Helvetica, sans-serif;
}

#game_over h1 {
  font-size: clamp(28px, 7vh, 52px);
  color: #ff2a2a;
  margin: 0 0 12px;
  letter-spacing: 0.08em;
}

#game_over h2 {
  font-size: clamp(14px, 2.5vh, 22px);
  color: white;
  margin: 0 0 24px;
  font-weight: 500;
  line-height: 1.5;
}

#restart_btn {
  min-width: 160px;
  padding: 12px 32px;
  border: 2px solid #ff2a2a;
  background: linear-gradient(180deg, #d41818 0%, #8b0000 100%);
  color: #fff;
  font-family: "Orbitron", Arial, Helvetica, sans-serif;
  font-size: clamp(14px, 2.2vh, 18px);
  font-weight: 800;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.15s ease, background 0.15s ease;
}

#restart_btn:hover {
  transform: scale(1.05);
  background: linear-gradient(180deg, #ff3030 0%, #b00000 100%);
}

@media (max-width: 520px), (max-height: 420px) {
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #title_logo {
    height: clamp(56px, 18vh, 100px);
  }

  .controls-card {
    max-height: min(50vh, 280px);
    overflow-y: auto;
  }
}

html, body {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* —— Mobile touch controls —— */
#mobile-controls {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}

#mobile-controls.hidden {
  display: none !important;
}

.touch-cluster {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}

.touch-dpad {
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  left: max(12px, env(safe-area-inset-left, 0px));
  display: grid;
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  gap: 6px;
}

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

.touch-actions {
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.touch-btn {
  width: 52px;
  height: 52px;
  border: 2px solid rgba(248, 113, 113, 0.85);
  border-radius: 14px;
  background: rgba(20, 8, 8, 0.72);
  color: #fecaca;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.touch-btn.jump,
.touch-btn.fire {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.touch-btn.jump {
  border-color: rgba(251, 191, 36, 0.9);
  color: #fbbf24;
}

.touch-btn.fire {
  border-color: rgba(248, 113, 113, 0.95);
  color: #ff6b6b;
}

.touch-btn:active,
.touch-btn.active {
  background: rgba(220, 38, 38, 0.45);
  transform: scale(0.94);
}

.touch-btn.jump:active,
.touch-btn.jump.active {
  background: rgba(251, 191, 36, 0.32);
}

@media (hover: none) and (pointer: coarse) {
  #mobile-controls:not(.hidden) {
    display: block;
  }
}

@media (hover: hover) and (pointer: fine), (pointer: fine) {
  #mobile-controls {
    display: none !important;
  }
}

@media (max-height: 480px) and (hover: none) and (pointer: coarse) {
  .touch-dpad {
    grid-template-columns: 40px 40px 40px;
    grid-template-rows: 40px 40px 40px;
    gap: 4px;
    bottom: 8px;
    left: 8px;
  }
  .touch-btn { width: 40px; height: 40px; font-size: 0.95rem; border-radius: 10px; }
  .touch-btn.jump,
  .touch-btn.fire { width: 56px; height: 56px; font-size: 0.7rem; }
  .touch-actions { bottom: 12px; right: 10px; gap: 8px; }
}
