:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --x-color: #ef4444;
    --o-color: #0ea5e9;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    user-select: none;
    padding-bottom: 50px;
}

/* Background effects */
.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.6;
    animation: float 10s ease-in-out infinite alternate;
}

.orb-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, rgba(59,130,246,0.3) 0%, rgba(15,23,42,0) 70%);
}

.orb-2 {
    bottom: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(239,68,68,0.2) 0%, rgba(15,23,42,0) 70%);
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 5%) scale(1.1); }
}

#app {
    width: 100%;
    max-width: 500px;
    padding: 1rem;
    z-index: 10;
}

/* Views */
.view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, transform 0.4s ease;
    width: 100%;
}

.view.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transform: scale(0.95);
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
    transform: scale(1);
}

/* Typography */
.title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    text-align: center;
    line-height: 1.1;
}

.subtitle {
    font-size: 1.2rem;
    font-weight: 300;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    text-align: center;
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1rem;
    color: var(--text-primary);
    font-family: inherit;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

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

.btn.primary:hover {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.2);
}

.btn.secondary:hover {
    border-color: var(--x-color);
    background: rgba(239, 68, 68, 0.2);
}

.btn-text {
    font-size: 1.3rem;
    font-weight: 600;
}

.btn-subtext {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    transition: color 0.2s;
}
.btn-icon:hover { color: var(--text-primary); }

/* Game View */
.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.mode-badge {
    background: rgba(255,255,255,0.1);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Scorecard */
.score-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.player-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 800;
    background: rgba(255,255,255,0.05);
}

.x-player .avatar { color: var(--x-color); box-shadow: 0 0 15px rgba(239, 68, 68, 0.2); }
.o-player .avatar { color: var(--o-color); box-shadow: 0 0 15px rgba(14, 165, 233, 0.2); }

.status-center {
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Board */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2vmin;
    width: 100%;
    max-width: 60vh; 
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    background: var(--border-color);
    padding: 2vmin;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    box-sizing: border-box;
}

.cell {
    background: #1e293b;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: min(10vmin, 4rem);
    font-weight: 800;
    transition: background 0.2s, transform 0.2s;
    user-select: none;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.cell:hover {
    background: #334155;
    transform: scale(0.98);
}

.cell.x { color: var(--x-color); text-shadow: 0 0 20px rgba(239, 68, 68, 0.4); }
.cell.o { color: var(--o-color); text-shadow: 0 0 20px rgba(14, 165, 233, 0.4); }
.cell.disabled { cursor: not-allowed; opacity: 0.9; }

/* Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: 24px;
    text-align: center;
    transform: translateY(20px);
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
    width: 90%;
    max-width: 400px;
    z-index: 1000;
}

.modal h2 { font-size: 2rem; margin-bottom: 0.5rem; }
.modal p { color: var(--text-secondary); margin-bottom: 1.5rem; }

@keyframes slideUp {
    to { transform: translateY(0); }
}

.mt-4 { margin-top: 1rem; }

.status-msg {
    margin-top: 2rem;
    color: var(--accent-primary);
    font-weight: 600;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.spinner-large {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 4px solid rgba(59, 130, 246, 0.3);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Animations for marking cells */
@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.cell.x::after { content: 'X'; animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.cell.o::after { content: 'O'; animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* Leaderboard */
.leaderboard-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    min-width: 250px;
    z-index: 50;
    transition: opacity 0.4s ease;
}

.leaderboard-panel.hidden {
    opacity: 0;
    pointer-events: none;
}

.leaderboard-panel h3 {
    margin-bottom: 1rem;
    text-align: center;
    color: var(--accent-primary);
}

.leaderboard-panel ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leaderboard-panel li {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 10px 0;
    background: linear-gradient(to top, rgba(15,23,42,1) 30%, transparent);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85rem;
    z-index: 100; /* stays above everything */
}

/* ======== MEDIA QUERIES ======== */

/* Mobile Portrait */
@media (max-width: 768px) {
    body {
        justify-content: flex-start;
        padding-top: 5vh;
        padding-bottom: 60px; /* Space for footer */
        gap: 2rem;
    }

    #app {
        padding: 0 1rem;
        margin-top: 0;
    }

    .title { font-size: 3rem; }
    .subtitle { margin-bottom: 2rem; font-size: 1rem; }
    .board { max-width: 100%; } /* Engedjük, hogy a mobil sávjában teljesen kiteljen */

    .leaderboard-panel {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 100%; 
        max-width: 400px;
        margin: 2rem auto 2rem auto;
    }
}

/* Landscape Mode (Mobile / Tablets) */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 10px 20px 40px 20px; /* Safe area for footer in landscape too */
    }

    #app {
        max-width: 900px;
        flex: 1;
        padding: 0;
    }

    /* CSS Grid varázslat HTML érintése nélkül a Főmenühöz */
    #view-menu.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 0 2rem;
        align-items: center;
    }

    #view-menu .title {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        align-self: end;
        font-size: 2.5rem;
        margin-bottom: 5px;
    }

    #view-menu .subtitle {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
        align-self: start;
        margin-bottom: 0;
    }

    #view-menu .menu-buttons {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
        gap: 0.8rem;
    }

    .btn { padding: 0.8rem; }
    .btn-text { font-size: 1rem; }

    /* CSS Grid varázslat a Játék nézethez */
    #view-game.active {
        display: grid;
        grid-template-columns: minmax(200px, 1fr) auto;
        grid-template-rows: auto 1fr;
        gap: 1rem 2rem;
        align-items: center;
        height: 100%;
    }

    .header {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        margin-bottom: 0;
    }

    .score-card {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
        margin-bottom: 0;
    }

    .board {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
        height: 80vh;
        max-height: 80vh;
        width: auto;
        aspect-ratio: 1 / 1;
        max-width: none;
    }

    .leaderboard-panel {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        margin-left: 1rem;
        flex-shrink: 0;
        z-index: 50;
    }
}
