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

:root {
    --bg-dark: #ffffff;
    --bg-card: #f0f0f5;
    --primary: #e94560;
    --secondary: #533483;
    --accent: #d0dae8;
    --gold: #ffd700;
    --text: #1a1a2e;
    --text-dim: #666;
}

body {
    font-family: 'Poppins', sans-serif;
    background: #ffffff;
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

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

/* ===== PANTALLA ACCESO ===== */
.lock-container {
    text-align: center;
    padding: 20px;
    max-width: 400px;
    width: 100%;
}
.lock-message {
    color: var(--text-dim);
    font-size: 1rem;
    margin: 15px 0 30px;
    line-height: 1.5;
}
.lock-input {
    width: 100%;
    padding: 14px 20px;
    font-size: 1.2rem;
    font-family: 'Fredoka One', cursive;
    text-align: center;
    border: 3px solid #ddd;
    border-radius: 50px;
    outline: none;
    background: #fff;
    color: #000;
    letter-spacing: 3px;
    transition: border-color 0.3s ease;
    margin-bottom: 20px;
}
.lock-input:focus {
    border-color: var(--primary);
}
.lock-error {
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 15px;
    min-height: 1.2em;
}

/* ===== PANTALLA SELECCION ===== */
.select-container {
    text-align: center;
    padding: 20px;
    max-width: 500px;
    width: 100%;
}

.title-glow {
    font-family: 'Fredoka One', cursive;
    font-size: 3.5rem;
    background: linear-gradient(135deg, var(--primary), var(--gold), var(--primary));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease infinite;
    margin-bottom: 5px;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.subtitle {
    color: var(--text-dim);
    font-size: 1.1rem;
    margin-bottom: 30px;
}

.characters {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.character-card {
    background: var(--bg-card);
    border: 3px solid transparent;
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    width: 180px;
}
.character-card:hover {
    border-color: var(--secondary);
    box-shadow: 0 8px 30px rgba(233, 69, 96, 0.2);
}
.character-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.4);
}

/* Carta con volteo */
.character-img-wrap {
    width: 120px;
    height: 120px;
    margin: 0 auto 12px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}
.flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
}
.flip-front, .flip-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.flip-front {
    background: #111;
    z-index: 2;
}
.flip-mark {
    font-family: 'Fredoka One', cursive;
    font-size: 2.8rem;
    color: #444;
}
.flip-back {
    background: var(--accent);
    z-index: 1;
}
.flip-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Cuando se voltea: frente se aplasta y desaparece, atras aparece */
.flip-inner.flipped .flip-front {
    transform: scaleX(0);
    opacity: 0;
}
.flip-inner.flipped .flip-back {
    z-index: 3;
}

.character-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
}

/* ===== BOTONES ===== */
.btn-main {
    background: linear-gradient(135deg, var(--primary), #c0392b);
    color: white;
    border: none;
    padding: 14px 40px;
    font-size: 1.1rem;
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn-main:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 5px 25px rgba(233, 69, 96, 0.5);
}
.btn-main:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-pulse {
    animation: pulse 1.5s ease infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.6); }
    50% { box-shadow: 0 0 0 15px rgba(233, 69, 96, 0); }
}

/* ===== PANTALLA JUEGO ===== */
.game-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    z-index: 10;
    border-bottom: 1px solid #e0e0e0;
}

.level-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
}

#level-label {
    font-family: 'Fredoka One', cursive;
    font-size: 1.3rem;
    color: #000;
}

.level-dots {
    display: flex;
    gap: 6px;
}
.level-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ddd;
    border: 2px solid #999;
    transition: all 0.3s ease;
}
.level-dot.completed {
    background: var(--gold);
    border-color: var(--gold);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}
.level-dot.current {
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(233, 69, 96, 0.6);
}
.level-dot.secret {
    background: var(--primary);
    border-color: var(--primary);
    animation: pulse 1s ease infinite;
}

#timer {
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    color: #000;
}

.maze-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 60px 10px 40px;
    width: 100%;
    overflow: hidden;
}

.death-counter {
    font-family: 'Fredoka One', cursive;
    font-size: 2rem;
    color: #000;
    text-align: center;
    position: relative;
    z-index: 6;
    margin-bottom: -20px;
    pointer-events: none;
}

#maze-canvas {
    border-radius: 8px;
    max-width: 100%;
    max-height: calc(100vh - 120px);
    touch-action: none;
    cursor: grab;
    transition: transform 0.15s ease-out;
    will-change: transform, transform-origin;
}
#maze-canvas:active {
    cursor: grabbing;
}

.game-hint {
    position: fixed;
    bottom: 12px;
    left: 0;
    right: 0;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    opacity: 0.6;
    pointer-events: none;
}

#danger-overlay {
    position: fixed;
    inset: 0;
    background: #e94560;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.08s linear;
}

/* ===== PANTALLA NIVEL SECRETO ===== */
.secret-container {
    text-align: center;
    padding: 20px;
}

.glitch {
    font-family: 'Fredoka One', cursive;
    font-size: 4rem;
    color: var(--primary);
    position: relative;
}
.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.glitch::before {
    color: #0ff;
    animation: glitchBefore 2s infinite;
    clip-path: inset(0 0 60% 0);
}
.glitch::after {
    color: #f0f;
    animation: glitchAfter 2s infinite;
    clip-path: inset(40% 0 0 0);
}

@keyframes glitchBefore {
    0%, 100% { transform: translate(0); }
    20% { transform: translate(-3px, 3px); }
    40% { transform: translate(3px, -3px); }
    60% { transform: translate(-2px, 1px); }
    80% { transform: translate(2px, -2px); }
}
@keyframes glitchAfter {
    0%, 100% { transform: translate(0); }
    20% { transform: translate(3px, -2px); }
    40% { transform: translate(-3px, 2px); }
    60% { transform: translate(2px, -1px); }
    80% { transform: translate(-2px, 3px); }
}

.secret-text {
    color: var(--text-dim);
    font-size: 1.1rem;
    margin: 20px 0 30px;
    animation: fadeInUp 1s ease 0.5s both;
}

.secret-anim {
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
}

/* Candado CSS sin emojis */
.lock-icon-css {
    position: relative;
    animation: shake 0.5s ease infinite;
}
.lock-body {
    width: 50px;
    height: 40px;
    background: var(--gold);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    color: var(--bg-dark);
}
.lock-shackle {
    width: 30px;
    height: 22px;
    border: 5px solid var(--gold);
    border-bottom: none;
    border-radius: 15px 15px 0 0;
    margin: 0 auto -2px;
}

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

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

/* ===== PANTALLA RECOMPENSA ===== */
.reward-container {
    text-align: center;
    padding: 20px;
    max-width: 500px;
    width: 100%;
    animation: fadeInUp 0.8s ease;
}

.reward-title {
    font-family: 'Fredoka One', cursive;
    font-size: 1.8rem;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--gold), #ff8c00, var(--gold));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 2s ease infinite;
}

/* Area de imagen con rayos */
.reward-image-area {
    position: relative;
    width: 350px;
    height: 350px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Rayos MUY intensos */
.rays-container {
    position: absolute;
    width: 100%;
    height: 100%;
    animation: spinRays 8s linear infinite;
    opacity: 0.5;
    transition: opacity 0.8s ease;
}
.rays-container.revealed {
    opacity: 1;
}

.ray {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 175px;
    margin-left: -4px;
    margin-top: -175px;
    transform-origin: bottom center;
    background: linear-gradient(to top, rgba(255, 200, 0, 0.9), rgba(255, 150, 0, 0.4), transparent);
    border-radius: 4px;
    filter: blur(1px);
}
.ray:nth-child(odd) {
    width: 5px;
    margin-left: -2.5px;
    height: 160px;
    margin-top: -160px;
    background: linear-gradient(to top, rgba(255, 255, 100, 0.8), rgba(255, 200, 0, 0.2), transparent);
}
.ray:nth-child(1)  { transform: rotate(0deg); }
.ray:nth-child(2)  { transform: rotate(20deg); }
.ray:nth-child(3)  { transform: rotate(40deg); }
.ray:nth-child(4)  { transform: rotate(60deg); }
.ray:nth-child(5)  { transform: rotate(80deg); }
.ray:nth-child(6)  { transform: rotate(100deg); }
.ray:nth-child(7)  { transform: rotate(120deg); }
.ray:nth-child(8)  { transform: rotate(140deg); }
.ray:nth-child(9)  { transform: rotate(160deg); }
.ray:nth-child(10) { transform: rotate(180deg); }
.ray:nth-child(11) { transform: rotate(200deg); }
.ray:nth-child(12) { transform: rotate(220deg); }
.ray:nth-child(13) { transform: rotate(240deg); }
.ray:nth-child(14) { transform: rotate(260deg); }
.ray:nth-child(15) { transform: rotate(280deg); }
.ray:nth-child(16) { transform: rotate(300deg); }
.ray:nth-child(17) { transform: rotate(320deg); }
.ray:nth-child(18) { transform: rotate(340deg); }

@keyframes spinRays {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Anillos de brillo */
.glow-ring {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    border: 3px solid rgba(255, 215, 0, 0.3);
    animation: glowRingPulse 2s ease-in-out infinite;
    pointer-events: none;
}
.glow-ring-2 {
    width: 320px;
    height: 320px;
    border-color: rgba(255, 180, 0, 0.15);
    animation-delay: 0.5s;
}
@keyframes glowRingPulse {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50%      { transform: scale(1.08); opacity: 1; }
}

/* Brillo central pulsante */
.rays-container::after {
    content: '';
    position: absolute;
    inset: -10%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.5) 0%, rgba(255, 180, 0, 0.2) 40%, transparent 70%);
    animation: glowPulse 1.5s ease-in-out infinite;
}
@keyframes glowPulse {
    0%, 100% { opacity: 0.5; transform: scale(0.95); }
    50%      { opacity: 1;   transform: scale(1.1); }
}

/* Imagen de recompensa */
.reward-image-wrap {
    width: 220px;
    height: 220px;
    border-radius: 18px;
    overflow: hidden;
    background: #111;
    border: 3px solid var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.4), 0 0 80px rgba(255, 180, 0, 0.15);
    transition: transform 0.6s cubic-bezier(.17,.67,.35,1.5), box-shadow 0.6s ease;
}
.reward-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Overlay misterio */
.mystery-overlay {
    position: absolute;
    inset: 0;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: opacity 0.5s ease;
}
.mystery-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.mystery-mark {
    font-family: 'Fredoka One', cursive;
    font-size: 5rem;
    color: #333;
    animation: mysteryPulse 2s ease-in-out infinite;
}
@keyframes mysteryPulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50%      { opacity: 0.8; transform: scale(1.1); }
}

/* Flotacion palpitante */
.reward-float {
    animation: floatPulse 3s ease-in-out infinite;
}
@keyframes floatPulse {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-10px) scale(1.04); }
}

/* Animacion de revelacion: imagen sale ENORME */
.reward-image-wrap.reveal-boom {
    animation: revealBoom 1.2s cubic-bezier(.17,.67,.35,1.3) forwards;
    box-shadow: 0 0 80px rgba(255, 215, 0, 0.8), 0 0 160px rgba(255, 150, 0, 0.4), 0 0 240px rgba(255, 100, 0, 0.2);
}
@keyframes revealBoom {
    0%   { transform: scale(1); }
    40%  { transform: scale(2.2); }
    60%  { transform: scale(1.8); }
    80%  { transform: scale(2); }
    100% { transform: scale(1) translateY(0); }
}

/* Flash blanco al revelar */
.reveal-flash {
    position: fixed;
    inset: 0;
    background: white;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    animation: flashBang 0.8s ease-out forwards;
}
@keyframes flashBang {
    0%   { opacity: 0.9; }
    100% { opacity: 0; }
}

.reward-instructions {
    color: var(--text-dim);
    margin-bottom: 15px;
    font-size: 0.95rem;
}

/* Scratch card */
.scratch-area {
    position: relative;
    width: 400px;
    height: 80px;
    margin: 0 auto 20px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-card);
    border: 2px solid var(--gold);
    max-width: 95vw;
}

#scratch-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    cursor: pointer;
    border-radius: 10px;
}

.code-behind {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    font-family: 'Fredoka One', cursive;
    font-size: 1.6rem;
    letter-spacing: 2px;
}

.code-full {
    color: #b8860b;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
    letter-spacing: 1px;
}

/* Boton copiar */
.btn-copy {
    background: linear-gradient(135deg, var(--gold), #ff8c00);
    color: var(--bg-dark);
    border: none;
    padding: 12px 30px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-copy:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 25px rgba(255, 215, 0, 0.4);
}

.copy-feedback {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--primary);
    color: #fff;
    padding: 10px 24px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.9rem;
    opacity: 0;
    transition: all 0.4s ease;
    z-index: 100;
}
.copy-feedback.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== TRANSICION NIVEL COMPLETADO ===== */
.level-complete-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 50;
    animation: fadeIn 0.3s ease;
}
.level-complete-overlay h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 10px;
}
.level-complete-overlay p {
    color: var(--text-dim);
    margin-bottom: 25px;
}

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

/* ===== PARTICULAS DE FONDO ===== */
.particle {
    position: fixed;
    width: 3px;
    height: 3px;
    background: rgba(233, 69, 96, 0.4);
    border-radius: 50%;
    opacity: 0.3;
    animation: float linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes float {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.3; }
    90% { opacity: 0.3; }
    100% { transform: translateY(-10vh) rotate(720deg); opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .title-glow { font-size: 2.5rem; }
    .character-card { width: 140px; padding: 14px; }
    .character-img-wrap { width: 90px; height: 90px; }
    .glitch { font-size: 2.8rem; }
    .reward-title { font-size: 1.4rem; }
    .code-behind { font-size: 1.1rem; letter-spacing: 1px; }
    .scratch-area { height: 60px; }
    .reward-image-wrap { width: 150px; height: 150px; }
}
