/* ============================================================
   styles.css — 15 Puzzle (Sliding Puzzle)
   Basado en el patrón visual de 2048, adaptado para 15 Puzzle
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    --fp-primary-hue: 200;
    --fp-primary-sat: 80%;
    --fp-primary: hsl(var(--fp-primary-hue), var(--fp-primary-sat), 60%);
    --fp-bg-dark: hsl(222, 47%, 7%);
    --fp-card-bg: hsl(222, 47%, 12%);
    --fp-text-main: hsl(210, 40%, 98%);
    --fp-text-muted: hsl(215, 20%, 65%);

    --fp-grad-primary: linear-gradient(135deg, hsl(200, 80%, 60%) 0%, hsl(240, 70%, 50%) 100%);
    --fp-grad-surface: linear-gradient(135deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.8) 100%);

    --fp-glass: rgba(30, 41, 59, 0.4);
    --fp-glass-border: rgba(255, 255, 255, 0.08);

    --fp-tile-gap: 8px;
    --fp-grid-size: 4;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--fp-text-main);
    background: var(--fp-bg-dark);
    line-height: 1.5;
    padding-top: 80px !important;
    overflow-x: hidden;
}

/* === Contenedor principal === */

.game-container {
    width: 98% !important;
    max-width: 420px !important;
    margin: 0 auto;
    background: var(--fp-grad-surface) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--fp-glass-border);
    border-radius: 32px;
    padding: 24px !important;
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.5);
    display: block !important;
    animation: slideUp 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Header === */

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

.header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: var(--fp-grad-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-game-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px var(--fp-primary));
}

.back-btn {
    padding: 10px 24px;
    background: var(--fp-glass);
    border: 1px solid var(--fp-glass-border);
    border-radius: 14px;
    color: var(--fp-text-main);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-4px);
}

/* === Barra de métricas === */

.metrics-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 24px;
    border-radius: 20px;
    border: 1px solid var(--fp-glass-border);
    text-align: center;
    min-width: 120px;
    flex: 1;
}

.info-label {
    font-size: 0.75rem;
    color: var(--fp-text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.info-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: #ffd700;
}

/* === Tablero === */

.board-outer {
    width: 100%;
    aspect-ratio: 1/1;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    padding: 8px;
    position: relative;
    overflow: hidden;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(var(--fp-grid-size, 4), 1fr);
    gap: var(--fp-tile-gap);
    width: 100%;
    height: 100%;
    position: relative;
}

.grid-cell {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    width: 100%;
    height: 100%;
}

/* === Fichas (tiles) === */

.tile-container {
    position: absolute;
    inset: 0;
    z-index: 10;
}

.tile {
    position: absolute;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 1.5rem;
    z-index: 12;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    will-change: transform;
    transition: transform 200ms cubic-bezier(0.19, 1, 0.22, 1);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.tile-number {
    pointer-events: none;
    line-height: 1;
}

/* Ficha del hueco (gap) — invisible */
.tile.gap-tile {
    opacity: 0;
    pointer-events: none;
    box-shadow: none;
}

/* === Colores de fichas por valor === */
/* Escala degradada: valores bajos → claros, valores altos → oscuros */

.tile-value-1  { background: #eee4da; color: #776e65; }
.tile-value-2  { background: #ede0c8; color: #776e65; }
.tile-value-3  { background: #f2b179; color: #f9f6f2; }
.tile-value-4  { background: #f59563; color: #f9f6f2; }
.tile-value-5  { background: #f67c5f; color: #f9f6f2; }
.tile-value-6  { background: #f65e3b; color: #f9f6f2; }
.tile-value-7  { background: #edcf72; color: #f9f6f2; }
.tile-value-8  { background: #edcc61; color: #f9f6f2; }
.tile-value-9  { background: #edc850; color: #f9f6f2; }
.tile-value-10 { background: #edc53f; color: #f9f6f2; }
.tile-value-11 { background: #edc22e; color: #f9f6f2; }
.tile-value-12 { background: #e9b82a; color: #f9f6f2; }
.tile-value-13 { background: #e5ae26; color: #f9f6f2; }
.tile-value-14 { background: #e1a422; color: #f9f6f2; }
.tile-value-15 { background: #dd9a1e; color: #f9f6f2; }
.tile-value-16 { background: #d9901a; color: #f9f6f2; }
.tile-value-17 { background: #d58616; color: #f9f6f2; }
.tile-value-18 { background: #d17c12; color: #f9f6f2; }
.tile-value-19 { background: #cd720e; color: #f9f6f2; }
.tile-value-20 { background: #c9680a; color: #f9f6f2; }
.tile-value-21 { background: #c55e06; color: #f9f6f2; }
.tile-value-22 { background: #c15402; color: #f9f6f2; }
.tile-value-23 { background: #bd4a00; color: #f9f6f2; }
.tile-value-24 { background: #b94000; color: #f9f6f2; }

/* === Modo imagen === */

.tile.image-mode {
    background-size: cover;
    background-repeat: no-repeat;
}

/* === Modal de inicio === */

.size-picker {
    margin: 20px 0;
    text-align: center;
}

.size-picker-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--fp-text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.size-picker-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.size-btn {
    flex: 1;
    padding: 14px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--fp-glass-border);
    border-radius: 14px;
    color: var(--fp-text-main);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
    min-height: 48px;
}

.size-btn.active {
    background: var(--fp-grad-primary);
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.size-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* === Selector de modo (segmented control) === */

.mode-toggle {
    margin: 20px 0;
    text-align: center;
}

.mode-toggle-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--fp-text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mode-toggle-buttons {
    display: flex;
    gap: 0;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 16px;
    border: 1px solid var(--fp-glass-border);
}

.mode-btn {
    flex: 1;
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-radius: 12px;
    color: var(--fp-text-muted);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
    min-height: 48px;
}

.mode-btn.active {
    background: var(--fp-grad-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.mode-btn.active:hover {
    background: var(--fp-grad-primary);
}

/* === Instrucciones (reutiliza estilos base de 2048) === */

.instructions-horizontal {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 24px;
    border: 1px solid var(--fp-glass-border);
    margin: 24px 0;
    text-align: left;
}

.instructions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--fp-text-muted);
    background: rgba(255, 255, 255, 0.02);
    padding: 8px 12px;
    border-radius: 12px;
}

/* === Botones === */

.btn-primary {
    width: 100%;
    padding: 18px;
    background: var(--fp-grad-primary);
    color: white;
    border: none;
    border-radius: 18px;
    font-weight: 800;
    font-size: 1.1rem;
    cursor: pointer;
    transition: 0.3s;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.btn-secondary {
    display: block;
    width: 100%;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border: 1px solid var(--fp-glass-border);
    border-radius: 18px;
    font-weight: 600;
    text-decoration: none;
    margin-top: 12px;
    transition: 0.3s;
    cursor: pointer;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* === Modal === */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 39, 0.95);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    padding-top: 100px;
}

.modal-content {
    background: var(--fp-card-bg);
    padding: 40px;
    border-radius: 36px;
    width: 100%;
    max-width: min(480px, 90vw);
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--fp-glass-border);
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.7);
    text-align: center;
    animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}

.modal-content h2 {
    font-size: 2.2rem;
    font-weight: 800;
    background: var(--fp-grad-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 12px;
}

.modal-content p {
    color: var(--fp-text-muted);
    margin-bottom: 24px;
}

.input-group {
    margin: 24px 0;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--fp-text-muted);
    margin-bottom: 8px;
}

.input-group input {
    width: 100%;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--fp-glass-border);
    border-radius: 16px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: 0.3s;
}

.input-group input:focus {
    border-color: var(--fp-primary);
}

/* === Pantalla de victoria === */

.score-summary {
    display: flex;
    gap: 16px;
    margin: 24px 0;
    justify-content: center;
}

.score-final {
    background: rgba(0, 0, 0, 0.2);
    padding: 16px 24px;
    border-radius: 20px;
    flex: 1;
}

.score-number {
    font-size: 2.5rem;
    font-weight: 900;
    color: #ffffff;
    line-height: 1.2;
}

.score-text {
    font-size: 0.8rem;
    color: var(--fp-text-muted);
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 4px;
}

.record-box {
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.2);
    padding: 20px;
    border-radius: 24px;
    margin: 24px 0;
}

.record-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #ffd700;
    font-weight: 800;
    letter-spacing: 1px;
}

.record-value {
    font-size: 2rem;
    font-weight: 900;
    color: #ffffff;
}

/* === Anuncios === */

.game-over-ad {
    margin-top: 30px;
    border-top: 1px solid var(--fp-glass-border);
    padding-top: 20px;
}

.bottom-ad {
    margin-top: 24px;
    text-align: center;
}

/* === Utilidades === */

.hidden {
    display: none !important;
}

/* === Responsive: Móvil (< 500px) === */

@media (max-width: 500px) {
    .game-container {
        border-radius: 0;
        padding: 16px !important;
        max-width: 100% !important;
    }

    .instructions-grid {
        grid-template-columns: 1fr;
    }

    .tile {
        font-size: 1.2rem;
    }

    .modal-content {
        padding: 24px;
        max-width: 95vw;
    }

    .modal-content h2 {
        font-size: 1.8rem;
    }

    .info-value {
        font-size: 1.5rem;
    }

    .metric-card {
        padding: 10px 16px;
        min-width: 80px;
    }

    .size-btn {
        min-height: 48px;
        font-size: 0.85rem;
    }

    .mode-btn {
        min-height: 48px;
    }
}

/* === Responsive: Tablet (501px — 1024px) === */

@media (min-width: 501px) and (max-width: 1024px) {
    .game-container {
        max-width: 380px !important;
    }
}

/* === Responsive: Escritorio (> 1024px) === */

@media (min-width: 1025px) {
    .game-container {
        max-width: 420px !important;
    }
}

/* === Confeti canvas === */
.confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* === Número overlay en modo imagen === */
.tile.image-mode .tile-number-overlay {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    z-index: 1;
}

/* === Botón de cambio de patrón === */
.btn-pattern-cycle {
    display: block;
    margin: 12px auto;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--fp-text, #e0e0e0);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-pattern-cycle:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* === Ajustes responsive para modo imagen === */
@media (max-width: 480px) {
    .tile.image-mode .tile-number-overlay {
        font-size: 0.5rem;
        bottom: 1px;
        right: 2px;
    }
}
