/**
 * Player UI styles (toolbar, upgrade bars, game-over overlay).
 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0f;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

body.play-page {
  overscroll-behavior: none;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Fill available height so content doesn't leave a gap at the bottom */
#root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#root > * {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Fix play page to viewport so no gap under upgrade bar (parent chain doesn't pass height) */
.play-page-container {
  position: fixed;
  inset: 0;
  top: env(safe-area-inset-top);
  right: env(safe-area-inset-right);
  bottom: env(safe-area-inset-bottom);
  left: env(safe-area-inset-left);
  width: auto;
  height: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0a0a0f;
}

.play-page-container #game-wrapper {
  touch-action: manipulation;
}

.pause-bar {
  flex-shrink: 0;
}

.pause-overlay {
  overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

#game-wrapper .game-info-btn {
  top: max(8px, env(safe-area-inset-top, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
}

#game-wrapper .game-info-overlay {
  top: max(48px, calc(env(safe-area-inset-top, 0px) + 44px));
  right: max(8px, env(safe-area-inset-right, 0px));
  left: max(8px, env(safe-area-inset-left, 0px));
  max-height: min(70vh, 400px);
  overflow-y: auto;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* Game over overlay */
#game-overlay {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.6);
  overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-overlay.visible {
  display: flex;
  pointer-events: auto;
}

#game-overlay .game-over-title {
  font-family: monospace;
  font-size: clamp(28px, 8vw, 56px);
  font-weight: bold;
  color: #ff3366;
  text-shadow: 0 0 20px rgba(255, 51, 102, 0.5);
}

#game-overlay .game-over-stats {
  font-family: monospace;
  font-size: clamp(14px, 4vw, 18px);
  color: rgba(0, 255, 204, 0.95);
}

#game-overlay .btn-replay-overlay {
  padding: 12px 28px;
  min-height: 44px;
  min-width: 44px;
  font-family: monospace;
  font-size: 18px;
  font-weight: 600;
  color: #00ffcc;
  background: rgba(0, 255, 204, 0.15);
  border: 2px solid #00ffcc;
  border-radius: 6px;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s, box-shadow 0.15s;
}

#game-overlay .btn-replay-overlay:hover,
#game-overlay .btn-replay-overlay:active {
  background: rgba(0, 255, 204, 0.3);
  box-shadow: 0 0 20px rgba(0, 255, 204, 0.4);
}

#game-overlay .btn-back-overlay {
  padding: 12px 28px;
  min-height: 44px;
  min-width: 44px;
  font-family: monospace;
  font-size: 18px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

#game-overlay .btn-back-overlay:hover,
#game-overlay .btn-back-overlay:active {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.3);
}

#game-overlay .btn-save-overlay {
  padding: 12px 28px;
  min-height: 44px;
  min-width: 44px;
  font-family: monospace;
  font-size: 18px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

#game-overlay .btn-save-overlay:hover,
#game-overlay .btn-save-overlay:active {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.3);
}

/* Upgrade bars — never shrink so they stay visible on small viewports */
#upgrade-bars {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  min-height: 52px;
  height: 64px;
  background: #0a0a0f;
  border-top: 1px solid rgba(0, 255, 204, 0.3);
}

#upgrade-bars.is-game-over {
  display: none !important;
}

.player-upgrade-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  background: #1a1a2e;
  padding: 0 8px;
}

.player-upgrade-bar .upgrade-buttons {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.player-upgrade-bar + .player-upgrade-bar {
  border-left: 1px solid rgba(0, 255, 204, 0.2);
}

.player-upgrade-bar .life-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.player-upgrade-bar .life-bar {
  width: 100px;
  min-width: 100px;
  height: 18px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 51, 102, 0.5);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  box-shadow: 0 0 8px rgba(255, 51, 102, 0.2);
}

.player-upgrade-bar .life-bar-fill {
  width: 100%;
  min-width: 0;
  height: 100%;
  background: linear-gradient(90deg, #cc2255, #ff3366);
  border-radius: 3px;
  transition: width 0.15s ease-out;
}

.player-upgrade-bar .player-money {
  font-family: monospace;
  font-size: 15px;
  font-weight: 700;
  color: #ffd700 !important;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
  min-width: 4ch;
  flex-shrink: 0;
}

.player-upgrade-bar button {
  padding: 10px 14px;
  min-height: 44px;
  min-width: 44px;
  font-family: monospace;
  font-size: clamp(10px, 1.5vw, 11px);
  font-weight: 600;
  color: #00ffcc;
  background: rgba(0, 255, 204, 0.1);
  border: 1px solid #00ffcc;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.player-upgrade-bar button:hover:not(:disabled) {
  background: rgba(0, 255, 204, 0.2);
  box-shadow: 0 0 10px rgba(0, 255, 204, 0.3);
}

.player-upgrade-bar button:active:not(:disabled) {
  background: rgba(0, 255, 204, 0.25);
}

.player-upgrade-bar button:disabled,
.player-upgrade-bar button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  color: #556;
  border-color: #334;
  background: rgba(20, 20, 30, 0.8);
  box-shadow: none;
}

/* Replay toolbar */
#replay-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: #0f0f18;
  border-bottom: 1px solid rgba(0, 255, 204, 0.2);
}

#replay-toolbar.is-game-over {
  display: none !important;
}

#replay-toolbar button,
#replay-toolbar label {
  padding: 6px 12px;
  font-family: monospace;
  font-size: 12px;
  color: #00ffcc;
  background: rgba(0, 255, 204, 0.1);
  border: 1px solid #00ffcc;
  border-radius: 4px;
  cursor: pointer;
}

#replay-toolbar button:hover,
#replay-toolbar label:hover {
  background: rgba(0, 255, 204, 0.2);
}

#replay-toolbar input[type="file"] {
  display: none;
}

.replay-speed-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.replay-speed-label {
  font-family: monospace;
  font-size: 12px;
  color: rgba(0, 255, 204, 0.9);
  margin-right: 4px;
}

.replay-speed-btn.active {
  background: rgba(0, 255, 204, 0.3);
}

/* ——— Mobile / responsive (ROADMAP V5) ——— */

@media (max-width: 768px) {
  .pause-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    justify-content: center;
  }

  .pause-bar .speed-group {
    gap: 6px;
  }

  .pause-bar button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
  }

  #game-wrapper .game-info-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  #upgrade-bars {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .player-upgrade-bar {
    min-width: 280px;
    flex-shrink: 0;
    padding: 6px 10px;
  }

  .player-upgrade-bar .life-bar {
    width: 70px;
    min-width: 70px;
  }

  .player-upgrade-bar .player-money {
    font-size: 13px;
  }

  .pause-overlay {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    gap: 16px;
  }

  .pause-overlay button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 24px;
  }
}

#replay-toolbar button,
#replay-toolbar label {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
}

/* Custom page responsive */
@media (max-width: 768px) {
  .custom-page .custom-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 12px;
  }

  .custom-page .custom-row .custom-label {
    min-width: 0;
  }

  .custom-page .custom-row input[type="range"] {
    min-height: 44px;
    width: 100%;
    max-width: none;
  }

  .custom-page .custom-section {
    padding: 12px;
    margin-bottom: 16px;
  }

  .custom-page .custom-actions {
    flex-wrap: wrap;
    gap: 10px;
  }

  .custom-page .custom-actions a,
  .custom-page .custom-actions button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
  }
}
