* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f172a;
    color: #fff;
    height: 100vh;
    overflow: hidden;
}
.screen { width: 100%; height: 100vh; }
.hidden { display: none !important; }

/* ── Join screen ── */
#joinScreen {
    display: flex;
    align-items: center;
    justify-content: center;
}
.join-card {
    background: #1e293b;
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.join-card h1 {
    font-size: 22px;
    margin: 0 0 20px;
    color: #60a5fa;
}
.preview-wrap {
    position: relative;
    background: #0f172a;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16/10;
    margin-bottom: 12px;
}
#previewVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}
.preview-off {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 14px;
}
.preview-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}
.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #334155;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}
.icon-btn.active { background: #2563eb; }
.icon-btn.off { background: #475569; opacity: 0.6; }

input[type="text"] {
    width: 100%;
    padding: 11px 14px;
    border-radius: 8px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #fff;
    font-size: 14px;
    margin-bottom: 10px;
    outline: none;
}
input[type="text"]:focus { border-color: #2563eb; }
.room-row { display: flex; gap: 8px; }
.room-row input { margin-bottom: 0; }

.btn-primary {
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}
.btn-primary:hover { background: #1d4ed8; }
.error-text { color: #f87171; font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ── Room screen ── */
#roomScreen { display: flex; flex-direction: column; }
.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #1e293b;
}
.room-code-badge {
    font-size: 13px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
}
.room-code-badge strong { color: #fff; letter-spacing: 1px; }
.room-code-badge button {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
}
.recording-badge {
    background: #dc2626;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.room-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative; /* anchors the draggable face bubble within this area */
}
.tiles-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
    padding: 10px;
    align-content: center;
    overflow-y: auto;
}

/* ── Spotlight mode: someone is screen-sharing ── */
/* Switches from the normal grid to: one big tile filling almost all the
   space, with everyone else shrunk into a slim scrollable strip below. */
.tiles-grid.spotlight-mode {
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
    align-content: unset;
}
.tiles-grid.spotlight-mode .tile.screen-share {
    flex: 1;
    min-height: 0;
    width: 100%;
    aspect-ratio: unset;
}
.tiles-grid.spotlight-mode .tile-strip {
    display: flex;
    gap: 8px;
    height: 110px;
    flex-shrink: 0;
    overflow-x: auto;
}
.tiles-grid.spotlight-mode .tile-strip .tile {
    flex: 0 0 160px;
    aspect-ratio: 16/10;
}

/* ── Draggable self-face bubble (shown while I'm sharing my screen) ── */
.face-bubble {
    /* Fixed to the viewport (not the room body) so it can never be clipped
       or pushed off-screen by any layout/overflow changes elsewhere
       (e.g. the spotlight-mode grid switching to flex/column). */
    position: fixed;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #2563eb;
    box-shadow: 0 6px 20px rgba(0,0,0,0.45);
    cursor: grab;
    z-index: 999;
    bottom: 90px;
    right: 24px;
    touch-action: none;
    user-select: none;
}
.face-bubble.dragging { cursor: grabbing; }
.face-bubble video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    pointer-events: none;
}
.tile {
    position: relative;
    background: #1e293b;
    border-radius: 10px;
    overflow: hidden;
    aspect-ratio: 16/10;
}
.tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.tile.mine video { transform: scaleX(-1); }
/* Screen-share content must NEVER be mirrored (only camera self-view should
   be) — without this override, sharing your screen showed everything
   backwards because this tile is also ".mine". */
.tile.mine.screen-share video { transform: none; }
.tile.screen-share { aspect-ratio: 16/9; grid-column: 1 / -1; }
.tile.screen-share video { object-fit: contain; background: #000; }
.tile-name {
    position: absolute;
    bottom: 6px;
    left: 8px;
    background: rgba(0,0,0,0.55);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
}
.tile-muted-icon {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 14px;
    background: rgba(0,0,0,0.55);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tile-avatar {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    background: #334155;
    color: #cbd5e1;
}

.chat-panel {
    width: 300px;
    background: #1e293b;
    border-left: 1px solid #334155;
    display: flex;
    flex-direction: column;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid #334155;
    font-weight: 600;
}
.chat-header button { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 14px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; font-size: 13px; }
.chat-msg { margin-bottom: 10px; }
.chat-msg .sender { color: #60a5fa; font-weight: 600; display: block; font-size: 12px; }
.chat-msg .body { color: #e2e8f0; }
.chat-msg.mine .sender { color: #34d399; }
.chat-form { display: flex; padding: 10px; border-top: 1px solid #334155; gap: 6px; }
.chat-form input { margin: 0; flex: 1; }
.chat-form button {
    background: #2563eb; border: none; color: #fff; border-radius: 8px; padding: 0 14px; cursor: pointer;
}

.controls-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: #1e293b;
    border-top: 1px solid #334155;
}
.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: #334155;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    position: relative;
}
.control-btn.active { background: #2563eb; }
.control-btn.off { background: #475569; }
.leave-btn { background: #dc2626 !important; }
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc2626;
    color: #fff;
    font-size: 10px;
    border-radius: 10px;
    min-width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

@media (max-width: 700px) {
    .chat-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
}

.toast-msg {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: #1e293b;
    border: 1px solid #2563eb;
    color: #e2e8f0;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-msg.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
