/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #0d0d1a;
  color: #fff;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.screen.hidden { display: none; }

/* ===== CANVAS ===== */
#game-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-block;
  padding: 14px 36px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 0.5px;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background: linear-gradient(135deg, #4CAF50, #2e7d32); color: #fff; }
.btn-secondary { background: linear-gradient(135deg, #1565C0, #0d47a1); color: #fff; }
.btn-ghost     { background: rgba(255,255,255,0.1); color: #ccc; border: 1px solid rgba(255,255,255,0.2); font-size: 15px; padding: 10px 24px; }

/* ===== MAIN MENU ===== */
#menu-screen {
  background: radial-gradient(ellipse at center, #1a1a4e 0%, #0d0d1a 70%);
}
.menu-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.game-title {
  font-size: 68px;
  font-weight: 900;
  background: linear-gradient(135deg, #4CAF50, #81C784, #FFD700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2px;
}
.subtitle { font-size: 20px; color: #aaa; letter-spacing: 1px; }

#menu-level-info {
  background: rgba(255,255,255,0.08);
  padding: 8px 22px;
  border-radius: 20px;
  font-size: 16px;
  color: #FFD700;
  border: 1px solid rgba(255,215,0,0.3);
}
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 270px;
}

/* ===== LEVEL SELECT ===== */
#level-select-screen {
  background: rgba(0,0,0,0.92);
}
.level-select-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 92vw;
  max-width: 700px;
}
.level-select-wrap h2 {
  font-size: 28px;
  color: #FFD700;
}
.level-select-hint {
  font-size: 13px;
  color: #888;
}
#level-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  width: 100%;
  max-height: 58vh;
  overflow-y: auto;
  padding: 6px 2px;
  scrollbar-width: thin;
  scrollbar-color: #444 #111;
}
/* Tablet: 7 columns */
@media (max-width: 700px) {
  #level-grid { grid-template-columns: repeat(7, 1fr); }
}
/* Phone: 5 columns */
@media (max-width: 420px) {
  #level-grid { grid-template-columns: repeat(5, 1fr); }
}
.level-btn {
  aspect-ratio: 1;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.level-btn:active { transform: scale(0.92); }
.level-btn.completed {
  background: linear-gradient(135deg, #B8860B, #FFD700);
  color: #1a1a00;
  border-color: #FFD700;
}
.level-btn.available {
  background: linear-gradient(135deg, #2e7d32, #4CAF50);
  color: #fff;
  border-color: #81C784;
}
.level-btn.available:hover { transform: scale(1.1); box-shadow: 0 4px 12px rgba(76,175,80,0.5); }
.level-btn.locked {
  background: rgba(255,255,255,0.06);
  color: #444;
  cursor: not-allowed;
  border-color: transparent;
}

/* ===== CUSTOMIZER ===== */
#customizer-screen { background: #10101e; }
.customizer-layout {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 36px;
  max-width: 720px;
  width: 90vw;
  max-height: 92vh;
  overflow-y: auto;
}
/* Stack on tablet portrait */
@media (max-width: 600px) {
  .customizer-layout { flex-direction: column; align-items: center; padding: 20px; gap: 20px; }
}
.customizer-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.customizer-left h2 { font-size: 22px; color: #FFD700; }
#avatar-preview-canvas {
  border-radius: 12px;
  border: 2px solid rgba(255,215,0,0.3);
  background: #1a1a2e;
}
.preview-hint { font-size: 12px; color: #555; }
.customizer-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 200px;
}
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label { font-size: 13px; color: #aaa; text-transform: uppercase; letter-spacing: 1px; }
.control-group input[type="text"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  font-size: 15px;
  outline: none;
}
.control-group input[type="text"]:focus { border-color: #4CAF50; }
.control-group input[type="color"] {
  width: 60px;
  height: 40px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
}
.hat-selector { display: flex; gap: 8px; flex-wrap: wrap; }
.hat-btn {
  padding: 8px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: #ccc;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.hat-btn:hover  { background: rgba(255,255,255,0.15); color: #fff; }
.hat-btn.active { background: rgba(255,215,0,0.2); border-color: #FFD700; color: #FFD700; }

/* ===== GAME SCREEN ===== */
#game-screen { touch-action: none; }

/* ===== HUD ===== */
#hud {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 14px;
  z-index: 20;
  pointer-events: none;
}
#level-badge, #checkpoint-badge {
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  backdrop-filter: blur(6px);
}
.hud-label { font-size: 10px; color: #aaa; letter-spacing: 1px; text-transform: uppercase; }
#hud-level { font-size: 28px; font-weight: 900; color: #FFD700; line-height: 1; }
.hud-max   { font-size: 12px; color: #aaa; }
#hud-checkpoint { font-size: 20px; font-weight: 700; color: #4CAF50; }

/* ===== MESSAGE OVERLAY ===== */
#message-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  padding: 16px 36px;
  border-radius: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  white-space: nowrap;
}
#message-overlay.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== DEATH OVERLAY ===== */
#death-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}
#death-overlay.hidden { display: none; }
.death-content { text-align: center; }
.skull { font-size: 64px; }
.death-content p { font-size: 20px; color: #ccc; margin-top: 10px; }

/* ===== CONTROLS HINT ===== */
#controls-hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  color: #aaa;
  font-size: 13px;
  padding: 8px 20px;
  border-radius: 20px;
  z-index: 20;
  pointer-events: none;
  white-space: nowrap;
}
#controls-hint strong { color: #fff; }

/* ===== TOUCH JOYSTICK ===== */
#joystick-outer {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.10);
  border: 3px solid rgba(255,255,255,0.28);
  display: none;           /* shown by JS when left-side touch starts */
  align-items: center;
  justify-content: center;
  pointer-events: none;    /* touches pass through to game-screen div */
  z-index: 22;
}
#joystick-inner {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255,255,255,0.42);
  border: 2px solid rgba(255,255,255,0.7);
  position: absolute;
  pointer-events: none;
  /* no transition — needs to feel instant */
}

/* ===== JUMP BUTTON ===== */
#jump-btn {
  position: fixed;
  bottom: 44px;
  right: 44px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(76, 175, 80, 0.62);
  border: 3px solid rgba(130, 230, 130, 0.8);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
#jump-btn:active { background: rgba(76, 175, 80, 0.9); }

/* ===== LEVEL COMPLETE ===== */
#level-complete-screen { background: rgba(0,0,0,0.85); }
.level-complete-content {
  background: linear-gradient(135deg, #1a1a3e, #0d2a0d);
  border: 2px solid rgba(255,215,0,0.4);
  border-radius: 20px;
  padding: 50px 60px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}
@media (max-width: 500px) {
  .level-complete-content { padding: 30px 24px; }
}
.star-row { font-size: 36px; letter-spacing: 4px; }
.level-complete-content h2 { font-size: 36px; color: #FFD700; }
.level-complete-content p  { font-size: 18px; color: #ccc; }

/* ===== WIN SCREEN ===== */
#win-screen {
  background: radial-gradient(ellipse at center, #1a0040 0%, #000010 70%);
  overflow: hidden;
}
.win-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  z-index: 2;
  position: relative;
  padding: 20px;
}
.trophy { font-size: 80px; animation: bounce 1s ease-in-out infinite alternate; }
@keyframes bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-14px); }
}
.win-content h1 {
  font-size: 60px;
  font-weight: 900;
  background: linear-gradient(135deg, #FFD700, #FF8C00, #FFD700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
@media (max-width: 500px) { .win-content h1 { font-size: 40px; } }
.win-sub  { font-size: 18px; color: #aaa; }
.wish-prompt { font-size: 20px; color: #FFD700; }
#wish-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
#wish-input {
  padding: 14px 20px;
  font-size: 16px;
  border-radius: 12px;
  border: 2px solid rgba(255,215,0,0.4);
  background: rgba(255,255,255,0.08);
  color: #fff;
  width: 320px;
  max-width: 90vw;
  outline: none;
}
#wish-input:focus { border-color: #FFD700; }
#wish-display { text-align: center; }
#wish-display h3 { font-size: 22px; color: #FFD700; margin-bottom: 8px; }
#wish-text {
  font-size: 24px;
  font-style: italic;
  color: #fff;
  background: rgba(255,255,255,0.08);
  padding: 16px 30px;
  border-radius: 12px;
  border: 1px solid rgba(255,215,0,0.3);
  max-width: 500px;
}
.wish-stars { font-size: 30px; margin-top: 10px; letter-spacing: 6px; }

/* ===== CONFETTI ===== */
#confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confettiFall linear infinite;
}
@keyframes confettiFall {
  0%   { top: -20px; transform: rotate(0deg) translateX(0); opacity: 1; }
  80%  { opacity: 1; }
  100% { top: 110vh;  transform: rotate(720deg) translateX(60px); opacity: 0; }
}
