/* ===================================================================
   MARIO ADVENTURE — Nivel 1 (escenario, HUD, overlays, controles)
   Los sprites de personajes viven en characters.css
   =================================================================== */

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

:root {
    --ground-h: 74px;          /* alto de la franja de suelo */
    --sky1: #5c94fc;
    --sky2: #8fc1ff;
}

html, body {
    height: 100%;
    font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
    background: #0c1022;
    color: #fff;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.back-home, .to-gallery {
    position: fixed; top: 10px; z-index: 60;
    text-decoration: none; color: #fff;
    background: rgba(0,0,0,.5); border: 2px solid #ffcc00;
    padding: 6px 12px; border-radius: 9px; font-weight: bold; font-size: 13px;
}
.back-home { left: 10px; }
.to-gallery { right: 10px; border-color: #ff9ec2; }
.back-home:hover, .to-gallery:hover { background: #e52521; }

/* ---------- Marco general ---------- */
.frame {
    position: relative;
    width: min(100vw, 980px);
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 52px 8px 8px;
}

/* ---------- HUD ---------- */
.hud {
    display: flex; gap: 8px; justify-content: space-between;
    background: #1a1a2e; border: 3px solid #000; border-radius: 12px 12px 0 0;
    padding: 8px 10px;
}
.hud-box { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.hud-label { font-size: 10px; color: #9aa3c7; letter-spacing: 1px; }
.hud-value { font-size: 18px; font-weight: 900; color: #ffcc00; }
.hud-lives { color: #ff3b3b; letter-spacing: 2px; }

/* ---------- Viewport / mundo ---------- */
.viewport {
    position: relative;
    flex: 1;
    min-height: 260px;
    border: 3px solid #000; border-top: none;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
    background:
        linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 70%, #c9e6ff 100%);
}

.world {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 5200px;            /* lo ajusta game.js (LEVEL_LENGTH) */
    will-change: transform;
}

/* Nubes y colinas pintadas en el fondo del mundo (se desplazan con él) */
/* Colinas redondeadas (SVG nítido, dos capas) */
.world::before {
    content: '';
    position: absolute; left: 0; right: 0; bottom: var(--ground-h);
    height: 170px; z-index: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='170'%3E%3Cpath d='M0,170 L0,98 C90,58 160,58 240,92 C320,126 400,64 490,84 C560,100 630,74 700,94 L700,170 Z' fill='%2384d36f'/%3E%3Cpath d='M0,170 L0,124 C80,99 150,138 230,121 C320,102 380,142 470,122 C560,103 620,138 700,118 L700,170 Z' fill='%2353bf46'/%3E%3Cpath d='M0,124 C80,99 150,138 230,121 C320,102 380,142 470,122 C560,103 620,138 700,118' fill='none' stroke='%233f9e34' stroke-width='4'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: left bottom;
    background-size: 700px 170px;
}
/* Nubes esponjosas (SVG) */
.world::after {
    content: '';
    position: absolute; left: 0; right: 0; top: 16px;
    height: 130px; z-index: 1; pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='480' height='130'%3E%3Cg fill='%23ffffff'%3E%3Cellipse cx='120' cy='72' rx='72' ry='22'/%3E%3Ccircle cx='84' cy='62' r='22'/%3E%3Ccircle cx='118' cy='48' r='30'/%3E%3Ccircle cx='154' cy='60' r='24'/%3E%3C/g%3E%3Cellipse cx='120' cy='86' rx='70' ry='8' fill='%23d8e8fb'/%3E%3Cg fill='%23ffffff'%3E%3Cellipse cx='352' cy='44' rx='46' ry='14'/%3E%3Ccircle cx='330' cy='38' r='16'/%3E%3Ccircle cx='354' cy='30' r='21'/%3E%3Ccircle cx='378' cy='39' r='15'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: 0 0;
    background-size: 480px 130px;
    opacity: .96;
}

/* ---------- Suelo: césped + tierra ---------- */
.ground {
    position: absolute; left: 0; right: 0; bottom: 0;
    height: var(--ground-h); z-index: 2;
    background-color: #a35f1b;
    background-image:
        linear-gradient(180deg, #74d35f 0, #57c24a 12px, #3f9e34 15px, transparent 15px),
        repeating-linear-gradient(90deg, #b06a24 0 40px, #a05e1c 40px 42px);
    background-repeat: no-repeat, repeat;
    background-position: 0 0, 0 0;
    background-size: 100% 100%, auto;
    box-shadow: inset 0 -6px 0 rgba(0,0,0,.14);
}
/* Matas de césped en el borde superior */
.ground::before {
    content: ''; position: absolute; top: -7px; left: 0; right: 0; height: 9px;
    background: radial-gradient(circle at 9px 9px, #5fca50 8px, transparent 9px) repeat-x;
    background-size: 18px 9px;
}

/* ---------- Actores ---------- */
.player-wrap, .enemy {
    position: absolute;
    bottom: var(--ground-h);
    z-index: 8;
}
.player-wrap { z-index: 9; }

/* contenedor que escala los sprites de enemigos a tamaño de juego */
.sprite-scale { transform-origin: bottom center; }

/* nube de derrota */
.enemy.dead { animation: enemyPoof .4s ease-in forwards; pointer-events: none; }

/* ---------- Bloques, monedas y potenciadores ---------- */
.block { position: absolute; width: 34px; height: 34px; z-index: 6; image-rendering: pixelated; }

.block.question {
    background: linear-gradient(180deg, #f7b81e, #e2911a);
    border: 3px solid #6e3a10; border-radius: 5px;
    box-shadow: inset 0 0 0 2px #ffd45a, inset 0 -5px 0 rgba(0,0,0,.18);
}
.block.question::after {
    content: '?'; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font: 900 21px/1 'Trebuchet MS', sans-serif; color: #fff; text-shadow: 1px 1px 0 #6e3a10;
}
.block.used {
    background: linear-gradient(180deg, #b98a4a, #8f6630);
    border: 3px solid #5a3a14; border-radius: 5px;
    box-shadow: inset 0 0 0 2px #caa46a, inset 0 -5px 0 rgba(0,0,0,.2);
}
.block.used::after { content: ''; }

.block.brick {
    border: 2px solid #5a3014; border-radius: 3px;
    box-shadow: inset 0 0 0 2px #d98a4a;
    background-color: #a85a20;
    background-image:
        linear-gradient(#5a3014 0 0), linear-gradient(#5a3014 0 0),
        linear-gradient(#5a3014 0 0), linear-gradient(#5a3014 0 0),
        linear-gradient(#5a3014 0 0), linear-gradient(180deg, #c87232, #a85a20);
    background-repeat: no-repeat;
    background-size: 100% 2px, 100% 2px, 2px 11px, 2px 11px, 2px 11px, 100% 100%;
    background-position: 0 11px, 0 22px, 9px 0, 25px 11px, 9px 22px, 0 0;
}
.block.broken { animation: enemyPoof .4s ease-in forwards; pointer-events: none; }

/* Golpe del bloque (rebote hacia arriba) — definido último para ganar al resto */
.block.bump { animation: blockBump .26s ease-out; }
@keyframes blockBump { 0% { transform: translateY(0); } 35% { transform: translateY(-11px); } 100% { transform: translateY(0); } }

/* Moneda que salta del bloque */
.coin {
    position: absolute; width: 20px; height: 26px; z-index: 13;
    background: radial-gradient(circle at 50% 38%, #ffe680, #f3ad14);
    border-radius: 50%; border: 2px solid #c8860a; box-shadow: inset -2px -2px 0 #c8860a;
}
.coin::after { content: ''; position: absolute; top: 5px; left: 8px; width: 4px; height: 14px; background: #c8860a; border-radius: 2px; }
.coin.pop { animation: coinPop .65s ease-out forwards; }
@keyframes coinPop {
    0%   { transform: translateY(0) scaleX(1);  opacity: 1; }
    55%  { transform: translateY(-46px) scaleX(.6); opacity: 1; }
    100% { transform: translateY(-66px) scaleX(.4); opacity: 0; }
}

/* Champiñón (potenciador) */
.mushroom { position: absolute; width: 34px; height: 33px; z-index: 11; }
.mushroom div { position: absolute; }
.mu-cap { top: 0; left: 0; width: 34px; height: 21px;
    background: radial-gradient(circle at 50% 75%, #ff6253 0 58%, #d6261a 100%);
    border-radius: 18px 18px 5px 5px; box-shadow: inset 0 -3px 0 #b01a10; }
.mu-spot { background: #fff; border-radius: 50%; box-shadow: inset -1px -1px 0 #e6e6e6; }
.mu-spot.s1 { top: 4px; left: 4px;  width: 9px; height: 9px; }
.mu-spot.s2 { top: 3px; left: 21px; width: 9px; height: 9px; }
.mu-spot.s3 { top: 10px; left: 13px; width: 7px; height: 7px; }
.mu-stem { bottom: 0; left: 7px; width: 20px; height: 14px; background: #ffe6c6;
    border-radius: 3px 3px 6px 6px; box-shadow: inset -2px 0 0 #e7c6a0; }
.mu-eye { bottom: 3px; width: 3px; height: 6px; background: #5a3a1a; border-radius: 2px; }
.mu-eye.left { left: 11px; } .mu-eye.right { left: 20px; }
.mushroom.sprout { animation: muSprout .4s ease-out; }
@keyframes muSprout { 0% { transform: translateY(20px) scale(.5); opacity: .4; } 100% { transform: translateY(0) scale(1); opacity: 1; } }

/* Héroe grande tras tomar el champiñón */
.hero { transform-origin: bottom center; }
.hero.big { transform: scale(1.3); }
.hero.big.face-left { transform: scale(1.3) scaleX(-1); }

/* ---------- Castillo de Peach ---------- */
.castle { position: absolute; bottom: var(--ground-h); z-index: 4; width: 260px; height: 220px; }
.castle div { position: absolute; }
.ct-main  { bottom: 0; left: 40px; width: 180px; height: 130px; background: #e6e6ee; border: 4px solid #9a9ab0;
    box-shadow: inset 0 -10px 0 rgba(0,0,0,.08); }
.ct-main::before { content:''; position:absolute; top:-2px; left:-4px; right:-4px; height:18px;
    background: repeating-linear-gradient(90deg, #cfcfe0 0 22px, transparent 22px 34px); }
.ct-keep  { bottom: 110px; left: 95px; width: 70px; height: 70px; background: #d63b6e; border: 4px solid #a32450;
    border-radius: 6px 6px 0 0; }
.ct-keep::before { content:''; position:absolute; top:-2px; left:-4px; right:-4px; height:14px;
    background: repeating-linear-gradient(90deg, #d63b6e 0 16px, transparent 16px 26px); }
.ct-tower { bottom: 0; width: 46px; height: 160px; background: #e6e6ee; border: 4px solid #9a9ab0; }
.ct-tower.left  { left: 8px; }
.ct-tower.right { left: 206px; }
.ct-tower::before { content:''; position:absolute; top:-2px; left:-4px; right:-4px; height:14px;
    background: repeating-linear-gradient(90deg, #cfcfe0 0 14px, transparent 14px 22px); }
.ct-door { bottom: 0; left: 110px; width: 40px; height: 56px; background: #3a2a14; border-radius: 20px 20px 0 0;
    box-shadow: inset 0 4px 0 rgba(255,255,255,.1); }
.ct-window { width: 18px; height: 26px; background: #3a2a14; border-radius: 9px 9px 0 0; }
.ct-window.w1 { bottom: 70px; left: 78px; }
.ct-window.w2 { bottom: 70px; left: 164px; }
.ct-flag { bottom: 178px; left: 124px; width: 4px; height: 40px; background: #6e6e80; }
.ct-flag::after { content:''; position:absolute; top:0; left:4px; width:28px; height:18px; background:#3aa3ff;
    clip-path: polygon(0 0,100% 0,100% 100%,0 100%,18% 50%); animation: flagWave 1.2s ease-in-out infinite; transform-origin: left center; }
@keyframes flagWave { 0%,100%{ transform: scaleX(1) } 50%{ transform: scaleX(.8) } }

.peach-wrap { position: absolute; bottom: calc(var(--ground-h) + 180px); z-index: 5; }

/* ---------- Asta de meta ---------- */
.goal { position: absolute; bottom: var(--ground-h); z-index: 4; width: 8px; height: 180px; background: #2f8f3f;
    border-radius: 4px; box-shadow: inset -2px 0 0 #1d5d28; }
.goal::before { content:''; position:absolute; top:-10px; left:-4px; width:16px; height:16px; background:#ffd11a; border-radius:50%; }
.goal-flag { position:absolute; top: 8px; left: 8px; width: 34px; height: 24px; background:#e52521;
    clip-path: polygon(0 0,100% 50%,0 100%); }

/* ---------- Overlays ---------- */
.overlay {
    position: absolute; inset: 0; z-index: 30;
    background: rgba(10,14,34,.86);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 16px;
    backdrop-filter: blur(2px);
}
.overlay.show { display: flex; }

.ov-title {
    font-size: clamp(30px, 7vw, 56px); color: #ffcc00; letter-spacing: 2px;
    -webkit-text-stroke: 2px #2b0606; text-shadow: 3px 3px 0 #7a0f0f;
}
.ov-lose { color: #ff5a4d; }
.ov-win  { color: #7dff8a; }
.ov-sub  { font-size: clamp(15px, 3.5vw, 22px); margin-top: 6px; color: #fff; }
.ov-pick { margin-top: 18px; font-size: 16px; color: #ffd23b; font-weight: bold; }
.ov-score { margin: 12px 0; font-size: 20px; color: #fff; }
.ov-hint { margin-top: 16px; font-size: 12.5px; color: #b9c2dd; line-height: 1.5; max-width: 420px; }

/* selección de personaje */
.char-select { display: flex; gap: 20px; margin-top: 12px; }
.pick {
    background: rgba(255,255,255,.06); border: 3px solid rgba(255,255,255,.2);
    border-radius: 14px; padding: 10px 14px 8px; cursor: pointer; color: #fff;
    transition: transform .12s, border-color .12s, background .12s;
}
.pick:hover { transform: translateY(-4px); }
.pick.selected { border-color: #ffcc00; background: rgba(255,204,0,.14); box-shadow: 0 0 18px rgba(255,204,0,.35); }
.pick-stage { width: 70px; height: 78px; display: flex; align-items: flex-end; justify-content: center; }
.pick-sprite { transform: scale(1.05); }
.pick.selected .pick-sprite { animation: pickBounce .7s ease-in-out infinite; }
@keyframes pickBounce { 0%,100%{ transform: translateY(0) scale(1.05) } 50%{ transform: translateY(-7px) scale(1.05) } }
.pick-name { display: block; margin-top: 6px; font-weight: 900; letter-spacing: 1px; }
#pickMario .pick-name { color: #ff6a5f; }
#pickLuigi .pick-name { color: #6fe07f; }

.big-btn {
    margin-top: 20px; cursor: pointer;
    font-size: 20px; font-weight: 900; letter-spacing: 1px;
    color: #2b0606; background: #ffcc00; border: 3px solid #fff;
    padding: 12px 26px; border-radius: 12px; box-shadow: 0 5px 0 #b58c00;
    transition: transform .1s;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b58c00; }

/* ---------- Botón de música ---------- */
.music-btn {
    position: absolute; top: 10px; right: 10px; z-index: 25;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(0,0,0,.5); border: 2px solid #ffcc00;
    color: #fff; font-size: 18px; cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s;
}
.music-btn:hover { transform: scale(1.1); }
.music-btn.off { border-color: #888; opacity: .8; }

/* ---------- Controles táctiles ---------- */
.touch-controls {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: none; justify-content: space-between; align-items: flex-end;
    padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
    pointer-events: none;
}
.touch-left { display: flex; gap: 14px; pointer-events: auto; }
.t-btn {
    pointer-events: auto;
    width: 66px; height: 66px; border-radius: 50%;
    background: rgba(0,0,0,.42); border: 3px solid rgba(255,255,255,.55);
    color: #fff; font-size: 26px; font-weight: 900;
}
.t-btn:active { background: rgba(255,204,0,.55); }
.t-jump { width: 78px; height: 78px; background: rgba(229,37,33,.5); border-color: #fff; }

/* Mostrar controles táctiles en pantallas con dedo / chicas */
@media (hover: none), (max-width: 820px) {
    .touch-controls { display: flex; }
}

/* ── Aviso de girar a horizontal (solo móviles en vertical) ── */
#rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) and (max-width: 600px) {
    #rotate-hint {
        display: flex;
        position: fixed; inset: 0;
        z-index: 100;
        flex-direction: column;
        align-items: center; justify-content: center;
        text-align: center; padding: 28px;
        padding-top: max(28px, env(safe-area-inset-top));
        padding-bottom: max(28px, env(safe-area-inset-bottom));
        background: linear-gradient(160deg, #16213e 0%, #0f1424 60%, #0a0d18 100%);
    }
    .rotate-phone {
        font-size: 110px; line-height: 1; margin-bottom: 26px;
        transform-origin: center;
        animation: rotatePhone 2.4s ease-in-out infinite;
        filter: drop-shadow(0 0 24px #ffcc00);
    }
    .rotate-text {
        font-size: 30px; font-weight: bold; color: #ffcc00;
        text-shadow: 0 0 14px #e52521; margin-bottom: 10px;
    }
    .rotate-sub { font-size: 17px; color: #f0d080; opacity: .9; line-height: 1.4; }
    /* ocultar el juego para que no se asome detrás del aviso */
    .frame, .back-home, .to-gallery, .touch-controls { visibility: hidden; }
}
@keyframes rotatePhone {
    0%, 25%   { transform: rotate(0deg); }
    55%, 100% { transform: rotate(-90deg); }
}

/* Ocultar los controles táctiles cuando hay un menú/overlay abierto */
.touch-controls.hidden { display: none !important; }

/* ── Pantallas de poca altura (móvil en horizontal): compactar y permitir scroll ── */
@media (max-height: 520px) {
    .frame { height: 100vh; height: 100dvh; padding: 40px 8px 6px; }
    .hud { padding: 4px 10px; border-radius: 10px 10px 0 0; }
    .hud-label { font-size: 9px; }
    .hud-value { font-size: 15px; }
    .viewport { min-height: 0; }

    /* overlays: alinear arriba y poder desplazar si no entra todo */
    .overlay { justify-content: flex-start; overflow-y: auto; padding: 10px 12px; }
    .ov-title { font-size: 24px; -webkit-text-stroke-width: 1px; }
    .ov-sub  { font-size: 14px; margin-top: 2px; }
    .ov-pick { margin-top: 8px; font-size: 13px; }
    .char-select { gap: 12px; margin-top: 6px; }
    .pick { padding: 6px 10px 5px; border-radius: 11px; }
    .pick-stage { width: 50px; height: 56px; }
    .pick-sprite { transform: scale(0.82); }
    .pick.selected .pick-sprite { animation: none; }
    .pick-name { font-size: 13px; margin-top: 3px; }
    .big-btn { margin-top: 10px; padding: 9px 22px; font-size: 17px; }
    .ov-hint { margin-top: 8px; font-size: 11px; max-width: 100%; }
    .ov-score { margin: 8px 0; font-size: 17px; }
}
