:root {
    --bg-dark: #0f172a;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-x: #0ea5e9;
    --accent-o: #f43f5e;
    --glow-x: 0 0 20px rgba(14, 165, 233, 0.6);
    --glow-o: 0 0 20px rgba(244, 63, 94, 0.6);
    --font-main: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    padding: 1rem;
}

/* Background Animations */
.background-orbs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 10s infinite ease-in-out;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: var(--accent-x);
    top: -50px;
    left: -50px;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: var(--accent-o);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {

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

    50% {
        transform: translate(30px, 50px);
    }
}

/* App Wrapper - Responsive Flex Layout */
.app-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 800px;
    z-index: 10;
}

/* Desktop: Side by side */
@media (min-width: 768px) {
    .app-wrapper {
        flex-direction: row;
        align-items: flex-start;
    }
}

/* Game Container - Glassmorphism */
.game-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
    text-align: center;
    flex-shrink: 0;
}

.game-header {
    margin-bottom: 1.5rem;
}

h1 {
    font-weight: 600;
    font-size: 2rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.05em;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status {
    font-size: 1rem;
    color: var(--text-secondary);
}

.current-player-name {
    font-weight: 600;
    color: var(--text-primary);
}

/* Game Mode Selection */
.game-mode-section {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mode-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.mode-btn.active {
    background: linear-gradient(135deg, var(--accent-x), #3b82f6);
    border-color: transparent;
    color: white;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.4);
}

/* Player Name Inputs */
.player-names-section {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.name-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.name-input-group label {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-secondary);
}

.name-input-group input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-main);
    font-size: 0.875rem;
    color: var(--text-primary);
    width: 90px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.name-input-group input:focus {
    outline: none;
    border-color: var(--accent-x);
    box-shadow: 0 0 8px rgba(14, 165, 233, 0.3);
}

.name-input-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.name-input-group input:disabled {
    background: rgba(0, 0, 0, 0.15);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 1.5rem;
}

.cell {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    aspect-ratio: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.cell:hover:not(.taken) {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(1.02);
}

.cell.x {
    color: var(--accent-x);
    text-shadow: var(--glow-x);
}

.cell.o {
    color: var(--accent-o);
    text-shadow: var(--glow-o);
}

.cell.winner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Footer & Scores */
.game-footer {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.score-board {
    display: flex;
    justify-content: space-around;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.score-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.player-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-value {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-restart {
    background: linear-gradient(135deg, var(--accent-x), #3b82f6);
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    color: white;
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.btn-restart:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(14, 165, 233, 0.5);
}

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

/* Session History Sidebar */
.history-sidebar {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    width: 100%;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .history-sidebar {
        width: 220px;
        max-height: 400px;
        flex-shrink: 0;
    }
}

.history-sidebar h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.history-list {
    list-style: none;
    font-size: 0.8rem;
    overflow-y: auto;
    flex: 1;
    padding-right: 0.5rem;
}

/* Custom Scrollbar */
.history-list::-webkit-scrollbar {
    width: 5px;
}

.history-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.history-list li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--glass-border);
    color: var(--text-secondary);
}

.history-list li:last-child {
    border-bottom: none;
}

.history-list li span.winner-x {
    color: var(--accent-x);
    font-weight: 600;
}

.history-list li span.winner-o {
    color: var(--accent-o);
    font-weight: 600;
}

.history-list li span.draw {
    color: var(--text-secondary);
    font-style: italic;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-dark);
    padding: 2.5rem;
    border-radius: 24px;
    text-align: center;
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal.visible .modal-content {
    transform: scale(1);
}

.modal h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.hidden {
    display: none;
}

/* Tutorial Modal */
.tutorial-content {
    max-width: 380px;
}

.tutorial-title {
    background: linear-gradient(to right, var(--accent-x), var(--accent-o));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0;
    animation: fadeSlideIn 0.6s ease-out forwards;
}

/* Mini Board Demo */
.tutorial-demo {
    margin-bottom: 1.5rem;
    opacity: 0;
    animation: fadeSlideIn 0.6s ease-out 0.3s forwards;
}

.mini-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 120px;
    margin: 0 auto;
}

.mini-cell {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 600;
    border: 1px solid var(--glass-border);
}

.mini-cell.x {
    color: var(--accent-x);
    text-shadow: var(--glow-x);
}

.mini-cell.o {
    color: var(--accent-o);
    text-shadow: var(--glow-o);
}

.mini-cell.winner-line {
    background: rgba(14, 165, 233, 0.2);
    border-color: var(--accent-x);
}

/* Tutorial Rules Animation */
.tutorial-rules {
    list-style: none;
    text-align: left;
    margin-bottom: 1.5rem;
    padding: 0;
}

.rule-item {
    position: relative;
    padding: 0.5rem 0 0.5rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--glass-border);
    opacity: 0;
    transform: translateX(-20px);
    animation: slideInRule 0.5s ease-out forwards;
}

.rule-item:nth-child(1) {
    animation-delay: 0.5s;
}

.rule-item:nth-child(2) {
    animation-delay: 0.7s;
}

.rule-item:nth-child(3) {
    animation-delay: 0.9s;
}

.rule-item:nth-child(4) {
    animation-delay: 1.1s;
}

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

.rule-item::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--accent-x);
}

.rule-item strong {
    color: var(--text-primary);
}

.tutorial-content .btn-restart {
    opacity: 0;
    animation: fadeSlideIn 0.6s ease-out 1.3s forwards;
}

/* Keyframes */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

@keyframes slideInRule {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

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

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0);
    }

    70% {
        transform: scale(1.2);
    }

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