/* ============================
   HOPSTER — Global Styles
   ============================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary:    #FF6B35;
  --primary-dk: #CC4A15;
  --accent:     #FFD700;
  --green:      #4CAF50;
  --blue:       #2196F3;
  --dark:       #1a1a2e;
  --panel:      rgba(0,0,0,0.75);
  --radius:     16px;
  --font:       'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d1a;
  font-family: var(--font);
  touch-action: none;
  user-select: none;
}

/* ---- Wrapper ---- */
#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  pointer-events: none;
  z-index: 10;
}

#hud-left, #hud-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#hud-right {
  align-items: flex-end;
}

#score-display, #best-display {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hud-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.6);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

#current-score {
  font-size: 36px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9), 0 0 20px rgba(255,107,53,0.5);
  line-height: 1;
}

#best-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  line-height: 1;
}

#coin-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,215,0,0.4);
  border-radius: 20px;
  padding: 4px 12px;
  pointer-events: none;
}

#coin-icon { font-size: 18px; }
#coin-count { font-size: 18px; font-weight: 800; color: var(--accent); }

#sound-toggle {
  pointer-events: all;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
  margin-top: 6px;
}
#sound-toggle:hover { background: rgba(255,255,255,0.1); transform: scale(1.1); }
#sound-toggle:active { transform: scale(0.95); }

/* ---- Mobile D-Pad ---- */
#mobile-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
}

#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dpad-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dpad-center {
  width: 50px; height: 50px;
}

.dpad-btn {
  width: 54px; height: 54px;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
}

.dpad-btn:active {
  background: rgba(255,107,53,0.5);
  transform: scale(0.92);
}

/* ---- Screens ---- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* ---- START SCREEN ---- */
#start-screen {
  background: #0d0d1a;
  flex-direction: column;
}

#startCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
}

/* Title */
#title-wrap {
  text-align: center;
}

#title-text {
  font-size: clamp(52px, 14vw, 100px);
  font-weight: 900;
  letter-spacing: -2px;
  background: linear-gradient(180deg, #FFD700 0%, #FF6B35 50%, #FF2D55 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 4px 16px rgba(255,107,53,0.8));
  line-height: 1;
  animation: titleBob 2s ease-in-out infinite;
}

@keyframes titleBob {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%       { transform: translateY(-8px) rotate(1deg); }
}

#title-sub {
  font-size: clamp(12px, 3vw, 18px);
  color: rgba(255,255,255,0.7);
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* Character Select */
#char-select-wrap {
  background: rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 16px 20px;
  width: 100%;
  backdrop-filter: blur(8px);
}

#char-select-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.5);
  text-align: center;
  margin-bottom: 12px;
}

#char-select-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.char-option {
  width: 60px; height: 60px;
  background: rgba(255,255,255,0.08);
  border: 3px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.char-option canvas {
  display: block;
}

.char-option.selected {
  border-color: var(--accent);
  background: rgba(255,215,0,0.15);
  box-shadow: 0 0 16px rgba(255,215,0,0.4);
  transform: scale(1.08);
}

.char-option.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.char-lock-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  gap: 1px;
}

.char-lock-score {
  font-size: 9px;
  color: var(--accent);
  font-weight: 700;
}

#char-name-display {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 10px;
  min-height: 20px;
  letter-spacing: 1px;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #FF2D55);
  color: #fff;
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 900;
  letter-spacing: 2px;
  border: none;
  border-radius: 50px;
  padding: 16px 48px;
  cursor: pointer;
  box-shadow: 0 6px 30px rgba(255,45,85,0.5), 0 2px 0 rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.btn-primary:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 40px rgba(255,45,85,0.7), 0 2px 0 rgba(0,0,0,0.3);
}

.btn-primary:active {
  transform: translateY(1px) scale(0.97);
  box-shadow: 0 3px 15px rgba(255,45,85,0.4);
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50px;
  padding: 12px 36px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
  transform: translateY(-2px);
}

#start-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#start-hiscore {
  font-size: 15px;
  color: rgba(255,255,255,0.6);
}

#start-controls-hint {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  text-align: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---- DEATH SCREEN ---- */
#death-screen {
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#death-content {
  background: rgba(20,20,40,0.95);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
  animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

#death-emoji {
  font-size: 60px;
  animation: wobble 0.6s ease 0.3s;
}

@keyframes wobble {
  0%,100% { transform: rotate(0); }
  25%      { transform: rotate(-15deg); }
  75%      { transform: rotate(15deg); }
}

#death-title {
  font-size: 36px;
  font-weight: 900;
  color: #FF2D55;
  text-shadow: 0 0 20px rgba(255,45,85,0.5);
  letter-spacing: 2px;
}

#death-message {
  font-size: 15px;
  color: rgba(255,255,255,0.7);
  text-align: center;
  line-height: 1.4;
  min-height: 40px;
}

#death-score-wrap {
  display: flex;
  gap: 24px;
}

.death-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.death-stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.4);
}

.death-stat-value {
  font-size: 32px;
  font-weight: 900;
  color: #fff;
}

#new-best-banner {
  background: linear-gradient(135deg, #FFD700, #FF6B35);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 8px 24px;
  border-radius: 50px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

#death-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#death-actions .btn-primary { width: 100%; text-align: center; }
#death-actions .btn-secondary { width: 100%; text-align: center; }

/* ---- Score Popup ---- */
#score-popup {
  position: absolute;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  pointer-events: none;
  z-index: 30;
  animation: scoreFloat 0.8s ease-out forwards;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
}

@keyframes scoreFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.2); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-50px) scale(0.8); }
}

/* ---- Unlock Toast ---- */
#unlock-toast {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #1a1a3e, #2d2d5e);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 40;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6), 0 0 20px rgba(255,215,0,0.3);
  animation: toastIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

#unlock-icon { font-size: 32px; }
#unlock-text {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  line-height: 1.4;
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 480px) {
  #death-content { padding: 24px 20px; gap: 12px; }
  #death-title   { font-size: 28px; }
  #death-emoji   { font-size: 48px; }
  .death-stat-value { font-size: 24px; }

  .dpad-btn { width: 50px; height: 50px; font-size: 20px; }
  .dpad-center { width: 46px; height: 46px; }

  #start-controls-hint { display: none; }
}

@media (max-height: 600px) {
  #start-content { gap: 14px; }
  #title-text { font-size: 44px; }
  #char-select-wrap { padding: 10px 14px; }
  .char-option { width: 48px; height: 48px; }
}
