body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

#app-chrome {
    padding-top: env(safe-area-inset-top);
}

#room-status {
    padding-bottom: env(safe-area-inset-bottom);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

#room-mode.stale {
    color: #f87171;
}

#room-status.stale {
    color: #f87171;
}

#room-status.stale #room-status-pill,
#room-status.stale #room-status-pill * {
    color: #f87171 !important;
}

#room-status-pill {
    color: #e4e4e7;
    background-color: #18181b;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
}

#header-toolbar {
    max-width: calc(100vw - 9rem);
}

.header-tool-btn {
    height: 2rem;
    width: 2rem;
    border-radius: 0.625rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.35);
    color: #e5e7eb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.header-tool-btn span:last-child {
    display: none;
}

.header-tool-btn:hover {
    background: rgba(99, 102, 241, 0.35);
    border-color: rgba(129, 140, 248, 0.8);
    color: #ffffff;
}

.header-tool-btn.active {
    background: rgba(99, 102, 241, 0.55);
    border-color: rgba(129, 140, 248, 1);
    color: #ffffff;
}

@media (max-width: 640px) {
    #header-toolbar {
        max-width: calc(100vw - 6rem);
        gap: 0.25rem;
        padding: 0.3rem;
    }

    .header-tool-btn {
        width: 2rem;
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Responsive video grid - auto-fits participants without scrolling */
#sfu-grid {
    display: grid;
    gap: 0.25rem;
    grid-auto-rows: minmax(0, 1fr);
    align-content: start;
}

/* Dynamic grid columns and rows based on participant count */
#sfu-grid[data-count="1"] { 
    grid-template-columns: 1fr; 
    grid-template-rows: 1fr;
}
#sfu-grid[data-count="2"] { 
    grid-template-columns: repeat(2, 1fr); 
    grid-template-rows: 1fr;
}
#sfu-grid[data-count="3"] { 
    grid-template-columns: repeat(2, 1fr); 
    grid-template-rows: repeat(2, 1fr);
}
#sfu-grid[data-count="4"] { 
    grid-template-columns: repeat(2, 1fr); 
    grid-template-rows: repeat(2, 1fr);
}
#sfu-grid[data-count="5"] { 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(2, 1fr);
}
#sfu-grid[data-count="6"] { 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(2, 1fr);
}
#sfu-grid[data-count="7"] { 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr);
}
#sfu-grid[data-count="8"] { 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr);
}
#sfu-grid[data-count="9"] { 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr);
}

 /* Video elements should fill their container without deformation */
 #sfu-grid video,
 #remote-video-container video {
     width: 100%;
     height: 100%;
     object-fit: contain;
     background: #18181b;
 }

 /* Full-screen P2P remote video: no card chrome, no letterboxing gaps */
 #remote-video-container #wrapper-p2p-remote {
     width: 100%;
     height: 100%;
     border-radius: 0;
     border: 0;
     background: transparent;
 }

 #remote-video-container #wrapper-p2p-remote video {
     object-fit: cover;
     background: transparent;
 }

 #sfu-grid.pinned {
     padding: 0 !important;
 }

 #sfu-grid .sfu-pinned {
     position: fixed;
     inset: 0;
     z-index: 50;
     border-radius: 0;
     border: 0;
     box-shadow: none;
     background: transparent;
 }

 #sfu-grid .sfu-pinned video {
     object-fit: cover;
     background: transparent;
 }

/* Local video PiP - ensure video fills without deformation */
#local-video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video-container {
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
    right: calc(1.5rem + env(safe-area-inset-right));
}

/* Draggable PiP indicator */
#local-video-container.dragging {
    opacity: 0.8;
    cursor: grabbing !important;
}

#local-video-container:hover {
    border-color: #6366f1;
}

#local-video-container.pip-transparent {
    background: rgba(24, 24, 27, 0.2) !important;
    border-color: rgba(161, 161, 170, 0.45) !important;
}

#local-video-container.pip-transparent video {
    opacity: 0.45;
}

/* PiP minimized state */
#local-video-container.minimized {
    width: 48px !important;
    height: 48px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

#local-video-container.minimized video,
#local-video-container.minimized .pip-controls {
    display: none;
}

#local-video-container.minimized::before {
    content: '⛶';
    font-size: 22px;
    color: white;
}

/* PiP controls overlay */
.pip-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
    pointer-events: none;
}

#local-video-container:hover .pip-controls {
    opacity: 1;
    pointer-events: auto;
}

.pip-btn {
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.375rem;
    color: white;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

 .pip-btn.pip-icon-btn {
     width: 28px;
     height: 28px;
     padding: 0;
     display: inline-flex;
     align-items: center;
     justify-content: center;
 }

 .pip-btn.pip-icon-btn svg {
     pointer-events: none;
 }

.pip-btn:hover {
    background: rgba(99, 102, 241, 0.8);
    border-color: rgba(99, 102, 241, 1);
}

.pip-btn.active {
    background: rgba(99, 102, 241, 0.6);
    border-color: rgba(99, 102, 241, 1);
}

/* Floating telepresence joystick (double-click on #video-grid) */
.hr-tp-joystick {
    position: fixed;
    z-index: 52;
    box-sizing: border-box;
    touch-action: none;
    user-select: none;
    font-family: inherit;
    color: #e4e4e7;
    background: rgba(24, 24, 27, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.hr-tp-joystick-surface {
    position: relative;
    box-sizing: border-box;
    border-radius: 50%;
    border: 2px solid rgba(99, 102, 241, 0.38);
    background: radial-gradient(
        circle at 35% 30%,
        rgba(99, 102, 241, 0.14),
        rgba(24, 24, 27, 0.35)
    );
    cursor: grab;
}

.hr-tp-joystick-surface:active {
    cursor: grabbing;
}

.hr-tp-joystick-knob {
    position: absolute;
    box-sizing: border-box;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.28);
    background: hsl(142, 55%, 42%);
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.hr-tp-joystick-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px 10px;
    font-size: 12px;
}

.hr-tp-joystick-keep {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: #a1a1aa;
}

.hr-tp-joystick-close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(39, 39, 42, 0.5);
    color: #e4e4e7;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hr-tp-joystick-close:hover {
    background: rgba(63, 63, 70, 0.95);
    color: #fff;
}

/* Head tilt row (Material Symbols from index.html) */
.hr-tp-head-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 4px 10px 2px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.hr-tp-head-btn {
    flex: 0 0 auto;
    width: 42px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(39, 39, 42, 0.45);
    color: #e4e4e7;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.hr-tp-head-btn:hover {
    background: rgba(99, 102, 241, 0.35);
    border-color: rgba(165, 180, 252, 0.45);
}

.hr-tp-head-btn:active {
    transform: scale(0.96);
}

.hr-tp-head-btn-icon {
    font-size: 22px;
    line-height: 1;
    font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

.hr-tp-head-btn--center .hr-tp-head-btn-icon {
    font-size: 24px;
}
