* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: sans-serif;
  background: linear-gradient(180deg, #10192f 0%, #18294f 100%);
  color: #eef4ff;
}

body.theme-orange {
  font-family: "Exo 2", sans-serif;
  background: linear-gradient(180deg, #402010 0%, #7a3b14 40%, #b45a12 100%);
}

body.theme-backrooms {
  font-family: "Builder Marker", "Permanent Marker", sans-serif;
  background: linear-gradient(180deg, #d8c663 0%, #e4d472 45%, #c9b24a 100%);
}

body.theme-jungle {
  background: linear-gradient(180deg, #05351b 0%, #0a4a26 40%, #0e331e 100%);
  color: #e8ffef;
  font-family: "Wild Jungle SVG", system-ui, sans-serif;
}

body.theme-blank {
  background: linear-gradient(180deg, #5a5a5f 0%, #2f2f33 55%, #141416 100%);
  color: #f2f2f2;
  font-family: "Press Start 2P", system-ui, monospace;
}

body.theme-blank .hud p,
body.theme-blank .legend {
  color: rgba(242, 242, 242, 0.78);
}

body.theme-blank .controls {
  color: rgba(242, 242, 242, 0.88);
}

.game-shell {
  width: min(1040px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

.hud,
.legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.hud h1 {
  margin: 0 0 4px;
  font-size: 2rem;
}

.hud p,
.legend {
  margin: 0;
  color: #c9d7ff;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-size: 0.95rem;
  color: #dce6ff;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 18px 0 16px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: #7ec8f6;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.legend {
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.settings {
  margin-top: 20px;
  padding: 16px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.settings h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: #c9d7ff;
}

.settings label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: #dce6ff;
}

.settings label span {
  min-width: 110px;
}

.settings input[type="range"] {
  width: 160px;
  height: 6px;
  accent-color: #53d58d;
}

.theme-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-buttons button {
  padding: 8px 18px;
  font-size: 0.95rem;
  font-family: inherit;
  color: #10192f;
  background: #c9d7ff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.theme-buttons button:hover {
  background: #dce6ff;
}

.theme-buttons button[aria-pressed="true"] {
  background: #53d58d;
  color: #0d1f14;
}

/* Mobile controls: hidden on desktop */
.mobile-controls {
  display: none;
}

@media (max-width: 900px) {
  /* On mobile, settings are shown only while paused. */
  .settings {
    display: none;
  }

  body.game-paused .settings {
    display: block;
  }

  body.game-ended .settings {
    display: block;
  }

  .mobile-controls {
    display: flex;
    position: fixed;
    bottom: calc(40px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 20;
  }

  body.game-paused .mobile-controls-left {
    display: flex;
  }

  body.game-paused .mobile-controls-center,
  body.game-paused .mobile-controls-right {
    display: none;
  }

  body.game-paused .mobile-controls {
    justify-content: flex-end;
  }

  /* When ended (won/lost) on mobile, show settings + keep only Restart visible. */
  body.game-ended .mobile-controls-left,
  body.game-ended .mobile-controls-center {
    display: none;
  }

  body.game-ended .mobile-controls-right .mobile-btn:not(.mobile-btn-restart) {
    display: none;
  }

  body.game-ended .mobile-controls {
    justify-content: flex-end;
  }

  .mobile-controls > * {
    pointer-events: auto;
    display: flex;
    gap: 10px;
    align-items: center;
  }

  .mobile-btn {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    padding: 0;
    font-size: 1.5rem;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }

  .mobile-btn:active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
  }

  .mobile-btn-jump {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
    font-size: 1.75rem;
  }
}

@media (max-width: 768px) {
  .hud,
  .legend {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls {
    align-items: flex-start;
  }
}
