:root {
    --primary: #1e88e5;
    --primary-dark: #1565c0;
    --primary-light: #64b5f6;
    --accent: #fdd835;
    --surface: #1f2a36;
    --surface-light: #283442;
    --surface-dark: #141a23;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(30, 136, 229, 0.4);
    --text-primary: #f5f7fa;
    --text-secondary: #9aa5b5;
    --shadow-strong: 0 18px 45px rgba(9, 12, 17, 0.55);
    --shadow-soft: 0 12px 30px rgba(15, 20, 30, 0.35);
}

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

html,
body {
    height: 100%;
    margin: 0;
}

body {
    font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
    background: radial-gradient(circle at top, #1f2733 0%, #0f141d 60%, #090c12 100%);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: stretch;
    min-height: 100vh;
    padding-bottom: 80px;
    overflow: hidden;
    position: relative;
}

/* Screens */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* Setup Screen */
.setup-wrapper {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 32px 24px;
    background: rgba(20, 26, 35, 0.76);
    border-radius: 24px;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-soft);
}

.setup-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    position: relative;
}

.game-icon {
    font-size: 46px;
    color: var(--primary-light);
    transform: translateY(0);
}

.game-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.3rem;
    text-transform: uppercase;
    text-align: center;
}

.header-controls {
    position: absolute;
    top: -6px;
    right: -4px;
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(15, 21, 30, 0.8);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: rgba(30, 136, 229, 0.15);
    border-color: rgba(30, 136, 229, 0.45);
}

.lang-dropdown {
    position: absolute;
    top: 48px;
    right: 0;
    width: 180px;
    padding: 8px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(16, 23, 33, 0.95);
    box-shadow: 0 18px 35px rgba(9, 12, 17, 0.45);
    z-index: 50;
}

.lang-dropdown.hidden {
    display: none;
}

.lang-option {
    width: 100%;
    border: none;
    background: none;
    color: var(--text-primary);
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.lang-option:hover {
    background: rgba(30, 136, 229, 0.12);
}

.setup-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.config-card {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    padding: 22px;
    border-radius: 20px;
    background: linear-gradient(140deg, rgba(26, 34, 44, 0.92), rgba(18, 23, 30, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--text-secondary);
}

.dropdown-wrapper {
    position: relative;
}

.config-dropdown {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(18, 24, 32, 0.95);
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 52px;
}

.config-dropdown:hover,
.config-dropdown.active {
    border-color: rgba(30, 136, 229, 0.45);
    box-shadow: 0 8px 18px rgba(15, 20, 30, 0.35);
}

.arrow {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.config-dropdown.active .arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    inset: calc(100% + 8px) 0 auto 0;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(19, 25, 35, 0.98);
    box-shadow: 0 18px 40px rgba(9, 12, 17, 0.5);
    z-index: 40;
}

.dropdown-menu.hidden {
    display: none;
}

.menu-item {
    padding: 14px 18px;
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: background 0.15s ease;
}

.menu-item:hover {
    background: rgba(30, 136, 229, 0.12);
}

.menu-item.active {
    color: var(--primary-light);
}

.start-btn {
    width: 100%;
    max-width: 360px;
    height: 62px;
    margin: 0 auto;
    border: none;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.28em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 12px 28px rgba(30, 136, 229, 0.35);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 36px rgba(30, 136, 229, 0.38);
}

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

.btn-icon {
    font-size: 16px;
}

/* Game Screen */
.game-wrapper {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 12px;
}

.game-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.score-panel {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 16px;
    border-radius: 18px;
    background: rgba(18, 24, 32, 0.86);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.score-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 120px;
    text-align: center;
}

.score-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
    background: rgba(30, 136, 229, 0.12);
    border: 1px solid rgba(30, 136, 229, 0.32);
    color: var(--primary-light);
}

.score-icon-o {
    background: rgba(120, 144, 156, 0.12);
    border-color: rgba(176, 190, 197, 0.32);
    color: #cfd8dc;
}

.score-icon-draw {
    background: rgba(253, 216, 53, 0.12);
    border-color: rgba(253, 216, 53, 0.42);
    color: var(--accent);
}

.score-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.26em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.score-number {
    min-width: 60px;
    padding: 8px 16px;
    border-radius: 12px;
    background: rgba(30, 136, 229, 0.12);
    border: 1px solid rgba(30, 136, 229, 0.35);
    color: var(--primary-light);
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.turn-indicator {
    padding: 14px 18px;
    border-radius: 16px;
    background: rgba(30, 136, 229, 0.14);
    border: 1px solid rgba(30, 136, 229, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 600;
    letter-spacing: 0.08em;
}

.turn-indicator.player-o {
    background: rgba(120, 144, 156, 0.14);
    border-color: rgba(176, 190, 197, 0.35);
}

.turn-indicator.player-x {
    background: rgba(30, 136, 229, 0.14);
    border-color: rgba(30, 136, 229, 0.4);
}

.turn-indicator.draw {
    background: rgba(253, 216, 53, 0.18);
    border-color: rgba(253, 216, 53, 0.54);
    color: #383838;
}

#currentPlayerText {
    font-size: 16px;
}

.ai-thinking {
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(120, 144, 156, 0.16);
    border: 1px solid rgba(176, 190, 197, 0.28);
    font-size: 13px;
    color: var(--text-primary);
    display: inline-flex;
    justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.ai-thinking.hidden {
    display: none;
}

.board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.game-board {
    width: 100%;
    height: 100%;
    max-width: 520px;
    max-height: 520px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
}

.board-row {
    display: flex;
    gap: 8px;
    flex: 1;
}

.cell {
    flex: 1;
    min-width: 56px;
    min-height: 56px;
    aspect-ratio: 1;
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(22, 30, 40, 0.92), rgba(14, 19, 27, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(24px, 8vw, 50px);
    font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 0.1em;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.cell:hover:not(.occupied):not(.game-over) {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(15, 20, 30, 0.55);
    background: linear-gradient(145deg, rgba(32, 42, 55, 0.95), rgba(20, 26, 36, 0.95));
}

.cell.player-x {
    background: linear-gradient(145deg, rgba(30, 136, 229, 0.95), rgba(21, 101, 192, 0.95));
    border-color: rgba(30, 136, 229, 0.55);
    box-shadow: 0 10px 24px rgba(30, 136, 229, 0.35);
    color: #ffffff;
}

.cell.player-o {
    background: linear-gradient(145deg, rgba(120, 144, 156, 0.95), rgba(84, 110, 122, 0.95));
    border-color: rgba(176, 190, 197, 0.5);
    box-shadow: 0 10px 24px rgba(84, 110, 122, 0.35);
}

.cell.winning {
    position: relative;
    border-width: 2px;
    border-color: rgba(253, 216, 53, 0.85);
    box-shadow: 0 0 0 3px rgba(253, 216, 53, 0.1), 0 18px 35px rgba(253, 216, 53, 0.25);
}

.cell.occupied,
.cell.game-over {
    cursor: default;
}

.game-actions {
    display: flex;
    gap: 12px;
    margin-top: auto;
    margin-bottom: 90px;
}

.action-btn {
    flex: 1;
    height: 48px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.18em;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    text-transform: uppercase;
}

.action-btn.primary {
    background: rgba(30, 136, 229, 0.16);
    border-color: rgba(30, 136, 229, 0.4);
    color: var(--primary-light);
}

.action-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(30, 136, 229, 0.28);
}

.action-btn.secondary {
    background: rgba(120, 144, 156, 0.14);
    border-color: rgba(176, 190, 197, 0.32);
    color: var(--text-primary);
}

.action-btn.secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(84, 110, 122, 0.24);
}

/* Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 20, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    backdrop-filter: blur(18px);
}

.overlay.draw {
    background: rgba(10, 14, 20, 0.86);
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    width: min(420px, 90%);
    padding: 36px 32px;
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(24, 30, 39, 0.96), rgba(16, 20, 27, 0.96));
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
    box-shadow: var(--shadow-strong);
}

.overlay-icon {
    font-size: 72px;
    margin-bottom: 18px;
}

.overlay-title {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 0.26em;
    color: var(--primary-light);
    margin-bottom: 12px;
}

.overlay.draw .overlay-title {
    color: var(--accent);
}

.overlay-message {
    font-size: 18px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 28px;
}

.overlay-btn {
    border: none;
    border-radius: 16px;
    padding: 14px 38px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 15px 35px rgba(30, 136, 229, 0.35);
}

.overlay-btn:hover {
    transform: translateY(-2px);
}

/* Ad Container */
.ad-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 640px;
    height: 70px;
    padding: 8px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 20, 30, 0.88);
    border-radius: 24px 24px 0 0;
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: 0 -14px 30px rgba(7, 10, 15, 0.6);
    backdrop-filter: blur(18px);
    z-index: 25;
}

.ad-container script,
.ad-container iframe,
.ad-container ins {
    display: block;
    width: 100%;
    height: 60px;
    max-width: 468px;
    border: none;
}

/* Responsive */
@media (max-width: 720px) {
    body {
        padding-bottom: 100px;
    }

    .setup-wrapper {
        padding: 28px 18px;
        border-radius: 20px;
    }

    .game-wrapper {
        padding: 0;
        gap: 14px;
    }

    .score-panel {
        padding: 12px;
        gap: 8px;
    }

    .score-number {
        font-size: 20px;
        min-width: 50px;
    }

    .game-board {
        padding: 8px;
        gap: 6px;
    }

    .ad-container {
        max-width: 95%;
        height: 76px;
        border-radius: 18px 18px 0 0;
    }
}

@media (max-width: 480px) {
    .setup-wrapper {
        gap: 22px;
    }

    .game-title {
        font-size: 24px;
        letter-spacing: 0.24em;
    }

    .config-card {
        padding: 18px;
        border-radius: 18px;
    }

    .start-btn {
        height: 56px;
        letter-spacing: 0.22em;
    }

    .turn-indicator {
        padding: 12px;
    }

    .game-actions {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 110px;
    }

    .action-btn {
        height: 46px;
        letter-spacing: 0.14em;
    }
}
