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

:root {
    --bg:        #0d0d18;
    --bg2:       #13131f;
    --bg3:       #1a1a2e;
    --card:      rgba(255,255,255,0.04);
    --card-h:    rgba(255,255,255,0.07);
    --border:    rgba(255,255,255,0.09);
    --accent:    #5865f2;
    --accent-h:  #6e7bf5;
    --green:     #3ba55d;
    --red:       #ed4245;
    --text:      #e3e5e8;
    --text-m:    #b5bac1;
    --text-d:    #6d7180;
    --radius:    12px;
}

html, body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

/* ── Layout ── */
.page { min-height: 100vh; display: flex; flex-direction: column; }

nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}

.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--text);
    text-decoration: none;
}
.nav-brand span { color: var(--accent); }

.nav-right { display: flex; align-items: center; gap: 12px; }

.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px 6px 8px;
}
.user-pill img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.user-pill .name { font-size: .85rem; font-weight: 600; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 600;
    transition: background .15s, transform .1s;
    text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-discord { background: var(--accent); color: #fff; }
.btn-discord:hover { background: var(--accent-h); }
.btn-outline { background: transparent; color: var(--text-m); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--card-h); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid rgba(237,66,69,.3); }
.btn-danger:hover { background: rgba(237,66,69,.1); }
.btn-sm { padding: 6px 14px; font-size: .8rem; }

/* ── Main ── */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

/* ── Login ── */
.login-wrap { text-align: center; max-width: 400px; width: 100%; }
.login-wrap h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 8px; letter-spacing: -.02em; }
.login-wrap h1 span { color: var(--accent); }
.login-wrap p { color: var(--text-m); margin-bottom: 32px; font-size: .95rem; }
.login-wrap .btn { width: 100%; justify-content: center; padding: 13px 20px; font-size: 1rem; }

/* ── Dashboard ── */
.dash-wrap { width: 100%; max-width: 480px; }
.dash-wrap h2 { font-size: 1.35rem; font-weight: 700; margin-bottom: 20px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}
.card h3 {
    font-size: .8rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-m);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.join-row { display: flex; gap: 8px; }

input[type="text"] {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text);
    font-size: .95rem;
    font-family: inherit;
    transition: border-color .15s;
    outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-d); }

.error-msg { color: var(--red); font-size: .83rem; margin-top: 8px; min-height: 1.2em; }

/* ── Lobby ── */
.lobby-wrap { width: 100%; max-width: 860px; }

.lobby-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}
.lobby-header h2 { font-size: 1.4rem; font-weight: 800; }

.code-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
}
.code-badge .label { font-size: .75rem; color: var(--text-d); text-transform: uppercase; letter-spacing: .08em; }
.code-badge .code  { font-size: 1.4rem; font-weight: 800; letter-spacing: .18em; color: var(--accent); }

.copy-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-d); padding: 4px; border-radius: 4px;
    transition: color .15s; display: flex; align-items: center;
}
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--green); }

/* ── Slots grid ── */
.slots {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 700px) { .slots { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 400px) { .slots { grid-template-columns: 1fr; } }

.slot {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 260px;
    position: relative;
    transition: border-color .2s;
}
.slot.empty { border-style: dashed; opacity: .5; }
.slot.is-me { border-color: rgba(88,101,242,.4); }
.slot.drag-over { border-color: var(--accent); background: rgba(88,101,242,.06); }

/* Member info bar */
.slot-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: rgba(0,0,0,.2);
    border-bottom: 1px solid var(--border);
    min-width: 0;
}
.slot-info img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.slot-info .slot-avatar-placeholder { width: 30px; height: 30px; border-radius: 50%; background: var(--bg3); flex-shrink: 0; }
.slot-name { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.slot-badge { margin-left: auto; font-size: .65rem; padding: 2px 6px; border-radius: 4px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.slot-badge.host { background: rgba(88,101,242,.2); color: var(--accent); }
.slot-badge.you  { background: rgba(59,165,93,.2);  color: var(--green); }

/* Image area */
.slot-image {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    min-height: 180px;
}
.slot-image img {
    width: 100%; height: 100%;
    object-fit: cover;
    position: absolute;
    inset: 0;
    transition: transform .2s;
}
.slot-image.has-image:hover img { transform: scale(1.03); }

.upload-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-d);
    font-size: .8rem;
    text-align: center;
    padding: 16px;
    transition: color .15s;
    z-index: 1;
    position: relative;
}
.upload-hint svg { opacity: .5; }
.slot-image:hover .upload-hint { color: var(--text-m); }
.slot-image:hover .upload-hint svg { opacity: .8; }

/* Change-image overlay (my slot with image) */
.slot-change-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
    background: linear-gradient(to top, rgba(0,0,0,.6) 0%, transparent 50%);
    opacity: 0;
    transition: opacity .2s;
    z-index: 2;
}
.slot-image.has-image:hover .slot-change-overlay { opacity: 1; }

.slot-change-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(20,20,40,.8);
    border: 1px solid var(--border);
    color: var(--text-m);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s, background .15s;
    font-family: inherit;
}
.slot-change-btn:hover { color: var(--text); background: rgba(88,101,242,.2); }

/* Uploading overlay */
.uploading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13,13,24,.75);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    color: var(--text-m);
    gap: 8px;
    z-index: 3;
}

/* Spinner */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.slot-empty-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-d);
    font-size: .8rem;
}

/* ── Tree section ── */
.slot-tree {
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,.25);
    padding: 8px;
}
.slot-tree svg { border-radius: 4px; }

.slot-tree-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 14px 8px;
    color: var(--text-d);
    font-size: .75rem;
}
.slot-tree-error { color: var(--red) !important; }

.tree-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 6px 4px 2px;
}
.tl-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .65rem;
    color: var(--text-d);
    text-transform: capitalize;
}
.tl-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Lightbox ── */
#lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
#lightbox.open {
    opacity: 1;
    pointer-events: all;
}
#lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .88);
    cursor: pointer;
}
#lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 92vw;
    max-height: 92vh;
}
#lightbox-name {
    color: var(--text-m);
    font-size: .9rem;
    font-weight: 600;
    letter-spacing: .02em;
}
#lightbox-img {
    max-width: 90vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 24px 80px rgba(0,0,0,.6);
    display: block;
}
#lightbox-close {
    position: absolute;
    top: -14px;
    right: -14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    z-index: 2;
}
#lightbox-close:hover { background: var(--card-h); }

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: .88rem;
    color: var(--text);
    pointer-events: none;
    transition: transform .25s ease, opacity .25s ease;
    opacity: 0;
    z-index: 2000;
    white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
