:root {
    /* Default Dark Theme / "Anti-Gravity" */
    --bg-color: #121212;
    --grid-bg: #1e1e24;
    --board-bg: #0d0d10;
    --text-color: #FFFFFF;
    --primary-x: #2979FF;
    --primary-o: #FF9100;
    --turn-bg: #252530;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --last-move-glow: rgba(255, 255, 255, 0.6);
    --gold: #FFD700;
    --gold-glow: rgba(255, 215, 0, 0.5);

    --header-height: 12vh;
    --footer-height: 12vh;
    --board-height: 76vh;
    --cell-base-size: 50px;

    /* Rank Colors */
    --rank-bronze: #cd7f32;
    --rank-silver: #c0c0c0;
    --rank-gold: #ffd700;
    --rank-platinum: #e5e4e2;
}

[data-theme="light"] {
    --bg-color: #F5F5F5;
    --grid-bg: #FFFFFF;
    --board-bg: #E0E0E0;
    --text-color: #111111;
    --primary-x: #2962FF;
    --primary-o: #F57C00;
    --turn-bg: #FFFFFF;
    --glass-bg: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
    --last-move-glow: rgba(0, 0, 0, 0.4);
}

/* SEASON THEMES */
body.theme-winter {
    --bg-color: #0f172a;
    --board-bg: #1e293b;
    --grid-bg: #334155;
    --primary-x: #38bdf8;
    --primary-o: #818cf8;
    --last-move-glow: #e0f2fe;
}

body.theme-spring {
    --bg-color: #f0fdf4;
    --board-bg: #dcfce7;
    --grid-bg: #ffffff;
    --primary-x: #ec4899;
    --primary-o: #22c55e;
    --text-color: #064e3b;
    --turn-bg: #ffffff;
}

body.theme-halloween {
    --bg-color: #2a0a0a;
    --board-bg: #1a0505;
    --grid-bg: #451a03;
    --primary-x: #ca8a04;
    --primary-o: #dc2626;
    --text-color: #fcd34d;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    transition: background 0.3s, color 0.3s;
}

/* SCREEN MANAGEMENT */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    transition: opacity 0.3s ease;
    z-index: 10;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.screen.game-screen {
    z-index: 5;
}

/* MAIN MENU */
.main-menu {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: radial-gradient(circle at 50% 30%, var(--turn-bg) 0%, var(--bg-color) 70%);
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Centers children horizontally */
    width: 100%;
}

.game-title {
    font-size: 3rem;
    line-height: 1.1;
    margin-bottom: 5px;
    background: linear-gradient(135deg, var(--primary-x), var(--primary-o));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.subtitle {
    letter-spacing: 4px;
    text-transform: uppercase;
    opacity: 0.6;
    font-size: 0.8rem;
    margin-bottom: 20px;
}

/* PROFILE SUMMARY (MENU) */
.profile-summary {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    border-radius: 50px;
    border: 1px solid var(--glass-border);
}

.avatar-circle {
    width: 50px;
    height: 50px;
    background: #333;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    border: 2px solid var(--primary-x);
}

.rank-info {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.rank-tier {
    font-weight: bold;
    color: var(--rank-bronze);
    text-transform: uppercase;
    font-size: 0.9rem;
}

.rank-mmr {
    font-size: 0.8rem;
    opacity: 0.7;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 300px;
}

.menu-btn {
    padding: 18px;
    border: none;
    border-radius: 12px;
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.menu-btn.primary {
    background: var(--primary-x);
    color: white;
    box-shadow: 0 5px 20px rgba(41, 121, 255, 0.4);
}

.menu-btn.primary:active {
    transform: scale(0.95);
}

.menu-btn.secondary {
    background: var(--turn-bg);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
}

.menu-btn.secondary:active {
    transform: scale(0.95);
}

.menu-btn.gold {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000;
    box-shadow: 0 0 15px var(--gold-glow);
    animation: pulseGold 2s infinite;
}

@keyframes pulseGold {
    0% {
        transform: scale(1);
        box-shadow: 0 0 15px var(--gold-glow);
    }

    50% {
        transform: scale(1.02);
        box-shadow: 0 0 25px var(--gold-glow);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 15px var(--gold-glow);
    }
}

.difficulty-group {
    width: 100%;
    display: flex;
    justify-content: center;
}

.difficulty-group button {
    width: 100%;
}

/* MODE SELECTION SCREEN */
.mode-screen {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 50%, #1a1a20 0%, #000 100%);
}

.screen-title {
    margin-bottom: 30px;
    letter-spacing: 2px;
}

.mode-cards {
    display: flex;
    gap: 15px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 400px;
}

.mode-card {
    background: var(--turn-bg);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.2s;
    width: 120px;
}

.mode-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-x);
}

.mode-card .icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.mode-card h3 {
    margin: 0;
    font-size: 0.9rem;
}

.mode-card p {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 5px;
}

.mode-card.ranked {
    border-color: var(--gold);
    background: rgba(255, 215, 0, 0.1);
}

/* DIFFICULTY SCREEN */
.difficulty-screen {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 50%, #1a1a20 0%, #000 100%);
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
    width: 80%;
    max-width: 300px;
}

/* ONLINE SCREEN */
.online-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.online-panel {
    width: 90%;
    max-width: 450px;
    background: #15151a;
    border: none;
}

.online-options {
    margin: 30px 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.option-block {
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.option-block h3 {
    margin-top: 0;
    font-size: 0.9rem;
    opacity: 0.7;
}

.divider {
    font-weight: bold;
    opacity: 0.5;
    font-size: 0.8rem;
}

.room-codebox {
    margin-top: 15px;
    animation: slideDown 0.3s;
}

.room-codebox .code {
    font-size: 2rem;
    letter-spacing: 5px;
    font-weight: bold;
    color: var(--primary-x);
    margin: 5px 0;
}

.status-pulse {
    font-size: 0.8rem;
    color: var(--primary-x);
    animation: pulse 1s infinite;
}

.code-input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: #000;
    color: white;
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* PROFILE SCREEN */
.profile-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
}

.wide-panel {
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: left;
}

.avatar-section h3,
.history-section h3 {
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 5px;
    margin-bottom: 15px;
    font-size: 1rem;
    opacity: 0.8;
}

.avatar-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
}

.avatar-option {
    width: 60px;
    height: 60px;
    font-size: 2rem;
    border-radius: 50%;
    background: var(--turn-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.avatar-option.selected {
    border-color: var(--primary-x);
    transform: scale(1.1);
    box-shadow: 0 0 10px var(--primary-x);
}

.avatar-option.locked {
    opacity: 0.5;
    filter: grayscale(1);
    position: relative;
}

.avatar-option.locked::after {
    content: '🔒';
    position: absolute;
    font-size: 1rem;
    bottom: 0;
    right: 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.history-item.win {
    border-left: 4px solid #4caf50;
}

.history-item.loss {
    border-left: 4px solid #f44336;
}

.history-item.draw {
    border-left: 4px solid #999;
}

.match-result {
    font-weight: bold;
}

.match-mmr {
    font-size: 0.8rem;
    margin-left: 5px;
}

.match-mmr.pos {
    color: #4caf50;
}

.match-mmr.neg {
    color: #f44336;
}

/* RANKED LOADING */
.searching-anim {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 30px auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 4px solid var(--primary-x);
    animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.large {
    width: 80px;
    height: 80px;
    font-size: 3rem;
}

@keyframes ping {

    75%,
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.text-btn.danger {
    color: #f44336;
    margin-top: 10px;
}

/* CHECKOUT/SUB SCREEN */
.sub-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.sub-panel {
    background: #111;
    border: 2px solid var(--gold);
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.2);
}

.icon-pulse {
    font-size: 4rem;
    margin-bottom: 10px;
    animation: popIn 0.5s;
}

.benefit-list {
    list-style: none;
    padding: 0;
    text-align: left;
    margin: 20px 0;
}

.benefit-list li {
    margin: 10px 0;
    font-size: 1.1rem;
}

.price-cards {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.price-btn {
    background: #222;
    border: 1px solid #444;
    color: #fff;
    padding: 15px;
    border-radius: 10px;
    width: 100px;
    cursor: pointer;
}

.price-btn.featured {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000;
    font-weight: bold;
    border: none;
    transform: scale(1.1);
}

.demo-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.text-btn {
    background: none;
    border: none;
    color: #888;
    text-decoration: underline;
    cursor: pointer;
}

/* SETTINGS SCREEN */
.settings-screen {
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.settings-panel {
    width: 85%;
    max-width: 350px;
    background: var(--turn-bg);
    color: var(--text-color);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.setting-block {
    margin-bottom: 20px;
    text-align: left;
}

.setting-block h3 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    opacity: 0.7;
}

.theme-selector {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.theme-option {
    padding: 8px 12px;
    background: var(--glass-bg);
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 0.9rem;
    white-space: nowrap;
}

.theme-option.active {
    border-color: var(--primary-x);
    background: rgba(41, 121, 255, 0.2);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

/* GAME HEADER */
.app-header {
    height: var(--header-height);
    background: var(--turn-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.back-icon {
    position: absolute;
    left: 20px;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
}

.turn-indicator {
    padding: 8px 24px;
    background: var(--bg-color);
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
}

.turn-indicator.player-x {
    color: var(--primary-x);
    border: 2px solid var(--primary-x);
}

.turn-indicator.player-o {
    color: var(--primary-o);
    border: 2px solid var(--primary-o);
}

.online-status {
    position: absolute;
    right: 20px;
}

.dot {
    width: 10px;
    height: 10px;
    background: #555;
    border-radius: 50%;
}

.dot.connected {
    background: #0f0;
    box-shadow: 0 0 5px #0f0;
}

/* BOARD AREA */
.board-container {
    height: var(--board-height);
    width: 100%;
    overflow: hidden;
    position: relative;
    background-color: var(--board-bg);
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(12, var(--cell-base-size));
    grid-template-rows: repeat(12, var(--cell-base-size));
    gap: 4px;
    padding: 20px;
    transform-origin: center;
    will-change: transform;
}

/* CELLS & ANIMATIONS */
.cell {
    width: 100%;
    height: 100%;
    background: var(--grid-bg);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: background 0.2s, transform 0.1s;
}

.cell:active {
    transform: scale(0.92);
}

.cell span {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: block;
}

.cell.x {
    color: var(--primary-x);
}

.cell.o {
    color: var(--primary-o);
}

.cell.last-move {
    box-shadow: inset 0 0 0 3px var(--last-move-glow);
    z-index: 2;
}

.cell.win-glow {
    animation: winPulse 1.5s infinite;
    z-index: 3;
    background: var(--grid-bg);
    filter: brightness(1.2);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

@keyframes winPulse {
    0% {
        box-shadow: inset 0 0 0 2px var(--primary-x);
        transform: scale(1);
    }

    50% {
        box-shadow: inset 0 0 0 6px var(--primary-x);
        transform: scale(1.05);
    }

    100% {
        box-shadow: inset 0 0 0 2px var(--primary-x);
        transform: scale(1);
    }
}

/* FOOTER */
.control-bar {
    height: var(--footer-height);
    background: var(--turn-bg);
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}

.control-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    padding: 15px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.control-btn:active {
    background: rgba(128, 128, 128, 0.2);
}

/* OVERLAY and AD Styles same as before */
.winner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(8px);
    transition: opacity 0.3s;
}

.winner-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.glass-panel {
    background: var(--turn-bg);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: popIn 0.3s;
    width: 90%;
    max-width: 400px;
}

.winner-subtext {
    font-size: 1.2rem;
    margin: 10px 0;
    color: var(--gold);
    font-weight: bold;
}

.overlay-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.glow-button {
    background: var(--primary-x);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1rem;
}

.glow-button.secondary {
    background: transparent;
    border: 2px solid var(--text-color);
    color: var(--text-color);
}

.glow-button.gold {
    background: var(--gold);
    color: #000;
    box-shadow: 0 0 15px var(--gold-glow);
}

.ad-banner {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;
    background: #333;
    color: #aaa;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    border-top: 1px solid #555;
    z-index: 10;
}

.ad-banner.hidden {
    display: none;
}

.ad-interstitial {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ad-interstitial.hidden {
    display: none;
}

.ad-content {
    text-align: center;
    color: white;
}

.ad-timer {
    font-size: 2rem;
    font-weight: bold;
    margin: 20px;
    border: 2px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    line-height: 56px;
    display: inline-block;
}