/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', 'Roboto', 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    position: fixed;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(230, 126, 34, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(243, 156, 18, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body.modal-open {
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    width: 100vw;
    height: 100vh;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.4s ease-out;
}

/* Settings and Policy Buttons */
.settings-icon,
.policy-btn {
    position: absolute;
    top: 20px;
    color: #ffffff;
    font-size: 1em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    padding: 12px;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 4px 15px rgba(230, 126, 34, 0.4),
        0 8px 0px #d35400,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.15s ease;
    z-index: 10;
    backdrop-filter: blur(10px);
}

.settings-icon {
    right: 20px;
}

.policy-btn {
    left: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
}

.settings-icon:hover,
.policy-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(230, 126, 34, 0.5),
        0 10px 0px #d35400,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.settings-icon:active,
.policy-btn:active {
    transform: translateY(4px);
    box-shadow: 
        0 2px 10px rgba(230, 126, 34, 0.3),
        0 4px 0px #d35400,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Modal Styles */
.settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 0;
}

.settings-modal.active {
    display: flex;
}

.settings-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 24px;
    padding: 40px 30px;
    width: 90%;
    max-width: 420px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: auto 0;
}

@keyframes slideUp {
    from { 
        transform: translateY(50px) scale(0.95); 
        opacity: 0; 
    }
    to { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(230, 126, 34, 0.2);
}

.settings-title {
    color: #2c3e50;
    font-size: 2em;
    font-weight: 700;
    background: linear-gradient(135deg, #e67e22, #f39c12);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.close-btn {
    color: #ffffff;
    font-size: 1.3em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: 8px 18px;
    box-shadow: 
        0 4px 12px rgba(230, 126, 34, 0.3),
        0 6px 0px #d35400;
    transition: all 0.15s ease;
    font-weight: 600;
}

.close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 16px rgba(230, 126, 34, 0.4),
        0 8px 0px #d35400;
}

.close-btn:active {
    transform: translateY(2px);
    box-shadow: 
        0 2px 8px rgba(230, 126, 34, 0.3),
        0 4px 0px #d35400;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    transition: background 0.2s ease;
    border-radius: 8px;
    margin: 0 -10px;
    padding-left: 10px;
    padding-right: 10px;
}

.setting-item:hover {
    background: rgba(230, 126, 34, 0.05);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.2em;
    color: #2c3e50;
    font-weight: 500;
}

.setting-icon {
    font-size: 1.5em;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Toggle Switch - Modern Glassmorphic Style */
.toggle-switch {
    appearance: none;
    width: 60px;
    height: 32px;
    background: linear-gradient(145deg, #cbd5e0, #e2e8f0);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    position: relative;
    cursor: pointer;
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: linear-gradient(145deg, #ffffff, #f1f5f9);
    border-radius: 50%;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.15),
        0 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch.active {
    background: linear-gradient(145deg, #e67e22, #f39c12);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.2),
        0 2px 8px rgba(230, 126, 34, 0.4);
}

.toggle-switch.active::before {
    transform: translateX(28px);
    background: linear-gradient(145deg, #ffffff, #fff5e6);
}

.toggle-switch:focus-visible {
    outline: 3px solid rgba(230, 126, 34, 0.3);
    outline-offset: 2px;
}

/* Main Menu */
.menu-title {
    color: white;
    font-size: 3.5em;
    margin-bottom: 50px;
    text-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.3),
        0 4px 12px rgba(230, 126, 34, 0.3),
        0 0 40px rgba(230, 126, 34, 0.2);
    animation: fadeIn 0.5s ease-in, float 3s ease-in-out infinite;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 400px;
}

.menu-btn {
    color: #ffffff;
    font-size: 1.6em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    padding: 22px 40px;
    box-shadow: 
        0 4px 15px rgba(230, 126, 34, 0.4),
        0 8px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.15s ease;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 6px 20px rgba(230, 126, 34, 0.5),
        0 10px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.menu-btn:active {
    transform: translateY(4px);
    box-shadow: 
        0 2px 10px rgba(230, 126, 34, 0.3),
        0 4px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-subtitle {
    font-size: 0.55em;
    opacity: 0.9;
    display: block;
    margin-top: 6px;
    font-weight: 400;
}

/* Game Screen */
.game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 10px;
}

.game-header {
    text-align: center;
}

.game-title {
    color: #2c3e50;
    font-size: 2em;
    margin-bottom: 15px;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    padding: 12px 24px;
    border-radius: 16px;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(230, 126, 34, 0.2);
    font-weight: 700;
    letter-spacing: 1px;
    display: inline-block;
}

.score {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.score-item {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    padding: 12px 24px;
    border-radius: 16px;
    color: #2c3e50;
    font-size: 1.4em;
    font-weight: 600;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 8px;
    border: 2px solid rgba(230, 126, 34, 0.2);
    transition: transform 0.2s ease;
}

.score-item:hover {
    transform: translateY(-2px);
}

.score-item span {
    font-weight: 700;
    font-size: 1.1em;
    background: linear-gradient(135deg, #e67e22, #f39c12);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status {
    color: #ffffff;
    font-size: 1.3em;
    font-weight: 600;
    min-height: 35px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    padding: 8px 20px;
    background: rgba(230, 126, 34, 0.15);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    display: inline-block;
    margin: 0 auto;
}

.board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 20px 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 12px;
    width: min(85vw, 400px);
    height: min(85vw, 400px);
    background: linear-gradient(145deg, #f5f5f5, #e8e8e8);
    padding: 15px;
    border-radius: 24px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.15),
        inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.cell {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border: none;
    border-radius: 16px;
    font-size: clamp(3em, 12vw, 5em);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(230, 126, 34, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cell:hover:not(:disabled)::before {
    opacity: 1;
}

.cell:hover:not(:disabled) {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 
        0 8px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.cell:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.cell:disabled {
    cursor: not-allowed;
    opacity: 0.9;
}

.cell.x {
    color: #3498db;
    text-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.cell.o {
    color: #e74c3c;
    text-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.cell.winner {
    background: linear-gradient(145deg, #f39c12, #e67e22);
    color: white;
    animation: winnerPulse 0.6s ease-in-out;
    box-shadow: 
        0 0 20px rgba(230, 126, 34, 0.5),
        0 4px 12px rgba(0, 0, 0, 0.2),
        inset 0 -2px 8px rgba(0, 0, 0, 0.2);
}

@keyframes winnerPulse {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.1) rotate(5deg); }
    75% { transform: scale(1.1) rotate(-5deg); }
}

.game-footer {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.game-btn {
    color: #ffffff;
    font-size: 1.2em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    padding: 16px 32px;
    box-shadow: 
        0 4px 15px rgba(230, 126, 34, 0.4),
        0 6px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.15s ease;
    font-weight: 600;
    flex: 1;
    max-width: 180px;
    min-width: 120px;
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 18px rgba(230, 126, 34, 0.5),
        0 8px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.game-btn:active {
    transform: translateY(2px);
    box-shadow: 
        0 2px 10px rgba(230, 126, 34, 0.3),
        0 4px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Difficulty Selection */
.difficulty-title {
    color: #2c3e50;
    font-size: 2.5em;
    margin-bottom: 40px;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    padding: 12px 24px;
    border-radius: 16px;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(230, 126, 34, 0.2);
    font-weight: 700;
    letter-spacing: 1px;
    display: inline-block;
}

.difficulty-btn {
    color: #ffffff;
    font-size: 1.5em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    padding: 20px 40px;
    box-shadow: 
        0 4px 15px rgba(230, 126, 34, 0.4),
        0 8px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.15s ease;
    font-weight: 600;
}

.difficulty-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 18px rgba(230, 126, 34, 0.5),
        0 10px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.difficulty-btn:active {
    transform: translateY(4px);
    box-shadow: 
        0 2px 10px rgba(230, 126, 34, 0.3),
        0 4px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.back-btn-small {
    color: #ffffff;
    font-size: 1.4em;
    background: linear-gradient(145deg, #e67e22, #d35400);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    padding: 18px 40px;
    box-shadow: 
        0 4px 15px rgba(230, 126, 34, 0.4),
        0 6px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.15s ease;
    font-weight: 600;
    margin-top: 30px;
    width: 100%;
    max-width: 400px;
}

.back-btn-small:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 18px rgba(230, 126, 34, 0.5),
        0 8px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.back-btn-small:active {
    transform: translateY(2px);
    box-shadow: 
        0 2px 10px rgba(230, 126, 34, 0.3),
        0 4px 0px #c0431f,
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .menu-title {
        font-size: 2.8em;
    }
    
    .game-title {
        font-size: 1.6em;
    }
    
    .score-item {
        font-size: 1.2em;
        padding: 10px 18px;
    }
    
    .menu-btn {
        font-size: 1.4em;
        padding: 18px 32px;
    }
}