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

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f0f8;
    --text-secondary: #8888aa;
    --color-x: #6c63ff;
    --color-x-glow: rgba(108, 99, 255, 0.35);
    --color-o: #ff6b9d;
    --color-o-glow: rgba(255, 107, 157, 0.35);
    --color-draw: #ffd166;
    --color-draw-glow: rgba(255, 209, 102, 0.25);
    --accent-gradient: linear-gradient(135deg, #6c63ff, #ff6b9d);
    --cell-size: 110px;
    --gap: 10px;
    --radius: 16px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
}

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

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

/* ========== BACKGROUND GLOWS ========== */
.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
    animation: float 12s ease-in-out infinite alternate;
}

.bg-glow-1 {
    width: 400px;
    height: 400px;
    background: var(--color-x);
    top: -100px;
    left: -100px;
    opacity: 0.15;
}

.bg-glow-2 {
    width: 350px;
    height: 350px;
    background: var(--color-o);
    bottom: -80px;
    right: -80px;
    opacity: 0.12;
    animation-delay: -4s;
}

.bg-glow-3 {
    width: 250px;
    height: 250px;
    background: var(--color-draw);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.06;
    animation-delay: -8s;
}

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

    100% {
        transform: translate(30px, -20px) scale(1.15);
    }
}

/* ========== CONTAINER ========== */
.container {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 24px;
    max-width: 480px;
    width: 100%;
}

/* ========== HEADER ========== */
header {
    margin-bottom: 24px;
}

h1 {
    font-size: 2.4rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -1px;
    line-height: 1.1;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

/* ========== LOBBY ========== */
.lobby-card,
.waiting-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 32px 28px;
    backdrop-filter: blur(12px);
    margin-top: 20px;
}

.lobby-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.lobby-btn {
    width: 100%;
    max-width: 260px;
    justify-content: center;
}

.lobby-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 260px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.lobby-divider::before,
.lobby-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.join-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.room-input {
    width: 100%;
    max-width: 260px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 12px;
    text-transform: uppercase;
    outline: none;
    transition: var(--transition);
}

.room-input::placeholder {
    letter-spacing: 2px;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--text-secondary);
    opacity: 0.6;
}

.room-input:focus {
    border-color: rgba(108, 99, 255, 0.5);
    box-shadow: 0 0 20px var(--color-x-glow);
    background: rgba(255, 255, 255, 0.05);
}

.lobby-error {
    color: #ef476f;
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 16px;
    min-height: 20px;
}

/* ========== WAITING CARD ========== */
.waiting-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.room-code-display {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 16px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
    user-select: all;
    cursor: pointer;
    padding-left: 16px;
    /* compensate letter-spacing */
}

.waiting-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.dots-anim::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }

    100% {
        content: '';
    }
}

.btn-small {
    padding: 8px 20px;
    font-size: 0.85rem;
}

/* ========== GAME INFO BAR ========== */
.game-info-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}

.room-badge,
.player-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.room-badge {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.player-badge {
    color: #fff;
}

.player-x {
    background: rgba(108, 99, 255, 0.25);
    border: 1px solid rgba(108, 99, 255, 0.4);
    color: var(--color-x);
}

.player-o {
    background: rgba(255, 107, 157, 0.25);
    border: 1px solid rgba(255, 107, 157, 0.4);
    color: var(--color-o);
}

/* ========== SCOREBOARD ========== */
.scoreboard {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
}

.score-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 20px;
    min-width: 80px;
    backdrop-filter: blur(10px);
    transition: var(--transition);
}

.score-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
}

.score-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 4px;
}

.score-x .score-label {
    color: var(--color-x);
}

.score-o .score-label {
    color: var(--color-o);
}

.score-draw .score-label {
    color: var(--color-draw);
}

.score-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ========== TURN INDICATOR ========== */
.turn-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 40px;
    padding: 8px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 20px;
    transition: var(--transition);
    color: var(--text-secondary);
}

.turn-indicator.x-turn {
    border-color: rgba(108, 99, 255, 0.3);
    box-shadow: 0 0 20px var(--color-x-glow);
}

.turn-indicator.o-turn {
    border-color: rgba(255, 107, 157, 0.3);
    box-shadow: 0 0 20px var(--color-o-glow);
}

.turn-symbol-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-icon,
.turn-icon,
.cell-icon {
    width: 1.8rem;
    height: 1.8rem;
    object-fit: contain;
}

.turn-icon {
    width: 2rem;
    height: 2rem;
}

.cell-icon {
    width: 80%;
    height: 80%;
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ========== BOARD ========== */
.board-wrapper {
    position: relative;
    display: inline-block;
    margin-bottom: 16px;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, var(--cell-size));
    grid-template-rows: repeat(3, var(--cell-size));
    gap: var(--gap);
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    transition: opacity 0.3s ease;
}

.board.opponent-turn {
    opacity: 0.65;
    pointer-events: none;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.cell:hover:not(.taken) {
    background: rgba(255, 255, 255, 0.07);
    transform: scale(1.04);
    border-color: rgba(255, 255, 255, 0.15);
}

.cell:active:not(.taken) {
    transform: scale(0.97);
}

.cell.taken {
    cursor: default;
}

.cell.x {
    color: var(--color-x);
    text-shadow: 0 0 20px var(--color-x-glow);
    border-color: rgba(108, 99, 255, 0.2);
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell.o {
    color: var(--color-o);
    text-shadow: 0 0 20px var(--color-o-glow);
    border-color: rgba(255, 107, 157, 0.2);
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell.win-cell {
    animation: winPulse 0.8s ease-in-out infinite alternate;
}

.cell.x.win-cell {
    background: rgba(108, 99, 255, 0.12);
    box-shadow: 0 0 30px var(--color-x-glow);
}

.cell.o.win-cell {
    background: rgba(255, 107, 157, 0.12);
    box-shadow: 0 0 30px var(--color-o-glow);
}

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

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

@keyframes winPulse {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.06);
    }
}

/* ========== WIN LINE SVG ========== */
.win-line-svg {
    position: absolute;
    top: 14px;
    left: 14px;
    width: calc(100% - 28px);
    height: calc(100% - 28px);
    pointer-events: none;
    z-index: 10;
}

.win-line-svg line {
    stroke: var(--text-primary);
    stroke-width: 0.8;
    stroke-linecap: round;
    opacity: 0;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.5));
    stroke-dasharray: 150;
    stroke-dashoffset: 150;
    transition: none;
}

.win-line-svg line.visible {
    opacity: 0.7;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease;
}

/* ========== STATUS ========== */
.status {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-height: 24px;
    margin-bottom: 20px;
    transition: var(--transition);
}

/* ========== BUTTONS ========== */
.actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.3px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 20px rgba(108, 99, 255, 0.25);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(108, 99, 255, 0.35);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.btn-secondary:active:not(:disabled) {
    transform: translateY(0);
}

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px 48px;
    text-align: center;
    max-width: 380px;
    width: 90%;
    transform: scale(0.85) translateY(20px);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
    line-height: 1;
}

.modal-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.modal-message {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

.modal-btn {
    min-width: 160px;
    justify-content: center;
}

/* ========== CONFETTI PARTICLES ========== */
.confetti {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    z-index: 200;
    pointer-events: none;
    animation: confettiFall 1.2s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg) scale(0.3);
    }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 480px) {
    :root {
        --cell-size: 85px;
        --gap: 8px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .container {
        padding: 16px;
    }

    .scoreboard {
        gap: 8px;
    }

    .score-card {
        padding: 8px 14px;
        min-width: 65px;
    }

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

    .score-value {
        font-size: 1.3rem;
    }

    .cell {
        font-size: 2.2rem;
    }

    .board {
        padding: 10px;
    }

    .btn {
        padding: 10px 18px;
        font-size: 0.85rem;
    }

    .modal {
        padding: 30px 28px;
    }

    .lobby-card,
    .waiting-card {
        padding: 24px 20px;
    }

    .room-code-display {
        font-size: 2.2rem;
        letter-spacing: 10px;
        padding-left: 10px;
    }

    .room-input {
        font-size: 1.1rem;
        letter-spacing: 8px;
    }
}

@media (max-width: 360px) {
    :root {
        --cell-size: 75px;
    }
}

/* ========== AUDIO CONTROLS ========== */
.audio-controls {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    padding: 8px 16px;
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: var(--transition);
}

.audio-controls:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.volume-slider-wrapper {
    display: flex;
    align-items: center;
    width: 0;
    overflow: hidden;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    opacity: 0;
}

.audio-controls:hover .volume-slider-wrapper {
    width: 100px;
    opacity: 1;
}

#volume-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--color-x);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--color-x-glow);
    transition: var(--transition);
}

#volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.3);
    background: var(--text-primary);
}

@media (max-width: 480px) {
    .audio-controls {
        bottom: 16px;
        right: 16px;
        padding: 6px 12px;
    }

    .audio-controls:hover .volume-slider-wrapper {
        width: 80px;
    }
}

/* ========== FOOTER ========== */
.footer {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.6;
}

.footer a {
    pointer-events: auto;
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
}

.footer a:hover {
    opacity: 1;
    color: var(--color-x);
}

.heart {
    color: var(--color-o);
    display: inline-block;
    animation: heartBeat 1.5s ease-in-out infinite;
    margin: 0 2px;
}

@keyframes heartBeat {

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

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

@media (max-width: 480px) {
    .footer {
        bottom: 16px;
    }

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