/* Aquí No Se Rueda — hoja única. Paleta de mar y piedra, sin dependencias. */

:root {
    --mar-hondo: #0a2e3d;
    --mar: #0d3b4a;
    --piedra: #9c8f78;
    --arena: #e6d3a3;
    --dorado: #f2c14e;
    --peligro: #e0483c;
    --verde: #4cd964;
    --texto: #f6f1e4;
    --panel: rgba(10, 32, 42, 0.94);
    --borde: rgba(246, 241, 228, 0.16);
}

* { box-sizing: border-box; }

/*
 * Varias reglas de abajo fijan display (flex/block) y ganarían al display:none
 * que la hoja del navegador aplica a [hidden]: sin esto, el botón CONTINUAR y
 * la capa de enfriamiento se veían aunque el JS los marcara como ocultos.
 */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--mar-hondo);
    color: var(--texto);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

#juego {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
}

/* ===== HUD superior ===== */
#hud {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 8px 58px;
    background: linear-gradient(180deg, #0a2e3d, #0d3b4a);
    border-bottom: 2px solid rgba(0, 0, 0, 0.4);
    flex-wrap: wrap;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--borde);
    border-radius: 10px;
    padding: 6px 12px;
    position: relative;
    min-width: 0;
}

.hud-icono { font-size: 1.15rem; line-height: 1; }

.hud-dato { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-dato b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.hud-dato small {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40ch;
}

.hud-oleada-item { flex: 1 1 300px; }

.hud-barra {
    position: absolute;
    left: 8px; right: 8px; bottom: 3px;
    height: 3px;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 2px;
    overflow: hidden;
}
.hud-barra-fill {
    height: 100%;
    width: 100%;
    background: var(--verde);
    transition: width 0.25s ease;
}
.hud-barra-fill.critica { background: var(--peligro); }

.hud-velocidad { display: flex; gap: 4px; margin-left: auto; }
.hud-velocidad button {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--borde);
    color: var(--texto);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.72rem;
    cursor: pointer;
    letter-spacing: -1px;
}
.hud-velocidad button.activo {
    background: var(--dorado);
    color: #1a1200;
    border-color: var(--dorado);
    font-weight: 700;
}

.menu-btn {
    position: fixed;
    top: 8px; left: 10px;
    z-index: 60;
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid var(--borde);
    background: rgba(10, 32, 42, 0.9);
    color: var(--texto);
    font-size: 1.15rem;
    cursor: pointer;
}

/* ===== Escenario ===== */
#escenario {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #08222e;
}

/* Absoluto a propósito: si participara del flujo, su altura realimentaría la
   del contenedor flex y el mapa crecería solo. */
#game-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

.mensaje-oleada {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translate(-50%, -16px);
    padding: 9px 20px;
    border-radius: 999px;
    background: rgba(10, 32, 42, 0.92);
    border: 1px solid var(--borde);
    font-weight: 700;
    font-size: 0.92rem;
    letter-spacing: 0.03em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    text-align: center;
    max-width: 90%;
}
.mensaje-oleada.visible { opacity: 1; transform: translate(-50%, 0); }
.mensaje-oleada.jefe { border-color: var(--peligro); color: #ffd9d5; box-shadow: 0 0 26px rgba(224, 72, 60, 0.5); }
.mensaje-oleada.ok { border-color: var(--verde); color: #d8ffe2; }

.btn-oleada {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #2f9e5d, #227a47);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 11px 24px;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.btn-oleada:hover { filter: brightness(1.12); }
.btn-oleada b { opacity: 0.85; font-weight: 600; }

/* ===== Panel de torre ===== */
.panel-torre {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 268px;
    max-width: calc(100% - 24px);
    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
}

.panel-cabecera { display: flex; align-items: center; gap: 10px; }
.panel-emoji { font-size: 1.8rem; }
.panel-cabecera h3 { margin: 0; font-size: 1rem; }
.panel-nivel { margin: 2px 0 0; font-size: 0.75rem; color: var(--dorado); }
.panel-cerrar {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--texto);
    opacity: 0.6;
    font-size: 1rem;
    cursor: pointer;
}
.panel-desc { font-size: 0.78rem; opacity: 0.75; margin: 10px 0; line-height: 1.45; }
.panel-stats { list-style: none; margin: 0 0 12px; padding: 0; font-size: 0.8rem; }
.panel-stats li { padding: 3px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.08); }
.panel-stats b { color: var(--dorado); }
.panel-acciones { display: flex; flex-direction: column; gap: 6px; }
.panel-acciones button {
    border: none;
    border-radius: 9px;
    padding: 9px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}
.btn-mejorar { background: var(--dorado); color: #1a1200; }
.btn-mejorar:disabled { background: rgba(255, 255, 255, 0.1); color: rgba(246, 241, 228, 0.4); cursor: not-allowed; }
.btn-vender { background: rgba(255, 255, 255, 0.1); color: var(--texto); }

/* ===== Barra inferior: tienda + habilidades ===== */
#barra-inferior {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    background: linear-gradient(0deg, #0a2e3d, #0d3b4a);
    border-top: 2px solid rgba(0, 0, 0, 0.4);
    align-items: stretch;
}

.tienda {
    display: flex;
    gap: 8px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: thin;
}

.tienda-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 96px;
    padding: 8px 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--borde);
    border-radius: 12px;
    color: var(--texto);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}
.tienda-item:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, 0.4); }
.tienda-item.activo {
    border-color: var(--dorado);
    background: rgba(242, 193, 78, 0.16);
    box-shadow: 0 0 18px rgba(242, 193, 78, 0.28);
}
.tienda-item.sin-dinero { opacity: 0.42; }
.tienda-emoji { font-size: 1.5rem; line-height: 1; }
.tienda-nombre { font-size: 0.66rem; text-align: center; line-height: 1.15; opacity: 0.85; }
.tienda-coste { font-size: 0.78rem; font-weight: 700; color: var(--dorado); }

.habilidades { display: flex; gap: 8px; }
.hab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 84px;
    padding: 8px 6px;
    background: rgba(127, 220, 255, 0.1);
    border: 1px solid rgba(127, 220, 255, 0.35);
    border-radius: 12px;
    color: var(--texto);
    cursor: pointer;
    overflow: hidden;
}
.hab.armada { border-color: var(--dorado); box-shadow: 0 0 18px rgba(242, 193, 78, 0.4); }
.hab.no-listo { opacity: 0.45; }
.hab-emoji { font-size: 1.4rem; line-height: 1; }
.hab-nombre { font-size: 0.66rem; opacity: 0.85; }
.hab-coste { font-size: 0.74rem; font-weight: 700; color: var(--dorado); }
.hab-cd {
    position: absolute;
    left: 0; bottom: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}

/* ===== Overlays ===== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(4, 18, 26, 0.9);
    backdrop-filter: blur(4px);
}
.overlay.overlay-active { display: flex; }

.overlay-content {
    width: min(560px, 100%);
    max-height: 88vh;
    overflow-y: auto;
    background: linear-gradient(160deg, #0e3d4d, #0a2733);
    border: 1px solid var(--borde);
    border-radius: 18px;
    padding: 26px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.overlay-content h1 {
    margin: 0 0 6px;
    font-size: 2rem;
    letter-spacing: 0.02em;
    color: var(--arena);
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.overlay-content h2 { margin: 0 0 14px; font-size: 1.4rem; color: var(--arena); }
.overlay-tagline { margin: 0 0 18px; color: var(--dorado); font-weight: 600; letter-spacing: 0.04em; }
.overlay-text { font-size: 0.92rem; line-height: 1.6; opacity: 0.9; text-align: left; margin: 0 0 14px; }

.btn-primary, .btn-secondary {
    display: block;
    width: 100%;
    margin: 8px 0 0;
    padding: 13px;
    border: none;
    border-radius: 11px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    box-sizing: border-box;
}
.btn-primary { background: linear-gradient(180deg, #2f9e5d, #227a47); color: #fff; }
.btn-secondary { background: rgba(255, 255, 255, 0.08); color: var(--texto); border: 1px solid var(--borde); }
.btn-primary:hover, .btn-secondary:hover { filter: brightness(1.15); }
.btn-kofi { background: rgba(242, 193, 78, 0.16); border-color: rgba(242, 193, 78, 0.4); }
.btn-link { display: inline-block; margin-top: 14px; color: rgba(246, 241, 228, 0.6); font-size: 0.82rem; }

.pausa-buttons { display: flex; flex-direction: column; gap: 2px; }
.pausa-hint { margin: 16px 0 0; font-size: 0.75rem; opacity: 0.5; }

.overlay-ayuda-content { text-align: left; }
.ayuda-section {
    border: 1px solid var(--borde);
    border-radius: 11px;
    margin-bottom: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
}
.ayuda-section summary {
    padding: 11px 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
}
.ayuda-body { padding: 0 14px 12px; font-size: 0.84rem; line-height: 1.55; opacity: 0.88; }
.ayuda-body p { margin: 0 0 8px; }

.nickname-input {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--borde);
    background: rgba(0, 0, 0, 0.3);
    color: var(--texto);
    font-size: 1rem;
    text-align: center;
    margin-bottom: 8px;
}
.nickname-error { color: var(--peligro); font-size: 0.8rem; margin: 0 0 8px; }

.ranking-nick-info { font-size: 0.82rem; opacity: 0.7; margin: 0 0 12px; }
.ranking-list { max-height: 46vh; overflow-y: auto; margin-bottom: 12px; }
.ranking-loading { opacity: 0.6; font-size: 0.88rem; padding: 18px 0; }
.ranking-fila {
    display: grid;
    grid-template-columns: 34px 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 0.84rem;
    text-align: left;
}
.ranking-fila.mia { background: rgba(242, 193, 78, 0.13); border-radius: 8px; }
.ranking-pos { font-weight: 700; color: var(--dorado); }
.ranking-nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-oleada { font-weight: 700; }
.ranking-tiempo { opacity: 0.6; font-variant-numeric: tabular-nums; }
.ranking-actions { display: flex; flex-direction: column; gap: 4px; }

/* ===== Móvil ===== */
@media (max-width: 720px) {
    #hud { padding: 6px 8px 6px 52px; gap: 6px; }
    .hud-item { padding: 5px 9px; }
    .hud-dato b { font-size: 0.92rem; }
    .hud-dato small { font-size: 0.6rem; max-width: 16ch; }
    .hud-oleada-item { flex-basis: 120px; }
    .hud-velocidad button { padding: 6px 8px; }

    #barra-inferior { flex-direction: column; gap: 8px; padding: 8px; }
    .tienda-item { min-width: 82px; padding: 6px 4px; }
    .tienda-emoji { font-size: 1.3rem; }
    .habilidades { justify-content: stretch; }
    .hab { flex: 1; min-width: 0; }

    .panel-torre { top: auto; bottom: 10px; right: 10px; left: 10px; width: auto; }
    .btn-oleada { bottom: auto; top: 60px; font-size: 0.8rem; padding: 9px 18px; }
    .overlay-content { padding: 20px; }
    .overlay-content h1 { font-size: 1.6rem; }
}

/* En vertical el mapa 16:9 queda diminuto: se pide girar el aparato. */
#rotar {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 30px;
    text-align: center;
    background: linear-gradient(160deg, #0e3d4d, #08222e);
}
#rotar .rotar-icono { font-size: 3.4rem; animation: girar 2.4s ease-in-out infinite; }
#rotar p { margin: 0; font-size: 1rem; line-height: 1.5; max-width: 30ch; opacity: 0.9; }
@keyframes girar {
    0%, 40% { transform: rotate(0deg); }
    60%, 100% { transform: rotate(90deg); }
}
@media (max-width: 860px) and (orientation: portrait) {
    #rotar { display: flex; }
}

/* Pantallas bajas (móvil apaisado): el mapa manda, la interfaz se encoge. */
@media (max-height: 560px) {
    #hud {
        flex-wrap: nowrap;
        padding: 4px 8px 4px 48px;
        gap: 5px;
    }
    .hud-item { padding: 4px 8px; gap: 5px; }
    .hud-icono { font-size: 0.95rem; }
    .hud-dato b { font-size: 0.88rem; }
    .hud-dato small { display: none; }
    .hud-oleada-item { flex: 1 1 auto; min-width: 0; }
    .hud-oleada-item .hud-dato small {
        display: block;
        font-size: 0.58rem;
        max-width: 34ch;
    }
    .hud-velocidad button { padding: 5px 7px; font-size: 0.62rem; }
    .menu-btn { width: 32px; height: 32px; top: 5px; left: 8px; font-size: 1rem; }

    #barra-inferior { flex-direction: row; padding: 6px 8px; gap: 6px; }
    .tienda-item { min-width: 68px; padding: 5px 4px; }
    .tienda-emoji { font-size: 1.15rem; }
    .tienda-nombre { font-size: 0.56rem; }
    .tienda-coste { font-size: 0.68rem; }
    .hab { min-width: 62px; padding: 5px 4px; }
    .hab-emoji { font-size: 1.1rem; }
    .hab-nombre { font-size: 0.56rem; }
    .hab-coste { font-size: 0.66rem; }

    .btn-oleada { bottom: 8px; padding: 7px 16px; font-size: 0.76rem; }
    .panel-torre { top: 6px; bottom: auto; left: auto; right: 8px; width: 232px; padding: 10px; }
    .panel-desc { display: none; }
    .mensaje-oleada { top: 6px; font-size: 0.78rem; padding: 6px 14px; }
}
