/* ===== TOSCAS: estética de la edad de piedra ===== */

:root {
    --bg-deep: #120f0d;
    --rock-900: #1c1815;
    --rock-800: #26211d;
    --rock-700: #322b26;
    --rock-600: #433a33;
    --rock-500: #5a4f45;
    --rock-400: #7a6d60;
    --rock-300: #9a8d7e;
    --sand-200: #cbbda6;
    --sand-100: #e6dccb;
    --ochre: #b08455;
    --ochre-dark: #7d5a36;
    --clay: #8f5a41;

    --font-title: 'Rubik Dirt', 'Rubik', system-ui, sans-serif;
    --font-body: 'Rubik', system-ui, sans-serif;

    /* Textura de roca: ruido fractal en SVG */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.42 0 0 0 0 0.34 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    --grain-coarse: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.035' numOctaves='4' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.08 0 0 0 0 0.06 0 0 0 0.9 -0.25'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

    /* Piedra tallada: bisel claro arriba, sombra abajo */
    --carved: inset 0 2px 0 rgba(230, 215, 190, 0.08), inset 0 -3px 0 rgba(0, 0, 0, 0.35), 0 6px 16px rgba(0, 0, 0, 0.45);
    --sunken: inset 0 3px 8px rgba(0, 0, 0, 0.6), inset 0 -1px 0 rgba(230, 215, 190, 0.06);
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--sand-100);
    background-color: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at 50% 0%, rgba(176, 132, 85, 0.12), transparent 60%),
        var(--grain-coarse),
        var(--grain),
        linear-gradient(180deg, #1d1916 0%, var(--bg-deep) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
    -webkit-tap-highlight-color: transparent;
}

/* Centrado vertical que no corta arriba cuando la ventana es más baja que el juego */
body > .game-container { margin-block: auto; }

/* ===== Contenedor principal: losa de piedra ===== */
.game-container {
    position: relative;
    background-color: var(--rock-800);
    background-image: var(--grain), linear-gradient(160deg, var(--rock-700), var(--rock-900));
    border-radius: 18px 22px 16px 24px / 22px 16px 24px 18px;
    padding: 20px 24px 22px;
    box-shadow: var(--carved), 0 30px 60px rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(0, 0, 0, 0.6);
    max-width: 100%;
}

/* ===== Encabezado ===== */
.game-header {
    text-align: center;
    margin-bottom: 18px;
}

.game-header h1 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 3.4rem;
    line-height: 1;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sand-200);
    /* Letras talladas en la roca */
    text-shadow:
        0 -1px 0 rgba(0, 0, 0, 0.8),
        0 2px 0 rgba(230, 215, 190, 0.12),
        0 4px 12px rgba(0, 0, 0, 0.6);
}

.score-panel {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 92px;
    padding: 8px 14px 6px;
    background: var(--rock-900);
    background-image: var(--grain);
    border-radius: 10px 12px 9px 13px;
    box-shadow: var(--sunken);
}

.score-label {
    font-size: 0.68rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--rock-300);
}

.score-value {
    font-weight: 800;
    font-size: 1.35rem;
    color: var(--ochre);
    font-variant-numeric: tabular-nums;
}

/* Récord personal: una losa con el número tallado en la piedra */
.best-slab {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
    margin: 8px auto 0;
    padding: 4px 18px 3px;
    width: fit-content;
    min-width: 60%;
    border-radius: 7px 11px 6px 12px / 9px 6px 11px 7px;
    background: var(--rock-400);
    background-image: var(--grain), var(--grain-coarse), linear-gradient(180deg, #8d7f70, #6b5f53 70%, #5d5248);
    box-shadow: inset 0 1px 0 rgba(255, 245, 225, 0.25), inset 0 -2px 0 rgba(0, 0, 0, 0.35), 0 3px 0 #1a1613, 0 5px 10px rgba(0, 0, 0, 0.45);
}
.best-slab[hidden] { display: none; }

/* Letras hundidas: oscuras, con la luz pegando en el borde de abajo */
.best-label,
.best-value {
    color: #2b231d;
    text-shadow: 0 1px 0 rgba(255, 244, 222, 0.35), 0 -1px 0 rgba(0, 0, 0, 0.55);
}
.best-label {
    font-family: var(--font-title);
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}
.best-value {
    font-family: var(--font-title);
    font-size: 1.15rem;
    letter-spacing: 0.06em;
    font-variant-numeric: tabular-nums;
}

/* Superando el récord en la partida: el tallado se llena de ocre */
.best-slab.beating .best-value {
    color: #f3c46a;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6), 0 0 10px rgba(243, 196, 106, 0.55);
}
.best-slab.carving { animation: bestCarve 0.9s ease-out; }
@keyframes bestCarve {
    0% { transform: scale(1); }
    20% { transform: scale(1.08) rotate(-1deg); }
    40% { transform: scale(0.98) rotate(0.6deg); }
    100% { transform: none; }
}

/* ===== Tablero y paneles ===== */
.game-board-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}

.next-piece-container,
.side-panel {
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.next-piece-container,
.controls,
.highscores-container {
    background: var(--rock-700);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-600), var(--rock-700));
    border-radius: 12px 14px 11px 15px;
    padding: 14px;
    box-shadow: var(--carved);
}

.next-piece-container h3,
.controls h3,
.highscores-container h3 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 1.15rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sand-200);
    margin-bottom: 10px;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);
}

#nextCanvas,
#holdCanvas {
    display: block;
    width: 110px;
    height: 110px;
    margin: 0 auto;
    background: var(--rock-900);
    background-image: var(--grain);
    border-radius: 10px;
    box-shadow: var(--sunken);
}

/* Hueco «Guardada»: se toca para guardar la pieza o cambiarla */
.hold-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.hold-label {
    align-self: stretch;
    font-family: var(--font-title);
    font-size: 1.15rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sand-200);
    text-align: left;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);
}
.hold-slot:active #holdCanvas { transform: translateY(1px); }
.hold-slot.used { cursor: default; }
.hold-slot.pop #holdCanvas { animation: holdPop 0.35s ease-out; }
@keyframes holdPop {
    0% { transform: scale(0.88); }
    60% { transform: scale(1.06); }
    100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .hold-slot.pop #holdCanvas { animation: none; }
}

.users-counter {
    margin-top: 12px;
}

.counter-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 10px;
    background: var(--rock-900);
    border-radius: 8px;
    box-shadow: var(--sunken);
}

.counter-text {
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--rock-300);
}

.counter-number {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--sand-200);
    font-variant-numeric: tabular-nums;
    animation: numberGlow 3s ease-in-out infinite alternate;
}

@keyframes numberGlow {
    from { color: var(--sand-200); }
    to { color: var(--ochre); }
}

@keyframes newUserCelebration {
    0% { transform: scale(1); }
    40% { transform: scale(1.35); color: var(--ochre); }
    100% { transform: scale(1); }
}

.control-info p {
    font-size: 0.82rem;
    color: var(--sand-200);
    margin: 7px 0;
    line-height: 1.4;
}

kbd {
    display: inline-block;
    min-width: 22px;
    padding: 1px 6px;
    margin-right: 4px;
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    color: var(--sand-100);
    background: var(--rock-500);
    border-radius: 5px 6px 4px 6px;
    box-shadow: inset 0 1px 0 rgba(230, 215, 190, 0.15), 0 2px 0 rgba(0, 0, 0, 0.5);
}

.desktop-controls { display: block; }
.touch-controls { display: none; }

/* ===== Área del juego ===== */
.main-game-area {
    position: relative;
    line-height: 0;
    padding: 10px;
    background: var(--rock-600);
    background-image: var(--grain), linear-gradient(160deg, var(--rock-500), var(--rock-700));
    border-radius: 14px 16px 13px 17px;
    box-shadow: var(--carved);
}

#gameCanvas {
    display: block;
    height: min(540px, calc(100dvh - 260px));
    min-height: 300px;
    width: auto;
    aspect-ratio: 360 / 540;
    border-radius: 3px;
    /* Marco tallado: deja claro dónde termina el tablero */
    box-shadow: 0 0 0 3px #15110e, 0 0 0 5px var(--rock-400), 0 0 0 6px rgba(0, 0, 0, 0.6);
    touch-action: none;
}

.explosion-container {
    position: absolute;
    inset: 10px;
    pointer-events: none;
    overflow: hidden; /* astillas y polvo no salen del tablero */
    border-radius: 3px;
    z-index: 5;
}

.explosion {
    position: absolute;
    left: 0;
    width: 100%;
}

.dust-band {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(203, 189, 166, 0.7), transparent);
    animation: dustBand 0.6s ease-out forwards;
}

@keyframes dustBand {
    0% { opacity: 1; transform: scaleY(1); }
    100% { opacity: 0; transform: scaleY(2.5); }
}

.rock-chip {
    position: absolute;
    top: 50%;
    border-radius: 50%;
    /* Piedrita con volumen: borde oscuro fino y sombra abajo */
    box-shadow: inset -1px -2px 1px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.45);
    animation: rockChip 1.1s cubic-bezier(0.3, 0.6, 0.6, 1) forwards;
}

@keyframes rockChip {
    0% { transform: translate(0, 0) rotate(0); opacity: 1; }
    35% { transform: translate(calc(var(--dx) * 0.45), var(--up)) rotate(calc(var(--rot) * 0.4)); opacity: 1; }
    100% { transform: translate(var(--dx), var(--fall)) rotate(var(--rot)); opacity: 0; }
}

.dust-puff {
    position: absolute;
    top: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(190, 175, 150, 0.55) 0%, rgba(150, 135, 115, 0.25) 45%, transparent 70%);
    animation: dustPuff 1.3s ease-out forwards;
}

@keyframes dustPuff {
    0% { transform: translate(0, 0) scale(0.3); opacity: 0.9; }
    100% { transform: translate(var(--dx), -40px) scale(2.2); opacity: 0; }
}

.screen-shake {
    animation: screenShake 0.45s ease-in-out;
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    15% { transform: translate(-4px, 2px); }
    30% { transform: translate(4px, -2px); }
    45% { transform: translate(-3px, 3px); }
    60% { transform: translate(3px, -1px); }
    80% { transform: translate(-1px, 1px); }
}

/* Derrumbes más grandes: temblor más fuerte y más largo, con un golpe hacia abajo */
.screen-shake.shake-2 {
    animation: screenShake2 0.56s ease-out;
}

.screen-shake.shake-3 {
    animation: screenShake3 0.76s ease-out;
}

@keyframes screenShake2 {
    0%, 100% { transform: translate(0, 0); }
    8% { transform: translate(0, 7px); }
    20% { transform: translate(-6px, -3px) rotate(-0.4deg); }
    34% { transform: translate(6px, 3px) rotate(0.4deg); }
    50% { transform: translate(-4px, 2px); }
    66% { transform: translate(3px, -2px); }
    82% { transform: translate(-1px, 1px); }
}

@keyframes screenShake3 {
    0%, 100% { transform: translate(0, 0); }
    6% { transform: translate(0, 11px) scale(1.01); }
    14% { transform: translate(-9px, -5px) rotate(-0.8deg); }
    24% { transform: translate(9px, 4px) rotate(0.8deg); }
    35% { transform: translate(-7px, 3px) rotate(-0.5deg); }
    47% { transform: translate(6px, -3px) rotate(0.4deg); }
    60% { transform: translate(-4px, 2px); }
    74% { transform: translate(3px, -1px); }
    88% { transform: translate(-1px, 1px); }
}

/* Fogonazo del garrotazo sobre la fila que se rompe */
.impact-flash {
    position: absolute;
    inset: -25% 0;
    background: linear-gradient(90deg, rgba(255, 244, 220, 0) 0%, rgba(255, 246, 226, 0.95) 18%, #fffaf0 50%, rgba(255, 246, 226, 0.95) 82%, rgba(255, 244, 220, 0) 100%);
    animation: impactFlash 0.24s ease-out forwards;
}

@keyframes impactFlash {
    0% { opacity: 1; transform: scaleY(1.4); }
    100% { opacity: 0; transform: scaleY(0.25); }
}

/* Fogonazo de todo el tablero en derrumbes grandes y en el final del granizo */
.board-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 60%, rgba(255, 240, 210, 0.42) 0%, rgba(255, 240, 210, 0.12) 55%, transparent 80%);
    animation: boardFlash 0.4s ease-out forwards;
}

.board-flash.big {
    background: radial-gradient(ellipse at 50% 60%, rgba(255, 244, 222, 0.65) 0%, rgba(255, 240, 210, 0.25) 60%, rgba(255, 240, 210, 0.08) 100%);
    animation-duration: 0.55s;
}

@keyframes boardFlash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .screen-shake.shake-2,
    .screen-shake.shake-3 {
        animation: none;
    }
}

/* ===== Botones: lajas de piedra ===== */
.game-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

button {
    font-family: var(--font-body);
    cursor: pointer;
}

.game-controls button,
#playAgainBtn,
.record-modal-buttons button {
    border: none;
    padding: 11px 20px;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--sand-100);
    background: var(--rock-500);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-400), var(--rock-500) 55%, var(--rock-600));
    border-radius: 10px 13px 9px 12px / 12px 9px 13px 10px;
    box-shadow:
        inset 0 1px 0 rgba(230, 215, 190, 0.2),
        inset 0 -3px 0 rgba(0, 0, 0, 0.3),
        0 4px 0 #1a1613,
        0 6px 12px rgba(0, 0, 0, 0.4);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.6);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.game-controls button:hover,
#playAgainBtn:hover,
.record-modal-buttons button:hover {
    filter: brightness(1.12);
}

.game-controls button:active,
#playAgainBtn:active,
.record-modal-buttons button:active {
    transform: translateY(3px);
    box-shadow:
        inset 0 1px 0 rgba(230, 215, 190, 0.15),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3),
        0 1px 0 #1a1613,
        0 2px 6px rgba(0, 0, 0, 0.4);
}

#startBtn,
#playAgainBtn,
#saveRecordBtn {
    background-image: var(--grain), linear-gradient(180deg, #c09466, var(--ochre) 55%, var(--ochre-dark));
    color: #24190f;
    text-shadow: 0 1px 0 rgba(255, 240, 215, 0.35);
}

#soundBtn,
#fullscreenBtn {
    padding: 11px 14px;
    min-width: 46px;
}

/* ===== Récords ===== */
.highscores-list {
    max-height: 230px;
    overflow-y: auto;
}

.highscore-item {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    margin-bottom: 6px;
    background: var(--rock-900);
    border-radius: 7px 9px 6px 8px;
    box-shadow: var(--sunken);
    font-size: 0.85rem;
}

.highscore-rank {
    font-weight: 800;
    color: var(--rock-300);
}

.highscore-name {
    color: var(--sand-100);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.highscore-score {
    font-weight: 600;
    color: var(--sand-200);
    font-variant-numeric: tabular-nums;
}

/* Podio: ocre, piedra clara y barro */
.highscore-item:nth-child(1) .highscore-rank,
.highscore-item:nth-child(1) .highscore-score { color: var(--ochre); }
.highscore-item:nth-child(1) { box-shadow: var(--sunken), inset 3px 0 0 var(--ochre); }
.highscore-item:nth-child(2) { box-shadow: var(--sunken), inset 3px 0 0 var(--sand-200); }
.highscore-item:nth-child(3) { box-shadow: var(--sunken), inset 3px 0 0 var(--clay); }

.no-records {
    font-size: 0.85rem;
    color: var(--rock-300);
    text-align: center;
    padding: 12px 4px;
    font-style: italic;
}

.highscores-list::-webkit-scrollbar { width: 6px; }
.highscores-list::-webkit-scrollbar-thumb { background: var(--rock-500); border-radius: 3px; }

/* ===== Pantallas superpuestas ===== */
.game-over-screen,
.record-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: rgba(10, 8, 6, 0.78);
    backdrop-filter: blur(3px);
    animation: fadeIn 0.25s ease-out;
}

.game-over-content,
.record-modal-content {
    width: min(380px, 100%);
    text-align: center;
    padding: 28px 26px;
    background: var(--rock-700);
    background-image: var(--grain), linear-gradient(170deg, var(--rock-600), var(--rock-800));
    border-radius: 16px 20px 14px 22px / 20px 14px 22px 16px;
    box-shadow: var(--carved), 0 24px 50px rgba(0, 0, 0, 0.6);
    animation: dropIn 0.35s cubic-bezier(0.3, 1.4, 0.6, 1);
}

.game-over-content h2,
.record-modal-content h2 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 2.2rem;
    color: var(--sand-200);
    margin-bottom: 14px;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8), 0 3px 10px rgba(0, 0, 0, 0.5);
}

.game-over-content p,
.record-modal-content p {
    color: var(--sand-200);
    margin: 6px 0;
}

.game-over-content span,
.record-score span {
    font-weight: 800;
    color: var(--ochre);
}

#playAgainBtn {
    margin-top: 18px;
    padding: 13px 28px;
    font-size: 1rem;
}

.new-record-notice {
    margin: 12px 0 4px;
}

.record-text {
    font-family: var(--font-title);
    font-size: 1.3rem;
    color: var(--ochre) !important;
    animation: pulse 1.4s ease-in-out infinite;
}

.record-score {
    font-size: 1.1rem;
    margin: 12px 0 !important;
}

.name-input-container {
    margin: 16px 0;
    text-align: left;
}

.name-input-container label {
    display: block;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--rock-300);
    margin-bottom: 6px;
}

#playerName {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font-body);
    font-size: 16px;
    color: var(--sand-100);
    background: var(--rock-900);
    border: 1px solid rgba(0, 0, 0, 0.6);
    border-radius: 9px;
    box-shadow: var(--sunken);
    outline: none;
}

#playerName::placeholder { color: var(--rock-400); }

#playerName:focus {
    border-color: var(--ochre);
    box-shadow: var(--sunken), 0 0 0 3px rgba(176, 132, 85, 0.25);
}

.record-modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.record-modal-buttons button {
    flex: 1;
}

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

@keyframes dropIn {
    from { transform: translateY(-40px) rotate(-1.5deg); opacity: 0; }
    to { transform: translateY(0) rotate(0); opacity: 1; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

/* ===== Ayudas táctiles ===== */
.touch-hint {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    color: #24190f;
    background: var(--ochre);
    background-image: var(--grain);
    border-radius: 10px 12px 9px 13px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 20;
    animation: touchHintPulse 2s ease-in-out infinite;
}

@keyframes touchHintPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.05); }
}

@media (hover: none) and (pointer: coarse) {
    .desktop-controls { display: none; }
    .touch-controls { display: block; }
    .touch-hint { display: block; }
}

/* ===== Pantallas medianas: paneles laterales debajo ===== */
@media (max-width: 900px) {
    body {
        padding: 10px;
        align-items: flex-start;
    }

    .game-container {
        padding: 14px 14px 16px;
        width: 100%;
    }

    .game-header { margin-bottom: 12px; }
    .game-header h1 { font-size: 2.4rem; }

    .game-board-container {
        display: grid;
        /* Columnas de los costados para que el panel de abajo no estire el tablero */
        grid-template-columns: 1fr auto auto 1fr;
        grid-template-areas:
            ". next board ."
            "side side side side";
        justify-content: center;
        gap: 12px;
    }

    .next-piece-container { grid-area: next; width: 120px; }
    .counter-item { flex-direction: column; align-items: center; gap: 2px; }
    .main-game-area { grid-area: board; }
    .side-panel {
        grid-area: side;
        width: 100%;
        flex-direction: row;
    }
    .side-panel > * { flex: 1; }

    #gameCanvas {
        height: min(540px, calc(100dvh - 250px));
    }
}

/* ===== Teléfonos: tablero a todo el ancho, botones justo debajo ===== */
@media (max-width: 520px) {
    body { padding: 0; }

    .game-container {
        display: flex;
        flex-direction: column;
        gap: 8px;
        border-radius: 0;
        min-height: 100dvh;
        padding: max(8px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
        box-shadow: none;
        border: none;
    }

    /* Los hijos del tablero pasan a ser parte de la columna principal */
    .game-board-container { display: contents; }
    .game-header { order: 0; margin-bottom: 0; }
    .next-piece-container { order: 1; }
    .main-game-area { order: 2; align-self: center; }
    .game-controls { order: 3; }
    .side-panel { order: 4; }

    .game-header h1 { font-size: 1.9rem; }
    .score-panel { gap: 6px; margin-top: 6px; }
    .score-item { min-width: 0; flex: 1; padding: 4px 6px 3px; }
    .score-label { font-size: 0.6rem; }
    .score-value { font-size: 1.05rem; }

    /* Próxima pieza y jugadores en una franja */
    .next-piece-container {
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        padding: 6px 10px;
    }
    .next-piece-container h3 { font-size: 0.8rem; margin: 0; }
    #nextCanvas, #holdCanvas { width: 48px; height: 48px; margin: 0; }
    .hold-slot { flex-direction: row; gap: 10px; }
    .hold-label { font-size: 0.8rem; align-self: auto; }
    .users-counter { margin: 0 0 0 auto; }
    .counter-item { flex-direction: row; align-items: baseline; gap: 8px; padding: 5px 9px; }
    .counter-text { font-size: 0.58rem; letter-spacing: 0.1em; }

    .main-game-area { padding: 5px; }
    .explosion-container { inset: 5px; }

    /* Alto limitado por la pantalla y por el ancho, sin deformar (2:3) */
    #gameCanvas {
        height: min(calc(100dvh - 250px), calc((100vw - 30px) * 1.5), 540px);
        min-height: 240px;
        max-width: none;
    }

    .side-panel { width: 100%; flex-direction: column; }
    .controls { display: none; }

    .game-controls { gap: 6px; margin-top: 2px; flex-wrap: nowrap; }
    .game-controls button { padding: 10px 8px; font-size: 0.85rem; flex: 1; min-width: 0; }
    #soundBtn, #fullscreenBtn { flex: 0 0 42px; min-width: 42px; padding: 10px 0; }
}

/* Pantalla horizontal baja (teléfono acostado) */
@media (max-height: 520px) and (orientation: landscape) {
    body { padding: 6px; align-items: center; }
    .game-header h1 { font-size: 1.6rem; }
    .controls { display: none; }
    .game-board-container {
        display: flex;
        gap: 10px;
    }
    .side-panel { width: 170px; flex-direction: column; }
    #gameCanvas {
        height: calc(100dvh - 140px);
        min-height: 200px;
    }
}

/* ===== Modo «solo juego» =====
   En celulares (con o sin pantalla completa) y en pantalla completa en cualquier
   equipo: todo entra en una pantalla, sin scroll. El ranking y la cuenta pasan a
   un panel que se abre con el botón 🏆. toscas.js pone la clase .compact en <html>
   y ajusta el tamaño exacto del tablero al espacio que queda. */
#fullscreenBtn[hidden] { display: none; }
.menu-btn,
.sheet-header,
.sheet-players,
.sheet-tip,
.sheet-backdrop { display: none; }

html.compact,
html.compact body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

html.compact body {
    position: fixed;
    inset: 0;
    padding: 0;
    display: block;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html.compact button { touch-action: manipulation; }

html.compact .user-chip,
html.compact .brand,
html.compact .users-counter,
html.compact .next-piece-container h3,
html.compact .side-panel {
    display: none;
}

html.compact .game-container {
    --safe-top: max(8px, env(safe-area-inset-top));
    --safe-bottom: max(8px, env(safe-area-inset-bottom));
    --safe-left: max(8px, env(safe-area-inset-left));
    --safe-right: max(8px, env(safe-area-inset-right));
    display: grid;
    width: 100%;
    height: 100vh;
    height: var(--app-height, 100dvh);
    min-height: 0;
    max-width: none;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

html.compact .game-board-container { display: contents; }
html.compact .game-header { grid-area: score; margin: 0; min-width: 0; }
html.compact .next-piece-container { grid-area: next; width: auto; margin: 0; padding: 4px; }
html.compact #nextCanvas,
html.compact #holdCanvas { width: 50px; height: 50px; margin: 0; }
html.compact .next-piece-container { flex-direction: row; gap: 6px; }
/* Sin títulos: un cartelito tallado abajo del hueco dice que es el de guardar */
html.compact .hold-slot { position: relative; }
html.compact .hold-label {
    position: absolute;
    left: 50%;
    bottom: -3px;
    transform: translateX(-50%);
    padding: 1px 5px 0;
    border-radius: 5px;
    font-size: 0.48rem;
    letter-spacing: 0.06em;
    line-height: 1.3;
    background: var(--rock-600);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    align-self: auto;
}
html.compact .main-game-area { grid-area: board; place-self: center; padding: 4px; }
html.compact .explosion-container { inset: 4px; }
html.compact #gameCanvas { min-height: 0; max-width: none; }
html.compact .game-controls { grid-area: controls; margin: 0; }
html.compact .score-panel { margin: 0; gap: 6px; }
html.compact .score-item { min-width: 0; padding: 5px 4px 4px; }
html.compact .score-label { font-size: 0.58rem; }
html.compact .score-value { font-size: 1.15rem; }
html.compact .best-slab { margin-top: 10px; padding: 3px 12px 2px; min-width: 0; width: 100%; box-sizing: border-box; }
html.compact .best-label { font-size: 0.62rem; }
html.compact .best-value { font-size: 0.95rem; }

html.compact .menu-btn {
    display: flex;
    grid-area: menu;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 12px 14px 11px 13px;
    font-size: 1.25rem;
    background: var(--rock-600);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-500), var(--rock-700));
    box-shadow: var(--carved);
}

html.compact .game-controls button {
    min-width: 0;
    padding: 11px 4px;
    font-size: 0.82rem;
    letter-spacing: 0.02em;
}

/* Vertical: próxima, puntos y 🏆 arriba; tablero; botones abajo */
@media (orientation: portrait) {
    html.compact .game-container {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "next score menu"
            "board board board"
            "controls controls controls";
        align-items: center;
        gap: 8px;
        padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    }

    html.compact .score-item { flex: 1; }

    html.compact #gameCanvas {
        height: min(calc(100dvh - 183px - var(--safe-top) - var(--safe-bottom)), calc((100vw - 24px) * 1.5));
    }

    html.compact .game-controls { display: flex; gap: 6px; flex-wrap: nowrap; }
    html.compact .game-controls button { flex: 1; }
    html.compact #soundBtn,
    html.compact #fullscreenBtn { flex: 0 0 44px; padding: 11px 0; }
}

/* Horizontal: puntos a la izquierda, tablero al centro, próxima y botones a la derecha */
@media (orientation: landscape) {
    html.compact .game-container {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        grid-template-areas:
            "menu board next"
            "score board controls";
        align-items: center;
        justify-items: center;
        column-gap: 14px;
        row-gap: 8px;
        padding: 6px var(--safe-right) 6px var(--safe-left);
    }

    html.compact .menu-btn { align-self: start; justify-self: start; }
    html.compact .game-header { align-self: start; }
    html.compact .score-panel { flex-direction: column; gap: 6px; }
    html.compact .score-item { min-width: 86px; }
    html.compact .next-piece-container { align-self: end; }
    html.compact #gameCanvas { height: calc(100dvh - 22px); }
    html.compact .game-controls {
        align-self: start;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        width: min(210px, 100%);
    }
    html.compact .game-controls button { padding: 9px 4px; font-size: 0.78rem; }
}

/* ===== Panel de récords y cuenta (solo en modo «solo juego») ===== */
html.compact.sheet-open .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 140;
    background: rgba(12, 10, 8, 0.6);
    backdrop-filter: blur(2px);
}

html.compact.sheet-open .side-panel {
    display: flex;
    position: fixed;
    z-index: 150;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(440px, 100%);
    max-height: min(85%, 560px);
    flex-direction: column;
    gap: 10px;
    padding: 14px max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    background: var(--rock-800);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-700), var(--rock-900));
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
    animation: sheetUp 0.22s ease-out;
    -webkit-user-select: text;
    user-select: text;
}

@keyframes sheetUp {
    from { transform: translate(-50%, 40px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

html.compact.sheet-open .side-panel .controls { display: none; }
html.compact.sheet-open .highscores-container { display: flex; flex-direction: column; min-height: 0; flex: 1; }
html.compact.sheet-open .highscores-list { max-height: none; flex: 1; min-height: 0; }

html.compact.sheet-open .sheet-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sheet-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    font-weight: 600;
    color: var(--sand-100);
}

.sheet-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-user img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.sheet-user img[hidden] { display: none; }

.sheet-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    font-size: 1rem;
    color: var(--sand-100);
    background: var(--rock-600);
}

html.compact.sheet-open .sheet-players {
    display: block;
    font-size: 0.8rem;
    color: var(--rock-300);
}

html.compact.sheet-open .sheet-players strong { color: var(--ochre); }

html.compact.sheet-open .sheet-tip:not([hidden]) {
    display: block;
    padding: 8px 10px;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--sand-200);
    background: var(--rock-900);
    border-radius: 10px;
    box-shadow: var(--sunken);
}

/* Las ventanas (login, fin, récord) siempre entran en pantallas bajas */
.login-content,
.game-over-content,
.record-modal-content {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
}

@media (max-width: 768px) {
    .highscores-list {
        -webkit-overflow-scrolling: touch;
    }
}

@media (prefers-reduced-motion: reduce) {
    .screen-shake,
    .counter-number,
    .record-text,
    .touch-hint {
        animation: none;
    }
}

/* ===== Login ===== */
.login-screen {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: rgba(12, 10, 8, 0.82);
    backdrop-filter: blur(4px);
}

.login-content {
    width: min(400px, 100%);
    text-align: center;
    padding: 34px 28px 28px;
    background: var(--rock-700);
    background-image: var(--grain), linear-gradient(170deg, var(--rock-600), var(--rock-800));
    border-radius: 16px 20px 14px 22px / 20px 14px 22px 16px;
    box-shadow: var(--carved), 0 24px 50px rgba(0, 0, 0, 0.6);
    animation: dropIn 0.35s cubic-bezier(0.3, 1.4, 0.6, 1);
}

.login-content h2 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 3rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sand-200);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8), 0 2px 0 rgba(230, 215, 190, 0.12), 0 4px 12px rgba(0, 0, 0, 0.6);
    margin-bottom: 12px;
}

.login-lead {
    color: var(--sand-100);
    font-size: 1rem;
    line-height: 1.45;
    margin-bottom: 6px;
}

.login-note {
    color: var(--rock-300);
    font-size: 0.85rem;
    margin-bottom: 22px;
}

.google-login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 280px;
    padding: 12px 18px;
    border: none;
    border-radius: 10px 12px 9px 13px;
    font-size: 1rem;
    font-weight: 600;
    color: #2a2420;
    background: var(--sand-100);
    background-image: var(--grain), linear-gradient(180deg, #f1e9dc, var(--sand-200));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 -3px 0 rgba(0, 0, 0, 0.15), 0 4px 0 #1a1613, 0 6px 12px rgba(0, 0, 0, 0.4);
    transition: transform 0.08s ease, filter 0.15s ease;
}

.google-login-btn:hover:not(:disabled) { filter: brightness(1.05); }
.google-login-btn:active:not(:disabled) { transform: translateY(3px); }
.google-login-btn:disabled { opacity: 0.7; cursor: default; }

/* Entrar con Apple: botón negro, como pide Apple */
.apple-login-btn {
    margin-top: 12px;
    color: #fff;
    background: #000;
    background-image: none;
}
.apple-login-btn[hidden] { display: none; }

.apple-logo {
    width: 18px;
    height: 20px;
    flex: none;
    margin-top: -2px;
}

.google-logo {
    width: 20px;
    height: 20px;
    flex: none;
}

.login-error {
    min-height: 1.3em;
    margin-top: 14px;
    font-size: 0.85rem;
    color: #e0a17a;
}

/* ===== Usuario logueado ===== */
.user-chip {
    position: absolute;
    top: 14px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 4px 6px;
    background: var(--rock-900);
    border-radius: 999px;
    box-shadow: var(--sunken);
    z-index: 10;
}

.user-chip[hidden] { display: none; }

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    max-width: 110px;
    font-size: 0.82rem;
    color: var(--sand-200);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    border: none;
    padding: 5px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sand-100);
    background: var(--rock-500);
    border-radius: 999px;
}

.logout-btn:hover { filter: brightness(1.15); }

@media (max-width: 520px) {
    .game-header { position: relative; }
    .user-chip {
        position: static;
        order: -1;
        align-self: flex-end;
        margin-bottom: -4px;
    }
    .user-name { max-width: 90px; }
    .login-content h2 { font-size: 2.4rem; }
}

/* ===== Logo: el cavernícola ===== */
.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 14px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    flex: none;
    border-radius: 22%;
    box-shadow: 0 0 0 2px #15110e, 0 4px 10px rgba(0, 0, 0, 0.5);
    transform: rotate(-4deg);
}

.login-logo {
    display: block;
    width: auto;
    height: 190px;
    margin: -12px auto 6px;
    transform-origin: 50% 100%;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
    animation: cavemanBob 3.2s ease-in-out infinite;
}

@keyframes cavemanBob {
    0%, 100% { transform: rotate(-3deg) translateY(0); }
    50% { transform: rotate(3deg) translateY(-4px); }
}

@media (max-width: 900px) {
    .brand-logo { width: 52px; height: 52px; }
}

@media (max-width: 520px) {
    .brand { gap: 8px; justify-content: flex-start; }
    .brand-logo { width: 40px; height: 40px; }
}

@media (max-height: 520px) and (orientation: landscape) {
    .brand-logo { width: 36px; height: 36px; }
    .login-logo { height: 96px; margin-bottom: 2px; }
}


@media (prefers-reduced-motion: reduce) {
    .login-logo { animation: none; }
}

/* Ventanas más compactas en celular acostado */
@media (max-height: 520px) and (orientation: landscape) {
    .login-content,
    .game-over-content,
    .record-modal-content { padding: 14px 20px; }
    .login-content h2 { font-size: 1.8rem; margin-bottom: 4px; }
    .login-logo { height: 72px; margin: -4px auto 2px; }
    .login-lead { font-size: 0.85rem; margin-bottom: 2px; }
    .login-note { margin-bottom: 10px; }
    .login-error { margin-top: 6px; }
    .game-over-content h2,
    .record-modal-content h2 { font-size: 1.8rem; margin-bottom: 6px; }
}

/* ===== El cavernícola rompe la fila ===== */
.caveman-smash {
    position: absolute;
    z-index: 8;
    pointer-events: none;
    aspect-ratio: 364 / 420;
    animation-name: cavemanSmash;
    animation-fill-mode: both;
    animation-timing-function: linear;
    will-change: transform;
}

.caveman-smash img {
    display: block;
    height: 100%;
    width: auto;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
}

/* Llega de costado, se echa apenas para atrás, garrotazo, festeja con un
   saltito y se va por donde vino. Siempre derecho, como en la imagen. La pose del golpe (--hit-rot) y la dirección de
   llegada (--fx, --fy) las calcula toscas.js para no tapar lo que explota. */
.caveman-smash.flipped img { transform: scaleX(-1); }

@keyframes cavemanSmash {
    0%   { transform: translate(var(--fx), 0) rotate(var(--hit-rot)); opacity: 0; animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
    10%  { opacity: 1; }
    24%  { transform: translate(0, -10%) rotate(var(--hit-rot)); animation-timing-function: ease-in; }
    30%  { transform: translate(0, 0) rotate(var(--hit-rot)) scale(1.04, 0.94); animation-timing-function: ease-out; }
    44%  { transform: translate(calc(var(--fx) * 0.06), 0) rotate(calc(var(--hit-rot) - 12deg * var(--flip))) scale(0.98, 1.03); animation-timing-function: cubic-bezier(0.7, 0, 1, 0.5); }
    50%  { transform: translate(0, 0) rotate(var(--hit-rot)) scale(1.05, 0.95); animation-timing-function: ease-out; }
    58%  { transform: translate(0, 0) rotate(calc(var(--hit-rot) + 3deg * var(--flip))) scale(1, 1); }
    66%  { transform: translate(0, 0) rotate(var(--hit-rot)); animation-timing-function: ease-in-out; }
    76%  { transform: translate(0, -12%) rotate(var(--hit-rot)); animation-timing-function: ease-in; }
    82%  { transform: translate(0, 0) rotate(var(--hit-rot)) scale(1.03, 0.96); animation-timing-function: ease-in; }
    100% { transform: translate(calc(var(--fx) * 1.1), 0) rotate(var(--hit-rot)); opacity: 0; }
}

/* El cartel de historieta del golpe */
.smash-word {
    /* Globito de diálogo: lo «dice» el personaje que golpea */
    --bubble: #fff3a6; /* amarillo claro */
    --bubble-line: #3d2410;
    position: absolute;
    z-index: 9;
    pointer-events: none;
    transform: translate(-50%, -50%);
    padding: 9px 15px 6px;
    font-family: 'Luckiest Guy', var(--font-title);
    font-size: clamp(1rem, 5.6vmin, 1.7rem);
    letter-spacing: 0.04em;
    white-space: nowrap;
    line-height: 1;
    color: #6b3a14; /* marrón */
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
    background: var(--bubble);
    border: 3px solid var(--bubble-line);
    border-radius: 22px 24px 20px 26px / 24px 20px 26px 22px;
    filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.35));
    animation: smashWord 0.9s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

/* Colita del globito: contorno (::before) y relleno (::after) */
.smash-word::before,
.smash-word::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

/* Por defecto, colita abajo al centro */
.smash-word::before {
    left: calc(50% - 9px);
    bottom: -17px;
    border-width: 16px 9px 0 9px;
    border-color: var(--bubble-line) transparent transparent transparent;
}
.smash-word::after {
    left: calc(50% - 6px);
    bottom: -11px;
    border-width: 11px 6px 0 6px;
    border-color: var(--bubble) transparent transparent transparent;
}

/* Colita hacia abajo a la izquierda / derecha (apunta al golpe) */
.smash-word.tail-left::before { left: 16px; border-width: 18px 4px 0 14px; }
.smash-word.tail-left::after  { left: 20px; border-width: 12px 3px 0 9px; }
.smash-word.tail-right::before { left: auto; right: 16px; border-width: 18px 14px 0 4px; }
.smash-word.tail-right::after  { left: auto; right: 20px; border-width: 12px 9px 0 3px; }

.smash-word.quad {
    --bubble: #ffec85;
    font-size: clamp(1.2rem, 7.2vmin, 2.2rem);
}

/* Carteles largos ("¡PEDREGULLO Y TOSCA!!"): letra más chica para que entren */
.smash-word.long {
    --bubble: #ffec85;
    font-size: clamp(0.85rem, 4.4vmin, 1.45rem);
}

@keyframes smashWord {
    0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-25deg); opacity: 0; }
    18%  { transform: translate(-50%, -50%) scale(1.25) rotate(-8deg); opacity: 1; }
    30%  { transform: translate(-50%, -50%) scale(1) rotate(-6deg); }
    75%  { transform: translate(-50%, -62%) scale(1) rotate(-4deg); opacity: 1; }
    100% { transform: translate(-50%, -80%) scale(0.9) rotate(-2deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .caveman-smash { animation-name: cavemanSmashCalm; }
    @keyframes cavemanSmashCalm {
        0%, 100% { opacity: 0; transform: rotate(var(--hit-rot)); }
        15%, 85% { opacity: 1; transform: rotate(var(--hit-rot)); }
    }
}

.club-swoosh {
    position: absolute;
    inset: 0;
    z-index: 7;
    pointer-events: none;
    overflow: visible;
    animation: clubSwoosh 0.32s ease-out both;
}

@keyframes clubSwoosh {
    0%   { opacity: 0; }
    25%  { opacity: 1; }
    100% { opacity: 0; }
}

/* Carteles largos ("¡PEDREGULLO Y TOSCA!!"): letra más chica para que entren */


/* ===== Loader: el cavernícola martilla una piedra mientras carga ===== */
.app-loader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at 50% 35%, rgba(176, 132, 85, 0.16), transparent 60%),
        var(--grain-coarse),
        var(--grain),
        linear-gradient(180deg, #1d1916 0%, var(--bg-deep) 100%);
    transition: opacity 0.35s ease, visibility 0.35s;
}

.app-loader.done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-stage {
    position: relative;
    width: 240px;
    height: 170px;
}

/* Imagen 420×391: pies en (28 %, 97 %), cabeza del garrote en (90 %, 18 %) */
.loader-caveman {
    position: absolute;
    left: 6px;
    bottom: 6px;
    height: 150px;
    width: auto;
    transform-origin: 28% 97%;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
    animation: loaderSwing 1.1s infinite;
}

@keyframes loaderSwing {
    0%   { transform: rotate(-26deg); animation-timing-function: ease-in-out; }
    45%  { transform: rotate(-34deg) scale(1.02, 0.98); animation-timing-function: cubic-bezier(0.7, 0, 1, 0.6); }
    58%  { transform: rotate(20deg) scale(1.03, 0.97); animation-timing-function: ease-out; }
    66%  { transform: rotate(15deg); }
    80%  { transform: rotate(18deg); animation-timing-function: ease-in-out; }
    100% { transform: rotate(-26deg); }
}

/* La piedra que recibe los garrotazos */
.loader-stone {
    position: absolute;
    left: 162px;
    top: 92px;
    width: 50px;
    height: 46px;
    border-radius: 7px 9px 6px 10px;
    background: var(--rock-400);
    background-image: var(--grain), linear-gradient(160deg, #a59886, #6f665c 70%, #57504a);
    box-shadow: inset 0 2px 0 rgba(255, 245, 225, 0.2), inset 0 -4px 0 rgba(0, 0, 0, 0.35), 0 6px 10px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: loaderStoneHit 1.1s infinite;
}

@keyframes loaderStoneHit {
    0%, 57%, 100% { transform: translate(0, 0); }
    60% { transform: translate(2px, 3px) scale(1.04, 0.94); }
    64% { transform: translate(-2px, 0); }
    68% { transform: translate(1px, 0); }
}

/* Grietas: una más con cada golpe; a los tres golpes, piedra nueva */
.loader-crack {
    position: absolute;
    height: 3px;
    background: #1d1814;
    border-radius: 2px;
    opacity: 0;
    animation: 3.3s infinite step-end;
}
.loader-crack.c1 { left: 6px; top: 14px; width: 30px; transform: rotate(18deg); animation-name: loaderCrack1; }
.loader-crack.c2 { left: 18px; top: 26px; width: 26px; transform: rotate(-32deg); animation-name: loaderCrack2; }
.loader-crack.c3 { left: 4px; top: 32px; width: 22px; transform: rotate(8deg); animation-name: loaderCrack3; }
@keyframes loaderCrack1 { 0% { opacity: 0; } 19.5% { opacity: 1; } }
@keyframes loaderCrack2 { 0% { opacity: 0; } 52.8% { opacity: 1; } }
@keyframes loaderCrack3 { 0% { opacity: 0; } 86% { opacity: 1; } }

/* Polvo en cada golpe */
.loader-dust {
    position: absolute;
    left: 146px;
    top: 70px;
    width: 80px;
    height: 70px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(203, 189, 166, 0.55) 0%, rgba(150, 135, 115, 0.2) 45%, transparent 70%);
    opacity: 0;
    pointer-events: none;
    animation: loaderDust 1.1s infinite;
}

@keyframes loaderDust {
    0%, 57% { opacity: 0; transform: scale(0.4); }
    61% { opacity: 1; transform: scale(0.9); }
    85%, 100% { opacity: 0; transform: scale(1.4) translateY(-10px); }
}

.loader-title {
    font-family: var(--font-title);
    font-size: 2.2rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sand-200);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8), 0 4px 12px rgba(0, 0, 0, 0.6);
    margin-top: 6px;
}

.loader-text {
    font-size: 0.9rem;
    color: var(--rock-300);
}

@media (prefers-reduced-motion: reduce) {
    .loader-caveman, .loader-stone, .loader-crack, .loader-dust { animation: none; }
    .loader-caveman { transform: rotate(18deg); }
}

/* ===== Fila «Creá tu acceso en el teléfono» =====
   Solo en el celular abierto desde el navegador: no en la app instalada ni en
   pantalla completa ni en computadoras (toscas.js pone .can-install en <html>). */
.install-row { display: none; }

html.can-install:not(.in-fullscreen) .install-row {
    display: flex;
    grid-area: install;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid rgba(230, 215, 190, 0.14);
    border-radius: 10px;
    font: inherit;
    color: var(--sand-100);
    background: rgba(40, 34, 29, 0.55);
    cursor: pointer;
    text-align: left;
}

html.can-install:not(.in-fullscreen) .install-row:active { opacity: 0.7; }

.install-row svg {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: var(--ochre);
    stroke-width: 2;
    stroke-linecap: round;
}

.install-text {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.install-how {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ochre);
}

/* En modo «solo juego» la fila ocupa su propia franja abajo de los botones */
html.compact.can-install:not(.in-fullscreen) .install-row { margin: 0; padding: 7px 12px; }

@media (orientation: portrait) {
    html.compact.can-install:not(.in-fullscreen) .game-container {
        grid-template-rows: auto minmax(0, 1fr) auto auto;
        grid-template-areas:
            "next score menu"
            "board board board"
            "controls controls controls"
            "install install install";
    }
}

@media (orientation: landscape) {
    html.compact.can-install:not(.in-fullscreen) .game-container {
        grid-template-rows: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "menu board next"
            "score board controls"
            "score board install";
    }
    html.compact.can-install:not(.in-fullscreen) .install-row { width: min(210px, 100%); align-self: end; }
    html.compact.can-install:not(.in-fullscreen) .install-text { font-size: 0.72rem; }
}

/* Guía de instalación */
.install-modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    background: rgba(12, 10, 8, 0.7);
}

.install-modal[hidden] { display: none; }

.install-card {
    width: min(480px, 100%);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 20px 18px 16px;
    background: var(--rock-700);
    background-image: var(--grain), linear-gradient(170deg, var(--rock-600), var(--rock-800));
    border-radius: 16px;
    box-shadow: var(--carved), 0 20px 40px rgba(0, 0, 0, 0.6);
    animation: dropIn 0.3s ease-out;
    -webkit-user-select: text;
    user-select: text;
}

.install-card h2 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 1.5rem;
    color: var(--sand-200);
    margin-bottom: 8px;
}

.install-lead {
    font-size: 0.88rem;
    color: var(--rock-300);
    margin-bottom: 12px;
    line-height: 1.4;
}

.install-steps {
    list-style: none;
    counter-reset: paso;
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 16px;
}

.install-steps li {
    counter-increment: paso;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.92rem;
    line-height: 1.35;
    color: var(--sand-100);
}

.install-steps li::before {
    content: counter(paso) ".";
    width: 18px;
    flex: none;
    font-weight: 800;
    color: var(--ochre);
}

.install-steps svg {
    width: 16px;
    height: 16px;
    flex: none;
    margin-top: 2px;
    fill: none;
    stroke: var(--ochre);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.install-ok {
    display: block;
    margin-left: auto;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font: inherit;
    font-weight: 700;
    color: #2a1d12;
    background: var(--sand-200);
    cursor: pointer;
}

/* ===== Tosca time: cartel mientras se apunta el pedrusco ===== */
.tosca-banner {
    --bubble: #fff3a6;
    --bubble-line: #3d2410;
    position: absolute;
    left: 50%;
    top: 38%;
    z-index: 9;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 22px 11px;
    pointer-events: none;
    line-height: 1.1;
    text-align: center;
    background: var(--bubble);
    border: 3px solid var(--bubble-line);
    border-radius: 26px 30px 24px 32px / 30px 24px 32px 26px;
    filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
    animation: toscaIn 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

/* Colita hacia arriba: «habla» el pedrusco */
.tosca-banner::before,
.tosca-banner::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}
.tosca-banner::before {
    left: calc(50% - 11px);
    top: -21px;
    border-width: 0 11px 20px 11px;
    border-color: transparent transparent var(--bubble-line) transparent;
}
.tosca-banner::after {
    left: calc(50% - 7px);
    top: -14px;
    border-width: 0 7px 14px 7px;
    border-color: transparent transparent var(--bubble) transparent;
}

.tosca-banner strong {
    font-family: 'Luckiest Guy', var(--font-title);
    font-weight: 400;
    font-size: clamp(1.6rem, 8.5vmin, 2.6rem);
    letter-spacing: 0.04em;
    white-space: nowrap;
    color: #6b3a14;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
    animation: toscaPulse 0.9s ease-in-out 0.5s infinite alternate;
}

.tosca-banner span {
    font-size: 0.8rem;
    font-weight: 600;
    color: #7a4a22;
    white-space: nowrap;
}

@keyframes toscaIn {
    from { transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1) rotate(-3deg); opacity: 1; }
}

@keyframes toscaPulse {
    from { transform: scale(1); }
    to   { transform: scale(1.07); }
}

@media (prefers-reduced-motion: reduce) {
    .tosca-banner, .tosca-banner strong { animation: none; }
}

.game-controls button:disabled {
    opacity: 0.45;
    cursor: default;
    filter: none;
    transform: none;
}

/* iPad en vertical: el mismo diseño que el teléfono, con todo un poco más grande */
@media (orientation: portrait) and (min-width: 700px) {
    html.compact .game-container { gap: 12px; }
    html.compact #nextCanvas,
    html.compact #holdCanvas { width: 72px; height: 72px; }
    html.compact .score-panel { gap: 10px; }
    html.compact .score-item { padding: 8px 6px 6px; }
    html.compact .score-label { font-size: 0.78rem; }
    html.compact .score-value { font-size: 1.7rem; }
    html.compact .menu-btn { width: 62px; height: 62px; font-size: 1.7rem; }
    html.compact .game-controls { gap: 10px; }
    html.compact .game-controls button { padding: 15px 8px; font-size: 1.05rem; }
    html.compact #soundBtn,
    html.compact #fullscreenBtn { flex: 0 0 62px; padding: 15px 0; }
    html.compact.can-install:not(.in-fullscreen) .install-row { padding: 11px 16px; }
    html.compact .install-text,
    html.compact .install-how { font-size: 0.98rem; }
    html.compact .smash-word { font-size: clamp(1.6rem, 4.5vmin, 2.6rem); }
}

/* Humito al encastrar: nubecitas semitransparentes que se abren y se desvanecen */
.land-smoke {
    position: absolute;
    width: calc(100% / 12 * 1.6);
    aspect-ratio: 1.3;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 60%,
        rgba(232, 222, 205, 0.72) 0%,
        rgba(210, 198, 180, 0.42) 34%,
        rgba(180, 168, 150, 0.16) 56%,
        transparent 72%);
    filter: blur(1px);
    opacity: 0;
    animation: landSmoke 0.75s ease-out forwards;
}

@keyframes landSmoke {
    0%   { transform: translate(-50%, -50%) scale(0.35); opacity: 0; }
    18%  { opacity: 0.95; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% - 16px)) scale(1.7); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .land-smoke { animation-duration: 0.4s; }
}

/* ===== Lluvia de granizo ===== */
.hailstone {
    position: absolute;
    top: -16px;
    border-radius: 48% 52% 45% 55% / 55% 45% 55% 45%;
    pointer-events: none;
    background: radial-gradient(circle at 35% 30%, #ffffff 0%, #e6eef3 45%, #a8b9c6 100%);
    box-shadow: 0 0 6px rgba(220, 235, 245, 0.6), inset -1px -2px 1px rgba(60, 80, 95, 0.35);
    opacity: 0;
    animation-name: hailFall;
    animation-timing-function: cubic-bezier(0.45, 0, 1, 1);
    animation-fill-mode: forwards;
}

@keyframes hailFall {
    0%   { transform: translate(0, 0); opacity: 0; }
    8%   { opacity: 1; }
    92%  { opacity: 1; }
    100% { transform: translate(var(--drift), var(--fall)); opacity: 0; }
}

/* Globo del granizo: sin colita (no lo dice nadie), bien al centro */
.hail-banner { top: 40%; }
.hail-banner::before,
.hail-banner::after { display: none; }
.hail-banner strong { font-size: clamp(1.3rem, 7vmin, 2.2rem); }

/* ===== Configuración ===== */
.settings-container {
    background: var(--rock-700);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-600), var(--rock-700));
    border-radius: 12px 14px 11px 15px;
    padding: 14px;
    box-shadow: var(--carved);
}

.settings-container h3 {
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 1.15rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sand-200);
    margin-bottom: 10px;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.setting-row + .setting-row { margin-top: 12px; }
.setting-row[hidden] { display: none; }

.setting-label {
    font-size: 0.78rem;
    color: var(--rock-300);
    letter-spacing: 0.04em;
}

/* Selector de idioma: dos botones pegados, el elegido resaltado */
.lang-switch {
    display: flex;
    padding: 3px;
    gap: 3px;
    background: var(--rock-900);
    border-radius: 10px;
    box-shadow: var(--sunken);
}

.lang-switch button {
    flex: 1;
    padding: 7px 8px;
    border: none;
    border-radius: 8px;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--rock-300);
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
}

.theme-switch button { min-width: 0; padding-inline: 3px; }

.lang-switch button[aria-pressed="true"] {
    color: #2a1d12;
    background: var(--sand-200);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 2px 4px rgba(0, 0, 0, 0.35);
}

/* En el login, más chico y centrado */
.login-lang {
    width: min(220px, 100%);
    margin: 14px auto 0;
}

/* En el panel del celular, la configuración va debajo de los récords */
html.compact.sheet-open .settings-container { flex: none; }

/* ===== Salir de la app (Android) ===== */
.exit-modal { z-index: 400; }

/* ===== Cartel de derrumbe: el cavernícola enojado ===== */
.over-caveman {
    position: relative;
    width: 140px;
    height: 162px;
    margin: -6px auto 6px;
}

.over-caveman img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.55)) saturate(1.15);
    transform-origin: 50% 100%;
    animation: overStomp 1.4s ease-in-out 0.35s infinite;
}

/* Marca de enojo, al lado de la cabeza */
.over-anger {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    fill: none;
    stroke: #e0402e;
    stroke-width: 4.5;
    stroke-linecap: round;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
    animation: overAnger 0.7s ease-in-out infinite;
}

/* Humo que le sale de la cabeza */
.over-steam {
    position: absolute;
    top: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(236, 227, 210, 0.55);
    opacity: 0;
    animation: overSteam 1.4s ease-out infinite;
}

.over-steam.st1 { left: 54px; }
.over-steam.st2 { left: 76px; animation-delay: 0.7s; }

@keyframes overStomp {
    0%, 55%, 100% { transform: translateY(0) rotate(0); }
    62% { transform: translateY(-8px) rotate(-4deg); }
    70% { transform: translateY(0) rotate(3deg); }
    76% { transform: translateX(-3px) rotate(-2deg); }
    82% { transform: translateX(3px) rotate(1deg); }
    88% { transform: translateX(0) rotate(0); }
}

@keyframes overAnger {
    0%, 100% { transform: scale(0.85); }
    50% { transform: scale(1.15); }
}

@keyframes overSteam {
    0% { transform: translateY(8px) scale(0.5); opacity: 0; }
    25% { opacity: 0.8; }
    100% { transform: translateY(-26px) scale(1.4); opacity: 0; }
}

@media (max-height: 520px) and (orientation: landscape) {
    .over-caveman { width: 70px; height: 80px; margin: -4px auto 2px; }
    .over-anger { width: 18px; height: 18px; top: 2px; right: 2px; }
    .over-steam { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .over-caveman img,
    .over-anger,
    .over-steam { animation: none; }
}

/* ===== Festejo al perder: récord personal / top 5 ===== */
.celebrate { display: none; position: relative; height: 170px; margin: -6px auto 4px; }
.game-over-content.is-celebrating .celebrate { display: block; }
.game-over-content.is-celebrating .over-caveman { display: none; }
.celebrate-small { display: block; height: 120px; margin: -4px auto 0; }
.celebrate-small:empty { display: none; }

.cel-cast {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 6px;
}
.cel-figure { height: 100%; transform-origin: 50% 100%; animation: celJump 0.9s ease-in-out var(--delay, 0s) infinite; }
.cel-figure img {
    height: 100%;
    width: auto;
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.55)) saturate(1.15);
}
.cel-woman { height: 90%; }
@keyframes celJump {
    0%, 100% { transform: translateY(0) scale(1.04, 0.94); }
    18% { transform: translateY(0) scale(0.96, 1.05); }
    45% { transform: translateY(-22%) rotate(-5deg) scale(1); }
    62% { transform: translateY(-16%) rotate(4deg); }
    85% { transform: translateY(0) scale(1.05, 0.93); }
}

.cel-star {
    position: absolute;
    left: var(--x);
    top: var(--y);
    font-size: 1.3rem;
    color: #ffd27a;
    text-shadow: 0 0 8px rgba(255, 200, 90, 0.8);
    animation: celTwinkle 1.2s ease-in-out var(--d) infinite;
    pointer-events: none;
}
@keyframes celTwinkle {
    0%, 100% { transform: scale(0.4) rotate(0deg); opacity: 0.2; }
    50% { transform: scale(1.15) rotate(30deg); opacity: 1; }
}

/* Piedritas que llueven como papel picado */
.cel-chip {
    position: absolute;
    top: -10px;
    left: var(--x);
    width: 7px;
    height: 6px;
    border-radius: 2px 3px 1px 3px;
    background: linear-gradient(135deg, #cbbda6, #7a6d60);
    transform: rotate(var(--r));
    animation: celChip 1.6s linear var(--d) infinite;
    pointer-events: none;
}
@keyframes celChip {
    0% { transform: translateY(0) rotate(var(--r)); opacity: 0; }
    10% { opacity: 1; }
    100% { transform: translateY(190px) rotate(calc(var(--r) + 300deg)); opacity: 0; }
}

.record-subtext { margin: 2px 0 0; font-size: 0.85rem; color: var(--sand-200); }
.record-place { margin: 0 0 4px; font-weight: 700; color: #ffd27a; }

@media (max-height: 700px) {
    .celebrate { height: 90px; margin: -4px auto 2px; }
    .celebrate-small { height: 80px; }
}
@media (prefers-reduced-motion: reduce) {
    .cel-figure, .cel-star, .cel-chip { animation: none; }
}

/* ===== Pieza de fuego ===== */
.smash-word.fire-word {
    --bubble: #ffd27a;
    color: #9a2a08;
}

/* Humo enrojecido sobre cada piedra que se quema */
.fire-burst {
    position: absolute;
    width: calc(100% / 12 * 1.7);
    aspect-ratio: 1;
    transform: translate(-50%, -50%) scale(0.4);
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle,
        rgba(225, 80, 40, 0.75) 0%,
        rgba(170, 70, 50, 0.45) 40%,
        rgba(110, 80, 70, 0) 70%);
    filter: blur(2px);
    opacity: 0;
    animation: fireBurst 1s ease-out forwards;
}

@keyframes fireBurst {
    0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
    15%  { opacity: 1; }
    100% { transform: translate(-50%, calc(-50% - 50px)) scale(2); opacity: 0; filter: blur(3px) grayscale(0.6); }
}

/* Escarcha de golpe sobre la pieza que se apaga */
.fire-frost {
    position: absolute;
    width: calc(100% / 12);
    aspect-ratio: 1;
    border-radius: 18%;
    pointer-events: none;
    background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.9), rgba(190, 225, 245, 0.7) 55%, rgba(140, 190, 225, 0.4));
    box-shadow: 0 0 10px rgba(200, 235, 255, 0.8);
    animation: fireFrost 0.8s ease-out forwards;
}

@keyframes fireFrost {
    0%   { opacity: 0; }
    10%  { opacity: 1; }
    40%  { opacity: 0.85; }
    100% { opacity: 0; }
}

/* Vapor que sube después de apagarse */
.fire-steam {
    position: absolute;
    width: calc(100% / 12 * 1.4);
    aspect-ratio: 1;
    transform: translate(-50%, -50%) scale(0.4);
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(245, 245, 240, 0.75) 0%, rgba(220, 220, 215, 0.35) 45%, transparent 70%);
    filter: blur(2px);
    opacity: 0;
    animation: fireSteam 1.4s ease-out forwards;
}

@keyframes fireSteam {
    0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
    20%  { opacity: 0.9; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% - 60px)) scale(2.2); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .fire-burst, .fire-steam { animation-duration: 0.5s; }
}

/* ===== Cambio de nivel: alguien golpea la pantalla ===== */
.level-up {
    position: fixed;
    inset: 0;
    z-index: 500;
    pointer-events: none;
    overflow: hidden;
}

/* Espejado de toda la escena (el personaje sigue centrado) */
.lu-flip {
    position: absolute;
    inset: 0;
    scale: var(--flip) 1;
}

.lu-actor {
    position: absolute;
    left: 50%;
    bottom: 0;
    height: min(58vh, 520px);
    width: auto;
    filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.6));
    animation-duration: 2.1s;
    animation-fill-mode: both;
}

/* Garrotazo: se prepara abajo y le pega al vidrio */
.lu-windup { animation-name: luWindup; transform-origin: 50% 100%; }
.lu-windup { height: min(58vh, 520px, 105vw); }
.lu-hit { animation-name: luHit; transform-origin: 30% 90%; height: min(50vh, 450px, 62vw); }

@keyframes luWindup {
    0%   { transform: translate(-50%, 90%) rotate(0); opacity: 1; animation-timing-function: cubic-bezier(0.2, 0.9, 0.4, 1); }
    16%  { transform: translate(-50%, 8%) rotate(-6deg); }
    24%  { transform: translate(-50%, 6%) rotate(-12deg) scale(0.97, 1.03); opacity: 1; }
    24.8%, 100% { opacity: 0; transform: translate(-50%, 6%) rotate(-12deg); }
}

@keyframes luHit {
    0%, 24.7% { opacity: 0; transform: translate(-50%, 4%) scale(1); }
    24.8% { opacity: 1; transform: translate(-50%, 2%) scale(1.25); }
    30%   { transform: translate(-50%, 4%) scale(1.3, 1.22); }
    58%   { opacity: 1; transform: translate(-50%, 6%) scale(1.25); animation-timing-function: ease-in; }
    82%, 100% { opacity: 0; transform: translate(-50%, 110%) scale(1.15) rotate(8deg); }
}

/* Vuelo hacia el vidrio: chico y lejos, se agranda, se estrola y se resbala */
.lu-fly {
    animation-name: luFly;
    bottom: auto;
    top: 50%;
    height: min(40vh, 380px, 34vw);
    transform-origin: 50% 50%;
}

.lu-fly.tall { height: min(44vh, 400px, 58vw); } /* figura casi cuadrada: más alta para que no quede chica */

@keyframes luFly {
    0%    { opacity: 0; transform: translate(calc(-50% - 70vw * var(--flip)), -120%) scale(0.12) rotate(-25deg); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.6); }
    6%    { opacity: 1; }
    24.8% { transform: translate(-50%, -55%) scale(1.45) rotate(0); }
    28%   { transform: translate(-50%, -55%) scale(1.62, 1.3) rotate(0); }
    34%   { transform: translate(-50%, -55%) scale(1.5, 1.42); }
    56%   { opacity: 1; transform: translate(-50%, -52%) scale(1.5, 1.42) rotate(2deg); animation-timing-function: ease-in; }
    90%, 100% { opacity: 0; transform: translate(-50%, 60%) scale(1.45, 1.5) rotate(12deg); }
}

/* Rajadura del vidrio donde pega */
.lu-crack {
    position: absolute;
    left: 50%;
    top: 40%;
    width: min(95vw, 80vh);
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    animation: luCrack 1.58s ease-out both;
}

.lu-crack::before {
    content: '';
    position: absolute;
    inset: 30%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 70%);
    animation: luFlash 0.35s ease-out both;
}

.lu-crack svg { width: 100%; height: 100%; overflow: visible; }
.lu-crack polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.lu-crack .shadow polyline { stroke: rgba(0, 0, 0, 0.5); stroke-width: 6; }
.lu-crack .line polyline { stroke: rgba(255, 255, 255, 0.95); stroke-width: 3; }

@keyframes luCrack {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    6%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    70%  { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

@keyframes luFlash {
    0%   { opacity: 1; transform: scale(0.5); }
    100% { opacity: 0; transform: scale(2); }
}

/* Cartel con el nivel que arranca */
.lu-banner {
    position: absolute;
    left: 50%;
    top: 22%;
    padding: 14px 26px 10px;
    font-family: 'Luckiest Guy', var(--font-title);
    font-size: clamp(2rem, 9vmin, 4rem);
    letter-spacing: 0.05em;
    line-height: 1;
    white-space: nowrap;
    color: #6b3a14;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
    background: #fff3a6;
    border: 4px solid #3d2410;
    border-radius: 26px 30px 24px 32px / 30px 24px 32px 26px;
    filter: drop-shadow(0 7px 0 rgba(0, 0, 0, 0.4));
    animation: luBanner 1.58s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.lu-banner strong { font-weight: normal; }

@keyframes luBanner {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); }
    18%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-3deg); }
    75%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-3deg); animation-timing-function: ease-in; }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(0.9) rotate(-3deg); }
}

@media (prefers-reduced-motion: reduce) {
    .lu-actor, .lu-crack, .lu-banner { animation-timing-function: linear; }
}

/* ===== Tablero limpio: cartel que festeja ===== */
.clean-banner {
    position: absolute;
    left: 50%;
    top: 45%;
    z-index: 9;
    pointer-events: none;
    padding: 14px 26px 10px;
    font-family: 'Luckiest Guy', var(--font-title);
    font-size: clamp(1.8rem, 8vmin, 3.4rem);
    letter-spacing: 0.05em;
    line-height: 1;
    white-space: nowrap;
    color: #2f5d1c;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
    background: #e9f7b8;
    border: 4px solid #3d2410;
    border-radius: 26px 30px 24px 32px / 30px 24px 32px 26px;
    filter: drop-shadow(0 7px 0 rgba(0, 0, 0, 0.4));
    animation: cleanBanner 2.9s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.clean-banner strong { font-weight: normal; }
/* Debajo del cartel de Tosca time o del granizo, para no taparlos */
.clean-banner.low { top: 70%; transition: top 0.25s ease-out; }

@keyframes cleanBanner {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(6deg); }
    10%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
    16%  { transform: translate(-50%, -50%) scale(1) rotate(2deg); }
    86%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(2deg); animation-timing-function: ease-in; }
    100% { opacity: 0; transform: translate(-50%, -90%) scale(0.9) rotate(2deg); }
}

/* Subtítulo bajo el título: autor y versión */
.game-subtitle {
    margin: -8px 0 14px;
    text-align: center;
    font-size: 0.95rem;
    font-style: italic;
    letter-spacing: 0.04em;
    color: var(--rock-300);
}

/* En el teléfono el encabezado no muestra el título: el subtítulo queda solo en la portada */
html.compact .game-subtitle:not(.login-subtitle) { display: none; }
.login-subtitle { margin: -6px 0 16px; }

/* Android: fila de la app de Play Store, todavía sin publicar */
html.can-install:not(.in-fullscreen) .install-row.play-soon { cursor: default; }
html.can-install:not(.in-fullscreen) .install-row.play-soon:active { opacity: 1; }
.install-row.play-soon svg { fill: var(--ochre); stroke: none; }
.install-row.play-soon .install-how {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    color: var(--sand-100);
    background: rgba(212, 150, 70, 0.28);
    border: 1px solid rgba(212, 150, 70, 0.5);
}

/* iPhone: fila que lleva a la app del App Store */
.install-row.app-store svg { width: 20px; height: 20px; stroke: none; }
.install-row.app-store .as-tile { fill: var(--ochre); }
.install-row.app-store .as-a { fill: none; stroke: var(--rock-900); stroke-width: 2; stroke-linecap: round; }
.install-row.app-store .install-how {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    color: var(--sand-100);
    background: rgba(212, 150, 70, 0.28);
    border: 1px solid rgba(212, 150, 70, 0.5);
}

/* Título del festejo en el modal: que entre en dos líneas en el teléfono */
.record-modal-content h2#recordTitle {
    font-size: clamp(1.35rem, 6.4vw, 2.1rem);
    line-height: 1.1;
}

/* Borrar la cuenta: discreto en el menú, rojo en la confirmación */
.delete-account-btn {
    display: block;
    margin: 18px auto 4px;
    padding: 6px 12px;
    border: none;
    background: none;
    box-shadow: none;
    font-size: 0.8rem;
    color: #d98b6a;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.delete-hint { font-size: 0.85rem; color: var(--rock-300); }
.record-modal-buttons .danger-btn {
    color: #fff3ea;
    background: #8f3a24;
    background-image: var(--grain), linear-gradient(180deg, #a8472c, #7a2f1c);
}

/* ===== Reloj de arena (arriba a la izquierda del tablero) ===== */
/* Una lajita de piedra con el reloj tallado: postes y tapas de roca, arena ocre */
.powerups {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    line-height: 1;
}
.power-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px 4px 6px;
    border: none;
    border-radius: 9px 14px 8px 15px / 12px 8px 14px 9px;
    background: var(--rock-400);
    background-image: var(--grain), var(--grain-coarse), linear-gradient(170deg, #9a8b7a, #6f6255 60%, #564b41);
    box-shadow: inset 0 1px 0 rgba(255, 245, 225, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.4), 0 3px 0 #1a1613, 0 5px 10px rgba(0, 0, 0, 0.5);
    color: #2b231d;
    font-family: var(--font-title);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.power-btn[hidden] { display: none; }
.power-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 245, 225, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.4), 0 1px 0 #1a1613; }
.hourglass-btn .hg-icon { width: 30px; height: 40px; flex: none; filter: drop-shadow(0 1px 0 rgba(255, 244, 222, 0.25)); }
.hg-stone { stroke: #211a15; stroke-width: 1.1; }
.hg-post { stroke: #211a15; stroke-width: 0.9; }
.hg-notch, .hg-crack { stroke: #211a15; stroke-width: 0.9; stroke-linecap: round; stroke-linejoin: round; fill: none; opacity: 0.8; }
.hg-chip { stroke: rgba(255, 240, 215, 0.4); stroke-width: 0.9; stroke-linecap: round; fill: none; }
.hg-glass { stroke: #211a15; stroke-width: 1.4; }
.hg-shine { stroke: rgba(255, 245, 225, 0.35); stroke-width: 1.1; stroke-linecap: round; fill: none; }
.hg-grains { stroke: #fff0c4; stroke-width: 1.3; stroke-linecap: round; opacity: 0.8; }
.hg-sand-top, .hg-sand-bottom { stroke: rgba(80, 45, 15, 0.5); stroke-width: 0.6; }
.hg-stream { fill: #e0aa55; opacity: 0; }
/* Número tallado: hundido en la piedra, con la luz en el borde de abajo */
.hg-count { padding-top: 3px; letter-spacing: 0.04em; text-shadow: 0 1px 0 rgba(255, 244, 222, 0.35), 0 -1px 0 rgba(0, 0, 0, 0.55); }
.hg-timer:empty { display: none; }
.hg-timer {
    padding: 3px 6px 2px;
    border-radius: 6px 8px 5px 9px;
    background: #2b231d;
    color: #e6c48f;
    font-size: 0.85rem;
    text-shadow: none;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.6);
}

/* Recién ganado: salta para que se note */
.power-btn.pop { animation: hgPop 0.9s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes hgPop {
    0% { transform: scale(0.2) rotate(-20deg); opacity: 0; }
    35% { transform: scale(1.35) rotate(8deg); opacity: 1; }
    60% { transform: scale(0.95) rotate(-4deg); }
    100% { transform: none; }
}

/* En uso: la arena corre y el botón late; sin relojes guardados queda tenue */
.power-btn.active { box-shadow: inset 0 1px 0 rgba(255, 245, 225, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.4), 0 3px 0 #1a1613, 0 0 14px rgba(230, 180, 100, 0.65); }
.hourglass-btn.active .hg-stream { opacity: 1; animation: hgStream 0.5s linear infinite; }
.hourglass-btn.active .hg-sand-top { animation: hgDrain 10s linear forwards; transform-origin: 50% 100%; }
.power-btn.active.empty .hg-count { opacity: 0.45; }
@keyframes hgStream { from { opacity: 1; } 50% { opacity: 0.55; } to { opacity: 1; } }
@keyframes hgDrain { from { transform: scaleY(1); } to { transform: scaleY(0.15); } }

/* Tablero en cámara lenta: un velo de arena muy suave */
.main-game-area.slow-motion::after {
    content: '';
    position: absolute;
    inset: 4px;
    z-index: 2;
    pointer-events: none;
    border-radius: 10px;
    box-shadow: inset 0 0 34px rgba(214, 160, 80, 0.45);
    background: rgba(214, 160, 80, 0.06);
}
.smash-word.hourglass-word { --bubble: #e6dccb; color: #4a3220; }

@media (prefers-reduced-motion: reduce) {
    .hourglass-btn.pop, .hourglass-btn.active .hg-stream, .hourglass-btn.active .hg-sand-top { animation: none; }
}

/* Garrote: mismo botón de piedra, con el garrote de los dibujos */
.club-btn .club-icon { width: 30px; height: 35px; object-fit: contain; filter: drop-shadow(0 1px 0 rgba(255, 244, 222, 0.25)); }
.power-btn.active .club-icon { animation: clubWiggle 0.6s ease-in-out infinite alternate; }
@keyframes clubWiggle { from { transform: rotate(-12deg); } to { transform: rotate(10deg); } }

/* En modo garrote: velo rojizo y el cursor es el garrote */
.main-game-area.club-mode #gameCanvas { cursor: pointer; }
.main-game-area.club-mode::before {
    content: '';
    position: absolute;
    inset: 4px;
    z-index: 2;
    pointer-events: none;
    border-radius: 10px;
    box-shadow: inset 0 0 34px rgba(200, 90, 50, 0.5);
}

.smash-word.club-word { --bubble: #f3d3b8; color: #7a2f1c; }

@media (prefers-reduced-motion: reduce) {
    .power-btn.active .club-icon { animation: none; }
}

/* ===== Tema claro: las mismas piedras, en beiges claritos =====
   La escala de roca se invierte: lo que era fondo oscuro pasa a ser
   arena clara y lo que era texto claro pasa a ser marrón. */
html[data-theme="light"] {
    color-scheme: light;
    --bg-deep: #ece2d0;
    --rock-900: #f7f1e6;
    --rock-800: #efe6d6;
    --rock-700: #e6dac5;
    --rock-600: #dccdb4;
    --rock-500: #cbb89a;
    --rock-400: #b3a083;
    --rock-300: #7f6d5a;
    --sand-200: #5b4a3b;
    --sand-100: #3a2f26;
    --ochre: #a06b37;
    --ochre-dark: #7d5a36;
    --clay: #9a5f43;

    --carved: inset 0 2px 0 rgba(255, 252, 245, 0.7), inset 0 -3px 0 rgba(120, 95, 65, 0.18), 0 6px 14px rgba(110, 85, 55, 0.18);
    --sunken: inset 0 3px 7px rgba(120, 95, 65, 0.22), inset 0 -1px 0 rgba(255, 252, 245, 0.8);
}

html[data-theme="light"] body,
html[data-theme="light"] .app-loader {
    background-image:
        radial-gradient(ellipse at 50% 0%, rgba(200, 150, 95, 0.18), transparent 60%),
        var(--grain),
        linear-gradient(180deg, #f4ecdf 0%, var(--bg-deep) 100%);
}

html[data-theme="light"] .game-container {
    box-shadow: var(--carved), 0 24px 50px rgba(110, 85, 55, 0.22);
    border-color: rgba(120, 95, 65, 0.25);
}

/* Letras talladas: sombra clara abajo en vez de la oscura */
html[data-theme="light"] .game-header h1,
html[data-theme="light"] .login-content h2,
html[data-theme="light"] .game-over-content h2,
html[data-theme="light"] .record-modal-content h2 {
    text-shadow: 0 1px 0 rgba(255, 252, 245, 0.9), 0 -1px 0 rgba(90, 70, 50, 0.25), 0 3px 8px rgba(110, 85, 55, 0.18);
}
html[data-theme="light"] .next-piece-container h3,
html[data-theme="light"] .hold-label,
html[data-theme="light"] .controls h3,
html[data-theme="light"] .highscores-container h3,
html[data-theme="light"] .settings-container h3 {
    text-shadow: 0 1px 0 rgba(255, 252, 245, 0.8);
}

/* Losa del récord y botones de piedra: piedra clara con letras oscuras */
html[data-theme="light"] .best-slab {
    background-image: var(--grain), var(--grain-coarse), linear-gradient(180deg, #d9cab2, #c4b294 70%, #b8a687);
    box-shadow: inset 0 1px 0 rgba(255, 250, 238, 0.6), inset 0 -2px 0 rgba(110, 85, 55, 0.25), 0 3px 0 #a8957a, 0 5px 10px rgba(110, 85, 55, 0.2);
}
html[data-theme="light"] .best-slab.beating .best-value {
    color: #b06a12;
    text-shadow: 0 1px 0 rgba(255, 250, 238, 0.7), 0 0 8px rgba(230, 170, 70, 0.45);
}

html[data-theme="light"] .game-controls button,
html[data-theme="light"] #playAgainBtn,
html[data-theme="light"] .record-modal-buttons button {
    text-shadow: 0 1px 0 rgba(255, 252, 245, 0.6);

    box-shadow:
        inset 0 1px 0 rgba(255, 252, 245, 0.7),
        inset 0 -3px 0 rgba(110, 85, 55, 0.2),
        0 4px 0 #b3a083,
        0 6px 12px rgba(110, 85, 55, 0.2);
}
html[data-theme="light"] .game-controls button:active,
html[data-theme="light"] #playAgainBtn:active,
html[data-theme="light"] .record-modal-buttons button:active {
    box-shadow: inset 0 1px 0 rgba(255, 252, 245, 0.6), inset 0 -2px 0 rgba(110, 85, 55, 0.2), 0 1px 0 #b3a083;
}
html[data-theme="light"] #startBtn,
html[data-theme="light"] #playAgainBtn,
html[data-theme="light"] #saveRecordBtn {
    background-image: var(--grain), linear-gradient(180deg, #d6aa78, #c08c58 55%, #a8743f);
    color: #2a1a0c;
    text-shadow: 0 1px 0 rgba(255, 240, 215, 0.45);
}

html[data-theme="light"] .power-btn {
    background-image: var(--grain), var(--grain-coarse), linear-gradient(170deg, #ddd0bb, #c6b498 60%, #b3a083);
    box-shadow: inset 0 1px 0 rgba(255, 250, 238, 0.6), inset 0 -2px 0 rgba(110, 85, 55, 0.25), 0 3px 0 #a8957a, 0 5px 10px rgba(110, 85, 55, 0.2);
}
html[data-theme="light"] .power-btn:active {
    box-shadow: inset 0 1px 0 rgba(255, 250, 238, 0.6), inset 0 -2px 0 rgba(110, 85, 55, 0.25), 0 1px 0 #a8957a;
}

html[data-theme="light"] kbd {
    box-shadow: inset 0 1px 0 rgba(255, 252, 245, 0.6), 0 2px 0 rgba(110, 85, 55, 0.35);
}

/* Marco del tablero */
html[data-theme="light"] #gameCanvas {
    box-shadow: 0 0 0 3px #8a7760, 0 0 0 5px var(--rock-500), 0 0 0 6px rgba(110, 85, 55, 0.3);
}

/* Velos detrás de los carteles: arena translúcida */
html[data-theme="light"] .record-modal,
html[data-theme="light"] .login-screen,
html[data-theme="light"] .install-modal,
html[data-theme="light"] .sheet-backdrop {
    background: rgba(90, 70, 50, 0.4);
}
html[data-theme="light"] .game-over-content,
html[data-theme="light"] .record-modal-content,
html[data-theme="light"] .login-content,
html[data-theme="light"] .install-card {
    box-shadow: var(--carved), 0 24px 50px rgba(80, 60, 40, 0.3);
}
html[data-theme="light"].compact.sheet-open .side-panel {
    box-shadow: 0 -10px 40px rgba(80, 60, 40, 0.3);
}

html[data-theme="light"].can-install:not(.in-fullscreen) .install-row {
    border-color: rgba(120, 95, 65, 0.2);
    background: rgba(255, 250, 240, 0.55);
}

html[data-theme="light"] .lang-switch button[aria-pressed="true"] {
    color: #fff8ec;
    background: var(--ochre);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 2px 4px rgba(110, 85, 55, 0.3);
}

html[data-theme="light"] .login-error { color: #a4472a; }
html[data-theme="light"] .google-login-btn {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 -3px 0 rgba(110, 85, 55, 0.15), 0 4px 0 #b3a083, 0 6px 12px rgba(110, 85, 55, 0.2);
}

/* En el teléfono: cada ajuste en una sola línea (nombre a la izquierda, botones a la
   derecha) y botones más chicos, para dejarle el lugar a los récords */
html.compact .settings-container { padding: 10px 12px; }
html.compact .settings-container h3 { margin-bottom: 6px; }
html.compact .setting-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
html.compact .setting-row + .setting-row { margin-top: 6px; }
html.compact .setting-row .lang-switch { flex: 0 1 230px; padding: 2px; gap: 2px; }
html.compact .setting-row .lang-switch button { padding: 4px 6px; font-size: 0.75rem; }
html.compact.sheet-open .side-panel { max-height: min(90%, 680px); }

/* ===== Pausa: una losa de piedra tapa el tablero ===== */
.pause-cover {
    position: absolute;
    inset: 10px;
    z-index: 8;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px;
    border: none;
    border-radius: 3px;
    font: inherit;
    line-height: 1.2;
    color: var(--sand-100);
    background-color: var(--rock-800);
    background-image:
        radial-gradient(ellipse at 50% 40%, rgba(176, 132, 85, 0.22), transparent 65%),
        var(--grain-coarse),
        var(--grain),
        linear-gradient(170deg, var(--rock-600), var(--rock-900));
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
html.game-paused .pause-cover {
    display: flex;
    animation: pauseCoverIn 0.22s ease-out;
}
@keyframes pauseCoverIn {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: none; }
}
.pause-caveman {
    width: min(58%, 210px);
    height: auto;
    filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5));
    animation: pauseBreathe 3.2s ease-in-out infinite;
    transform-origin: 50% 100%;
}
@keyframes pauseBreathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.025, 0.985); }
}
.pause-title {
    font-family: var(--font-title);
    font-size: clamp(2.2rem, 9vw, 3.2rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sand-200);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8), 0 3px 10px rgba(0, 0, 0, 0.5);
}
.pause-hint {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ochre);
    animation: pauseHint 1.6s ease-in-out infinite alternate;
}
@keyframes pauseHint { from { opacity: 0.55; } to { opacity: 1; } }
html.compact .pause-cover { inset: 4px; }
/* La próxima pieza también queda tapada */
html.game-paused #holdCanvas,
html.game-paused #nextCanvas { filter: blur(8px) grayscale(1); opacity: 0.35; }
/* Los poderes no se usan en pausa */
html.game-paused .powerups { visibility: hidden; }

html[data-theme="light"] .pause-cover {
    background-image:
        radial-gradient(ellipse at 50% 40%, rgba(200, 150, 95, 0.2), transparent 65%),
        var(--grain),
        linear-gradient(170deg, var(--rock-600), var(--rock-800));
    box-shadow: inset 0 0 40px rgba(110, 85, 55, 0.25);
}
html[data-theme="light"] .pause-title {
    text-shadow: 0 1px 0 rgba(255, 252, 245, 0.9), 0 3px 8px rgba(110, 85, 55, 0.2);
}

/* ===== Reglas ===== */
.rules-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 8px 10px;
    border: none;
    border-radius: 10px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--sand-100);
    background: var(--rock-500);
    background-image: var(--grain), linear-gradient(180deg, var(--rock-400), var(--rock-500) 55%, var(--rock-600));
    box-shadow: inset 0 1px 0 rgba(230, 215, 190, 0.2), inset 0 -2px 0 rgba(0, 0, 0, 0.3), 0 3px 0 #1a1613;
    cursor: pointer;
    touch-action: manipulation;
}
.rules-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(230, 215, 190, 0.15), 0 1px 0 #1a1613; }
html.compact .rules-btn { margin-top: 8px; padding: 6px 10px; font-size: 0.8rem; }
html[data-theme="light"] .rules-btn {
    box-shadow: inset 0 1px 0 rgba(255, 252, 245, 0.7), inset 0 -2px 0 rgba(110, 85, 55, 0.2), 0 3px 0 #b3a083;
}

.rules-modal { align-items: center; }
.rules-card {
    display: flex;
    flex-direction: column;
    width: min(520px, 100%);
    max-height: calc(100dvh - 32px);
    overflow: hidden;
}
.rules-body {
    overflow-y: auto;
    margin: 0 -6px 14px;
    padding: 0 6px;
    -webkit-overflow-scrolling: touch;
}
.rules-body h3 {
    margin: 16px 0 8px;
    font-family: var(--font-title);
    font-weight: 400;
    font-size: 1.05rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ochre);
}
.rules-body h3:first-child { margin-top: 4px; }
.rules-list {
    list-style: none;
    counter-reset: regla;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.rules-list li {
    counter-increment: regla;
    display: grid;
    grid-template-columns: 22px 1fr;
    column-gap: 6px;
    font-size: 0.88rem;
    line-height: 1.38;
    color: var(--sand-100);
}
.rules-list li::before {
    content: counter(regla) ".";
    grid-row: span 2;
    font-weight: 800;
    color: var(--ochre);
}
.rules-list strong { font-weight: 700; color: var(--sand-200); }
.rules-list span { color: var(--rock-300); }
html[data-theme="light"] .rules-list span { color: #6b5a48; }
