*,
*::before,
*::after {
    box-sizing: inherit;
}

:root {
    --primary-bg: #f5f0e6;
    /* Warm Beige */
    --card-bg: rgba(255, 255, 255, 0.6);
    --card-hover: rgba(255, 255, 255, 0.9);
    --accent: #d32f2f;
    /* Deep Red */
    --accent-gradient: linear-gradient(135deg, #d32f2f, #b71c1c);
    --text-color: #3e2723;
    /* Dark Brown for contrast */
    --grid-gap: 12px;
    --cell-size: clamp(60px, 10vw, 100px);
    --selected-bg: #ef9a9a;
    /* Light Red */
    --selected-border: #c62828;
    --disabled-bg: #e0e0e0;
}

body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Global box-sizing */
    background-color: var(--primary-bg);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(211, 47, 47, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(183, 28, 28, 0.05) 0%, transparent 40%);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
    z-index: 10;
}

h1 {
    font-size: 3rem;
    margin: 0;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 4px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

#message {
    font-size: 4rem;
    font-weight: 700;
    color: #2e7d32;
    /* Win Green */
    text-shadow: 0 0 20px rgba(76, 175, 80, 0.4);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 100;
    pointer-events: none;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 40px;
    border-radius: 12px;
    border: 3px solid #2e7d32;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
}

#message.show {
    transform: translate(-50%, -50%) scale(1);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(76, 175, 80, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.board {
    display: grid;
    gap: var(--grid-gap);
    padding: 20px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        inset 0 0 20px rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    position: relative;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--card-bg);
    border: 1px solid rgba(211, 47, 47, 0.1);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 5px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    hyphens: auto;
    overflow: hidden;
    color: #5d4037;
}

.cell:hover:not(.disabled):not(.center-cell) {
    background: var(--card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-color: rgba(211, 47, 47, 0.3);
}

.cell.selected {
    background: var(--selected-bg);
    border-color: var(--selected-border);
    color: #b71c1c;
    /* Dark Red text */
    transform: scale(0.96);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cell.center-cell {
    background: transparent !important;
    cursor: default;
    border: none;
    padding: 0;
    box-shadow: none;
    overflow: visible;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cell.center-cell img {
    width: 100%;
    /* Full fill as requested */
    height: 100%;
    object-fit: cover;
    /* Cover or contain? "same size as other tiles" likely means fill the box. */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    border-radius: 8px;
    /* Slight radius to match cell */
}

/* Grayed out cells - treated as auto-selected */
.cell.disabled {
    background: var(--disabled-bg);
    color: #9e9e9e;
    cursor: not-allowed;
    opacity: 0.7;
    border: 1px dashed #bdbdbd;
}

.warning {
    color: #fff;
    background: #d32f2f;
    padding: 10px 20px;
    border-radius: 8px;
    margin-top: 10px;
    font-weight: bold;
    font-size: 0.9rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.warning.hidden {
    display: none;
}

/* Winning Line Highlight */
.win-line {
    position: absolute;
    background: #2e7d32;
    /* Win Green */
    border-radius: 5px;
    z-index: 50;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
    pointer-events: none;
}

#reset-btn {
    margin-top: 20px;
    padding: 12px 30px;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: white;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 10px rgba(211, 47, 47, 0.3);
}

#reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(211, 47, 47, 0.4);
}

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

#confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}