* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark Theme - Hacker/Developer Aesthetic */
    --color-primary-gradient-start: #02040a;
    --color-primary-gradient-end: #0f172a;

    /* Accent Colors - Vibrant on Dark */
    --color-accent-blue: #38bdf8;
    --color-accent-cyan: #22d3ee;
    --color-accent-purple: #c084fc;
    --color-accent-orange: #fb923c;
    --color-accent-pink: #f472b6;
    --color-accent-green: #4ade80;
    --color-accent-yellow: #facc15;

    /* Backgrounds - Deep Dark Theme */
    --color-bg-gradient-start: #02040a;
    --color-bg-gradient-end: #0f172a;
    --color-bg-card: rgba(15, 23, 42, 0.6);
    --color-bg-elevated: rgba(30, 41, 59, 0.7);
    --color-bg-light: rgba(51, 65, 85, 0.8);

    /* Text Colors */
    --color-text: #f8fafc;
    --color-text-primary: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-text-dim: #64748b;

    /* Borders - Subtle White/Grey */
    --color-border: rgba(255, 255, 255, 0.1);
    --color-border-medium: rgba(255, 255, 255, 0.15);
    --color-border-strong: rgba(255, 255, 255, 0.25);

    /* Status Colors */
    --color-success: #4ade80;
    --color-success-light: #86efac;
}

/* Scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Selection */
::selection {
    background: var(--color-accent-cyan);
    color: var(--color-primary-gradient-start);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--color-bg-gradient-start) 0%, var(--color-bg-gradient-end) 100%);
    color: var(--color-text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
    gap: 20px;
}

.title {
    font-size: clamp(24px, 5vmin, 42px);
    font-weight: 800;
    margin-bottom: 0;
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.25);
    text-align: center;
    flex-shrink: 0;
}

#board-container {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.bingo-board {
    display: grid;
    /* grid-template-columns is set dynamically by JS */
    grid-auto-rows: 1fr;
    gap: 10px;

    /* Force board to fill available space while maintaining square aspect ratio */
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    margin: auto;
}

/* Bingo Cell */
.bingo-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 5px;
    background: var(--color-bg-card);
    border: 1.5px solid var(--color-border);
    border-radius: 24px;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.15), inset 0 1px 3px rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    word-wrap: break-word;
    overflow: hidden;
}

.bingo-cell:hover {
    border-color: var(--color-border-strong);
    background: var(--color-bg-elevated);
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.bingo-cell.completed {
    background-color: var(--color-success);
    color: #333;
    border-color: var(--color-success-light);
}

.bingo-cell.completed .cell-text,
.bingo-cell.completed .cell-emoji {
    color: #333;
}

.bingo-cell .cell-text {
    font-size: clamp(0.6rem, 2vmin, 0.9rem);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    color: var(--color-text-secondary);
}

.bingo-cell .cell-emoji {
    font-size: clamp(1.5rem, 8vmin, 4rem);
    line-height: 1;
    margin-bottom: 5px;
    color: var(--color-text-primary);
}

.free-space {
    background: var(--color-bg-elevated);
    font-weight: bold;
    border-color: var(--color-accent-purple);
}

/* Setup Screen Card */
#setup-screen .card {
    background: var(--color-bg-card);
    border: 1.5px solid var(--color-border);
    border-radius: 24px;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), inset 0 1px 3px rgba(255, 255, 255, 0.4);
    max-width: 500px;
    color: var(--color-text);
}

.card-title {
    color: var(--color-text-primary);
    font-weight: 800;
}

.card-text {
    color: var(--color-text-secondary);
}

/* Form Elements */
.form-select,
.form-control {
    background-color: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: 12px;
}

.form-select:focus,
.form-control:focus {
    background-color: var(--color-bg-light);
    border-color: var(--color-border-medium);
    color: var(--color-text-primary);
    box-shadow: 0 0 0 0.25rem rgba(126, 159, 245, 0.25);
}

/* Buttons */
.btn-primary {
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    color: var(--color-text-primary);
    font-weight: 700;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--color-accent-cyan) 0%, var(--color-accent-purple) 100%);
    opacity: 0.9;
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    border-radius: 16px;
}

.btn-secondary:hover {
    background: var(--color-bg-light);
    color: var(--color-text-primary);
}

/* Modals */
.modal-content {
    background: var(--color-bg-card);
    border: 1.5px solid var(--color-border);
    border-radius: 24px;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    color: var(--color-text);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header,
.modal-footer {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Emoji Picker */
.emoji-option {
    border-radius: 12px;
    transition: background-color 0.2s;
}

.emoji-option:hover {
    background-color: var(--color-bg-elevated);
}

.emoji-option.selected {
    background-color: var(--color-bg-light);
    border: 1px solid var(--color-border);
}

/* Board Controls - Toolbar */
.button-container {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
}

#resetBtn,
#downloadBtn {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 13px;
    padding: 8px 16px;
}

#resetBtn:hover,
#downloadBtn:hover {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-medium);
    color: var(--color-text-primary);
    transform: translateY(-1px);
    box-shadow: none;
}

/* Emoji Picker Element Customization */
emoji-picker {
    width: 100%;
    height: 320px;
    border-radius: 12px;
    --background: var(--color-bg-elevated);
    --border-color: var(--color-border);
    --input-border-color: var(--color-border);
    --input-font-color: var(--color-text);
    --button-hover-background: var(--color-bg-light);
    --category-emoji-padding: 8px;
    --indicator-color: var(--color-accent-cyan);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Emoji Input Styling */
#emoji-input {
    width: 60px;
    font-size: 1.5rem;
    cursor: default;
}

/* Better Contrast for Placeholders */
::placeholder {
    color: var(--color-text-secondary) !important;
    opacity: 0.7;
}

.form-control::placeholder {
    color: var(--color-text-secondary) !important;
    opacity: 0.7;
}

/* Status Badge */
.status-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    backdrop-filter: blur(10px);
    cursor: help;
    transition: all 0.3s ease;
    z-index: 100;
}

.status-badge:hover {
    background: var(--color-bg-light);
    border-color: var(--color-border-medium);
    color: var(--color-text-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-text-muted);
    transition: background-color 0.3s ease;
}

.status-badge.connected .status-dot {
    background-color: var(--color-success);
    box-shadow: 0 0 8px var(--color-success);
}

.status-badge.connected {
    border-color: rgba(74, 222, 128, 0.3);
    color: var(--color-success-light);
}

/* Logout Button */
.logout-btn {
    background: rgba(220, 38, 38, 0.2);
    /* Slight red tint */
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 12px;
    color: #fca5a5;
    /* Light red text */
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    margin-left: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: rgba(220, 38, 38, 0.4);
    color: #fff;
    border-color: rgba(220, 38, 38, 0.6);
}

/* Fix for Year Dropdown visibility on white/system backgrounds */
#year-select option {
    background-color: var(--color-bg-elevated);
    color: var(--color-text);
}

/* Export Optimization */
.bingo-board.exporting .bingo-cell {
    border-width: 2px !important;
    /* Fix sub-pixel rendering issues */
    box-shadow: none !important;
    /* Remove shadows which render as thick muddy borders in png */
    backdrop-filter: none !important;
    /* html2canvas struggles with this */
    background: #0f172a !important;
    /* Solid Slate-900 background (no transparency) */
    transform: none !important;
}

.bingo-board.exporting .bingo-cell.completed {
    background: #4ade80 !important;
    /* Solid Green */
    border-color: #22c55e !important;
}