:root{
    --primary: #5787C1;
    --primary-dark: #3B5F8C;
    --primary-light: #8BAFD8;
    --accent: #E63946;
    --accent-dark: #A61F29;

    --bg: #f8fafc;
    --text: #222;
    --surface: rgba(255, 255, 255, 0.96);
    --table-bg: #fff;
    --table-border: #e2e8f0;
    --td-hover: #EEF4FB;
    --overlay: rgba(0, 0, 0, 0.35);
    --panel-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    --table-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);

    --radius: 18px;
    --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

[data-theme="dark"]{
    --bg: #0f172a;
    --text: #f1f5f9;
    --surface: rgba(30, 41, 59, 0.96);
    --table-bg: #1e293b;
    --table-border: #334155;
    --td-hover: #334155;
    --overlay: rgba(0, 0, 0, 0.65);
    --panel-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    --table-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

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

html{
    height: 100%;
}

body{
    font-family: var(--font);
    min-height: 100%;
    background: url('../images/fondo.jpg') center/cover no-repeat fixed;
    color: var(--text);
    display: flex;
    flex-direction: column;
}

body::before{
    content: '';
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: -1;
}

header{
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

#logoelcdem{
    height: 50px;
    width: auto;
    flex-shrink: 0;
    -webkit-filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
            filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.header-text{
    text-align: center;
}

header h1{
    text-transform: uppercase;
    color: #fff;
    font-size: clamp(1.3rem, 5vw, 2rem);
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.25);
}

.subtitle{
    color: rgba(255,255,255,0.85);
    font-size: clamp(0.75rem, 2.5vw, 0.95rem);
    margin-top: 0.15rem;
}

.theme-switch{
    margin-left: auto;
    position: relative;
    display: inline-flex;
    width: 60px;
    height: 30px;
    flex-shrink: 0;
    cursor: pointer;
}

.theme-switch input{
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-switch-slider{
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background 0.2s ease;
}

.theme-switch-slider i{
    color: #fff;
    font-size: 1rem;
    z-index: 1;
    transition: opacity 0.2s ease;
}

.theme-switch-slider .ri-moon-line{
    opacity: 0.35;
}

.theme-switch input:checked + .theme-switch-slider{
    background: rgba(0,0,0,0.25);
}

.theme-switch input:checked + .theme-switch-slider .ri-sun-line{
    opacity: 0.35;
}

.theme-switch input:checked + .theme-switch-slider .ri-moon-line{
    opacity: 1;
}

.theme-switch-thumb{
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25);
    transition: transform 0.25s ease;
    z-index: 2;
}

.theme-switch input:checked + .theme-switch-slider .theme-switch-thumb{
    transform: translateX(30px);
}

#container{
    flex: 1;
    width: min(96%, 1200px);
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 1.5rem;
}

.panel{
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--panel-shadow);
    padding: 1.25rem;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.control-panel{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    flex: 1 1 280px;
    max-width: 360px;
    min-width: 260px;
}

.balotera{
    position: relative;
    width: min(72vw, 300px);
    height: 90px;
    margin-bottom: -12px;
    border: 4px solid var(--primary-dark);
    border-bottom: none;
    border-radius: 50% 50% 0 0 / 35% 35% 0 0;
    background:
        radial-gradient(circle, rgba(255,255,255,0.35) 28%, transparent 32%) 0 0 / 22px 22px,
        linear-gradient(180deg, rgba(0,0,0,0.1), transparent);
    box-shadow: inset 0 0 18px rgba(0,0,0,0.2);
    z-index: 1;
}

.balotera::after{
    content: '';
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 22px;
    background: var(--primary-dark);
    border-radius: 0 0 14px 14px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#fondobola{
    background: radial-gradient(circle at 35% 30%, #FFEB3B 0%, #FFD600 40%, #B8860B 100%);
    border-radius: 50%;
    width: min(72vw, 300px);
    height: min(72vw, 300px);
    aspect-ratio: 1 / 1;
    box-shadow:
        inset -12px -12px 30px rgba(0,0,0,0.25),
        inset 12px 12px 30px rgba(255,255,255,0.35),
        0 15px 35px rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}

#fondobola.drop{
    -webkit-animation: drop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
            animation: drop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#selected{
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.burbuja{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.75;
    pointer-events: none;
}

#letter-number{
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 3px 6px rgba(0,0,0,0.5);
    padding: 0 0.5rem;
}

#letter-number .ball-letter{
    font-size: 1em;
    line-height: 1;
    margin-bottom: -0.05em;
    text-transform: uppercase;
}

#letter-number .ball-number{
    font-size: 2em;
    line-height: 1;
}

#random-btn{
    width: 100%;
    border: none;
    border-radius: 12px;
    padding: 0.9rem 1.25rem;
    background: linear-gradient(180deg, var(--primary-light), var(--primary));
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--primary-dark), 0 8px 16px rgba(0,0,0,0.2);
    transition: transform 0.08s ease, box-shadow 0.08s ease, -webkit-filter 0.15s ease;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease, -webkit-filter 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#random-btn:hover{
    -webkit-filter: brightness(1.08);
            filter: brightness(1.08);
}

#random-btn:active{
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--primary-dark), 0 4px 8px rgba(0,0,0,0.2);
}

#reset-btn{
    width: 100%;
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 0.85rem 1.25rem;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#reset-btn:hover{
    background: var(--primary);
    color: #fff;
}

#reset-btn:active{
    transform: scale(0.98);
}

#bingo-btn{
    width: 100%;
    border: none;
    border-radius: 12px;
    padding: 0.9rem 1.25rem;
    background: linear-gradient(180deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--accent-dark), 0 8px 16px rgba(0,0,0,0.2);
    transition: transform 0.08s ease, box-shadow 0.08s ease, -webkit-filter 0.15s ease;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#bingo-btn:hover{
    -webkit-filter: brightness(1.08);
            filter: brightness(1.08);
}

#bingo-btn:active{
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--accent-dark), 0 4px 8px rgba(0,0,0,0.2);
}

#bingo-celebration{
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

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

#confetti-canvas{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.bingo-message{
    position: relative;
    z-index: 1;
    font-size: clamp(3rem, 15vw, 8rem);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 10px rgba(0,0,0,0.4);
    -webkit-animation: bingoPop 0.6s ease both;
            animation: bingoPop 0.6s ease both;
    pointer-events: none;
}

@-webkit-keyframes bingoPop{
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

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

.board-panel{
    flex: 2 1 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 260px;
    max-width: 620px;
}

.table-wrap{
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
}

table{
    width: 100%;
    min-width: 320px;
    border-collapse: collapse;
    background: var(--table-bg);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--table-shadow);
    table-layout: fixed;
}

th, td{
    width: 20%;
    padding: clamp(0.45rem, 1.5vw, 0.85rem);
    text-align: center;
    font-weight: 700;
    border: 1px solid var(--table-border);
}

th{
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: clamp(1.4rem, 5vw, 2rem);
    padding: clamp(0.5rem, 2vw, 1rem);
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

td{
    font-size: clamp(0.95rem, 3vw, 1.3rem);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

td:hover{
    background-color: var(--td-hover);
}

td:active{
    transform: scale(0.96);
}

.cell.selected{
    background: linear-gradient(180deg, var(--accent), var(--accent-dark));
    color: #fff;
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 2px 6px rgba(0,0,0,0.15);
    -webkit-animation: pop 0.25s ease;
            animation: pop 0.25s ease;
}

@-webkit-keyframes pop{
    0% { transform: scale(0.6); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes pop{
    0% { transform: scale(0.6); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@-webkit-keyframes drop{
    0% { transform: translateY(-90px) scale(0.35); }
    40% { transform: translateY(-90px) scale(0.35); }
    65% { transform: translateY(12px) scale(1.08); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes drop{
    0% { transform: translateY(-90px) scale(0.35); }
    40% { transform: translateY(-90px) scale(0.35); }
    65% { transform: translateY(12px) scale(1.08); }
    100% { transform: translateY(0) scale(1); }
}

@media (min-width: 860px){
    #container{
        align-items: center;
        justify-content: space-around;
    }
    .control-panel{
        position: -webkit-sticky;
        position: sticky;
        top: 1rem;
    }
}

@media (max-width: 480px){
    header{
        padding: 0.6rem 0.75rem;
    }
    #logoelcdem{
        height: 42px;
    }
    #container{
        gap: 1rem;
        padding: 1rem 0.5rem;
    }
    .panel{
        padding: 1rem;
        border-radius: 14px;
    }
}
