:root { --safe-bottom: env(safe-area-inset-bottom, 0px); }

html, body {
  overscroll-behavior: none;
}

#game-wrapper {
  height: calc(100vh - var(--header-height, 0px) - var(--bottom-nav-height, 0px));
  height: calc(100dvh - var(--header-height, 0px) - var(--bottom-nav-height, 0px));
  position: relative;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  transition: opacity 0.3s;
  z-index: 500;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Start screen shows the tunnel behind it */
#startOverlay {
  background: rgba(8, 3, 2, 0.58);
  backdrop-filter: blur(2px);
}


.overlay-content {
  width: min(92vw, 640px);
  max-height: min(calc(100dvh - var(--header-height, 0px) - var(--bottom-nav-height, 0px) - 24px), 88vh);
  overflow: auto;
  padding: 24px 22px;
  border-radius: 18px;
  border: 2px solid rgba(186, 218, 85, 0.35);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.55);
}

@media (max-height: 600px), (max-width: 420px) {
  .overlay-content {
    padding: 14px 14px;
    border-radius: 12px;
  }
  .score-display {
    font-size: 1.3rem;
    margin-bottom: 14px;
  }
  .btn {
    padding: 14px 28px;
    font-size: 1.1rem;
    min-width: 140px;
    min-height: 48px;
  }
  .lb-wrap { margin-top: 10px; gap: 12px; }
  .lb-col h3 { font-size: 13px; }
  .lb-list   { font-size: 12px; }
}

.title-start    { color: #00d9ff; }
.title-gameover { color: #ff4d4d; }

.controls {
  color: white;
  font-size: 1.2rem;
  margin-bottom: 30px;
  padding: 0 20px;
  text-align: center;
}

@media (max-width: 768px) {
  .controls { font-size: 1rem; margin-bottom: 20px; }
}

.score-display {
  color: white;
  font-size: 2rem;
  margin-bottom: 5px;
  display: flex;
  justify-content: center;
}

.btn {
  padding: 10px 15px;
  font-size: 1.5rem;
  font-weight: bold;
  background: #bada55;
  color: #0b5285;
  border: 4px solid #0b74bf;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 8px 0 #0b74bf;
  transition: all 0.1s;
  min-width: 200px;
  min-height: 60px;
}

@media (max-width: 768px) {
  .btn { padding: 18px 40px; font-size: 1.3rem; min-width: 180px; min-height: 56px; }
}

.btn:hover  { box-shadow: 0 4px 0 #0b74bf; transform: translateY(4px); }
.btn:active { box-shadow: 0 2px 0 #0b74bf; transform: translateY(6px); }

/* In-game stats HUD (top-left) */
.stats {
  position: absolute;
  top: 15px;
  left: 15px;
  background: none;
  color: white;
  padding: 0;
  border-radius: 12px;
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 1px;
  border: none;
  text-align: left;
  pointer-events: none;
  line-height: 1.5;
}

.stats .game-title-hud {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #bada55;
  opacity: 0.75;
  margin-bottom: 2px;
}

.stats .score-hud { font-size: 1.1rem; color: #ffffff; }

@media (max-width: 768px) {
  .stats              { font-size: 0.95rem; }
  .stats .game-title-hud { font-size: 0.65rem; }
  .stats .score-hud   { font-size: 0.95rem; }
}

/* Health bar */
.health-bar-container {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 55vw);
  height: 18px;
  pointer-events: none;
}

.health-bar {
  height: 100%;
  box-shadow: 0 0 10px currentColor;
  transition: width 0.3s, background 0.3s;
}

/* Fullscreen: game wrapper fills the whole viewport */
#game-wrapper:fullscreen,
#game-wrapper:-webkit-full-screen,
#game-wrapper:-moz-full-screen,
#game-wrapper:-ms-fullscreen {
  height: 100dvh !important;
  height: 100vh !important;
}

/* Leaderboard */
.lb-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
  width: 100%;
}

@media (max-width: 600px) { .lb-wrap { grid-template-columns: 1fr; } }

.lb-col h3  { margin: 0 0 8px; font-size: 16px; opacity: 0.9; }

.lb-list {
  margin: 0;
  padding-left: 22px;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
               "Liberation Mono", monospace;
  font-size: 14px;
}

.lb-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lb-list .lb-name  { opacity: 0.95; }
.lb-list .lb-score { opacity: 0.85; }
.lb-empty          { opacity: 0.65; padding: 6px 0; }
.lb-title          { margin-top: 10px; }
.lb-sub            { opacity: 0.9; margin-top: -6px; }
.lb-wrap-page      { margin-top: 14px; max-width: 720px; }