@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap');

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

:root {
    --bg-dark:        #020e0d;
    --bg-card:        #091c1b;
    --bg-cell:        #0d2422;
    --border-color:   #174440;
    --accent-color:   #2dd4bf;
    --accent-dark:    #14b8a6;
    --glow:           rgba(45, 212, 191, 0.3);
    --x-color:        #2dd4bf;
    --o-color:        #fb923c;
    --text-primary:   #dff7f5;
    --text-secondary: #4d9994;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(ellipse 70% 55% at 10% 0%,   rgba(45, 212, 191, 0.07) 0%, transparent 100%),
        radial-gradient(ellipse 60% 50% at 90% 100%, rgba(20, 184, 166, 0.05) 0%, transparent 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-wrapper {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    width: 100%;
    padding: 1.5rem 2.5rem;
    gap: 1.25rem;
    box-sizing: border-box;
}

/* ── Top bar ─────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* ── Back link ───────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    transition: color 0.2s;
    white-space: nowrap;
}
.back-link:hover { color: var(--accent-color); }

/* ── Score board ─────────────────────────── */
.score-board {
    background: var(--bg-card);
    padding: 0.65rem 1.5rem;
    border-radius: 1.25rem;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.8rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.score-item { text-align: center; }
.score-val {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent-color);
    line-height: 1.1;
}

/* ── Main two-column layout ──────────────── */
.main-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2rem;
    align-items: start;
}

/* ── Left panel ──────────────────────────── */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 1.5rem;
}

.panel-title {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 0.25rem;
}

/* ── Status bar ──────────────────────────── */
#status {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(45, 212, 191, 0.05), 0 2px 12px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.01em;
}

/* ── Mode selector ───────────────────────── */
.mode-selector {
    display: flex;
    gap: 0.5rem;
}

/* ── Buttons ─────────────────────────────── */
.btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.65rem 1.25rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: 'Poppins', sans-serif;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: center;
}
.btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    box-shadow: 0 0 14px var(--glow);
    transform: translateY(-1px);
}
.btn.active {
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-dark) 100%);
    border-color: transparent;
    color: #020e0d;
    box-shadow: 0 0 18px var(--glow), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.actions {
    display: flex;
    gap: 0.75rem;
}

/* ── Divider ─────────────────────────────── */
.divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0.25rem 0;
}

/* ── Right panel: board ──────────────────── */
.board-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.grid-container {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 2rem;
    border: 1px solid var(--border-color);
    box-shadow:
        0 0 0 1px rgba(45, 212, 191, 0.04),
        0 24px 64px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(45, 212, 191, 0.07);
    width: 100%;
    max-width: min(calc(100vh - 10rem), 100%);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
    height: 100%;
}

.cell {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    background-color: var(--bg-cell);
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    background-size: 84%;
    background-repeat: no-repeat;
    background-position: center;
    transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 50% 10%, rgba(45, 212, 191, 0.09) 0%, transparent 65%);
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
}

.cell:hover {
    border-color: var(--accent-color);
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6), 0 0 18px var(--glow);
}

.cell:hover::before { opacity: 1; }

/* Themes */
.theme-mario-luigi .cell.x { background-image: url('../assets/mario.png'); color: transparent; }
.theme-mario-luigi .cell.o { background-image: url('../assets/luigi.png'); color: transparent; }

.theme-sonic-shadow .cell.x { background-image: url('../assets/sonic.png'); color: transparent; }
.theme-sonic-shadow .cell.o { background-image: url('../assets/shadow.png'); color: transparent; }

.cell.x, .cell.o {
    animation: pop 0.32s cubic-bezier(0.23, 1, 0.32, 1);
}

.winning-cell {
    animation: win-pulse 0.55s ease forwards;
    background-color: rgba(45, 212, 191, 0.07);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color), 0 0 30px var(--glow), 0 0 70px rgba(45, 212, 191, 0.1);
}

.difficulty-selector {
    display: none;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
    animation: slideDown 0.3s ease;
}

.difficulty-selector.active {
    display: flex;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
    0%   { transform: scale(0.3) rotate(-8deg); opacity: 0; }
    65%  { transform: scale(1.18) rotate(3deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); }
}

@keyframes win-pulse {
    0%, 100% { transform: scale(1); }
    45%      { transform: scale(1.08); }
}

/* Score character icons */
.score-char {
    width: 36px;
    height: 36px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    filter: drop-shadow(0 2px 8px rgba(45, 212, 191, 0.3));
}

#iconX { background-image: url('../assets/mario.png'); }
#iconO { background-image: url('../assets/luigi.png'); }

/* ── Responsive Design ───────────────────── */
@media (max-width: 850px) {
    .page-wrapper {
        padding: 1rem;
        gap: 1rem;
    }

    .top-bar {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        text-align: center;
    }

    .top-bar-left {
        flex-direction: column;
        gap: 0.5rem;
    }

    .panel-title {
        font-size: 1.8rem;
    }

    .score-board {
        width: 100%;
        justify-content: space-around;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .score-char {
        width: 28px;
        height: 28px;
    }

    .score-val {
        font-size: 1.2rem;
    }

    .main-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .left-panel {
        position: static;
        order: 2;
    }

    .board-panel {
        order: 1;
    }

    .grid-container {
        padding: 1rem;
        border-radius: 1.5rem;
        max-width: 100%;
    }

    .grid {
        gap: 0.5rem;
    }

    .cell {
        border-radius: 0.75rem;
    }
}

@media (max-width: 480px) {
    .panel-title {
        font-size: 1.5rem;
    }

    #status {
        padding: 0.75rem;
        font-size: 1rem;
    }

    .score-board {
        font-size: 0.7rem;
    }

    .actions {
        flex-direction: column;
    }

    .btn {
        padding: 0.5rem 1rem;
    }
}

