/* ─── Reset & Fullscreen ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: #0a0a0f;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

/* ─── Canvas ─────────────────────────────────────────────────────────────── */
#game-canvas {
    position: fixed;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
    cursor: grab;
    touch-action: none;
}
#game-canvas:active { cursor: grabbing; }

/* ─── Loading Screen ─────────────────────────────────────────────────────── */
#loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 50%, #0a1a2a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.9s ease;
}
#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}
.loading-inner {
    text-align: center;
    width: 360px;
}
.loading-logo {
    font-size: 2.8rem;
    font-weight: 900;
    letter-spacing: 0.4em;
    color: #fff;
    text-transform: uppercase;
    text-shadow: 0 0 60px rgba(102, 126, 234, 0.9), 0 0 20px rgba(102, 126, 234, 0.5);
    margin-bottom: 0.5rem;
    animation: logo-pulse 2.5s ease-in-out infinite;
}
.loading-sub {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    margin-bottom: 2.5rem;
}
@keyframes logo-pulse {
    0%, 100% { text-shadow: 0 0 60px rgba(102,126,234,0.9), 0 0 20px rgba(102,126,234,0.5); }
    50%       { text-shadow: 0 0 80px rgba(118,75,162,0.9), 0 0 30px rgba(118,75,162,0.6); }
}
.loading-bar-wrap {
    width: 100%;
    height: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto 1.2rem;
}
.loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #667eea, #764ba2, #f093fb);
    border-radius: 2px;
    transition: width 0.4s ease;
    box-shadow: 0 0 8px rgba(102,126,234,0.8);
}
.loading-text {
    color: rgba(255,255,255,0.4);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
}

/* ─── HUD ────────────────────────────────────────────────────────────────── */
#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
}
#hud.hidden { display: none; }

.hud-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
    pointer-events: auto;
}
.hud-room-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0,0,0,0.6);
    letter-spacing: 0.04em;
}
.hud-online {
    font-size: 0.75rem;
    color: #4ade80;
    padding: 2px 10px;
    background: rgba(74,222,128,0.1);
    border: 1px solid rgba(74,222,128,0.25);
    border-radius: 20px;
}
.hud-exit-btn {
    margin-left: auto;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    padding: 4px 14px;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 7px;
    backdrop-filter: blur(6px);
    background: rgba(255,255,255,0.05);
    transition: all 0.2s;
}
.hud-exit-btn:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.45);
    background: rgba(255,255,255,0.12);
}
.hud-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 7px 18px;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 24px;
    transition: opacity 1s ease;
    pointer-events: none;
}
.hud-controls.fade-out { opacity: 0; }
.hud-controls span {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.45);
    display: flex;
    align-items: center;
    gap: 5px;
}
.hud-controls span::before {
    content: '';
    display: inline-block;
    width: 5px; height: 5px;
    background: rgba(102,126,234,0.6);
    border-radius: 50%;
}

/* ─── Floating Buttons ───────────────────────────────────────────────────── */
.fab {
    position: fixed;
    width: 48px; height: 48px;
    background: rgba(10,10,25,0.88);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 50%;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}
.fab:hover {
    background: rgba(102,126,234,0.25);
    border-color: rgba(102,126,234,0.5);
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(102,126,234,0.3);
}
.fab.hidden { display: none; }

#customiser-toggle { bottom: 80px; right: 20px; }
#chat-toggle       { bottom: 20px;  right: 20px; }

.fab .badge {
    position: absolute;
    top: -3px; right: -3px;
    width: 16px; height: 16px;
    background: #ef4444;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #0a0a0f;
}

/* ─── MMO Chat Panel — always visible, bottom-left ──────────────────────── */
#chat-panel {
    position: fixed;
    bottom: 0; left: 0;
    width: 320px;
    z-index: 200;
    background: rgba(6,6,18,0.80);
    backdrop-filter: blur(14px);
    border-top-right-radius: 10px;
    border-right: 1px solid rgba(255,255,255,0.06);
    border-top:   1px solid rgba(255,255,255,0.06);
    pointer-events: auto;
}

/* Channel tabs */
#chat-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px 0;
}
.chat-tab {
    padding: 4px 14px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    border: none;
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.38);
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.chat-tab:hover { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.65); }
.chat-tab.active                      { background: rgba(99,102,241,0.22); color: #a78bfa; }
.chat-tab[data-channel="trade"].active { background: rgba(52,211,153,0.18); color: #34d399; }
.chat-tab[data-channel="help"].active  { background: rgba(251,191,36,0.18); color: #fbbf24; }

#chat-messages {
    height: 170px;
    overflow-y: auto;
    padding: 8px 12px 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.10) transparent;
}
#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 2px; }

.chat-msg {
    font-size: 0.82rem;
    line-height: 1.45;
    animation: chat-in 0.18s ease;
}
@keyframes chat-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}
.msg-channel {
    font-size: 0.72rem;
    font-weight: 700;
    margin-right: 4px;
    opacity: 0.85;
}
.chat-msg .msg-name {
    font-weight: 700;
    color: #a78bfa;
}
.chat-msg .msg-text { color: rgba(255,255,255,0.82); }
.chat-msg.system-msg .msg-text {
    color: rgba(255,255,255,0.32);
    font-style: italic;
}
.chat-msg.self-msg .msg-name { color: #67e8f9; }

#chat-input-row {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
#chat-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 7px;
    color: #fff;
    padding: 7px 11px;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
#chat-input:focus {
    border-color: rgba(102,126,234,0.60);
    background: rgba(255,255,255,0.10);
}
#chat-input::placeholder { color: rgba(255,255,255,0.22); }
#chat-send-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    border-radius: 7px;
    color: #fff;
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    letter-spacing: 0.02em;
}
#chat-send-btn:hover  { opacity: 0.85; }
#chat-send-btn:active { transform: scale(0.97); }

/* ─── Customiser Panel ───────────────────────────────────────────────────── */
#customiser-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 290px;
    background: rgba(8,8,20,0.94);
    backdrop-filter: blur(24px);
    border-left: 1px solid rgba(255,255,255,0.07);
    z-index: 200;
    transform: translateX(110%);
    transition: transform 0.38s cubic-bezier(0.34,1.56,0.64,1);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#customiser-panel.panel-open   { transform: translateX(0); }
#customiser-panel.panel-hidden { transform: translateX(110%); }

.cust-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: sticky;
    top: 0;
    background: rgba(8,8,20,0.98);
    z-index: 1;
}
.cust-header h2 {
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
}
#customiser-close {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.5);
    width: 26px; height: 26px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
#customiser-close:hover { color: #fff; border-color: rgba(255,255,255,0.4); background: rgba(255,255,255,0.06); }

.cust-body {
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.cust-section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.cust-section label {
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.cust-section input[type="color"] {
    width: 100%;
    height: 36px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    padding: 3px;
    cursor: pointer;
}
.cust-section input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.cust-section input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px; height: 15px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(102,126,234,0.5);
}
.range-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.range-row input { flex: 1; }
.range-val {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    min-width: 30px;
    text-align: right;
}
.style-btns {
    display: flex;
    gap: 6px;
}
.style-btns button {
    flex: 1;
    padding: 7px 4px;
    font-size: 0.78rem;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.5);
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
}
.style-btns button:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.09); }
.style-btns button.active {
    background: rgba(102,126,234,0.2);
    border-color: rgba(102,126,234,0.5);
    color: #a78bfa;
    font-weight: 700;
}
.cust-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 2px 0;
}
.cust-body input[type="file"] {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.45);
    cursor: pointer;
    background: rgba(255,255,255,0.04);
    border: 1px dashed rgba(255,255,255,0.12);
    border-radius: 7px;
    padding: 10px 12px;
    width: 100%;
}
.cust-body input[type="file"]::file-selector-button {
    background: rgba(102,126,234,0.2);
    border: 1px solid rgba(102,126,234,0.3);
    color: #a78bfa;
    border-radius: 5px;
    padding: 3px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-right: 10px;
}
#c-photo-status {
    font-size: 0.78rem;
    color: #a78bfa;
    min-height: 18px;
    line-height: 1.4;
}
.save-btn {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    border-radius: 9px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: opacity 0.2s, transform 0.15s;
    box-shadow: 0 4px 15px rgba(102,126,234,0.35);
}
.save-btn:hover  { opacity: 0.87; }
.save-btn:active { transform: scale(0.97); }

/* ─── Mini Mobile Controls (on-screen DPAD for touch) ───────────────────── */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 20px;
    z-index: 150;
    gap: 4px;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
}
@media (pointer: coarse) {
    #mobile-controls { display: grid; }
}
.dpad-btn {
    background: rgba(10,10,25,0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.dpad-btn:active { background: rgba(102,126,234,0.3); }
#dpad-up    { grid-column: 2; grid-row: 1; }
#dpad-left  { grid-column: 1; grid-row: 2; }
#dpad-down  { grid-column: 2; grid-row: 2; }
#dpad-right { grid-column: 3; grid-row: 2; }
#dpad-jump  { grid-column: 3; grid-row: 1; font-size: 0.65rem; }

/* ─── Ready Player Me Button ───────────────────────────────────────────────── */
.rpm-btn {
    width: 100%;
    padding: 11px 10px;
    background: linear-gradient(135deg, #1d4ed8, #7c3aed);
    border: none;
    border-radius: 9px;
    color: #fff;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: opacity 0.2s, transform 0.15s;
    box-shadow: 0 4px 15px rgba(124,58,237,0.4);
}
.rpm-btn:hover  { opacity: 0.88; }
.rpm-btn:active { transform: scale(0.97); }
#rpm-model-status {
    font-size: 0.78rem;
    color: #a78bfa;
    min-height: 16px;
    line-height: 1.4;
}

/* ── Avatar preset picker grid ── */
#avatar-preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-bottom: 4px;
}
.avatar-preset-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 4px 7px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    text-align: center;
    user-select: none;
}
.avatar-preset-card:hover {
    background: rgba(99,102,241,0.18);
    border-color: rgba(99,102,241,0.45);
    transform: translateY(-1px);
}
.avatar-preset-card.apc-active {
    background: rgba(99,102,241,0.28);
    border-color: #818cf8;
    box-shadow: 0 0 0 1px #818cf8;
}
.apc-emoji { font-size: 1.5rem; line-height: 1; }
.apc-name  { font-size: 0.72rem; font-weight: 700; color: #e2e8f0; }
.apc-desc  { font-size: 0.62rem; color: #94a3b8; }
