html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;

    /* iOS notch safe area if needed */
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

/* The main game canvas can be absolutely positioned or centered. */

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #222;
    z-index: 1;  /* behind overlays */
}

/* When in “light overlay” mode, we might scoot the canvas up to make room. */
body.inCall #gameCanvas {
    /*transform: translateY(100px);*/
    /*transition: transform 0.3s ease-in-out;*/
}

/* LIGHT OVERLAY */
#lightOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 25vh;        /* The bar's height */
    z-index: 999;
    background: #000;

    display: flex;
    align-items: center;
}


#lightOverlayVideos {
    display: flex;
    flex-wrap: nowrap;        /* No wrapping => single row */
    width: 100%;
    height: 100%;
    overflow-x: hidden;       /* If you want zero horizontal scrolling */
    align-items: center;
    justify-content: center;
}

/* HEAVY OVERLAY */
#videoOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; /* fill entire viewport on mobile */
    background: rgba(0,0,0,0.8);
    display: none;
    z-index: 1000;
    flex-direction: column;
    align-items: end;
    justify-content: center;
}

#videoOverlay.active {
    display: grid;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    grid-template-rows: 1fr auto;
    overflow: hidden; /* no scrollbars; everything must shrink to fit */
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
}

#videoOverlay.active.pinned-empty {
    /* If pinned is empty, let the gallery row fill 100%. */
    grid-template-rows: 1fr;
}

#overlayVideosContainer {
    width: 100%;
    height: 100%;
    overflow: auto;
    display: flex; /* fallback for non-mobile: flex row or wrap, etc. */
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding-top: 3rem; /* add space so button at top doesn't overlap videos */
}

#overlayVideosContainer video,
#overlayVideosContainer audio {
    margin: 5px;
    background: black;
    object-fit: cover;
}

#lightOverlayVideos video {
    /* Let them grow/shrink equally */
    flex: 1 1 auto;

    /* Optional min-size so they never vanish entirely: */
    min-width: 80px;

    /* Match the overlay’s height so they are scaled properly */
    height: 90%;

    margin: 5px;
    background: black;
    object-fit: cover;
}
#lightOverlayVideos audio {
    flex: 1 1 0;           /* let them grow/shrink equally */
    margin: 5px;
    height: 90%;           /* still fill most of overlay’s height */
    background: black;
    object-fit: cover;
}

#closeOverlayBtn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 9999;      /* ensure on top of videos */
    font-size: 1.2rem;
    background: #222;
    color: #fff;
    border: none;
    cursor: pointer;
    padding: 10px 15px;
}

@media (max-width: 768px) {
    #overlayVideosContainer {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        grid-auto-rows: 1fr;
        align-items: center;
        justify-items: center;
    }

    #overlayVideosContainer video,
    #overlayVideosContainer audio {
        width: 100%;    /* fill the grid cell */
        height: auto;
    }
}

#mobileControls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;

    display: grid;
    grid-template-columns: 3rem 3rem 3rem;  /* 3 columns */
    grid-template-rows: 3rem 3rem 3rem;     /* 3 rows */
    gap: 0.2rem;

    /* to prevent double‐tap zoom on iOS */
    touch-action: none;
}

#mobileControls button,
#mobileControls .cell {
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0; /* keep them aligned nicely */
}

#mobileControls button {
    font-size: 1.2rem;
    border: none;
    border-radius: 0.3rem;
    background: #333;
    color: #fff;
    cursor: pointer;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#mobileControls button:active {
    background: #555;
}

/* By default, hide mic/video buttons when not in a call. */
#btnToggleAudio, #btnToggleVideo {
    display: none;
}

/* But when body.inCall is set (i.e. BFS joined), we show them. */
body.inCall #btnToggleAudio,
body.inCall #btnToggleVideo {
    display: flex; /* or inline-flex */
}

#muteControls {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 10000; /* or something large */
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
}


.gallery-section video {
    /* Force a 16:9 shape for every tile */
    aspect-ratio: 16 / 9;
    object-fit: cover;
    width: 100%;     /* fill the grid cell horizontally */
    height: auto;    /* keep the forced ratio */
    background: black;
}

#pinned {
    display: grid;
    /* This will pack pinned videos side by side, and then wrap onto multiple
       rows within that 50% area if there are many pinned users. */
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: 8px;
    background: rgba(0,0,0,0.7); /* or whatever you like */
    place-items: center; /* center each tile inside the grid cell */
    max-height: 100%;
    overflow: hidden;
    grid-row:1;
    width: 100%;
    bottom: 0px;
    height: 100%;
}

/* Make the video/audio fill its grid cell */
#pinned video,
#pinned audio {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: black;
}

/* Single gallery grid for all un-pinned videos */
#gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: 8px;
    background: black;
    place-items: center; /* center each tile */
    /* No scroll => everything must shrink into that 50% of screen */
    overflow: auto;
    grid-row:2;
    width: 100%;
    height: auto;
}

#gallery video,
#gallery audio {
    width: 100%;
    height: auto;
    object-fit: cover;
    background: black;
}

/*#gallery video {*/
/*    flex: 1 1 auto;*/
/*    background: black;*/
/*    object-fit: cover;*/
/*}*/e7eeyuy

#pinned .screenshare {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
}

.videoContainer {
    position: relative; /* So label can be absolutely positioned inside */
    width: 100%;
    height: 100%;
    overflow: hidden;   /* Hide anything beyond container edges */
    background: transparent !important;
}

/* Fill container space with the media element. */
.videoContainer video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: transparent;
}

/* The label in bottom-left corner, semi-transparent. */
.videoContainer .label {
    position: absolute;
    bottom: 0;
    left: 0;
    margin: 4px;
    padding: 2px 6px;
    font-size: 0.9rem;
    color: #fff;
    background: rgba(0,0,0,0.4);
    border-radius: 4px;
}


.videoContainer.audioOnly {
    display: none !important;
}

#lightOverlayVideos video {
    height: 100%;
}

.videoContainer .fullscreenBtn {
    position: absolute;
    right: 0;
    bottom: 0;
    margin: 4px;
    padding: 2px 6px;
    font-size: 0.9rem;
    color: #fff;
    background: transparent;
    border-radius: 4px;
    border: none;
    cursor: pointer;

    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    /*padding: 4px;  !* optional, so the icon isn’t flush against the edges *!*/
}
.videoContainer .fullscreenBtn:hover {
    background: transparent;
}

.videoContainer .fullscreenIcon {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;

    background-color: transparent;

    transition: filter 0.2s ease-in-out;
    filter: drop-shadow(0 0 0px rgba(0, 0, 0, 0));
}

.videoContainer .fullscreenIcon:hover {
    transform: rotate(10deg) translateY(-3px); /* Rotate 10 degrees and lift 3 pixels on hover */
    drop-shadow(1px 1px 20px white)
}

.videoContainer .fullscreenIcon {
    transition: transform 0.2s ease-in-out;
    transform: rotate(0deg) translateY(0px); /* Start with no rotation or lift */
    drop-shadow(1px 1px 20px white)
}