/* Base Variables & Themes */
:root {
    /* Default Light Theme - Red based */
    --primary-color: #e63946;
    --primary-hover: #d62828;
    --secondary-color: #f1faee;
    --accent-color: #a8dadc;
    --text-color: #1d3557;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.1);
    
    /* Bingo Board Colors */
    --board-bg: #ffffff;
    --cell-bg: #fff;
    --cell-border: #333;
    --cell-text: #000;
    --cell-hover: rgba(0,0,0,0.05);
    --cell-marked: var(--primary-color);
    --cell-marked-text: #ffffff;
    
    /* Animation timings */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Fonts */
    --font-main: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --text-color: #f8f9fa;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --border-color: #333333;
    --shadow-color: rgba(0, 0, 0, 0.5);
    
    --board-bg: #1e1e1e;
    --cell-bg: rgba(255,255,255,0.9);
    --cell-border: #000;
    --cell-text: #000;
    --cell-hover: rgba(0,0,0,0.1);
}

/* Theme Colors */
[data-color="blue"] {
    --primary-color: #0077b6;
    --primary-hover: #023e8a;
    --cell-marked: var(--primary-color);
}
[data-color="yellow"] {
    --primary-color: #ffb703;
    --primary-hover: #fb8500;
    --cell-marked: var(--primary-color);
}
[data-color="green"] {
    --primary-color: #2a9d8f;
    --primary-hover: #21867a;
    --cell-marked: var(--primary-color);
}
[data-color="purple"] {
    --primary-color: #7209b7;
    --primary-hover: #560bad;
    --cell-marked: var(--primary-color);
}

/* Reset & Global */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color var(--transition-normal), color var(--transition-normal);
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 1rem;
    max-width: 1600px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 20px var(--shadow-color);
    margin-bottom: 1.5rem;
    transition: all var(--transition-normal);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    font-size: 2.5rem;
    animation: bounce 2s infinite;
}

.logo-text h1 {
    font-weight: 900;
    font-size: 1.8rem;
    color: var(--primary-color);
    letter-spacing: 1px;
}

.logo-text p {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Role Selector */
.role-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.5rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}
.role-label {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text-color);
    opacity: 0.7;
}
.role-options {
    display: flex;
    gap: 1rem;
}
.role-radio {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 600;
}
.role-radio input {
    accent-color: var(--primary-color);
    width: 1.2rem;
    height: 1.2rem;
}

.header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Buttons */
.btn {
    font-family: var(--font-main);
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.btn.secondary {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: rgba(0,0,0,0.05);
}

.btn.icon-btn {
    padding: 0.6rem;
    border-radius: 50%;
    background: transparent;
    font-size: 1.2rem;
}

.btn.icon-btn:hover {
    background: rgba(0,0,0,0.05);
    transform: rotate(30deg);
}

.btn.massive {
    width: 100%;
    padding: 1.5rem;
    font-size: 1.5rem;
    justify-content: center;
    border-radius: 12px;
    font-weight: 800;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Ripple Effect */
.ripple::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple 600ms linear;
    background-color: rgba(255, 255, 255, 0.3);
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Main Container */
.main-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    flex: 1;
    transition: all 0.3s ease;
}

/* Caller mode layout */
.main-container[data-role="caller"] {
    grid-template-columns: 300px 1fr;
}
.main-container[data-role="caller"] .left-panel {
    display: flex;
}

/* Player mode layout */
.main-container[data-role="player"] {
    grid-template-columns: 1fr;
}
.main-container[data-role="player"] .left-panel {
    display: none;
}

/* Cards & Panels */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px var(--shadow-color);
    transition: all var(--transition-normal);
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Caller Section */
.caller-section {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.caller-section h2 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.current-number-display {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: var(--bg-color);
    border: 8px solid var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 0 30px rgba(0,0,0,0.1) inset;
    transition: all var(--transition-fast);
}

.number-circle {
    font-size: 4rem;
    font-weight: 900;
    color: var(--primary-color);
    font-family: var(--font-heading);
    transition: all var(--transition-fast);
}

.number-circle.new-number {
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), glow 1s ease-in-out infinite alternate;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes glow {
    from { text-shadow: 0 0 10px var(--primary-color); }
    to { text-shadow: 0 0 20px var(--primary-color), 0 0 30px var(--primary-color); }
}

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

.pulse {
    animation: pulse 2s infinite;
}

/* Stats Section */
.stats-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.stat-label {
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.8;
}

.stat-value {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--primary-color);
}

/* History Section */
.history-section {
    display: flex;
    flex-direction: column;
    max-height: 400px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.history-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.9rem;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Boards Grid */
.boards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    align-items: start;
    justify-items: center;
}

.board-container {
    background: var(--board-bg);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 4px 20px var(--shadow-color);
    transition: all var(--transition-normal);
    max-width: 500px;
    width: 100%;
}

.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.ticket-wrapper {
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    border: 2px dashed rgba(0,0,0,0.1);
    margin-bottom: 10px;
}

.ticket-header {
    text-align: center;
    font-size: 0.8rem;
    font-weight: bold;
    color: rgba(0,0,0,0.4);
    letter-spacing: 2px;
    margin-bottom: 5px;
    text-transform: uppercase;
}

/* Sheet specific styles */
.sheet-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bingo-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    border: 2px solid var(--cell-border);
    background: transparent;
}

.bingo-cell {
    background: var(--cell-bg);
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
    color: var(--cell-text);
    border: 1px solid var(--cell-border);
    font-family: var(--font-heading);
}

.bingo-cell.empty-cell {
    background: transparent;
}

.bingo-cell:not(.empty-cell):hover {
    background: var(--cell-hover);
}

.bingo-cell.marked {
    background: var(--cell-marked) !important;
    color: var(--cell-marked-text) !important;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: all var(--transition-normal);
}

.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.modal {
    width: 90%;
    max-width: 400px;
    transform: translateY(0) scale(1);
    transition: all var(--transition-normal);
}

.modal-overlay.hidden .modal {
    transform: translateY(50px) scale(0.9);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group label {
    font-weight: 600;
}

.theme-picker {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.color-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.color-btn:hover {
    transform: scale(1.2);
}

.color-btn.active {
    border-color: var(--text-color);
    transform: scale(1.1);
}

/* Toggle Switch */
.toggle-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.select-box {
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
    cursor: pointer;
}

/* Ticket Pool Sets */
.set-group {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.set-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-family: var(--font-heading);
    color: var(--text-color);
    border-bottom: 2px dashed var(--border-color);
    padding-bottom: 0.5rem;
}

/* Ticket Pool Grid */
.ticket-pool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.ticket-item {
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.ticket-item:hover {
    transform: translateY(-5px) scale(1.02);
}

.ticket-item.taken {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(80%);
}

.ticket-item.taken::after {
    content: attr(data-owner);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    z-index: 10;
    border: 2px solid white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.ticket-item .bingo-cell {
    font-size: 1rem;
}

/* Winners History */
.winners-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.winner-item {
    background: var(--bg-color);
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.winner-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.winner-info strong {
    color: var(--primary-color);
    font-size: 1.1rem;
}
.winner-ticket {
    font-size: 0.85rem;
    opacity: 0.7;
}
.winner-time {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.6;
}

/* Confetti Container */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00;
    animation: fall linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(720deg);
    }
}

/* Bingo Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9000;
    backdrop-filter: blur(8px);
}

.overlay.hidden {
    display: none;
}

.bingo-message {
    text-align: center;
    color: white;
    animation: zoomIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bingo-message h1 {
    font-size: 6rem;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(255,255,255,0.5), 0 0 40px var(--primary-color);
    margin-bottom: 1rem;
    animation: bounce 1s infinite;
}

.bingo-message p {
    font-size: 1.5rem;
    margin-bottom: 2rem;
}

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

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}


/* Responsive */
@media (max-width: 1024px) {
    .main-container[data-role="caller"] {
        grid-template-columns: 250px 1fr;
    }
    .header {
        flex-direction: column;
        gap: 1rem;
    }
    .board-container {
        padding: 0.75rem;
    }
    .bingo-cell {
        font-size: 1.1rem;
    }
}

@media (max-width: 768px) {
    .main-container[data-role="caller"] {
        grid-template-columns: 1fr;
    }
    .boards-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 1rem;
    }
    .board-header {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    .current-number-display {
        width: 120px;
        height: 120px;
    }
    .number-circle {
        font-size: 3.5rem;
    }
}

@media (max-width: 480px) {
    .header-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    .role-options {
        flex-direction: column;
        gap: 0.5rem;
    }
    .boards-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .board-container {
        padding: 0.5rem;
        border-radius: 12px;
        max-width: 100%;
    }
    .bingo-cell {
        font-size: 0.9rem;
    }
    .board-header {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    .current-number-display {
        width: 100px;
        height: 100px;
    }
    .number-circle {
        font-size: 3rem;
    }
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
}
