/* ============================================
   SCAVENGER HUNT - 8-BIT RETRO THEME
   ============================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark: #0a0a1a;
  --bg-card: rgba(255,255,255,0.05);
  --bg-card-hover: rgba(255,255,255,0.1);
  --text: #e8e8e8;
  --text-dim: #7788aa;
  --accent: #ffcc00;
  --primary: #4488ff;
  --primary-dark: #2244aa;
  --primary-light: #88bbff;
  --success: #00ff41;
  --danger: #ff2040;
  --font: 'Press Start 2P', monospace;
  --font-body: 'Nunito', sans-serif;
  --pixel-border: 3px;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-dark);
  image-rendering: pixelated;
}

button { cursor: pointer; font-family: var(--font); border: none; outline: none; }
input { font-family: var(--font-body); outline: none; }

/* Scanline overlay */
#scanlines {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.08) 0px, rgba(0,0,0,0.08) 1px, transparent 1px, transparent 3px);
}

#bg-particles { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* --- Screens --- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.screen.active { opacity: 1; pointer-events: all; }

/* --- Retro Buttons --- */
.btn-primary {
  background: var(--primary);
  color: #fff; font-size: 10px; padding: 14px 28px;
  border: var(--pixel-border) solid;
  border-color: var(--primary-light) var(--primary-dark) var(--primary-dark) var(--primary-light);
  text-transform: uppercase; letter-spacing: 1px;
  transition: background 0.1s;
  image-rendering: pixelated;
}
.btn-primary:hover { background: #5599ff; }
.btn-primary:active { border-color: var(--primary-dark) var(--primary-light) var(--primary-light) var(--primary-dark); }

.btn-glow { box-shadow: 0 0 16px rgba(68,136,255,0.4); }

.btn-secondary {
  background: #222233; color: var(--text-dim);
  font-size: 9px; padding: 10px 20px;
  border: var(--pixel-border) solid;
  border-color: #444466 #111122 #111122 #444466;
  transition: background 0.1s;
}
.btn-secondary:hover { background: #333344; color: var(--text); }

.btn-small { padding: 8px 14px; font-size: 8px; }

.btn-hud {
  background: #1a1a2e; color: var(--text);
  padding: 10px 18px; font-size: 11px;
  border: 3px solid;
  border-color: #555577 #222233 #222233 #555577;
  transition: background 0.1s;
}
.btn-hud:active { border-color: #222233 #555577 #555577 #222233; }
.btn-hud:hover { background: #2a2a3e; border-color: #5555aa; }

/* ===== SPLASH SCREEN ===== */
.splash-content { text-align: center; }
.splash-logo {
  font-size: 36px; color: #fff; letter-spacing: 6px;
  text-shadow: 4px 4px 0 #222244;
  animation: splashGrow 1.5s ease-out forwards;
}
@keyframes splashGrow { 0%{transform:scale(0);opacity:0} 40%{transform:scale(1.2);opacity:1} 60%{transform:scale(0.95)} 100%{transform:scale(1);opacity:1} }
.splash-tm {
  font-size: 10px; color: #555577; margin-top: 12px; letter-spacing: 4px;
  animation: splashFadeIn 1s ease-out 0.8s both;
}
@keyframes splashFadeIn { 0%{opacity:0} 100%{opacity:1} }
.splash-tap { font-size: 8px; color: #555577; margin-top: 30px; animation: charFlash 1.2s ease-in-out infinite; cursor: pointer; }

/* ===== TITLE SCREEN ===== */
.title-content { text-align: center; }
.title-logo { margin-bottom: 20px; }
.title-icon { font-size: 3rem; margin-bottom: 8px; animation: titleBounce 1s ease-in-out infinite; }
@keyframes titleBounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.title-text {
  font-size: 28px; line-height: 1.4; letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #aa8800, -1px -1px 0 #ffe066;
}
.title-text span {
  font-size: 32px; color: var(--primary);
  text-shadow: 3px 3px 0 #224488, -1px -1px 0 #88bbff;
}
.title-subtitle { color: var(--text-dim); font-size: 9px; margin-bottom: 20px; max-width: 420px; line-height: 1.8; font-family: var(--font-body); }
.insert-coin { font-size: 10px; color: var(--success); margin-bottom: 16px; animation: charFlash 1s ease-in-out infinite; }
.high-scores { margin-top: 20px; background: #0a0a14; border: 3px solid; border-color: #444466 #111122 #111122 #444466; padding: 12px 20px; min-width: 260px; }
.hs-title { font-size: 11px; color: var(--accent); text-align: center; margin-bottom: 8px; text-shadow: 2px 2px 0 #aa8800; }
.hs-row { display: flex; justify-content: space-between; font-size: 11px; padding: 4px 0; gap: 8px; }
.hs-row .hs-rank { color: var(--text-dim); width: 24px; }
.hs-row .hs-name { color: var(--accent); width: 40px; }
.hs-row .hs-pts { color: var(--success); text-align: right; flex: 1; }
.hs-entry { margin: 12px 0; text-align: center; }
.hs-initials { display: flex; gap: 8px; justify-content: center; }
.hs-char { width: 36px; height: 40px; background: #0a0a14; color: var(--accent); border: 3px solid #444466; font-size: 18px; text-align: center; text-transform: uppercase; font-family: var(--font); }
#btn-start { margin-bottom: 36px; font-size: 12px; padding: 16px 36px; }
.title-features { display: flex; gap: 20px; }
.feature { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 7px; line-height: 1.4; }
.feature-icon { font-size: 1.1rem; }

/* ===== CHARACTER SELECT (Arcade Style) ===== */
.char-select { width: 100%; max-width: 960px; padding: 12px 20px; display: flex; flex-direction: column; align-items: center; max-height: 100vh; overflow-y: auto; }
.char-header { font-size: 20px; color: var(--accent); text-shadow: 3px 3px 0 #aa8800; text-align: center; margin-bottom: 8px; animation: charFlash 0.8s ease-in-out infinite; }
@keyframes charFlash { 0%,100%{opacity:1} 50%{opacity:0.6} }
.char-name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.char-label { font-size: 11px; color: var(--primary); }
.char-name-input { background: #111122; color: var(--accent); border: 3px solid; border-color: #555577 #222233 #222233 #555577; padding: 8px 14px; font-size: 12px; font-family: var(--font); text-align: center; width: 200px; text-transform: uppercase; }
.char-name-input:focus { border-color: var(--accent); }
.char-name-input::placeholder { color: #445566; font-size: 9px; }
.char-presets { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; justify-content: center; }
.char-preset { padding: 6px 12px; font-size: 8px; background: #1a1a2e; color: var(--text-dim); border: 2px solid #333355; cursor: pointer; transition: all 0.1s; }
.char-preset:hover { border-color: var(--primary); color: #fff; background: #1a2244; }
.char-preset.active { border-color: var(--accent); color: var(--accent); background: #2a2210; }
.char-main { display: flex; gap: 16px; width: 100%; align-items: flex-start; }
.char-options { flex: 1; display: flex; flex-direction: column; gap: 4px; max-height: 400px; overflow-y: auto; padding-right: 4px; }
.char-opt-row { display: flex; align-items: center; background: #0a0a14; padding: 8px 10px; border: 2px solid #222244; gap: 6px; }
.char-opt-label { font-size: 10px; color: var(--accent); width: 100px; flex-shrink: 0; }
.char-opt-arrow { padding: 6px 10px; font-size: 14px; background: #1a1a2e; color: var(--accent); border: 2px solid #333355; cursor: pointer; flex-shrink: 0; width: 38px; text-align: center; }
.char-opt-arrow:hover { background: #2a2a3e; border-color: var(--primary); }
.char-opt-val { font-size: 11px; color: #fff; flex: 1; text-align: center; }
.char-preview-col { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.char-canvas-wrap { background: #0a0a14; border: 3px solid; border-color: #444466 #111122 #111122 #444466; padding: 4px; }
#character-canvas { display: block; width: 180px; height: 234px; image-rendering: pixelated; }
.char-stats { margin-top: 6px; background: #0a0a14; border: 2px solid #222244; padding: 6px 10px; width: 100%; font-size: 7px; }
.char-stat-row { display: flex; justify-content: space-between; padding: 2px 0; }
.char-stat-name { color: var(--text-dim); }
.char-stat-bar { display: flex; gap: 1px; }
.char-stat-fill { width: 6px; height: 8px; background: var(--accent); }
.char-stat-empty { width: 6px; height: 8px; background: #222244; }
.char-bottom-row { display: flex; gap: 12px; margin-top: 10px; align-items: center; }
.char-press-start { font-size: 12px; color: var(--success); text-shadow: 2px 2px 0 #005500; margin-top: 8px; animation: charFlash 1s ease-in-out infinite; text-align: center; }

/* ===== WORLD SELECT ===== */
#screen-worlds { flex-direction: column; padding: 28px; gap: 20px; }
.worlds-header { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 1200px; }
.worlds-header h2 { font-size: 16px; color: var(--accent); text-shadow: 2px 2px 0 #aa8800; }
.worlds-avatar { display: flex; align-items: center; gap: 8px; }
.worlds-avatar canvas { border: 2px solid #444466; }
.worlds-avatar span { font-size: 8px; }

.world-grid { display: grid; grid-template-columns: repeat(5,1fr); gap: 10px; max-width: 1200px; width: 100%; }
.world-card {
  position: relative; overflow: hidden;
  background: #111122; cursor: pointer;
  border: 3px solid;
  border-color: #444466 #111122 #111122 #444466;
  transition: all 0.1s; min-height: 140px;
}
.world-card:hover { border-color: var(--primary-light) var(--primary-dark) var(--primary-dark) var(--primary-light); }
.world-card-bg { position: absolute; inset: 0; transition: transform 0.3s; }
.world-card-content {
  position: relative; z-index: 1; padding: 16px;
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 180px;
  background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 60%, transparent 100%);
}
.world-card-name { font-size: 11px; margin-bottom: 6px; color: var(--accent); }
.world-card-desc { font-size: 8px; color: var(--text-dim); margin-bottom: 8px; font-family: var(--font-body); line-height: 1.4; }
.world-card-meta { display: flex; gap: 12px; font-size: 7px; }
.world-card-meta span { display: flex; align-items: center; gap: 4px; }
.world-card.locked { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.6); }
.world-card.locked:hover { border-color: #444466 #111122 #111122 #444466; }
.lock-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 2rem; z-index: 2; }
.check-icon { position: absolute; top: 8px; right: 8px; z-index: 3; font-size: 9px; background: #00aa33; padding: 3px 6px; border: 2px solid #00ff41; }

/* ===== GAMEPLAY ===== */
#screen-game { flex-direction: column; padding: 0; align-items: stretch; justify-content: stretch; }

.game-hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; background: #0a0a14;
  border-bottom: 3px solid #222244; z-index: 10; flex-shrink: 0;
}
.hud-left { display: flex; align-items: center; gap: 8px; }
.hud-left canvas { border: 2px solid #444466; }
.hud-left span { font-size: 8px; }
.hud-center { display: flex; gap: 20px; }
.hud-stat { text-align: center; }
.hud-label { display: block; font-size: 6px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.hud-value { display: block; font-size: 12px; color: var(--accent); text-shadow: 1px 1px 0 #aa8800; }
.hud-right { display: flex; gap: 6px; }

.game-world { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.level-intro { position: absolute; inset: 0; z-index: 50; background: #0a0a1a; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.level-intro.hidden { display: none; }
.li-world { font-size: 9px; color: var(--text-dim); margin-bottom: 8px; }
.li-name { font-size: 20px; color: var(--accent); text-shadow: 3px 3px 0 #aa8800; margin-bottom: 16px; animation: charFlash 0.5s ease-in-out infinite; }
.li-ready { font-size: 28px; color: var(--success); text-shadow: 3px 3px 0 #005500; }
.game-canvas { display: block; width: 100%; height: 100%; }

/* Item Bar */
.item-bar {
  display: flex; gap: 6px; padding: 8px 12px;
  background: #0a0a14; border-top: 3px solid #222244;
  overflow-x: auto; flex-shrink: 0; z-index: 10;
}
.item-bar-entry {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  background: #111122; font-size: 7px;
  white-space: nowrap; flex-shrink: 0;
  border: 2px solid #222244; transition: all 0.2s;
}
.item-bar-entry .ib-icon { font-size: 1rem; }
.item-bar-entry.found { background: #0a2a0a; border-color: #00aa33; color: var(--success); }

/* ===== MODALS ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.modal-box {
  position: relative; z-index: 1;
  background: #111122; padding: 36px; max-width: 520px; width: 90%;
  border: 4px solid; border-color: #444466 #111122 #111122 #444466;
  text-align: center;
}
.challenge-icon { font-size: 3rem; margin-bottom: 10px; }
.challenge-box h3 { font-size: 18px; margin-bottom: 16px; color: var(--accent); text-shadow: 2px 2px 0 #aa8800; }
.challenge-box p { color: #fff; margin-bottom: 24px; line-height: 1.6; font-size: 22px; font-family: var(--font); }
.challenge-input {
  width: 100%; padding: 14px 18px;
  background: #0a0a1a; color: var(--accent);
  border: 3px solid #333355; font-size: 16px; margin-bottom: 12px; text-align: center;
  font-family: var(--font);
}
.challenge-input:focus { border-color: var(--primary); }
.challenge-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.challenge-opt-btn {
  padding: 20px 16px; background: #1a1a2e; color: var(--text);
  font-size: 16px; border: 3px solid #333355; transition: all 0.1s;
  width: 100%;
}
.challenge-opt-btn:hover { background: #2a2a3e; border-color: var(--primary); }
.challenge-feedback { margin-top: 14px; font-size: 14px; min-height: 1.5em; }
.challenge-feedback.correct { color: var(--success); }
.challenge-feedback.wrong { color: var(--danger); }
.challenge-box .btn-primary { width: 100%; }

/* Found Popup */
.found-popup {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  z-index: 90; text-align: center; pointer-events: none;
  animation: foundBlink 0.3s ease;
}
.found-popup.hidden { display: none; }
@keyframes foundBlink { 0%{opacity:0;transform:translate(-50%,-50%) scale(2)} 100%{opacity:1;transform:translate(-50%,-50%) scale(1)} }
.found-glow {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 120px; height: 120px;
  background: radial-gradient(circle, rgba(255,204,0,0.3) 0%, transparent 70%);
  animation: glowPulse 0.6s ease-in-out infinite;
}
@keyframes glowPulse { 0%,100%{transform:translate(-50%,-50%) scale(1)} 50%{transform:translate(-50%,-50%) scale(1.3)} }
.found-popup .found-icon { font-size: 3rem; position: relative; z-index: 1; }
.found-popup h3 { font-size: 11px; margin-top: 8px; color: var(--accent); position: relative; z-index: 1; text-shadow: 2px 2px 0 #aa8800; }
.found-popup p { color: var(--text-dim); font-size: 8px; position: relative; z-index: 1; font-family: var(--font-body); }
.found-points { font-size: 12px; color: var(--success); margin-top: 4px; position: relative; z-index: 1; text-shadow: 1px 1px 0 #005500; }

/* Hearts */
.hud-hearts { color: #ff2040; letter-spacing: 2px; text-shadow: 1px 1px 0 #aa0020; }

/* ===== GAME OVER ===== */
.gameover-content { text-align: center; }
.gameover-qmarks { font-size: 24px; color: var(--accent); margin-bottom: 8px; animation: titleBounce 1s ease-in-out infinite; text-shadow: 2px 2px 0 #aa8800; }
.gameover-content h1 { font-size: 28px; color: var(--danger); margin-bottom: 12px; text-shadow: 3px 3px 0 #880010; }
.gameover-sub { color: var(--text-dim); font-size: 12px; margin-bottom: 4px; }
.gameover-score { font-size: 14px; color: var(--accent); margin-bottom: 24px; text-shadow: 2px 2px 0 #aa8800; }

/* ===== COMPLETE & VICTORY ===== */
.complete-content, .victory-content { text-align: center; }
.complete-stars { font-size: 2.5rem; margin-bottom: 8px; animation: titleBounce 1.5s ease-in-out infinite; }
.complete-content h2 { font-size: 18px; color: var(--accent); margin-bottom: 8px; text-shadow: 2px 2px 0 #aa8800; }
.complete-world-name { font-size: 10px; color: var(--text-dim); margin-bottom: 20px; }
.complete-stats {
  background: #111122; border: 3px solid; border-color: #444466 #111122 #111122 #444466;
  padding: 16px 24px; margin-bottom: 20px; min-width: 280px;
}
.stat-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 8px; border-bottom: 1px solid #222244; }
.stat-row:last-child { border-bottom: none; }
.stat-row span:last-child { color: var(--accent); }
.stat-row.total { font-size: 10px; border-top: 2px solid #333355; margin-top: 4px; padding-top: 10px; }
.stat-row.total span:last-child { color: var(--success); font-size: 12px; }
.complete-buttons { display: flex; flex-direction: column; gap: 8px; align-items: center; }

.victory-crown { font-size: 4rem; animation: titleBounce 1.5s ease-in-out infinite; }
.victory-content h1 { font-size: 28px; color: var(--accent); margin-bottom: 8px; text-shadow: 3px 3px 0 #aa8800; }
.victory-sub { color: var(--text-dim); font-size: 9px; margin-bottom: 20px; max-width: 380px; line-height: 1.8; font-family: var(--font-body); }
.victory-stats {
  background: #111122; border: 3px solid; border-color: #444466 #111122 #111122 #444466;
  padding: 16px 24px; margin-bottom: 24px; min-width: 280px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a1a; }
::-webkit-scrollbar-thumb { background: #333355; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .character-creator { flex-direction: column; gap: 16px; padding: 12px; }
  #character-canvas { width: 200px; height: 260px; }
  .world-grid { grid-template-columns: repeat(2,1fr); }
  .title-features { flex-direction: column; align-items: center; }
  .title-text { font-size: 20px; } .title-text span { font-size: 24px; }
}

/* ===== CREDITS ===== */
.btn-credits {
  background: none; border: none; color: var(--text-dim); font-family: var(--font);
  font-size: 8px; padding: 10px 20px; margin-top: 16px; cursor: pointer;
  letter-spacing: 2px; transition: color 0.2s;
}
.btn-credits:hover { color: var(--accent); }

.credits-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5,5,15,0.92); display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.credits-box {
  text-align: center; padding: 32px 40px;
  border: var(--pixel-border) solid var(--accent);
  background: var(--bg-dark);
  box-shadow: 0 0 30px rgba(255,204,0,0.15);
  max-width: 380px; width: 90%;
}
.credits-title {
  font-size: 14px; color: var(--accent); margin-bottom: 24px; letter-spacing: 4px;
}
.credits-body { display: flex; flex-direction: column; gap: 16px; }
.credits-section { }
.credits-label { font-size: 7px; color: var(--text-dim); letter-spacing: 2px; margin-bottom: 4px; }
.credits-name { font-size: 10px; color: var(--text); }
.credits-copy { font-size: 6px; color: var(--text-dim); margin-top: 8px; letter-spacing: 1px; }

.victory-credits {
  display: flex; flex-direction: column; gap: 14px;
  margin-top: 20px; padding-top: 16px;
  border-top: 2px solid rgba(255,204,0,0.2);
}

.hidden { display: none !important; }
