/* ═══════════════════════════════════════════
   🎂 SALA DE CUMPLEAÑOS RPG — Estilo SNES
   Inspirado en Zelda: A Link to the Past
   ═══════════════════════════════════════════ */

/* ──── Reset ──── */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

/* ──── Paleta ──── */

body {
    --color-bg:          oklch(0.06 0.030 265);
    --color-bg2:         oklch(0.10 0.035 260);
    --color-surface:     oklch(0.14 0.040 260);
    --color-primary:     oklch(0.55 0.16  245);
    --color-primary-dim: oklch(0.35 0.12  245);
    --color-accent:      oklch(0.78 0.20  80);
    --color-accent-dim:  oklch(0.50 0.16  75);
    --color-ink:         oklch(0.92 0.01  260);
    --color-muted:       oklch(0.55 0.03  260);
    --color-glow:        oklch(0.80 0.18  80 / 0.35);
}

body {
    background: var(--color-bg);
    color: var(--color-ink);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    /* subtle starfield pattern */
    background-image:
        radial-gradient(1.5px 1.5px at 20% 30%, oklch(1 0 0 / 0.30), transparent),
        radial-gradient(1px 1px at 40% 70%, oklch(1 0 0 / 0.20), transparent),
        radial-gradient(2px 2px at 60% 20%, oklch(1 0 0 / 0.25), transparent),
        radial-gradient(1px 1px at 80% 80%, oklch(1 0 0 / 0.18), transparent),
        radial-gradient(1.5px 1.5px at 10% 60%, oklch(1 0 0 / 0.20), transparent),
        radial-gradient(1px 1px at 90% 40%, oklch(1 0 0 / 0.22), transparent),
        radial-gradient(2px 2px at 50% 10%, oklch(1 0 0 / 0.18), transparent),
        radial-gradient(1px 1px at 30% 90%, oklch(1 0 0 / 0.15), transparent);
}

/* ──── Contenedor principal ──── */

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 6px;
    gap: 6px;
}

/* ──── Header / Título ──── */

#page-header {
    text-align: center;
    flex-shrink: 0;
}

.star-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 6px;
}

.star {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: clamp(16px, 2.5vw, 28px);
    color: var(--color-accent);
    text-shadow: 0 0 10px var(--color-glow);
    animation: twinkle 2s ease-in-out infinite alternate;
}

.star:nth-child(2) {
    animation-delay: 0.7s;
    font-size: clamp(20px, 3vw, 32px);
}

.star:nth-child(3) {
    animation-delay: 1.4s;
}

@keyframes twinkle {
    0%   { opacity: 0.5; transform: scale(0.9); }
    100% { opacity: 1;   transform: scale(1.1); }
}

h1 {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 0.3em;
    font-family: 'Press Start 2P', monospace;
    font-weight: 400;
    text-transform: uppercase;
    line-height: 1.4;
    text-shadow:
        3px 3px 0 var(--color-accent-dim),
        -1px -1px 0 var(--color-accent-dim),
        0 0 30px var(--color-glow);
    color: var(--color-accent);
}

.title-feliz {
    font-size: clamp(20px, 3.5vw, 40px);
}

.title-cumple {
    font-size: clamp(22px, 4vw, 48px);
}

.title-name {
    font-size: clamp(24px, 4.5vw, 52px);
    color: oklch(0.90 0.15 60);
    text-shadow:
        3px 3px 0 oklch(0.55 0.20 50),
        -1px -1px 0 oklch(0.55 0.20 50),
        0 0 35px oklch(0.85 0.20 60 / 0.5);
}

#subtitle {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(8px, 1.2vw, 13px);
    color: var(--color-primary);
    text-shadow: 0 0 12px oklch(0.55 0.16 245 / 0.5);
    margin-top: 6px;
    letter-spacing: 0.15em;
}

/* ──── Área de juego ──── */

#game-area {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* ──── Borde decorativo SNES ──── */

#canvas-wrapper {
    position: relative;
    aspect-ratio: 4 / 3;
    flex-shrink: 0;

    /* Outer border: royal blue SNES frame */
    border: 8px solid var(--color-primary);

    /* Decorative glow */
    box-shadow:
        0 0 30px oklch(0.78 0.20 80 / 0.20),
        0 8px 32px oklch(0 0 0 / 0.5);
}

/* — Corner decorations — */

#canvas-wrapper::before,
#canvas-wrapper::after {
    content: '';
    position: absolute;
    z-index: 5;
    pointer-events: none;
}

/* top-left */
#canvas-wrapper::before {
    top: -6px;
    left: -6px;
    width: 38px;
    height: 38px;
    border-top: 6px solid var(--color-accent);
    border-left: 6px solid var(--color-accent);
}

/* bottom-right */
#canvas-wrapper::after {
    bottom: -6px;
    right: -6px;
    width: 38px;
    height: 38px;
    border-bottom: 6px solid var(--color-accent);
    border-right: 6px solid var(--color-accent);
}

/* top-right, bottom-left (span elements) */
#canvas-wrapper .corner-tr,
#canvas-wrapper .corner-bl {
    position: absolute;
    z-index: 5;
    pointer-events: none;
}

#canvas-wrapper .corner-tr {
    top: -6px;
    right: -6px;
    width: 38px;
    height: 38px;
    border-top: 6px solid var(--color-accent);
    border-right: 6px solid var(--color-accent);
}

#canvas-wrapper .corner-bl {
    bottom: -6px;
    left: -6px;
    width: 38px;
    height: 38px;
    border-bottom: 6px solid var(--color-accent);
    border-left: 6px solid var(--color-accent);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #d1bfae;
    image-rendering: pixelated;
}

/* ──── Pantalla de carga ──── */

#loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a12;
    transition: opacity 0.6s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-spinner {
    font-size: 48px;
    animation: loadBounce 0.8s ease-in-out infinite alternate;
}

@keyframes loadBounce {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-12px) scale(1.1); }
}

.loading-text {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 1.5vw, 14px);
    color: #feca57;
    text-shadow: 0 0 12px oklch(0.78 0.20 80 / 0.4);
    letter-spacing: 0.1em;
}

.loading-bar-track {
    width: 200px;
    height: 10px;
    background: oklch(0.14 0.040 260);
    border: 2px solid var(--color-primary);
    border-radius: 5px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px oklch(0 0 0 / 0.3);
}

.loading-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #feca57);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.loading-hint {
    font-family: 'Segoe UI', sans-serif;
    font-size: clamp(11px, 1.2vw, 13px);
    color: var(--color-muted);
    opacity: 0.7;
}

/* ──── Pantalla de título ──── */

#title-screen {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a12;
    animation: titleFadeIn 0.6s ease;
}

#title-screen.hidden {
    display: none;
}

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

.title-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.title-star {
    position: absolute;
    color: var(--color-accent);
    opacity: 0.2;
    animation: starFloat 4s ease-in-out infinite;
    font-size: 24px;
}
.title-star-1 { top: 15%; left: 10%; animation-delay: 0s; }
.title-star-2 { top: 25%; right: 15%; animation-delay: 1s; }
.title-star-3 { bottom: 30%; left: 20%; animation-delay: 2s; }
.title-star-4 { bottom: 20%; right: 10%; animation-delay: 0.5s; }
.title-star-5 { top: 50%; left: 50%; animation-delay: 1.5s; font-size: 32px; }

@keyframes starFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.15; }
    50% { transform: translateY(-20px) rotate(180deg); opacity: 0.35; }
}

.title-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    z-index: 1;
}

.title-cake {
    font-size: 64px;
    animation: cakeBounce 1.2s ease-in-out infinite;
}

@keyframes cakeBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.05); }
}

.title-main {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(14px, 2.5vw, 24px);
    line-height: 1.6;
    text-shadow: 0 0 20px var(--color-glow);
}

.t-feliz { color: #feca57; }
.t-cumple { color: var(--color-accent); }
.t-name { color: var(--color-primary); font-size: 1.2em; }

.title-border {
    font-size: 18px;
    color: var(--color-accent-dim);
    letter-spacing: 0.5em;
    opacity: 0.6;
}

.title-prompt {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(8px, 1vw, 11px);
    color: var(--color-muted);
    animation: blink 1.2s step-end infinite;
    margin-top: 8px;
}

/* ──── Controles táctiles ──── */

#touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* D-Pad */

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

.dpad-row {
    display: flex;
    gap: 5px;
}

.dpad-empty, .dpad-center {
    width: clamp(44px, 9vw, 58px);
    height: clamp(44px, 9vw, 58px);
    pointer-events: none;
}

.dpad-btn {
    width: clamp(44px, 9vw, 58px);
    height: clamp(44px, 9vw, 58px);
    border: none;
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-accent);
    font-size: clamp(18px, 3.5vw, 24px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.08s, transform 0.06s;
    box-shadow:
        0 4px 0 var(--color-primary-dim),
        0 6px 12px oklch(0 0 0 / 0.4);
}

.dpad-btn:active {
    background: var(--color-primary);
    color: white;
    transform: translateY(3px);
    box-shadow:
        0 1px 0 var(--color-primary-dim),
        0 3px 8px oklch(0 0 0 / 0.4);
}

.arrow {
    display: block;
    line-height: 1;
}

/* Action buttons */

#action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    width: clamp(50px, 10vw, 64px);
    height: clamp(50px, 10vw, 64px);
    border: none;
    border-radius: 50%;
    font-size: clamp(20px, 4vw, 28px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.08s, transform 0.06s;
    box-shadow:
        0 4px 0 oklch(0 0 0 / 0.3),
        0 6px 12px oklch(0 0 0 / 0.4);
}

.action-btn:active {
    transform: translateY(3px);
    box-shadow:
        0 1px 0 oklch(0 0 0 / 0.3),
        0 3px 8px oklch(0 0 0 / 0.4);
}

.interact-btn {
    background: oklch(0.30 0.10 140);
    color: oklch(0.80 0.15 140);
}

.interact-btn:active {
    background: oklch(0.40 0.14 140);
    color: white;
}

.bag-btn {
    background: oklch(0.30 0.10 45);
    color: oklch(0.80 0.15 45);
}

.bag-btn:active {
    background: oklch(0.42 0.14 45);
    color: white;
}

.close-btn {
    background: oklch(0.28 0.10 20);
    color: oklch(0.75 0.15 20);
}

.close-btn:active {
    background: oklch(0.38 0.14 20);
    color: white;
}

/* ──── Playlist de Música (Spotify) ──── */

#music-overlay {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    transition: opacity 0.3s ease;
}

#music-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.music-content {
    position: relative;
    background: var(--color-surface);
    border: 3px solid var(--color-accent);
    border-radius: 12px;
    padding: 16px;
    width: 92%;
    max-width: 420px;
    box-shadow: 0 0 30px var(--color-glow);
}

.music-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.music-title {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(9px, 1.2vw, 12px);
    color: var(--color-accent);
    text-shadow: 0 0 12px var(--color-glow);
}

.music-close {
    background: none;
    border: 2px solid var(--color-accent-dim);
    color: var(--color-accent);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}

.music-close:active {
    background: var(--color-primary-dim);
    transform: scale(0.9);
}
.music-close:focus,
.music-close:focus-visible {
    outline: none;
    box-shadow: none;
}

.music-btn {
    background: oklch(0.28 0.10 280);
    color: oklch(0.78 0.15 280);
}

.music-btn:active {
    background: oklch(0.40 0.14 280);
    color: white;
}

.dance-btn {
    background: oklch(0.30 0.12 330);
    color: oklch(0.80 0.15 330);
}

.dance-btn:active {
    background: oklch(0.42 0.16 330);
    color: white;
}

/* ──── Reproductor YouTube API ──── */

.yt-bg {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.mini-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 0 6px;
}

.mc-btn {
    background: var(--color-surface);
    border: 2px solid var(--color-accent-dim);
    color: var(--color-accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, transform 0.08s;
}
.mc-btn:active {
    background: var(--color-primary-dim);
    transform: scale(0.92);
}
.mc-btn:focus,
.mc-btn:focus-visible {
    outline: none;
    box-shadow: none;
}
.mc-play {
    width: 48px;
    height: 48px;
    font-size: 20px;
    border-color: var(--color-accent);
}

.mc-song {
    width: 100%;
    text-align: center;
    font-size: clamp(12px, 1.1vw, 14px);
    color: var(--color-accent);
    padding: 6px 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Segoe UI', sans-serif;
}

.mc-pos {
    width: 100%;
    text-align: center;
    font-size: clamp(11px, 1vw, 12px);
    color: var(--color-muted);
    padding-bottom: 2px;
    font-family: 'Segoe UI', sans-serif;
}

.mc-list {
    width: 100%;
    max-height: 150px;
    overflow-y: auto;
    font-size: clamp(11px, 1vw, 12px);
    color: var(--color-muted);
    border-top: 1px solid var(--color-accent-dim);
    padding-top: 4px;
    margin-top: 2px;
    font-family: 'Segoe UI', sans-serif;
}
.mc-list > div {
    padding: 2px 0;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mc-list > div.mc-a {
    color: var(--color-accent);
    font-weight: bold;
}
.mc-n {
    display: inline-block;
    width: 24px;
    text-align: right;
    margin-right: 6px;
    opacity: 0.5;
}
.mc-a .mc-n {
    opacity: 1;
}
.mc-list::-webkit-scrollbar {
    width: 4px;
}
.mc-list::-webkit-scrollbar-thumb {
    background: var(--color-accent-dim);
    border-radius: 2px;
}

/* ──── Portrait ────
   Canvas arriba, controles tipo GameBoy
   Marco SNES envuelve el canvas
*/
@media (orientation: portrait) {
    #game-container {
        padding: 8px;
    }
    #game-area {
        flex-direction: column;
        gap: 10px;
    }
    #canvas-wrapper {
        width: min(100%, 800px);
        max-height: 62vh;
    }
    #touch-controls {
        width: 100%;
        max-width: 520px;
        padding: 6px 20px 0 20px;
    }
}

/* ──── Landscape ────
   Controles laterales tipo gamepad
   D-Pad fijo izquierda, Acción fijo derecha
*/
@media (orientation: landscape) {
    #page-header {
        display: none;
    }

    #game-container {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 8px;
    }

    #game-area {
        flex-direction: row;
        gap: 0;
    }

    #canvas-wrapper {
        height: min(90vh, calc(100vw - 240px));
        max-width: 800px;
    }

    #dpad {
        position: fixed;
        left: max(20px, env(safe-area-inset-left));
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
    }

    #action-buttons {
        position: fixed;
        right: max(20px, env(safe-area-inset-right));
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
    }

    #touch-controls {
        position: static;
        width: auto;
    }

    .dpad-btn {
        width: clamp(40px, 8vh, 56px);
        height: clamp(40px, 8vh, 56px);
    }
    .dpad-empty, .dpad-center {
        width: clamp(40px, 8vh, 56px);
        height: clamp(40px, 8vh, 56px);
    }
    .action-btn {
        width: clamp(44px, 9vh, 60px);
        height: clamp(44px, 9vh, 60px);
    }
}

/* ──── Indicaciones de teclado (PC) ──── */

#key-hints {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 20px 24px;
    background: var(--color-surface);
    border: 3px solid var(--color-primary);
    border-radius: 8px;
    box-shadow:
        inset 0 0 20px oklch(0 0 0 / 0.3),
        0 0 20px oklch(0.78 0.20 80 / 0.15);
    flex-shrink: 0;
    align-self: flex-start;
    margin-left: 24px;
}

.hints-title {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 1.2vw, 13px);
    color: var(--color-accent);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-shadow: 0 0 12px var(--color-glow);
    margin-bottom: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-primary-dim);
}

.hint-row {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.hint-row kbd {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(8px, 0.9vw, 10px);
    color: var(--color-accent);
    background: var(--color-bg2);
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid var(--color-primary-dim);
    letter-spacing: 0.05em;
}

.hint-action {
    font-family: 'Segoe UI', sans-serif;
    font-size: clamp(12px, 1.2vw, 14px);
    color: var(--color-ink);
    opacity: 0.9;
}

/* Desktop: mostrar hints a la derecha del canvas, ocultar retro */
@media (hover: hover) and (pointer: fine) {
    #page-header {
        display: none !important;
    }
    #touch-controls,
    #dpad,
    #action-buttons {
        display: none !important;
    }
    #key-hints {
        display: flex;
    }
}