/* ===== Design Tokens ===== */
:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(18, 18, 42, 0.85);
    --neon-green: #00ff88;
    --neon-pink: #ff2d75;
    --neon-blue: #00d4ff;
    --neon-purple: #b44dff;
    --neon-yellow: #ffe600;
    --x-color: #00d4ff;
    --o-color: #ff2d75;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #50506a;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --glow-x: 0 0 10px rgba(0, 212, 255, 0.5), 0 0 30px rgba(0, 212, 255, 0.2);
    --glow-o: 0 0 10px rgba(255, 45, 117, 0.5), 0 0 30px rgba(255, 45, 117, 0.2);
    --border-radius: 12px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 30% 40%, rgba(0, 212, 255, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 60%, rgba(255, 45, 117, 0.06) 0%, transparent 50%);
    z-index: 0;
    animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

/* ===== App Layout ===== */
#app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    max-width: 500px;
    width: 100%;
}

/* ===== Top Bar ===== */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
}

#back-link {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: var(--neon-purple);
    text-decoration: none;
    letter-spacing: 0.1em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.3s;
}

#back-link span {
    font-size: 1rem;
}

#back-link:hover {
    color: var(--neon-green);
}

#mute-btn {
    background: none;
    border: 1px solid rgba(0, 255, 136, 0.2);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 1rem;
    cursor: pointer;
    color: var(--neon-green);
    font-family: 'Orbitron', sans-serif;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
}

.mute-label {
    font-size: 0.55rem;
    letter-spacing: 0.1em;
}

/* ===== Header ===== */
#header {
    text-align: center;
}

#title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: clamp(1.6rem, 5vw, 2.6rem);
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, var(--x-color), var(--o-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 18px rgba(0, 212, 255, 0.25));
}

#subtitle {
    font-family: 'Orbitron', sans-serif;
    font-weight: 400;
    font-size: 0.65rem;
    letter-spacing: 0.5em;
    color: var(--neon-purple);
    margin-top: 2px;
}

/* ===== Mode Selector ===== */
#mode-selector {
    display: flex;
    gap: 8px;
}

.mode-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 8px 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.mode-btn:hover {
    border-color: rgba(0, 255, 136, 0.2);
    color: var(--text-primary);
}

.mode-btn.active {
    border-color: rgba(0, 255, 136, 0.4);
    background: rgba(0, 255, 136, 0.08);
    color: var(--neon-green);
    box-shadow: 0 0 12px rgba(0, 255, 136, 0.12);
}

.mode-icon {
    font-size: 0.9rem;
}

/* ===== Variant Toggle ===== */
#variant-toggle {
    display: flex;
    gap: 6px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 30px;
    padding: 3px;
}

.variant-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.55rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 6px 16px;
    border: none;
    border-radius: 26px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.variant-btn:hover {
    color: var(--text-secondary);
}

.variant-btn.active {
    background: rgba(255, 230, 0, 0.1);
    color: var(--neon-yellow);
    box-shadow: 0 0 10px rgba(255, 230, 0, 0.08);
}

/* ===== Vanishing / Fading Cells (Infinite mode) ===== */
.cell.fading {
    opacity: 0.35;
    border-style: dashed;
    border-color: rgba(255, 255, 255, 0.08);
}

.cell.vanish {
    animation: cellVanish 0.35s ease forwards;
}

@keyframes cellVanish {
    0% {
        transform: scale(1);
        opacity: 0.35;
    }

    50% {
        transform: scale(1.15);
        opacity: 0.5;
    }

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

/* ===== Scoreboard ===== */
#scoreboard {
    display: flex;
    gap: 24px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius);
    padding: 10px 28px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 50px;
}

.score-mark {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 1rem;
}

.x-color {
    color: var(--x-color);
    text-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

.o-color {
    color: var(--o-color);
    text-shadow: 0 0 8px rgba(255, 45, 117, 0.5);
}

.draw-color {
    color: var(--text-secondary);
}

.score-val {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-primary);
}

/* ===== Status ===== */
#status {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    min-height: 1.3em;
}

#status.x-turn {
    color: var(--x-color);
}

#status.o-turn {
    color: var(--o-color);
}

#status.win-state {
    color: var(--neon-yellow);
    text-shadow: 0 0 8px rgba(255, 230, 0, 0.4);
}

#status.draw-state {
    color: var(--text-secondary);
}

/* ===== Board ===== */
#board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: min(340px, 85vw);
    height: min(340px, 85vw);
    position: relative;
}

.cell {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: clamp(2.2rem, 8vw, 3.5rem);
    transition: var(--transition);
    user-select: none;
    position: relative;
    aspect-ratio: 1;
}

.cell:hover:not(.taken) {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(0, 255, 136, 0.2);
    transform: scale(1.03);
}

.cell.taken {
    cursor: default;
}

.cell.x {
    color: var(--x-color);
    text-shadow: var(--glow-x);
    animation: markPop 0.25s ease;
}

.cell.o {
    color: var(--o-color);
    text-shadow: var(--glow-o);
    animation: markPop 0.25s ease;
}

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

    60% {
        transform: scale(1.15);
    }

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

.cell.win-cell {
    animation: winPulse 0.8s ease-in-out infinite alternate;
    border-color: rgba(255, 230, 0, 0.4);
}

@keyframes winPulse {
    0% {
        box-shadow: 0 0 8px rgba(255, 230, 0, 0.15);
    }

    100% {
        box-shadow: 0 0 22px rgba(255, 230, 0, 0.35);
    }
}

/* Win line SVG */
#win-line {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

#win-line-el {
    stroke: var(--neon-yellow);
    stroke-width: 4;
    stroke-linecap: round;
    filter: drop-shadow(0 0 8px rgba(255, 230, 0, 0.6));
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    opacity: 0;
}

#win-line-el.animate {
    opacity: 1;
    animation: drawLine 0.5s ease forwards;
}

@keyframes drawLine {
    to {
        stroke-dashoffset: 0;
    }
}

/* ===== Buttons ===== */
.neon-btn {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    padding: 12px 32px;
    border: 2px solid var(--neon-green);
    border-radius: 50px;
    background: transparent;
    color: var(--neon-green);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.2);
    text-transform: uppercase;
}

.neon-btn:hover {
    background: var(--neon-green);
    color: var(--bg-primary);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
    transform: translateY(-2px);
}

.ghost-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    padding: 6px 16px;
    border: none;
    border-radius: 20px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s;
}

.ghost-btn:hover {
    color: var(--neon-pink);
}

/* ===== Footer ===== */
#footer {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ===== Hidden ===== */
.hidden {
    display: none !important;
}

/* ===== Online Panel ===== */
#online-panel {
    width: 100%;
    max-width: 340px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(180, 77, 255, 0.2);
    border-radius: var(--border-radius);
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

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

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

#online-lobby {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.online-action-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 10px 24px;
    border: 1px solid rgba(180, 77, 255, 0.3);
    border-radius: 30px;
    background: rgba(180, 77, 255, 0.08);
    color: var(--neon-purple);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

.online-action-btn:hover {
    background: rgba(180, 77, 255, 0.18);
    border-color: rgba(180, 77, 255, 0.5);
    box-shadow: 0 0 14px rgba(180, 77, 255, 0.15);
    transform: translateY(-1px);
}

.join-btn {
    width: auto;
    padding: 10px 20px;
    flex-shrink: 0;
}

.online-divider {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.55rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
}

#join-section {
    display: flex;
    gap: 8px;
    width: 100%;
}

#room-code-input {
    flex: 1;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-align: center;
    text-transform: uppercase;
    padding: 10px 14px;
    border: 1px solid rgba(180, 77, 255, 0.2);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--neon-purple);
    outline: none;
    transition: border-color 0.3s;
}

#room-code-input::placeholder {
    color: var(--text-muted);
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    text-transform: none;
}

#room-code-input:focus {
    border-color: rgba(180, 77, 255, 0.5);
    box-shadow: 0 0 10px rgba(180, 77, 255, 0.1);
}

/* Waiting state */
#online-waiting {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

#waiting-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
}

.waiting-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(180, 77, 255, 0.15);
    border-top-color: var(--neon-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#room-code-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid rgba(180, 77, 255, 0.2);
}

.room-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.5rem;
    letter-spacing: 0.15em;
    color: var(--text-muted);
}

.room-code {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: 0.25em;
    color: var(--neon-purple);
    text-shadow: 0 0 10px rgba(180, 77, 255, 0.4);
}

.copy-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 2px;
    transition: transform 0.2s;
}

.copy-btn:hover {
    transform: scale(1.2);
}

#share-hint {
    font-size: 0.65rem;
    color: var(--neon-green);
    letter-spacing: 0.06em;
}

/* Connected state */
#online-connected {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.connected-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--neon-green);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 136, 0.3);
    background: rgba(0, 255, 136, 0.06);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--neon-green);
    animation: pulseDot 1.5s ease-in-out infinite;
}

@keyframes pulseDot {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 4px rgba(0, 255, 136, 0.5);
    }

    50% {
        opacity: 0.5;
        box-shadow: 0 0 10px rgba(0, 255, 136, 0.8);
    }
}

#your-mark-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Danger button */
.ghost-btn.danger {
    color: var(--neon-pink);
}

.ghost-btn.danger:hover {
    color: #ff5c99;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
    body {
        overflow-y: auto;
        align-items: flex-start;
    }

    #board {
        width: min(290px, 80vw);
        height: min(290px, 80vw);
    }

    #scoreboard {
        padding: 8px 18px;
        gap: 16px;
    }

    #mode-selector {
        flex-wrap: wrap;
        justify-content: center;
    }

    #app {
        padding: 12px;
        gap: 10px;
    }
}