/* Mobile-first redesign */
:root {
    --bg: #414568;
    --surface: #141624;
    --surface-2: #1b1e2f;
    --text: #e6e8ef;
    --muted: #a0a6b8;
    --primary: #6d9eff;
    --accent: #ffcc66;
    --square-light: #ccd6f6;
    --square-dark: #434860;
    --ring: rgba(109, 158, 255, 0.35);
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, sans-serif;
    line-height: 1.4;
}

h1 {
    margin: 16px auto 12px;
    text-align: center;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: var(--text);
}

/* Top toolbar (AI toggle) */
.centro:first-of-type {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    max-width: 980px;
    margin: 0 auto 10px;
}

label:has(#toggle-ai) {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 999px;
    padding: 8px 12px 8px 8px;
    box-shadow: var(--shadow);
}

#toggle-ai {
    appearance: none;
    width: 42px;
    height: 24px;
    background: var(--surface-2);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 999px;
    position: relative;
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

#toggle-ai::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 999px;
    transition: transform 0.2s ease;
}

#toggle-ai:checked {
    background: var(--primary);
}

#toggle-ai:checked::after {
    transform: translateX(18px);
}

/* Main container */
.centro:not(:first-of-type) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 14px;
    margin: 0 auto 24px;
    width: 100%;
    max-width: 980px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Board */
.tab {
    width: 92vw;
    max-width: 640px;
    height: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    /* La altura vendrá dada por las casillas (aspect-ratio) */
    border-radius: 10px;
    overflow: hidden;
    outline: 1px solid rgba(255,255,255,0.08);
}

.tab .even { background: var(--square-dark); }
.tab .odd { background: var(--square-light); }
/* Cada casilla fuerza cuadrado y define la altura de su fila */
.tab > div { aspect-ratio: 1 / 1; }

img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.45));
}

.overlay { z-index: 2; width: 100%; height: 100%; }

/* Side panels */
.side {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
}

.player-title { font-weight: 700; color: var(--text); }

.timer { display: none; }
.timer.hidden { display: none; }

.captured {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    min-height: 72px;
    background: var(--surface-2);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 8px;
    width: 100%;
}

.captured img { width: 100%; height: auto; filter: none; }

.end-turn {
    --progress: 0;
    margin-top: 6px;
    background: linear-gradient(90deg, var(--accent) calc(var(--progress) * 100%), var(--primary) calc(var(--progress) * 100%));
    color: #0b1225;
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.06s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 6px 14px rgba(109, 158, 255, 0.35);
}

.end-turn:hover { transform: translateY(-1px); }
.end-turn:active { transform: translateY(0); }
.end-turn:disabled { opacity: 0.6; cursor: not-allowed; }

.promotion-modal.hidden { display: none; }
.promotion-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.promotion-content {
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 16px;
    min-width: 260px;
    box-shadow: var(--shadow);
}
.promotion-title { font-weight: 800; margin-bottom: 12px; text-align: center; }
.promotion-choices {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.promo-choice {
    background: var(--surface-2);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 6px;
    cursor: pointer;
    transition: box-shadow 0.2s ease, outline-color 0.2s ease;
}
.promo-choice:hover { box-shadow: 0 0 0 3px var(--ring) inset; }

.end-turn-mobile { display: none; align-self: center; }

/* Desktop / larger screens */
@media (min-width: 900px) {
    h1 { margin-top: 24px; margin-bottom: 16px; font-size: 2rem; }
    .centro:not(:first-of-type) {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
        padding: 20px;
    }
    .side {
        width: 260px;
        min-width: 220px;
        height: fit-content;
        position: sticky;
        top: 16px;
    }
    .tab { width: 640px; max-width: 640px; height: auto; }
    .end-turn { display: inline-block; }
    .end-turn-mobile { display: none; }
}

/* Small screens tweaks */
@media (max-width: 480px) {
    .timer { font-size: 1.1rem; }
    .captured { grid-template-columns: repeat(6, 1fr); min-height: 64px; }
    .promotion-content { min-width: 240px; }
}

/* Mobile order: black player on top */
@media (max-width: 900px) {
    .centro:not(:first-of-type) {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-areas:
            "right"
            "board"
            "left";
    }
    .side.right { grid-area: right; }
    #tablero { grid-area: board; justify-self: center; }
    .side.left { grid-area: left; }
}
