:root {
    --bg: #050505;
    --fg: #edf0f4;
    --panel: rgba(15, 15, 15, 0.78);
    --panel-border: #2d2d2d;
    --chip: #141414;
    --chip-border: #343434;
    --muted: #a5a9b2;
    --good: #24b36b;
    --good-border: #44d98c;
    --my-accent: #60a5fa;
    --stage-inset: 10px;
    --tile-control-inset: 8px;
    --lobby-settings-scale: 0.8;
    --lobby-preview-width: 280px;
    --lobby-preview-tile-width: 220px;
    --seat-grid-gap: calc(6px * var(--lobby-settings-scale));
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: "Sora", "Avenir Next", "Segoe UI", sans-serif;
}

#app-shell {
    position: relative;
    width: 100%;
    height: 100%;
}

.view {
    position: absolute;
    inset: 0;
    display: none;
}

.view.visible {
    display: block;
}

#lobby-view {
    padding: 20px;
}
#lobby-view.visible {
    display: grid;
    place-items: center;
}

#lobby-card {
    width: 334px;
    max-height: 94vh;
    overflow: auto;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(18px) saturate(130%);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.34);
    padding: 10px;
}

.top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.top-actions {
    display: inline-flex;
    gap: 8px;
}

#room-title {
    margin: 0;
    font-size: 26px;
    letter-spacing: 0.03em;
    font-weight: 600;
    line-height: 1.12;
    padding-left: calc((100% - var(--lobby-preview-width)) / 2);
    white-space: nowrap;
}

.icon-btn, .toggle-btn, .join-btn {
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--fg);
    border-radius: 999px;
    cursor: pointer;
}

.icon-btn {
    width: 42px;
    height: 42px;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.icon-btn svg {
    width: 21px;
    height: 21px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#lobby-invite-btn.invite-error {
    color: #ff9a9a;
}

#lobby-invite-btn svg {
    transform: translateX(-1.2px);
}

.icon-btn.action-accent {
    color: var(--action-accent, var(--my-accent));
    border-color: color-mix(in srgb, var(--action-accent, var(--my-accent)) 78%, var(--chip-border) 22%);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--action-accent, var(--my-accent)) 20%, transparent);
}

.invite-bubble {
    position: fixed;
    left: 0;
    top: 0;
    transform: translate(-50%, calc(-100% + 4px));
    background: color-mix(in srgb, var(--chip) 88%, #000 12%);
    color: var(--fg);
    border: 1px solid color-mix(in srgb, var(--chip-border) 74%, transparent);
    border-radius: 999px;
    font-size: 11px;
    line-height: 1;
    padding: 6px 8px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, transform 120ms ease;
    z-index: 80;
}

.invite-bubble.visible {
    opacity: 1;
    transform: translate(-50%, -100%);
}

.toast {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: var(--chip);
    color: var(--fg);
    border: 1px solid var(--chip-border);
    border-radius: 8px;
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
    z-index: 200;
    animation: toast-in 0.15s ease;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.self-tile {
    width: var(--lobby-preview-tile-width);
    height: var(--lobby-preview-width);
    margin: 10px auto 14px auto;
    border-radius: 20px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.11);
    background: rgba(255, 255, 255, 0.06);
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--seat-color, #fff) 54%, transparent),
      0 0 16px color-mix(in srgb, var(--seat-color, #fff) 58%, transparent),
      0 0 38px color-mix(in srgb, var(--seat-color, #fff) 46%, transparent);
}

.self-tile.is-screen {
    width: var(--lobby-preview-tile-width);
    height: var(--lobby-preview-width);
}

.lobby-video-actions {
    z-index: 6;
}

.self-tile .tile-top {
    top: 6px;
    left: 6px;
    gap: 4px;
    max-width: none;
    flex-wrap: nowrap;
}

.lobby-video-actions .tile-btn {
    white-space: nowrap;
    flex: 0 0 auto;
}

.self-tile .mute-btn {
    right: 6px;
    bottom: 6px;
}

.pulse-ring {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--seat-color, #fff);
    box-shadow:
      0 0 20px color-mix(in srgb, var(--seat-color, #fff) 70%, transparent),
      0 0 44px color-mix(in srgb, var(--seat-color, #fff) 52%, transparent);
    pointer-events: none;
}

@keyframes pulse {
    0% { transform: scale(0.98); opacity: 0.45; }
    50% { transform: scale(1.03); opacity: 0.85; }
    100% { transform: scale(0.98); opacity: 0.45; }
}

#self-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

#self-preview.visible { display: block; }
#self-preview.mirror { transform: scaleX(-1); }
#self-preview.is-screen { object-fit: contain; background: #000; }

.swirl {
    position: absolute;
    inset: -30%;
    background:
      conic-gradient(from 120deg at 50% 50%, var(--seat-mix-stops, #5eead4, #f472b6, #60a5fa, #f59e0b, #a78bfa, #5eead4));
    filter: blur(36px) saturate(90%);
    opacity: 0.55;
    animation: swirl 16s linear infinite;
    display: none;
}

.swirl.visible { display: block; }

@keyframes swirl {
    from { transform: rotate(0deg) scale(1.12); }
    to { transform: rotate(360deg) scale(1.12); }
}

.seat-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--seat-grid-gap);
    width: var(--lobby-preview-width);
    min-height: calc((var(--lobby-preview-width) - (5 * var(--seat-grid-gap))) / 6);
    margin: 0 auto calc(8px * var(--lobby-settings-scale)) auto;
}

.seat {
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: color-mix(in srgb, var(--seat) 42%, transparent);
    opacity: 0.34;
    transition: 0.15s ease;
    position: relative;
}

.seat.available:hover {
    opacity: 0.64;
    transform: translateY(-1px);
}

.seat.occupied {
    opacity: 0.8;
    border-color: color-mix(in srgb, var(--seat) 56%, #fff 14%);
    box-shadow:
      inset 0 0 18px color-mix(in srgb, var(--seat) 36%, transparent),
      0 0 12px color-mix(in srgb, var(--seat) 42%, transparent);
}

.seat.selected {
    opacity: 1;
    border: 2px solid color-mix(in srgb, var(--seat) 72%, #fff 18%);
    box-shadow:
      inset 0 0 30px color-mix(in srgb, var(--seat) 54%, transparent),
      0 0 22px color-mix(in srgb, var(--seat) 70%, transparent);
}

.toggle-btn {
    min-width: 46px;
    height: 34px;
    padding: 0 14px;
}

.toggle-btn.active {
    border-color: rgba(255, 255, 255, 0.45);
    box-shadow: 0 0 9px rgba(255, 255, 255, 0.2);
}

#whiteboard-tools .toggle-btn.active {
    background: color-mix(in srgb, var(--my-accent) 78%, #000 10%);
    border-color: color-mix(in srgb, var(--my-accent) 84%, #111 16%);
    color: #f7fbff;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--my-accent) 24%, transparent), 0 6px 16px color-mix(in srgb, var(--my-accent) 30%, transparent);
}

.picker-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-content: stretch;
    align-items: start;
    gap: calc(8px * var(--lobby-settings-scale));
    margin-bottom: calc(10px * var(--lobby-settings-scale));
}

.picker-row label {
    display: flex;
    flex-direction: column;
    gap: calc(4px * var(--lobby-settings-scale));
    font-size: calc(12px * var(--lobby-settings-scale));
    color: var(--muted);
    flex: 1;
}

.picker-row select {
    width: 100%;
    background: var(--chip);
    color: var(--fg);
    border: 1px solid var(--chip-border);
    border-radius: calc(10px * var(--lobby-settings-scale));
    padding: calc(8px * var(--lobby-settings-scale));
}

.join-btn,
/* Override global #join-btn styling from style.css on the room page. */
#join-btn.join-btn {
    --action-accent: #7f8ca3;
    width: 100%;
    height: calc(40px * var(--lobby-settings-scale));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: color-mix(in srgb, var(--action-accent, var(--my-accent)) 68%, #000 32%);
    border-color: color-mix(in srgb, var(--action-accent, var(--my-accent)) 74%, #fff 26%);
    color: #f6fbff;
    box-shadow: none;
}

.join-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

#room-view {
    padding: 10px;
}

.participant-grid {
    position: absolute;
    inset: var(--stage-inset);
    display: grid;
    gap: 8px;
}

.participant-tile {
    --speak-level: 0;
    container-type: inline-size;
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--seat, #fff) 65%, #000 8%);
    box-shadow:
      inset 0 0 0 2px color-mix(in srgb, var(--seat, #fff) 26%, transparent);
    background: rgba(0, 0, 0, 0.18);
}

.participant-tile::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
    opacity: var(--speak-level);
    box-shadow:
      inset 0 0 22px var(--seat, #8fb6ff),
      inset 0 0 46px var(--seat, #8fb6ff);
    transition: opacity 120ms linear;
}

.participant-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tile-surface {
    position: absolute;
    inset: 0;
}
.tile-surface.mirror { transform: scaleX(-1); }


.tile-top {
    position: absolute;
    top: var(--tile-control-inset);
    left: var(--tile-control-inset);
    transform: none;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    z-index: 4;
}

/* Only reserve space for the expand button when it's actually visible */
.focus-btn:not(.hidden) ~ .tile-top {
    max-width: calc(100% - 2 * var(--tile-control-inset) - 72px);
}

.focus-btn {
    position: absolute;
    top: var(--tile-control-inset);
    right: var(--tile-control-inset);
    z-index: 5;
}

.mute-btn {
    position: absolute;
    right: var(--tile-control-inset);
    bottom: var(--tile-control-inset);
    z-index: 5;
}

.tile-btn {
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.42);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.tile-btn.action-accent {
    border-color: color-mix(in srgb, var(--action-accent, var(--my-accent)) 76%, #fff 20%);
    background: color-mix(in srgb, var(--action-accent, var(--my-accent)) 36%, rgba(0, 0, 0, 0.42));
}

.tile-btn.leave {
    position: absolute;
    left: 50%;
    bottom: var(--tile-control-inset);
    transform: translateX(-50%);
    z-index: 5;
    width: 40px;
    height: 40px;
    padding: 0;
    border-color: rgba(255, 255, 255, 0.45);
    color: #ffffff;
    background: rgba(0, 0, 0, 0.54);
}

.tile-btn.leave svg {
    width: 20px;
    height: 20px;
    display: block;
    margin: 0 auto;
}

.tile-btn.leave svg path {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.1;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.participant-tile.locally-muted::after,
.self-tile.locally-muted::after,
#focus-content.locally-muted::after,
.participant-tile.self-muted::after,
.self-tile.self-muted::after,
#focus-content.self-muted::after,
.participant-tile.peer-self-muted::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.participant-tile.locally-muted::after,
.self-tile.locally-muted::after,
#focus-content.locally-muted::after {
    background: rgba(138, 22, 22, 0.2);
    box-shadow: inset 0 0 0 1px rgba(255, 90, 90, 0.28), inset 0 0 48px rgba(140, 20, 20, 0.24);
}

.participant-tile.self-muted::after,
.self-tile.self-muted::after,
#focus-content.self-muted::after {
    background: rgba(28, 70, 132, 0.34);
    box-shadow: inset 0 0 0 1px rgba(108, 168, 255, 0.46), inset 0 0 64px rgba(30, 84, 164, 0.34);
}

.participant-tile.peer-self-muted::after {
    background: rgba(44, 88, 142, 0.24);
    box-shadow: inset 0 0 0 1px rgba(124, 176, 252, 0.36), inset 0 0 56px rgba(42, 92, 156, 0.28);
}

.participant-tile.locally-muted.peer-self-muted::after {
    background: rgba(138, 22, 22, 0.2);
    box-shadow: inset 0 0 0 1px rgba(255, 90, 90, 0.28), inset 0 0 48px rgba(140, 20, 20, 0.24);
}

.self-muted-hint {
    position: absolute;
    left: 50%;
    bottom: 50px;
    transform: translateX(-50%);
    z-index: 4;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #d7e9ff;
    background: rgba(36, 64, 102, 0.48);
    border: 1px solid rgba(121, 173, 255, 0.36);
    box-shadow: 0 0 0 1px rgba(18, 36, 62, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.self-muted-hint.visible {
    opacity: 1;
}

.self-muted-hint.lobby {
    color: #d9dde6;
    background: rgba(40, 44, 52, 0.58);
    border-color: rgba(161, 170, 186, 0.35);
    box-shadow: 0 0 0 1px rgba(18, 20, 26, 0.16);
}

.self-muted-hint.backgrounded {
    color: #d9dde6;
    background: rgba(46, 50, 58, 0.62);
    border-color: rgba(156, 166, 182, 0.42);
    box-shadow: 0 0 0 1px rgba(20, 24, 31, 0.24);
}

.tile-canvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}
.participant-tile.is-screen video {
    object-fit: contain;
    background: #000;
}

#whiteboard-pip {
    position: absolute;
    left: 24px;
    bottom: 24px;
    width: 62px;
    height: 62px;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: 0 0 22px rgba(0, 0, 0, 0.34);
    background: rgba(0, 0, 0, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    z-index: 40;
}

#whiteboard-pip canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    filter: contrast(1.24) saturate(1.12);
}

#whiteboard-pip span {
    position: absolute;
    inset: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    letter-spacing: 0.05em;
    pointer-events: none;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 8px rgba(0, 0, 0, 0.65);
}

#focus-view {
    background: var(--bg);
    padding: 0;
}

#focus-toolbar {
    position: absolute;
    top: calc(var(--stage-inset) + var(--tile-control-inset));
    right: calc(var(--stage-inset) + var(--tile-control-inset));
    z-index: 30;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

#focus-exit {
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.42);
    color: #fff;
    border-radius: 999px;
    font-size: 16px;
}

#focus-content {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 0;
    overflow: hidden;
    background: #000;
}

#focus-content .tile-top {
    top: calc(var(--tile-control-inset) + var(--stage-inset));
    left: calc(var(--tile-control-inset) + var(--stage-inset));
}

#focus-content .focus-btn {
    top: calc(var(--tile-control-inset) + var(--stage-inset));
    right: calc(var(--tile-control-inset) + var(--stage-inset));
}

#focus-content .mute-btn {
    right: calc(var(--tile-control-inset) + var(--stage-inset));
    bottom: calc(var(--tile-control-inset) + var(--stage-inset));
}

#focus-content .tile-btn.leave {
    bottom: calc(var(--tile-control-inset) + var(--stage-inset));
}

#focus-content video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

#focus-content video.is-screen {
    object-fit: contain;
}

#focus-content video.mirror {
    transform: scaleX(-1);
}

#whiteboard-canvas {
    width: min(99vw, calc(100vh - 8px));
    max-width: 100vw;
    aspect-ratio: 1 / 1;
    height: auto;
    max-height: 100vh;
    margin: 0 auto;
    display: block;
    border-radius: 8px;
    background: #14171e;
    touch-action: none;
}

.whiteboard-eraser-ghost {
    position: fixed;
    width: 1px;
    height: 1px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.022);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14), 0 0 7px rgba(0, 0, 0, 0.09);
    pointer-events: none;
    z-index: 35;
    transform: translate(-50%, -50%);
}

.whiteboard-eraser-ghost.active {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.055);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22), 0 0 12px rgba(255, 255, 255, 0.14);
}

#focus-view.whiteboard #focus-content {
    display: none;
}
#focus-view.whiteboard.visible {
    display: grid;
    place-items: center;
}
.hidden { display: none !important; }

@media (max-width: 760px) {
    #lobby-card { padding: 8px; border-radius: 14px; }
}

/* Adjust tile control placement when tiles are narrow enough that leave and mute would overlap */
@container (max-width: 240px) {
    .tile-btn.leave {
        /* Raise leave button above the mute button so they don't overlap */
        bottom: calc(var(--tile-control-inset) + 40px + 4px);
    }
}
