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

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

body {
    overflow: hidden;
    background: #0a0e27;
    font-family: 'Outfit', sans-serif;
    color: #e0e0e0;
    -webkit-font-smoothing: antialiased;
}

#game-canvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

.hidden {
    display: none !important;
}

/* ========== LOBBY ========== */

#lobby {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 39, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

#lobby-box {
    text-align: center;
    padding: 50px 44px;
    background: rgba(20, 25, 60, 0.6);
    border: 1px solid rgba(102, 217, 239, 0.15);
    border-radius: 24px;
    min-width: 340px;
    max-width: 420px;
}

#lobby-title {
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 4px;
    color: #e0e0e0;
}

#lobby-title .accent {
    color: #66d9ef;
    text-shadow: 0 0 20px rgba(102, 217, 239, 0.5);
}

#lobby-subtitle {
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: rgba(102, 217, 239, 0.5);
    margin-bottom: 36px;
}

/* Lobby buttons */

.lobby-btn {
    display: block;
    width: 100%;
    padding: 14px 24px;
    margin-bottom: 12px;
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #e0e0e0;
    background: rgba(102, 217, 239, 0.08);
    border: 1px solid rgba(102, 217, 239, 0.25);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.lobby-btn:hover {
    background: rgba(102, 217, 239, 0.18);
    border-color: rgba(102, 217, 239, 0.5);
    box-shadow: 0 0 20px rgba(102, 217, 239, 0.15);
    transform: translateY(-2px);
}

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

.lobby-btn.primary {
    background: rgba(230, 57, 70, 0.2);
    border-color: rgba(230, 57, 70, 0.4);
}

.lobby-btn.primary:hover {
    background: rgba(230, 57, 70, 0.35);
    border-color: rgba(230, 57, 70, 0.7);
    box-shadow: 0 0 20px rgba(230, 57, 70, 0.2);
}

.lobby-btn.small {
    display: inline-block;
    width: auto;
    padding: 12px 24px;
    font-size: 14px;
}

.lobby-btn.ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.15);
    font-weight: 400;
}

.lobby-btn.ghost:hover {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: none;
}

/* Join row */

#join-row {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

#join-input {
    flex: 1;
    padding: 12px 16px;
    font-family: 'Outfit', sans-serif;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 8px;
    text-align: center;
    color: #e0e0e0;
    background: rgba(10, 14, 39, 0.8);
    border: 1px solid rgba(102, 217, 239, 0.25);
    border-radius: 14px;
    outline: none;
    transition: border-color 0.3s;
}

#join-input::placeholder {
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.2);
}

#join-input:focus {
    border-color: rgba(102, 217, 239, 0.6);
}

/* Waiting room */

.waiting-label {
    font-size: 13px;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 16px;
}

#room-code-display {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: transform 0.2s;
}

#room-code-display:hover {
    transform: scale(1.05);
}

#room-code-display.copied {
    animation: copyFlash 0.5s ease;
}

@keyframes copyFlash {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.code-digit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 68px;
    font-size: 32px;
    font-weight: 700;
    color: #66d9ef;
    text-shadow: 0 0 15px rgba(102, 217, 239, 0.5);
    background: rgba(102, 217, 239, 0.08);
    border: 1px solid rgba(102, 217, 239, 0.3);
    border-radius: 12px;
}

.waiting-hint {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 24px;
}

#waiting-spinner {
    width: 32px;
    height: 32px;
    margin: 0 auto 12px;
    border: 3px solid rgba(102, 217, 239, 0.15);
    border-top-color: #66d9ef;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.waiting-status {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 20px;
}

/* Lobby error */

#lobby-error {
    margin-top: 12px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #e63946;
    background: rgba(230, 57, 70, 0.1);
    border: 1px solid rgba(230, 57, 70, 0.3);
    border-radius: 10px;
    animation: fadeIn 0.3s ease;
}

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

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

/* ========== HUD ========== */

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding: 20px;
}

#turn-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    background: rgba(10, 14, 39, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(102, 217, 239, 0.2);
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    transition: all 0.4s ease;
}

#turn-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e63946;
    box-shadow: 0 0 12px #e63946;
    transition: all 0.4s ease;
}

/* ========== Message overlay ========== */

#message-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    pointer-events: none;
    z-index: 20;
    text-align: center;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#message-overlay.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

#message-text {
    font-size: 42px;
    font-weight: 700;
    color: #66d9ef;
    text-shadow: 0 0 30px rgba(102, 217, 239, 0.5);
    margin-bottom: 24px;
    letter-spacing: 1px;
}

#restart-btn,
#menu-btn {
    padding: 14px 40px;
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #e0e0e0;
    background: rgba(10, 14, 39, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(102, 217, 239, 0.4);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 6px;
}

#restart-btn:hover,
#menu-btn:hover {
    background: rgba(102, 217, 239, 0.15);
    border-color: rgba(102, 217, 239, 0.8);
    box-shadow: 0 0 20px rgba(102, 217, 239, 0.3);
    transform: translateY(-2px);
}

#restart-btn:active,
#menu-btn:active {
    transform: translateY(0);
}

#restart-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#menu-btn {
    font-size: 13px;
    padding: 10px 24px;
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
}

/* ========== Title / Branding ========== */

#title {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    font-size: 13px;
    font-weight: 300;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(102, 217, 239, 0.35);
    pointer-events: none;
}

/* ========== Controls hint ========== */

#controls-hint {
    position: fixed;
    bottom: 20px;
    right: 24px;
    z-index: 10;
    font-size: 11px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.25);
    pointer-events: none;
    text-align: right;
    line-height: 1.7;
}

/* ========== Responsive ========== */

@media (max-width: 768px) {
    #message-text {
        font-size: 28px;
    }

    #turn-indicator {
        font-size: 13px;
        padding: 8px 18px;
    }

    #controls-hint {
        display: none;
    }

    #lobby-box {
        padding: 36px 24px;
        min-width: 0;
        margin: 16px;
    }

    #lobby-title {
        font-size: 36px;
    }

    .code-digit {
        width: 46px;
        height: 56px;
        font-size: 26px;
    }

    #chat-panel {
        width: 260px;
        bottom: 60px;
        right: 12px;
        max-height: 320px;
    }

    #chat-toggle {
        bottom: 14px;
        right: 12px;
        width: 42px;
        height: 42px;
        font-size: 18px;
    }
}

/* ========== CHAT PANEL ========== */

#chat-panel {
    position: fixed;
    bottom: 70px;
    right: 20px;
    width: 300px;
    max-height: 400px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    background: rgba(10, 14, 39, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(102, 217, 239, 0.2);
    border-radius: 16px;
    overflow: hidden;
    animation: chatSlideIn 0.3s ease;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.95);
    }

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

#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(102, 217, 239, 0.06);
    border-bottom: 1px solid rgba(102, 217, 239, 0.12);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.7);
}

#chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.2s;
}

#chat-close:hover {
    color: #e63946;
    background: rgba(230, 57, 70, 0.1);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    min-height: 120px;
    max-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(102, 217, 239, 0.2);
    border-radius: 4px;
}

.chat-msg {
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 85%;
    word-wrap: break-word;
    animation: msgFade 0.2s ease;
}

@keyframes msgFade {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

.chat-msg.mine {
    align-self: flex-end;
    background: rgba(230, 57, 70, 0.15);
    border: 1px solid rgba(230, 57, 70, 0.25);
    color: #f0c0c0;
}

.chat-msg.theirs {
    align-self: flex-start;
    background: rgba(102, 217, 239, 0.1);
    border: 1px solid rgba(102, 217, 239, 0.18);
    color: #c0dde8;
}

.chat-msg.system {
    align-self: center;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.3);
    font-size: 11px;
    font-style: italic;
}

#chat-input-row {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid rgba(102, 217, 239, 0.1);
    background: rgba(10, 14, 39, 0.5);
}

#chat-input {
    flex: 1;
    padding: 8px 12px;
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    color: #e0e0e0;
    background: rgba(20, 25, 60, 0.6);
    border: 1px solid rgba(102, 217, 239, 0.15);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.3s;
}

#chat-input:focus {
    border-color: rgba(102, 217, 239, 0.5);
}

#chat-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

#chat-send {
    padding: 8px 12px;
    font-size: 16px;
    background: rgba(102, 217, 239, 0.12);
    border: 1px solid rgba(102, 217, 239, 0.25);
    border-radius: 10px;
    color: #66d9ef;
    cursor: pointer;
    transition: all 0.2s;
}

#chat-send:hover {
    background: rgba(102, 217, 239, 0.25);
    border-color: rgba(102, 217, 239, 0.5);
}

/* Chat toggle button */

#chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 30;
    width: 48px;
    height: 48px;
    font-size: 22px;
    line-height: 48px;
    text-align: center;
    background: rgba(10, 14, 39, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(102, 217, 239, 0.25);
    border-radius: 50%;
    color: #66d9ef;
    cursor: pointer;
    transition: all 0.3s;
    padding: 0;
}

#chat-toggle:hover {
    background: rgba(102, 217, 239, 0.15);
    border-color: rgba(102, 217, 239, 0.6);
    box-shadow: 0 0 16px rgba(102, 217, 239, 0.2);
    transform: scale(1.08);
}

#chat-toggle.has-unread {
    border-color: #e63946;
    box-shadow: 0 0 12px rgba(230, 57, 70, 0.4);
    animation: unreadPulse 1.5s ease infinite;
}

@keyframes unreadPulse {

    0%,
    100% {
        box-shadow: 0 0 12px rgba(230, 57, 70, 0.4);
    }

    50% {
        box-shadow: 0 0 20px rgba(230, 57, 70, 0.7);
    }
}