/* === Custom Properties === */
:root {
  --navy: #0B214A;
  --turquesa: #00E6BC;
  --lime: #04FFB4;
  --mint: #C5FFDF;
  --lemon: #FFFFAB;
  --rojo: #E74C3C;
  --navy-light: #1A3366;
  --navy-dark: #091A3A;
  --gold: #D4AF37;
  --gold-light: #F5D061;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Baloo 2', cursive;
  background: var(--navy);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html.results { overflow: visible; overflow-y: auto; -webkit-overflow-scrolling: touch; }
html.results body { overflow: visible; overflow-y: auto; height: auto; min-height: 100%; }

/* === Layout === */
.wrapper {
  max-width: 430px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#intro .wrapper {
  justify-content: flex-start;
  position: relative;
}

.avatar-intro-bg {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 85%;
  width: auto;
  opacity: 1;
  pointer-events: none;
  z-index: 0;
}

#intro .wrapper > *:not(.avatar-intro-bg) {
  position: relative;
  z-index: 1;
}

.results-wrapper {
  height: auto;
  min-height: 100%;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 40px);
}

/* === Screens === */
.screen { display: none; width: 100%; height: 100%; position: relative; z-index: 0; }
.screen.active { display: block; }
html.results #results { height: auto; min-height: 100%; }

.screen-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.15;
  z-index: -1;
}

/* === Intro === */
.title {
  font-size: 28px;
  font-weight: 800;
  color: var(--lemon);
  text-align: center;
  margin-top: 40px;
}

.subtitle {
  font-size: 16px;
  color: var(--mint);
  text-align: center;
  margin-bottom: 16px;
}


.speech-bubble {
  background: rgba(11,33,74,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
  font-size: 14px;
  line-height: 1.5;
  max-width: 340px;
}

#intro .speech-bubble {
  margin-top: auto;
}

/* === Buttons === */
.btn-primary {
  background: var(--turquesa);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 12px 32px;
  width: 100%;
  max-width: 300px;
  height: 48px;
  cursor: pointer;
  margin-top: 16px;
  transition: transform 0.15s ease;
}

.btn-primary:active { transform: scale(0.96); }

/* === HUD === */
#hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 66px;
  margin-bottom: 4px;
  z-index: 100;
}

#hud-score {
  font-size: 18px;
  font-weight: 700;
  color: var(--turquesa);
  transition: transform 0.3s ease-out;
}

#hud-progress {
  display: flex;
  gap: 4px;
}

#hud-progress .seg {
  width: 24px;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  transition: background 0.3s ease;
}

#hud-progress .seg.ok { background: var(--turquesa); }
#hud-progress .seg.fail { background: rgba(255,255,255,0.3); }

.round-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--lemon);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  text-align: center;
}

/* === Scenario Area === */
#scenario-area {
  position: relative;
  width: 320px;
  height: 360px;
  border-radius: 6px;
  overflow: hidden;
  margin: 0 auto 8px;
}

#scenario-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#scratch-canvas, #shimmer-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#scratch-canvas { z-index: 20; }
#shimmer-canvas { z-index: 21; pointer-events: none; }

#glow-finger {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245,208,97,0.5) 0%, transparent 70%);
  pointer-events: none;
  opacity: 0;
  z-index: 22;
  transition: opacity 0.15s ease;
  transform: translate(-50%, -50%);
}

#reveal-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.3);
  opacity: 0;
  pointer-events: none;
  z-index: 23;
}

/* === Judgment Buttons === */
#judgment-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
  z-index: 30;
}

.btn-judgment {
  font-family: 'Baloo 2', cursive;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  width: 140px;
  height: 48px;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.btn-pro { background: var(--turquesa); color: var(--navy); }
.btn-chapuza { background: var(--rojo); color: #fff; }
.btn-judgment:active { transform: scale(0.95); }

/* === Detail Options (quality/defect) === */
#detail-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  max-width: 320px;
  z-index: 30;
}

.btn-detail {
  background: var(--navy-light);
  color: #fff;
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  height: 44px;
  width: 100%;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn-detail:active { transform: scale(0.97); }
.btn-detail.selected { background: var(--turquesa); color: var(--navy); }
.btn-detail.correct { background: var(--turquesa); color: var(--navy); }
.btn-detail.wrong { background: var(--rojo); color: #fff; }
.btn-detail.missed { border: 2px dashed var(--turquesa); background: transparent; color: var(--turquesa); }

.btn-confirm {
  background: var(--lemon);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  height: 48px;
  width: 100%;
  cursor: pointer;
  margin-top: 4px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.btn-confirm:active { transform: scale(0.97); }
.btn-confirm:disabled { opacity: 0.3; cursor: default; }

/* === Contestant Card === */
#contestant-card {
  background: rgba(0,0,0,0.6);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
  margin-top: 16px;
  width: 100%;
  max-width: 320px;
  z-index: 35;
  transition: opacity 0.2s ease, transform 0.3s ease;
}

.card-name {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
  line-height: 1.7;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  text-align: left;
}

.card-label {
  color: var(--lemon);
  font-weight: 600;
}

/* === Public Reaction Text === */
#public-text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  font-weight: 800;
  z-index: 40;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* === Toast === */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 360px;
  width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  z-index: 150;
  transition: opacity 0.3s ease;
}

#toast.success { background: var(--mint); color: var(--navy); }
#toast.partial { background: var(--lemon); color: var(--navy); }
#toast.wrong-selections { background: #FFD6D6; color: var(--navy); border: 2px solid var(--rojo); }

#toast .toast-avatar {
  width: 48px;
  height: auto;
  display: block;
  margin: 0 auto 6px;
}

#toast .btn-entendido {
  background: var(--turquesa);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  padding: 8px 24px;
  margin-top: 8px;
  cursor: pointer;
}

/* === Gameplay Avatar === */
.avatar-gameplay {
  display: none;
}

/* === Tutorial Modal Overlay === */
#tutorial-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}

#tutorial-card {
  max-width: 320px;
  padding: 24px;
  border-radius: 10px;
  background: var(--navy-dark);
  border: 1px solid rgba(255,255,255,0.15);
  text-align: center;
}

#tutorial-avatar {
  width: 120px;
  height: auto;
  display: block;
  margin: 0 auto 12px;
}

#tutorial-text {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 16px;
  color: #fff;
}

#tutorial-card .btn-entendido {
  background: var(--turquesa);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 10px 32px;
  cursor: pointer;
}

/* === Educational Overlay === */
#edu-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}

#edu-card {
  max-width: 340px;
  padding: 24px;
  border-radius: 10px;
  background: var(--navy-dark);
  border: 1px solid var(--rojo);
  text-align: center;
}

#edu-card .edu-avatar {
  width: 60px;
  height: auto;
  display: block;
  margin: 0 auto 8px;
}

#edu-card .edu-icon { font-size: 32px; margin-bottom: 8px; }
#edu-card .edu-verdict { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
#edu-card .edu-defect { font-size: 16px; font-weight: 700; color: var(--lemon); margin-bottom: 12px; }
#edu-card .edu-explanation { font-size: 14px; line-height: 1.5; margin-bottom: 16px; }

#edu-card .edu-img {
  width: 160px;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* === Round Transition Overlay === */
#round-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}

#round-content {
  text-align: center;
}

#round-content h2 {
  font-size: 24px;
  color: var(--lemon);
  margin-bottom: 16px;
}

/* === Results === */
.results-title {
  font-size: 24px;
  color: var(--lemon);
  text-align: center;
  margin: 20px 0 16px;
}

#results-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--turquesa);
  text-align: center;
  transition: transform 0.2s ease;
}

#results-pts {
  font-size: 16px;
  color: var(--turquesa);
  text-align: center;
  margin-bottom: 8px;
}

#results-record {
  font-size: 14px;
  color: var(--lemon);
  text-align: center;
  min-height: 20px;
  margin-bottom: 12px;
}

#results-progress {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 16px;
}

.avatar-results {
  display: none;
}

#results-message {
  width: 100%;
  max-width: 340px;
  margin: 0 auto 12px;
}

#results-detail {
  width: 100%;
  margin: 16px 0;
}

.detail-row {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.detail-row:nth-child(odd) { background: rgba(255,255,255,0.03); }

.detail-row .name { font-weight: 700; }
.detail-row .ok { color: var(--turquesa); }
.detail-row .fail { color: var(--rojo); }

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

/* === Animations === */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes popIn { 0% { transform: scale(0); } 80% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes fadeUp { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-40px); } }

@keyframes particleFade {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.3); }
}

.shake { animation: shake 0.3s linear 3; }
.pop-in { animation: popIn 0.2s ease-out; }
.score-pop { animation: pulse 0.3s ease-out; }

.scratch-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-light);
  pointer-events: none;
  animation: particleFade 0.6s ease-out forwards;
  z-index: 25;
}
