* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e22ce 100%);
    overflow: hidden;
    position: relative;
}

/* Animated Background */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 50%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(168, 85, 247, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(14, 165, 233, 0.15) 0%, transparent 50%);
    animation: backgroundMove 15s ease-in-out infinite;
    z-index: 0;
    overflow: hidden;
}

.background-animation::before {
    content: '❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕';
    position: absolute;
    top: -10%;
    left: 0;
    width: 200%;
    height: 120%;
    font-size: 4rem;
    color: rgba(255, 255, 255, 0.25);
    line-height: 2;
    word-spacing: 3rem;
    animation: floatSymbols 30s linear infinite;
    pointer-events: none;
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.background-animation::after {
    content: '⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌ ⭕ ❌';
    position: absolute;
    bottom: -10%;
    right: 0;
    width: 200%;
    height: 120%;
    font-size: 3.5rem;
    color: rgba(255, 255, 255, 0.2);
    line-height: 2.5;
    word-spacing: 2.5rem;
    animation: floatSymbolsReverse 35s linear infinite;
    pointer-events: none;
    text-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
}

@keyframes floatSymbols {
    from {
        transform: translateX(0) translateY(0) rotate(0deg);
    }

    to {
        transform: translateX(-50%) translateY(10%) rotate(5deg);
    }
}

@keyframes floatSymbolsReverse {
    from {
        transform: translateX(0) translateY(0) rotate(0deg);
    }

    to {
        transform: translateX(50%) translateY(-10%) rotate(-5deg);
    }
}

@keyframes backgroundMove {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    50% {
        transform: scale(1.1) rotate(5deg);
    }
}

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    padding: 20px;
}

/* Screen Management */
.screen {
    display: none;
    animation: fadeIn 0.5s ease-in-out;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Setup Screen */
.setup-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 50px 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #3b82f6 0%, #a855f7 50%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    animation: titlePulse 2s ease-in-out infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.subtitle {
    font-size: 1.2rem;
    color: #666;
    margin-bottom: 40px;
}

.player-inputs {
    display: flex;
    gap: 30px;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.input-group {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.input-group label {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 15px;
}

.player-x label {
    color: #ef4444;
}

.player-o label {
    color: #3b82f6;
}

.input-group input {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.1rem;
    font-family: 'Cairo', sans-serif;
    border: 3px solid transparent;
    border-radius: 15px;
    background: #f8f9fa;
    transition: all 0.3s ease;
    text-align: center;
}

.player-x input:focus {
    outline: none;
    border-color: #ef4444;
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.3);
}

.player-o input:focus {
    outline: none;
    border-color: #3b82f6;
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(59, 130, 246, 0.3);
}

.player-icon {
    font-size: 3rem;
    margin-top: 15px;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.vs-divider {
    font-size: 2rem;
    font-weight: 900;
    color: #a855f7;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-start {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #a855f7 100%);
    color: white;
    border: none;
    padding: 18px 60px;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4);
}

.btn-start:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.6);
}

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

/* Game Screen */
.game-header {
    margin-bottom: 30px;
}

.scoreboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.player-score {
    display: flex;
    align-items: center;
    gap: 15px;
}

.score-icon {
    font-size: 3rem;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.score-info {
    text-align: center;
}

.player-name {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.player-x-score .player-name {
    color: #ef4444;
}

.player-o-score .player-name {
    color: #3b82f6;
}

.score {
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #3b82f6 0%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.current-turn {
    text-align: center;
    padding: 0 20px;
}

.turn-text {
    font-size: 1rem;
    color: #666;
    margin-bottom: 5px;
}

.turn-player {
    font-size: 2.5rem;
    font-weight: 900;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    max-width: 500px;
    margin: 0 auto 30px;
    padding: 30px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.cell {
    aspect-ratio: 1;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.3) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.cell:hover::before {
    width: 200%;
    height: 200%;
}

.cell:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.cell.x {
    color: #ef4444;
    animation: cellPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.o {
    color: #3b82f6;
    animation: cellPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes cellPop {
    0% {
        transform: scale(0) rotate(0deg);
    }

    50% {
        transform: scale(1.2) rotate(180deg);
    }

    100% {
        transform: scale(1) rotate(360deg);
    }
}

.cell.winning {
    animation: winningCell 0.6s ease-in-out infinite;
}

@keyframes winningCell {

    0%,
    100% {
        background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
        transform: scale(1);
    }

    50% {
        background: linear-gradient(135deg, #ffed4e 0%, #ffd700 100%);
        transform: scale(1.1);
    }
}

/* Game Controls */
.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-control {
    background: rgba(255, 255, 255, 0.95);
    color: #3b82f6;
    border: 3px solid #3b82f6;
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-control:hover {
    background: #3b82f6;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(59, 130, 246, 0.4);
}

/* Victory Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 30px;
    padding: 60px 40px;
    text-align: center;
    max-width: 500px;
    position: relative;
    animation: modalPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

@keyframes modalPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.trophy {
    font-size: 8rem;
    animation: trophyBounce 1s ease-in-out infinite;
}

@keyframes trophyBounce {

    0%,
    100% {
        transform: translateY(0) rotate(-10deg);
    }

    50% {
        transform: translateY(-20px) rotate(10deg);
    }
}

.victory-title {
    font-size: 3rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 20px 0;
}

.victory-message {
    font-size: 1.5rem;
    color: #666;
    margin-bottom: 30px;
}

.btn-next {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #a855f7 100%);
    color: white;
    border: none;
    padding: 15px 50px;
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4);
}

.btn-next:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.6);
}

/* Confetti */
.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f0f;
    top: -10px;
    animation: confettiFall 3s linear;
}

@keyframes confettiFall {
    to {
        transform: translateY(600px) rotate(360deg);
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        padding: 10px 0;
    }

    .container {
        padding: 10px;
        max-width: 100%;
    }

    .setup-card {
        padding: 30px 20px;
        border-radius: 20px;
        margin: 10px;
    }

    .game-title {
        font-size: 2.2rem;
        margin-bottom: 10px;
    }

    .subtitle {
        font-size: 1rem;
        margin-bottom: 30px;
    }

    .player-inputs {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 30px;
    }

    .input-group {
        min-width: auto;
        width: 100%;
    }

    .input-group label {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }

    .input-group input {
        padding: 12px 15px;
        font-size: 1rem;
    }

    .player-icon {
        font-size: 2.5rem;
        margin-top: 12px;
    }

    .vs-divider {
        transform: rotate(90deg);
        font-size: 1.5rem;
        margin: 8px 0;
    }

    .btn-start {
        padding: 15px 40px;
        font-size: 1.2rem;
        width: 100%;
        max-width: 350px;
    }

    .game-header {
        margin-bottom: 20px;
    }

    .scoreboard {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 15px;
        padding: 20px 15px;
        border-radius: 15px;
        justify-content: space-around;
    }

    .player-score {
        gap: 12px;
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    .score-icon {
        font-size: 2.5rem;
    }

    .player-name {
        font-size: 1rem;
    }

    .score {
        font-size: 2rem;
    }

    .current-turn {
        padding: 10px;
        width: 100%;
        order: -1;
    }

    .turn-text {
        font-size: 0.9rem;
    }

    .turn-player {
        font-size: 2rem;
    }

    .game-board {
        padding: 20px;
        gap: 10px;
        max-width: 100%;
        border-radius: 15px;
        margin-bottom: 20px;
    }

    .cell {
        font-size: 2.8rem;
        border-radius: 12px;
    }

    .game-controls {
        flex-direction: row;
        gap: 10px;
        padding: 0 15px;
    }

    .btn-control {
        flex: 1;
        padding: 14px 20px;
        font-size: 1rem;
    }

    .modal-content {
        padding: 40px 25px;
        margin: 0 20px;
        border-radius: 25px;
        max-width: 90%;
    }

    .trophy {
        font-size: 5rem;
    }

    .victory-title {
        font-size: 2rem;
        margin: 20px 0;
    }

    .victory-message {
        font-size: 1.2rem;
        margin-bottom: 25px;
    }

    .btn-next {
        padding: 15px 40px;
        font-size: 1.1rem;
        width: 100%;
        max-width: 300px;
    }

    .game-footer {
        font-size: 0.8rem;
        bottom: 10px;
        left: 10px;
    }

    /* تحسينات للخلفية المتحركة */
    .background-animation::before {
        font-size: 3rem;
        word-spacing: 2rem;
    }

    .background-animation::after {
        font-size: 2.5rem;
        word-spacing: 1.5rem;
    }
}

/* Portrait orientation optimization */
@media (max-width: 768px) and (orientation: portrait) {
    .container {
        padding: 5px 10px;
    }

    .scoreboard {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .player-score {
        width: 100%;
        justify-content: space-between;
    }

    .current-turn {
        order: 0;
        padding: 15px 10px;
        border-top: 2px solid rgba(59, 130, 246, 0.2);
        border-bottom: 2px solid rgba(59, 130, 246, 0.2);
    }

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

    .cell {
        font-size: 2.5rem;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    .game-title {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .setup-card {
        padding: 25px 15px;
    }

    .btn-start {
        font-size: 1.1rem;
        padding: 12px 35px;
    }

    .scoreboard {
        padding: 12px;
    }

    .score-icon {
        font-size: 2rem;
    }

    .player-name {
        font-size: 0.9rem;
    }

    .score {
        font-size: 1.8rem;
    }

    .turn-player {
        font-size: 1.8rem;
    }

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

    .cell {
        font-size: 2rem;
    }

    .btn-control {
        font-size: 0.95rem;
        padding: 12px 15px;
    }

    .trophy {
        font-size: 4rem;
    }

    .victory-title {
        font-size: 1.6rem;
    }

    .victory-message {
        font-size: 1.1rem;
    }

    .game-footer {
        font-size: 0.75rem;
    }
}

/* Very small screens - landscape */
@media (max-height: 600px) and (orientation: landscape) {
    .container {
        padding: 5px;
    }

    .game-header {
        margin-bottom: 10px;
    }

    .scoreboard {
        padding: 10px;
        gap: 10px;
    }

    .score-icon {
        font-size: 1.5rem;
    }

    .score {
        font-size: 1.5rem;
    }

    .player-name {
        font-size: 0.8rem;
    }

    .turn-player {
        font-size: 1.5rem;
    }

    .game-board {
        padding: 10px;
        gap: 5px;
        margin-bottom: 10px;
    }

    .cell {
        font-size: 1.8rem;
    }

    .btn-control {
        padding: 8px 15px;
        font-size: 0.9rem;
    }

    .trophy {
        font-size: 3rem;
    }

    .victory-title {
        font-size: 1.5rem;
        margin: 10px 0;
    }

    .victory-message {
        font-size: 1rem;
        margin-bottom: 15px;
    }

    .btn-next {
        padding: 10px 30px;
        font-size: 1rem;
    }
}

/* Footer */
.game-footer {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: auto;
    text-align: left;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    font-weight: 600;
    z-index: 100;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}