/* --- Root Variables & General Setup --- */
:root {
    --bg-gradient-start: #3d2c5a;
    --bg-gradient-end: #2c1e3f;
    --panel-bg: rgba(255, 255, 255, 0.1); 
    --cell-bg: rgba(0, 0, 0, 0.4);      
    --cell-hover: rgba(0, 0, 0, 0.5);
    --text-color: #f0f0f0;

    /* Button Gradients */
    --btn-blue-start: #0abde3;
    --btn-blue-end: #01a9ac;
    --btn-red-start: #e94560;
    --btn-red-end: #d62947;
    --btn-yellow-start: #f7b733; 
    --btn-yellow-end: #f39c12;

    /* Player Colors (CHANGED) */
    --x-color: #e94560; /* Red */
    --x-shadow: rgba(233, 69, 96, 0.5);
    --o-color: #f7b733; /* CHANGED to Yellow */
    --o-shadow: rgba(247, 183, 51, 0.5); /* CHANGED to Yellow */

    /* Accent Color (CHANGED) */
    --accent-color: var(--o-color); /* CHANGED to Yellow */
    --glow-color: var(--o-shadow); /* CHANGED to Yellow */
    --win-bg: rgba(247, 183, 51, 0.25); /* CHANGED to Yellow */
    --win-border-color: #f39c12; /* CHANGED to Yellow */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent; 
}

html, body {
    height: 100%;
    width: 100%;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-color);
    overflow: hidden; 
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    height: 100%;
    background: var(--container-bg);
    padding: 2vh 2vw; 
    display: flex;
    flex-direction: column;
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
}

.hidden {
    display: none !important;
}

/* --- Mode Select & Headers --- */
#mode-select-screen {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* ... (styles for title, mode-buttons, etc. are unchanged) ... */
.header-icons {
    position: absolute;
    top: 2vh;
    right: 3vh;
    z-index: 10;
}

.title {
    text-align: center;
    font-size: 10vh;
    font-weight: 700;
    margin-bottom: 3vh;
    color: var(--accent-color); /* Now Yellow */
}

.mode-buttons {
    display: flex;
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    gap: 3vh;
    width: 100%;
}

.mode-btn {
    width: 70%;
    max-width: 50vh;
    height: auto;
    padding: 2.5vh;
    font-size: 3.5vh;
    font-weight: 600;
    border: none;
    border-radius: 2vh;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2vh;
}

.mode-btn span {
    font-size: 4vh;
    line-height: 1;
}

#pvp-btn {
    background: linear-gradient(135deg, var(--btn-blue-start), var(--btn-blue-end));
}

#pvc-btn {
    background: linear-gradient(135deg, var(--btn-red-start), var(--btn-red-end));
}

.mode-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 4vh;
    color: var(--text-color);
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 1vh;
}

.icon-btn:hover {
    transform: scale(1.2);
}

/* --- Game Screen --- */
#game-screen {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    align-items: center;
    width: 100%;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1vh;
    width: 100%;
}

.header-icons-right {
    display: flex;
    align-items: center;
    gap: 1vh;
}

.game-body {
    flex-grow: 1;
    display: grid; 
    /* CHANGED: Center column is now larger */
    grid-template-columns: 1fr 1.7fr 1fr; 
    align-items: center;
    justify-items: center; 
    width: 100%;
    min-height: 0;
    gap: 2vw; 
}

.player-info {
    width: 90%; 
    max-width: 350px; 
    flex-basis: auto; 
    
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2vh 1vw; /* More vertical padding */
    border-radius: 2vh;
    transition: all 0.3s ease;
    text-align: center;
    /* CHANGED: Player name font size smaller */
    font-size: 2.2vh;
    background: var(--panel-bg); 
    
    word-break: break-all;
}

#player1-info.active {
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--x-shadow);
}

/* Active highlight for P2 is now yellow */
#player2-info.active {
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--o-shadow);
}

/* NEW: Style for "WINS" and "DRAWS" labels */
.score-label {
    font-size: 1.8vh;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 1.5vh;
}

.score {
    /* CHANGED: Score font size smaller to fit */
    font-size: 4vh; 
    font-weight: bold;
    line-height: 1.2; /* Tighter line height */
}

/* --- Game Board & Cells --- */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5vh;
    
    width: 90%; 
    height: auto; 
    aspect-ratio: 1 / 1; 

    margin: 0; 
    flex-shrink: 0;
}

.cell {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--cell-bg); 
    border-radius: 1.5vh;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.3s ease, border 0.3s ease;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 70%;
}

.cell:not(.X):not(.O):hover {
    background-color: var(--cell-hover);
}

/* --- Stylish X and O --- */
.cell.X {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 10 L50 40 L80 10 L90 20 L60 50 L90 80 L80 90 L50 60 L20 90 L10 80 L40 50 L10 20 Z" fill="%23e94560"/></svg>');
    background-size: 75%;
}

/* CHANGED: O is now yellow (#f7b733) */
.cell.O {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="%23f7b733" stroke-width="15" fill="none"/></svg>');
    background-size: 70%;
}

/* Winning highlight is now yellow */
.cell.winning {
    border: 0.5vh solid var(--win-border-color);
    box-shadow: 0 0 20px var(--glow-color);
}

/* --- Result Popup --- */
#result-popup {
    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: 1000;
}

.popup-content {
    background: #2c1e3f;
    border: 1px solid var(--btn-yellow-start);
    padding: 4vh 6vh;
    border-radius: 2vh;
    text-align: center;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    position: relative; 
}

#result-message {
    font-size: 5vh;
    margin-bottom: 3vh;
    color: var(--text-color);
}

#next-round-btn {
    padding: 2vh 4vh;
    font-size: 2.5vh;
    border: none;
    border-radius: 1vh;
    background: linear-gradient(135deg, var(--btn-yellow-start), var(--btn-yellow-end));
    color: #333;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

#next-round-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* --- Name Popup Styles --- */
#name-popup {
    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: 1000;
}

/* Name popup border and button are now yellow */
#name-popup .popup-content {
    border-color: var(--btn-yellow-start);
}

#name-popup h3 {
    font-size: 4vh;
    margin-bottom: 2vh;
    color: var(--text-color);
}

.input-group {
    margin-bottom: 2vh;
}

.input-group input {
    width: 100%;
    padding: 1.5vh;
    font-size: 2.5vh;
    border-radius: 1vh;
    border: 2px solid var(--btn-yellow-end);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-color);
    text-align: center;
}

.input-group input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.popup-action-btn {
    padding: 2vh 4vh;
    font-size: 2.5vh;
    border: none;
    border-radius: 1vh;
    background: linear-gradient(135deg, var(--btn-yellow-start), var(--btn-yellow-end));
    color: #333;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}
.popup-action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.popup-back-btn {
    position: absolute;
    top: 1vh;
    left: 0.1vh;
    background: none;
    border: none;
    font-size: 4vh;
    color: var(--text-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}
.popup-back-btn:hover {
    transform: scale(1.2);
}

/* --- Fluid Design for TALL Screens --- */
@media (max-aspect-ratio: 1/1) {
    .container {
        padding: 1vh 1vw; 
    }
    .title {
        font-size: 15vw;
    }
    .mode-btn {
        width: 90%;
        font-size: 5vw; 
        padding: 3vw;
    }
    .mode-btn span {
        font-size: 6vw;
    }
    
    .game-body {
        display: flex; 
        flex-direction: column; 
        justify-content: center; 
        gap: 0; 
    }

    .player-info {
        flex-basis: auto; 
        width: 80%; 
        max-width: none; 
        margin-bottom: 1vh;
        font-size: 4vw; /* Player name on mobile */
    }

    /* Labels and scores on mobile */
    .score-label {
        font-size: 3vw;
        margin-top: 1vh;
    }
    .score {
        font-size: 6vw;
    }

    .board {
        width: 90vw; 
        height: 90vw;
        max-width: 90vw; 
        max-height: 90vw; 
        margin: 2vh 0; 
        order: -1; 
    }

    #player1-info { order: 1; }
    #player2-info { order: 2; }

    .icon-btn {
        font-size: 6vw; 
    }
}