:root{
    --board-size: 8;
    --gap: 0px; /* Se eliminó el espacio entre casillas */
    --bg:#0f172a;
    --panel:#0b1220;
    --accent:#ff6b6b;
    --accent-red: #ef4444;
    --accent-green: #4ade80;
    --accent-blue: #60a5fa;
    --accent-purple: #a855f7;
    --glow: 0 8px 32px rgba(255,107,107,0.18);
    --tile-font-size: clamp(14px, 5.5vmin, 50px);
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body{
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg,#0a0e27 0%, #1a1b3a 50%, #2d1b69 100%);
    color:#e6eef8;
    -webkit-font-smoothing:antialiased;
    -moz-osx-font-smoothing:grayscale;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container{
    width: 100%;
    height: 100%;
    display:flex;
    align-items:center;
    justify-content: center;
}

.container.shake {
    animation: screen-shake 0.4s ease-in-out;
}
.container.shake-hard {
    animation: screen-shake-hard 0.5s ease-in-out;
}

@keyframes screen-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
@keyframes screen-shake-hard {
    0%, 100% { transform: translate(0, 0); }
    10%, 90% { transform: translate(-8px, 2px); }
    20%, 80% { transform: translate(6px, -4px); }
    30%, 70% { transform: translate(-3px, 6px); }
    40%, 60% { transform: translate(7px, -2px); }
    50% { transform: translate(-5px, 3px); }
}


.panel{
    background: linear-gradient(135deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border:none;
    backdrop-filter: blur(10px);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.game-ui {
    display: flex;
    flex-direction: column;
}

.hud{
    display:flex;
    flex-direction: column;
    gap: 1.5vmin;
    padding: 2vmin;
    flex-shrink: 0;
}

.hud .title{
    font-weight:800;
    font-size: clamp(20px, 5vmin, 32px);
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
}

.stats{
    display:flex;
    gap: 1.5vmin;
    align-items:center;
    justify-content: space-between;
    width: 100%;
}

.stats-left {
    display: flex;
    gap: 1.5vmin;
    align-items: center;
}

.badge{
    background:rgba(255,255,255,0.08);
    padding: 1vmin 2vmin;
    border-radius: 2vmin;
    font-size: clamp(14px, 3vmin, 20px);
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.1);
}

.superpowers {
    display: flex;
    gap: 3vmin;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.2);
    padding: 1.5vmin;
    border-radius: 2vmin;
    border: 1px solid rgba(255,255,255,0.1);
}

.power-item {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: clamp(24px, 6vmin, 36px);
    padding: 0.5vmin;
    border-radius: 1.5vmin;
    transition: all 0.2s ease;
    position: relative;
}

.power-item.active {
    background: var(--accent-purple);
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--accent-purple);
}

.power-item:hover {
    background: rgba(255,255,255,0.1);
}

.power-count {
    position: absolute;
    bottom: -0.5vmin;
    right: -0.5vmin;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-size: clamp(12px, 2.8vmin, 16px);
    font-weight: bold;
    width: 3.5vmin;
    height: 3.5vmin;
    min-width: 20px;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid white;
}

.hud-buttons {
    display: flex;
    gap: 1.5vmin;
    align-items: center;
}

.progress-container {
    width: auto;
    background: rgba(0,0,0,0.3);
    border-radius: 2vmin;
    height: 5vmin;
    min-height: 15px;
    margin: 0 2vmin 1.5vmin;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0; /* Prevent from shrinking */
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, #ffd93d 50%, var(--accent-green) 100%);
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.board-wrap{
    position:relative;
    display: grid;
    place-content: center;
    flex-grow: 1;
    min-height: 0;
    overflow: hidden;
}

.board-wrap.hammer-cursor { cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15.5 22v-5.5a2.5 2.5 0 0 0-5 0V22M2 10.5a2.5 2.5 0 0 0 5 0V2a2 2 0 0 0-2-2h-1a2 2 0 0 0-2 2v8.5Z"/></svg>'), auto; }
.board-wrap.bomb-cursor { cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m14.5 9.5-5 5m0-5 5 5"/></svg>'), auto; }


.board{
    display:grid;
    grid-template-columns: repeat(var(--board-size), 1fr);
    grid-template-rows: repeat(var(--board-size), 1fr);
    gap: var(--gap);
    background: linear-gradient(135deg,#1a1d35 0%, #2d1b69 100%);
    padding: var(--gap);
    border-radius: 2.5vmin;
    position:relative;
    touch-action: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.combo-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(2em, 8vmin, 4em);
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5), 0 0 20px var(--accent-purple);
    pointer-events: none;
    z-index: 100;
    animation: combo-fade 1.5s ease-out forwards;
}

@keyframes combo-fade {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
    80% { transform: translate(-50%, -80%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -100%) scale(1.5); opacity: 0; }
}

.tile{
    display:flex;
    align-items:center;
    justify-content:center;
    font-size: var(--tile-font-size);
    cursor:pointer;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    border-radius: 1.5vmin;
    user-select:none;
    transition:all 200ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
    position:relative;
    z-index:1;
    border: 1px solid rgba(255,255,255,0.1);
}

.tile.objective {
    animation: pulse-objective 2s infinite;
}

@keyframes pulse-objective {
    0% { box-shadow: 0 0 0 0 rgba(255,215,0,0.6); }
    70% { box-shadow: 0 0 0 8px rgba(255,215,0,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,215,0,0); }
}

.tile.chocolate {
    background: linear-gradient(135deg, #5d4037 0%, #3e2723 100%);
    box-shadow: 0 0 15px rgba(93, 64, 55, 0.6);
    border: 2px solid #8d6e63;
}

.tile.chocolate .emoji, .tile.ice .emoji {
    opacity: 0.5;
}
.tile.chocolate::after, .tile.ice::after {
    content: "🍫";
    position: absolute;
    font-size: inherit;
    opacity: 0.9;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 2;
}

.tile.ice::after {
    content: '';
    background: rgba(173, 216, 230, 0.7);
    width: 90%;
    height: 90%;
    border-radius: 1vmin;
    border: 1px solid rgba(255,255,255,0.5);
    backdrop-filter: blur(2px);
    animation: pulse-ice 2.5s infinite;
}

/* --- NUEVOS ESTILOS PARA OBSTÁCULOS ESPECIALES --- */
.tile.trash, .tile.ice-bomb, .tile.chocolate-spawner {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
    border: 2px solid #718096;
    cursor: not-allowed;
}

.tile.trash .emoji, .tile.ice-bomb .emoji, .tile.chocolate-spawner .emoji {
    opacity: 0.2; /* Hacer el emoji de fruta de abajo casi invisible */
}

.tile.trash::after, .tile.ice-bomb::after, .tile.chocolate-spawner::after {
    position: absolute;
    font-size: 1.2em; /* Un poco más grande que el emoji normal */
    opacity: 1;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 2;
    animation: pulse-special-obstacle 2s infinite ease-in-out;
}

.tile.trash::after { content: '🗑️'; }
.tile.ice-bomb::after { content: '❄️'; }
.tile.chocolate-spawner::after { content: '🏭'; }

@keyframes pulse-special-obstacle {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Estilo para el daño del obstáculo */
.tile.damaged-1::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M20 80 L80 20" stroke="rgba(255,255,255,0.6)" stroke-width="8" stroke-linecap="round"/></svg>');
    background-size: 70%;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 3;
    opacity: 0.8;
}
/* -------------------------------------------------- */

@keyframes special-glow {
    0% {
        box-shadow: 0 0 4px rgba(255, 255, 255, 0.2), 0 0 8px var(--accent-purple), 0 0 12px var(--accent-blue);
        border-color: var(--accent-purple);
    }
    50% {
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.4), 0 0 16px var(--accent-purple), 0 0 24px var(--accent-blue);
        border-color: var(--accent-blue);
    }
    100% {
        box-shadow: 0 0 4px rgba(255, 255, 255, 0.2), 0 0 8px var(--accent-purple), 0 0 12px var(--accent-blue);
        border-color: var(--accent-purple);
    }
}

.tile[data-special] {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.35), rgba(96, 165, 250, 0.35));
    animation: special-glow 2.5s infinite ease-in-out;
    border-width: 2px;
}

.tile .special-icon {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    pointer-events: none;
    z-index: 3;
}

.tile[data-special="H"] .special-icon::before { content: '↔'; color: white; text-shadow: 0 0 10px rgba(255,107,107,1); animation: pulse-special 1.5s infinite; }
.tile[data-special="V"] .special-icon::before { content: '↕'; color: white; text-shadow: 0 0 10px rgba(96,165,250,1); animation: pulse-special 1.5s infinite; }
.tile[data-special="BOMB"] .special-icon::after { content: '💣'; animation: pulse-special 1.2s infinite alternate; }
.tile[data-special="RAINBOW"] .special-icon::after { content: '🌈'; animation: pulse-rainbow 2s infinite; }

@keyframes pulse-special {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.2); opacity: 1; }
}
@keyframes pulse-rainbow {
    0% { transform: rotate(0deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1.1); }
}

.tile:hover { transform: translateY(-2px); }
.tile:active{ transform:scale(0.95); }
.tile.selected{ box-shadow:0 0 15px var(--accent); transform:scale(1.08); z-index:10; border: 2px solid var(--accent); }
.pop{ animation: pop 300ms ease forwards; }
@keyframes pop { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.4); opacity: 0.7; } 100% { transform: scale(0); opacity: 0; } }

button.btn{ background:linear-gradient(135deg,#ff6b6b,#ff5252); border:none; padding: 1.5vmin 2.5vmin; border-radius:2vmin; color:white; font-weight:700; cursor:pointer; transition: all 200ms ease; font-size: clamp(14px, 3vmin, 20px); }
button.ghost{ background:rgba(255,255,255,0.05); border:1px solid rgba(255,255,255,0.1); color:inherit; }
button.btn.active {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

/* --- Difficulty Toggle Button --- */
#btn-toggle-difficulty {
    font-weight: 600;
    font-size: clamp(14px, 3vmin, 20px);
    padding: 1.5vmin 2.5vmin;
    border-radius: 2vmin;
    position: relative;
    overflow: hidden;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.05);
    color: #e6eef8;
    cursor: pointer;
    transition: color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}

#btn-toggle-difficulty span {
    position: relative;
    z-index: 2;
}

#btn-toggle-difficulty::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, var(--accent-red), var(--accent-purple));
    transform: translateX(-101%);
    transition: transform 0.4s cubic-bezier(0.77, 0, 0.175, 1);
    z-index: 1;
}

#btn-toggle-difficulty.active {
    color: white;
    border-color: rgba(255, 107, 107, 0.5);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}

#btn-toggle-difficulty.active::before {
    transform: translateX(0);
}


.level-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); z-index: 200; border-radius: 2.5vmin; opacity: 0; transition: opacity 400ms ease; pointer-events: none; text-align: center; padding: 2vmin; }
.level-overlay.show { opacity: 1; pointer-events: all; }

.objectives { display: flex; flex-wrap: wrap; gap: 1.5vmin; justify-content: center; padding: 0 2vmin; flex-shrink: 0; }
.objective-item { display: flex; align-items: center; gap: 1vmin; padding: 1.5vmin 2vmin; background: rgba(255,255,255,0.08); border-radius: 1.5vmin; font-size: clamp(14px, 3vmin, 18px); font-weight: 600; }
.objective-item .emoji { font-size: clamp(18px, 4.5vmin, 28px); }
.objective-item.complete { background: rgba(74,222,128,0.2); color: #4ade80; }

.moves-counter.low, .timer-display.low {
    animation: shake-low-indicator 0.5s ease-in-out infinite;
    color: var(--accent-red);
}
@keyframes shake-low-indicator { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.particles { pointer-events: none; position: absolute; inset: 0; z-index: 50; }

/* --- Settings Menu --- */
.settings-container {
    position: relative;
}

#btn-settings {
    font-size: clamp(20px, 4.5vmin, 28px);
    padding: 1vmin;
    line-height: 1;
    border-radius: 50%;
}

#btn-sound {
    font-size: clamp(18px, 4vmin, 24px);
    padding: 1vmin;
    line-height: 1;
    border-radius: 50%;
    width: 44px; /* Fixed width for consistency */
    height: 44px; /* Fixed height for consistency */
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-menu {
    position: absolute;
    top: 110%;
    right: 0;
    background: var(--panel);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 2vmin;
    padding: 2vmin;
    display: flex;
    flex-direction: column;
    gap: 2vmin;
    z-index: 200;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
    align-items: center;
}

.settings-menu.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.settings-menu .btn {
    width: 100%;
}

.footer {
    padding: 0.5vmin;
    text-align: center;
    font-size: clamp(9px, 1.5vmin, 11px);
    color: rgba(255,255,255,0.4);
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0; /* Prevent footer from shrinking */
}

@keyframes p-anim{
    0%{transform:scale(1);opacity:1}
    100%{transform:scale(0) translateY(100px) translateX(var(--tx));opacity:0}
}

/* --- Desktop Layout --- */
@media (min-width: 768px) {
    .panel {
        display: grid;
        grid-template-columns: 300px 1fr;
        grid-template-rows: auto 1fr;
        padding: 1.5vmin;
        gap: 1.5vmin;
    }

    .game-ui {
        grid-area: 1 / 1 / 3 / 2;
        display: flex;
        flex-direction: column;
        padding: 0;
        gap: 2vmin;
        border-right: 1px solid rgba(255,255,255,0.1);
        overflow-y: hidden;
    }

    .hud {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: space-between;
        padding: 0;
        margin-bottom: 0;
        gap: 2vmin;
    }

    .hud .title {
        text-align: center;
        flex-shrink: 0;
    }

    .stats {
        flex-direction: column;
        flex-grow: 1;
        justify-content: flex-start;
    }

    .stats-left {
        flex-direction: column;
    }

    .superpowers {
        margin-top: auto;
        margin-bottom: auto;
    }

    .hud-buttons {
        justify-content: center;
        flex-shrink: 0;
    }

    .objectives {
        justify-content: flex-start;
        padding: 0;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .progress-container {
        grid-area: 1 / 2 / 2 / 3;
        margin: 0;
        height: 20px;
    }

    .board-wrap {
        grid-area: 2 / 2 / 3 / 3;
    }



    .settings-menu {
        top: 100%;
        left: auto;
        right: 0;
        transform-origin: top right;
    }
}
