@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap');

/* --- Theme Variables --- */
:root {
    --background-color: #f8f9fa;
    --text-color: #212529;
    --primary-accent: #17a2b8; /* Teal */
    --secondary-accent: #6c757d; /* Grey */
    --board-bg: #e9ecef;
    --board-border: #dee2e6;
    --cell-bg: #ffffff;
    --cell-shadow: #ced4da;
    --x-color: #17a2b8; /* Teal for X */
    --o-color: #E57373; /* Coral Red for O */
    --glow-color: #17a2b8;
}

/* --- General Styles --- */
body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--background-color) !important; /* Use important to override Bootstrap */
    color: var(--text-color);
}

/* Add spacing between icons and button text */
#create-game-button i,
#join-game-button i,
#show-leaderboard-button i,
#restart-button i,
.btn-danger i {
    margin-right: 8px;
}

/* --- Game Dashboard --- */
.game-dashboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--board-bg);
    border: 1px solid var(--board-border);
    border-radius: 12px;
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto 1rem auto; /* Center the dashboard */
}

.player-info {
    flex: 1;
}

.player-info .player-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary-accent);
}

.player-info .timer {
    font-size: 1.5rem;
    font-weight: 700;
}

.player-info.active {
    color: var(--primary-accent);
}

.player-info.active .player-name {
    color: var(--primary-accent);
}

.game-meta #game-id-display {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.game-meta .status-text {
    font-size: 1.1rem;
    font-weight: bold;
    line-height: 1.2;
    margin-bottom: 4px;
}

#sound-toggle-btn {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    padding: 0;
}

#sound-toggle-btn i {
    margin: 0; /* Remove any default margins from the icon */
}

/* --- Standard Board --- */
.board {
    display: grid;
    /* Use clamp for responsive sizing with min/max */
    grid-template-columns: repeat(3, clamp(60px, 25vw, 100px));
    grid-gap: clamp(5px, 2.5vw, 10px);
    justify-content: center;
    background-color: var(--board-bg);
    padding: clamp(5px, 2.5vw, 10px);
    border-radius: 10px;
}

.cell {
    width: clamp(60px, 25vw, 100px);
    height: clamp(60px, 25vw, 100px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(36px, 13vw, 52px); /* Responsive font size */
    font-weight: bold;
    appearance: button;
    background-color: var(--cell-bg);
    border: solid transparent;
    border-radius: 12px; /* Stable radius */
    border-width: 0 0 4px; /* Stable border */
    box-sizing: border-box;
    cursor: pointer;
    margin: 0;
    outline: none;
    overflow: hidden; /* Prevent content from spilling out */
    padding: 0;
    text-align: center;
    text-transform: uppercase;
    touch-action: manipulation;
    transform: translateZ(0);
    transition: filter .2s;
    user-select: none;
    -webkit-user-select: none;
    vertical-align: middle;
    white-space: nowrap;
    color: var(--text-color);
}

.cell:after {
    background-clip: padding-box;
    background-color: var(--cell-shadow);
    border: solid transparent;
    border-radius: 12px; /* Stable radius */
    border-width: 0 0 4px; /* Stable border */
    bottom: -4px;
    content: "";
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    z-index: -1;
}

.cell:hover:not(.disabled) {
    filter: brightness(1.05);
}

.cell.disabled {
    cursor: auto;
    background-color: #f8f9fa;
    color: #adb5bd;
    filter: none;
}

.cell.X {
    color: var(--x-color);
}

.cell.O {
    color: var(--o-color);
}

/* --- Ultimate Board --- */
.board.ultimate {
    width: clamp(320px, 95vw, 600px); /* Responsive width with min/max */
    grid-template-columns: repeat(3, 1fr);
    grid-gap: clamp(5px, 2vw, 15px);
    background-color: var(--board-border);
    border-width: clamp(5px, 1vw, 5px);
    border-style: solid;
    border-color: var(--board-border);
    padding: clamp(5px, 2vw, 15px);
    border-radius: 15px;
}

.micro-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: clamp(2px, 1vw, 5px);
    position: relative;
    background-color: var(--board-bg);
    border-radius: 10px;
    transition: box-shadow 0.3s, transform 0.3s, opacity 0.3s;
    opacity: 0.5;
    padding: clamp(2px, 1vw, 5px);
}

.ultimate .cell {
    width: auto; /* Let the grid determine the width */
    height: 0;
    padding-bottom: 100%; /* Create a square aspect ratio */
    position: relative;
    font-size: clamp(20px, 7vw, 34px); /* Responsive font size */
    border-radius: 8px; /* Stable radius */
}

/* We need a wrapper inside the ultimate cell for centering */
.ultimate .cell-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ultimate .cell:after {
    border-radius: 8px; /* Stable radius */
}

.micro-board.active {
    box-shadow: 0 0 20px 5px var(--glow-color);
    transform: scale(1.02);
    opacity: 1;
}

/* Make the buttons on the active board slightly darker */
.micro-board.active .cell {
    background-color: #e9ecef; /* A slightly darker, clean grey */
}

.micro-board.active .cell:after {
    background-color: #ced4da; /* A corresponding darker shade for the bottom */
}

/* The hover effect for ultimate cells should be the same as standard cells */
.ultimate .cell:hover:not(.disabled) {
    filter: brightness(1.1);
    -webkit-filter: brightness(1.1);
}

/* Keep the disabled logic the same */
.micro-board.active .cell:disabled {
    cursor: not-allowed;
    background-color: #F7F7F7;
    color: #adb5bd;
    filter: none;
}

.micro-board.active .cell:disabled:after {
    background-color: #EAEAEA;
}

/* The X and O colors should be the standard ones, not white */
.ultimate .cell.X .cell-content {
    color: var(--x-color);
}

.ultimate .cell.O .cell-content {
    color: var(--o-color);
}

.micro-board.won, .micro-board.draw {
    /* No longer needed, the overlay will be solid */
}

.winner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(70px, 25vw, 130px); /* Responsive font size with min/max */
    font-weight: bold;
    color: #ffffff; /* White text for all overlays */
    pointer-events: none;
    border-radius: 10px;
}

/* Solid background colors for won/drawn boards */
.micro-board.won.X .winner-overlay {
    background-color: var(--x-color);
}

.micro-board.won.O .winner-overlay {
    background-color: var(--o-color);
}

.micro-board.draw .winner-overlay {
    background-color: var(--secondary-accent);
}

/* --- Connection Indicator --- */
.connection-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 500;
}

.connection-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

/* Connection States */
.connection-indicator.connected .connection-dot {
    background-color: #28a745; /* Green */
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.3);
}

.connection-indicator.connected .connection-text {
    color: #28a745;
}

.connection-indicator.disconnected .connection-dot {
    background-color: #dc3545; /* Red */
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.3);
}

.connection-indicator.disconnected .connection-text {
    color: #dc3545;
}

.connection-indicator.reconnecting .connection-dot {
    background-color: #ffc107; /* Yellow */
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.3);
    animation: pulse 1.5s infinite;
}

.connection-indicator.reconnecting .connection-text {
    color: #ffc107;
}

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

/* --- Utility --- */
.hidden {
    display: none;
}

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

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

.card {
    animation: fadeIn 0.5s ease-out forwards;
}

/* The animation is now triggered by a specific class */
.cell.played {
    animation: popIn 0.3s ease-out forwards;
}

/* --- Mode Selection Styling --- */
#mode-selection .btn-primary {
    background-color: var(--primary-accent);
    border-color: var(--primary-accent);
    font-weight: 600;
}

#mode-selection .btn-primary:hover {
    background-color: #138496;
    border-color: #117a8b;
}

/* Back button styling */
#back-to-mode-selection {
    color: var(--primary-accent);
    text-decoration: none;
    font-weight: 500;
}

#back-to-mode-selection:hover {
    text-decoration: underline;
}

/* Form title styling */
#form-title {
    color: var(--primary-accent);
    font-weight: 600;
}
