/* ================================================================
   BINGO DE ESPAÑA — Rediseño: huecos + bola + panel lateral 30%
   ================================================================ */

/* ---- CSS Custom Properties (Dark Theme) ---- */
:root {
    --bg-body: #0b1120;
    --bg-board-section: #111827;
    --bg-sidepanel: #0f172a;
    --bg-cell-hole: #0b1120;
    --cell-hole-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
    --cell-number-hole: #334155;
    --ball-bg: radial-gradient(circle at 33% 28%, #ffffff 0%, #f1f5f9 60%, #cbd5e1 100%);
    --ball-shadow: 0 4px 14px rgba(0, 0, 0, 0.4), inset 0 -3px 6px rgba(0, 0, 0, 0.12);
    --ball-text: #0f172a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #1e3a5f;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition: 0.3s ease;
    --board-border: #1e293b;
    --panel-divider: #1e293b;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, Arial, Helvetica, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ================================================================
   LAYOUT: 70/30
   ================================================================ */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
}

/* ---- LEFT: TABLERO 70% ---- */
.board-section {
    flex: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-board-section);
    padding: 12px;
    position: relative;
    overflow: hidden;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(9, 1fr);
    row-gap: 12px;
    column-gap: 6px;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

/* ================================================================
   CELDAS — Hueco con número + bola blanca
   ================================================================ */
.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: default;
    user-select: none;
    min-height: 0;
    min-width: 0;
    padding: 0.4rem;
}

/* Hueco: círculo oscuro con número pequeño gris */
.cell::before {
    content: attr(data-number);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--bg-cell-hole);
    box-shadow: var(--cell-hole-shadow);
    color: var(--cell-number-hole);
    font-size: clamp(0.45rem, 1.1vw, 1.1rem);
    font-weight: 600;
    transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease,
                color 0.3s ease, font-size 0.3s ease;
    flex-shrink: 0;
}

/* ---- Bola blanca colocada ---- */
.cell.called::before {
    content: attr(data-number);
    background: var(--ball-bg);
    color: var(--ball-text);
    font-size: clamp(0.8rem, 2.2vw, 2.8rem);
    font-weight: 800;
    box-shadow: var(--ball-shadow);
    transform: scale(1.04);
}

/* ---- Animación drop ---- */
.cell.just-called::before {
    animation: ballDrop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
}

@keyframes ballDrop {
    0%   { transform: scale(0.3) translateY(-40px); opacity: 0; }
    40%  { transform: scale(1.22) translateY(0); opacity: 1; }
    65%  { transform: scale(0.93) translateY(0); }
    80%  { transform: scale(1.06) translateY(0); }
    100% { transform: scale(1.04) translateY(0); opacity: 1; }
}

/* ================================================================
   SIDE PANEL 30% (Dark)
   ================================================================ */
.side-panel {
    flex: 3;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidepanel);
    border-left: 1px solid var(--board-border);
    padding: 20px 16px 16px;
    overflow-y: auto;
    gap: 12px;
    min-width: 0;
}

.section-title {
    font-size: clamp(0.75rem, 1.1vw, 1rem);
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ---- BOLA ACTUAL ---- */
.current-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 0 12px;
    border-bottom: 1px solid var(--panel-divider);
}

.current-ball {
    width: min(20vw, 260px);
    height: min(20vw, 260px);
    border-radius: 50%;
    background: var(--bg-cell-hole);
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.3), var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.4s ease, box-shadow 0.4s ease;
    flex-shrink: 0;
}

.current-ball.has-number {
    background: var(--ball-bg);
    box-shadow: var(--ball-shadow);
}

.current-ball-number {
    font-size: clamp(2.5rem, 8vw, 7rem);
    font-weight: 800;
    color: var(--cell-number-hole);
    transition: color 0.3s ease;
    line-height: 1;
}

.current-ball.has-number .current-ball-number {
    color: var(--ball-text);
}

/* ---- ÚLTIMAS BOLAS ---- */
.recent-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.recent-balls {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    padding: 4px 2px;
}

.recent-ball {
    flex: 0 0 auto;
    width: clamp(32px, 4.5vw, 52px);
    height: clamp(32px, 4.5vw, 52px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.6rem, 1.2vw, 1.1rem);
    font-weight: 700;
    color: var(--ball-text);
    background: var(--ball-bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 -2px 4px rgba(0, 0, 0, 0.1);
    animation: recentPop 0.3s ease both;
}

@keyframes recentPop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- CONTROLES (Dark) ---- */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--panel-divider);
    flex-shrink: 0;
}

.controls-row {
    display: flex;
    gap: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: clamp(0.8rem, 1.1vw, 1rem);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    line-height: 1.2;
    touch-action: manipulation;
    flex: 1;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    padding: 14px 18px;
    font-size: clamp(0.95rem, 1.3vw, 1.15rem);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
    background: #1e293b;
    color: var(--text-primary);
    border: 1.5px solid #334155;
}
.btn-secondary:hover { background: #334155; border-color: var(--accent); }
.btn-secondary.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

.btn-danger {
    background: #2d1a1a;
    color: var(--danger);
    border: 1.5px solid #5c2020;
}
.btn-danger:hover { background: #3d2222; border-color: var(--danger); }

/* Velocidad */
.speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: clamp(0.7rem, 1vw, 0.9rem);
    font-weight: 500;
}

.speed-control input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #334155;
    outline: none;
    cursor: pointer;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.speed-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.speed-value {
    font-weight: 700;
    color: var(--accent);
    min-width: 28px;
    text-align: center;
}

/* Contador */
.ball-counter {
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-light);
    padding: 6px 14px;
    border-radius: var(--radius);
    text-align: center;
    border: 1.5px solid var(--accent);
}

/* ================================================================
   MODAL REUTILIZABLE
   ================================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-box {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 32px 36px;
    max-width: min(90vw, 440px);
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    text-align: center;
}

@keyframes modalIn {
    0%   { transform: scale(0.85) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-icon {
    font-size: 2.8rem;
    margin-bottom: 12px;
    display: block;
}

.modal-title {
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 10px;
    line-height: 1.3;
}

.modal-message {
    font-size: clamp(0.85rem, 1.3vw, 1.05rem);
    color: #94a3b8;
    line-height: 1.5;
    margin-bottom: 8px;
}

.modal-message strong {
    color: #f1f5f9;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    justify-content: center;
}

.modal-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1.2;
    min-width: 100px;
}

.modal-btn:active {
    transform: scale(0.96);
}

.modal-btn.primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}
.modal-btn.primary:hover {
    background: var(--accent-hover);
}

.modal-btn.secondary {
    background: #334155;
    color: #f1f5f9;
    border: 1px solid #475569;
}
.modal-btn.secondary:hover {
    background: #475569;
}

.modal-btn.danger {
    background: #7f1d1d;
    color: #fca5a5;
    border: 1px solid #991b1b;
}
.modal-btn.danger:hover {
    background: #991b1b;
}

/* ================================================================
   MODAL BINGO
   ================================================================ */
.bingo-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.bingo-overlay.show { opacity: 1; visibility: visible; }

.bingo-modal {
    text-align: center;
    animation: bingoAppear 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.bingo-title {
    font-size: clamp(3rem, 10vw, 8rem);
    font-weight: 800;
    color: white;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    line-height: 1.1;
    margin-bottom: 16px;
}

.bingo-subtitle {
    font-size: clamp(1.2rem, 3vw, 2.5rem);
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 40px;
}

.btn-large {
    padding: 16px 40px;
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    border-radius: var(--radius);
}

@keyframes bingoAppear {
    0%   { transform: scale(0) rotate(-5deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .board-section {
        flex: none;
        height: 60vh;
        padding: 8px;
    }

    .board { row-gap: 8px; column-gap: 4px; }

    .cell::before { width: 75%; }

    .side-panel {
        flex: none;
        flex-direction: row;
        flex-wrap: wrap;
        border-left: none;
        border-top: 1px solid var(--board-border);
        padding: 12px;
        gap: 10px;
        max-height: 40vh;
        overflow-y: auto;
    }

    .current-section {
        flex: 1;
        min-width: 120px;
        border-bottom: none;
        padding: 0;
    }

    .current-ball {
        width: min(25vw, 120px);
        height: min(25vw, 120px);
    }

    .current-ball-number { font-size: clamp(1.5rem, 8vw, 3rem); }

    .recent-section { flex: 2; min-width: 150px; }

    .controls-section {
        flex: 1 1 100%;
        border-top: 1px solid var(--panel-divider);
        padding-top: 10px;
        margin-top: 4px;
    }

    .recent-ball { width: 28px; height: 28px; font-size: 0.6rem; }
}

@media (max-width: 480px) {
    .board-section { height: 50vh; padding: 4px; }
    .board { row-gap: 5px; column-gap: 2px; }
    .cell::before { width: 70%; }
    .cell { font-size: clamp(0.4rem, 3vw, 0.7rem); }

    .side-panel { max-height: 50vh; padding: 8px; }

    .current-ball { width: min(30vw, 80px); height: min(30vw, 80px); }
    .current-ball-number { font-size: clamp(1rem, 6vw, 1.8rem); }

    .btn { padding: 6px 10px; font-size: clamp(0.6rem, 2.5vw, 0.8rem); }
    .btn-primary { padding: 10px 12px; }
}

/* ---- Fix 100vh en móviles ---- */
@supports (-webkit-touch-callout: none) {
    .app-container { height: -webkit-fill-available; }
}
