/* ===== CSS Variables ===== */
:root {
    /* Bold, distinctive color palette - warm & energetic */
    --color-primary: #FF5722;
    --color-primary-dark: #D84315;
    --color-secondary: #FFC107;
    --color-accent: #00BCD4;
    --color-success: #4CAF50;
    
    /* Backgrounds */
    --color-bg: #1A1A2E;
    --color-bg-light: #16213E;
    --color-surface: #0F3460;
    --color-surface-hover: #1A4D8F;
    
    /* Text */
    --color-text: #FFFFFF;
    --color-text-dim: #B0B0B0;
    
    /* Cell states */
    --color-cell-bg: #2C3E50;
    --color-cell-marked: var(--color-primary);
    --color-cell-border: rgba(255, 255, 255, 0.1);
    
    /* Bingo letters */
    --color-bingo-letter: #FFD700;
    
    /* Spacing */
    --gap: 8px;
    --padding: 20px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--color-bg) 0%, var(--color-bg-light) 100%);
    background-attachment: fixed;
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

/* Subtle animated background texture */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255, 87, 34, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(0, 188, 212, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(255, 193, 7, 0.05) 0%, transparent 50%);
    pointer-events: none;
    animation: backgroundPulse 20s ease-in-out infinite alternate;
    z-index: 0;
}

@keyframes backgroundPulse {
    0% {
        opacity: 0.3;
    }
    100% {
        opacity: 0.6;
    }
}

/* ===== Container ===== */
.container {
    max-width: 600px;
    width: 100%;
    position: relative;
    z-index: 1;
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Header ===== */
header {
    text-align: center;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

h1 {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 900;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary), var(--color-accent));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 5s ease infinite;
    text-shadow: 0 0 40px rgba(255, 87, 34, 0.3);
    flex: 1;
}

@keyframes gradientShift {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* ===== Reset Button ===== */
.reset-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: var(--color-text);
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.reset-btn:hover {
    background: var(--color-primary);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 87, 34, 0.4);
}

.reset-btn:active {
    transform: translateY(0);
}

.reset-btn svg {
    transition: transform var(--transition-normal);
}

.reset-btn:hover svg {
    transform: rotate(-180deg);
}

/* ===== Bingo Status ===== */
.bingo-status {
    margin-bottom: 20px;
    min-height: 40px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.bingo-badge {
    background: linear-gradient(135deg, var(--color-success), #66BB6A);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.1em;
    box-shadow: 
        0 4px 15px rgba(76, 175, 80, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: bingoAppear 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bingo-badge::before {
    content: '🎉';
    font-size: 16px;
}

@keyframes bingoAppear {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    60% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

/* ===== Card Wrapper ===== */
.card-wrapper {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: var(--padding);
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Bingo Card Grid ===== */
.bingo-card {
    display: grid;
    gap: var(--gap);
    width: 100%;
    aspect-ratio: 1;
}

/* 5x5 grid */
.bingo-card.grid-5x5 {
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
}

/* 3x9 grid (3 rows, 9 columns) */
.bingo-card.grid-3x9 {
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(3, 1fr);
    aspect-ratio: 3 / 1;
}

/* ===== Cell ===== */
.cell {
    background: var(--color-cell-bg);
    border: 2px solid var(--color-cell-border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    user-select: none;
    overflow: hidden;
}

/* Hover effect */
.cell:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-accent);
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 188, 212, 0.3);
    z-index: 10;
}

/* Marked state */
.cell.marked {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    border-color: var(--color-primary);
    color: white;
    box-shadow: 
        0 4px 20px rgba(255, 87, 34, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.cell.marked:hover {
    transform: scale(1.05);
    box-shadow: 
        0 8px 30px rgba(255, 87, 34, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Number (default display) */
.cell-number {
    transition: opacity var(--transition-fast);
}

/* BINGO letter overlay */
.cell-bingo-letter {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(2rem, 6vw, 3.5rem);
    font-weight: 900;
    color: var(--color-bingo-letter);
    opacity: 0;
    pointer-events: none;
    text-shadow: 
        0 0 10px rgba(255, 215, 0, 0.8),
        0 0 20px rgba(255, 215, 0, 0.6),
        0 2px 4px rgba(0, 0, 0, 0.5);
    animation: letterAppear 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    z-index: 2;
}

@keyframes letterAppear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0) rotate(-180deg);
    }
    70% {
        transform: translate(-50%, -50%) scale(1.2) rotate(10deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0);
    }
}

/* When BINGO letter is shown, fade out the number */
.cell.has-bingo-letter .cell-number {
    opacity: 0.2;
}

/* Pulse animation for new bingo */
@keyframes cellPulse {
    0%, 100% {
        box-shadow: 
            0 4px 20px rgba(255, 87, 34, 0.5),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 
            0 8px 40px rgba(255, 215, 0, 0.8),
            inset 0 1px 0 rgba(255, 255, 255, 0.5);
    }
}

.cell.bingo-cell {
    animation: cellPulse 1s ease-in-out 3;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal {
    background: var(--color-surface);
    border-radius: 20px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    box-shadow: 
        0 30px 90px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: modalSlideIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.modal-header svg {
    color: var(--color-secondary);
    stroke-width: 2.5;
}

.modal-header h2 {
    font-size: 24px;
    font-weight: 700;
    text-align: center;
}

.modal-message {
    color: var(--color-text-dim);
    text-align: center;
    line-height: 1.6;
    margin-bottom: 30px;
}

.modal-actions {
    display: flex;
    gap: 15px;
}

.btn {
    flex: 1;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-confirm {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    border: 2px solid var(--color-primary);
    box-shadow: 0 4px 15px rgba(255, 87, 34, 0.4);
}

.btn-confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 87, 34, 0.6);
}

.btn:active {
    transform: translateY(0);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    :root {
        --gap: 6px;
        --padding: 15px;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
    }
    
    h1 {
        font-size: 3rem;
    }
    
    .reset-btn {
        width: 100%;
        justify-content: center;
    }
    
    .modal {
        padding: 30px 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
}

@media (max-width: 400px) {
    .cell {
        font-size: 1rem;
    }
    
    .cell-bingo-letter {
        font-size: 1.8rem;
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.cell:focus-visible,
.reset-btn:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}