/* ==========================================================================
   Video call between the two players of an online game (ui/video-call.js).

   Everything here is scoped to `#screen-game.video-call-on` (a call exists)
   or to the call's own elements, which are `hidden` until then. Without a call
   no rule in this file applies and the game screen is laid out exactly as
   before. The board is never restyled: only the room it is given changes.

   Layouts:
     phone portrait (<= 600px)       board, own player strip, cameras, controls
     short phone (<= 700px tall)     cameras and controls share one row
     tablet portrait (601-1099px)    as the phone, with larger cameras
     wide (>= 1100px, or landscape)  cameras in a column to the right of the board
   ========================================================================== */

#screen-game {
    --vc-gap: 6px;
    --vc-radius: 14px;
    --vc-btn: 48px;
    --vc-tile-h: 148px;
    --vc-side-w: clamp(196px, 17vw, 280px);
    --vc-ink: #14110e;
    --vc-end: #c4342b;
}

.video-call[hidden],
.video-call-invite[hidden],
#game-menu-overlay #btn-video-call[hidden] { display: none !important; }

.video-call__sr {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ── the dock ─────────────────────────────────────────────────────────────── */
.video-call {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--vc-gap);
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
    padding: 2px 0;
    color: var(--tp-color-text, #ece7df);
}

.video-call__tiles {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    gap: var(--vc-gap);
    height: var(--vc-tile-h);
    min-width: 0;
    min-height: 0;
}

.video-call__tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid var(--tp-color-border, rgba(236, 231, 223, .16));
    border-radius: var(--vc-radius);
    background: var(--vc-ink);
}

.video-call__tile video {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--vc-ink);
}
.video-call__tile[data-video="off"] video { visibility: hidden; }
/* Your own picture reads like a mirror; what the opponent receives is not flipped. */
.video-call__tile--self video[data-mirror="true"] { transform: scaleX(-1); }

.video-call__placeholder {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    box-sizing: border-box;
    text-align: center;
    color: rgba(255, 255, 255, .82);
    background: radial-gradient(circle at 50% 38%, #2c2620 0, var(--vc-ink) 72%);
}
.video-call__tile[data-video="on"] .video-call__placeholder { display: none; }
/* Keep the sentence clear of the name label in the corner. */
.video-call__tile--peer .video-call__placeholder { padding-bottom: 30px; }
.video-call__avatar { width: 34px; height: 34px; flex: 0 0 auto; opacity: .7; }
.video-call__tile--self .video-call__avatar { width: 26px; height: 26px; }

.video-call__status {
    margin: 0;
    max-width: 100%;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    color: #fff;
    overflow-wrap: anywhere;
}
.video-call__status:empty { display: none; }

.video-call__label,
.video-call__live,
.video-call__badge {
    position: absolute;
    z-index: 2;
    background: rgba(12, 10, 8, .66);
    color: #fff;
}
.video-call__label {
    left: 6px;
    bottom: 6px;
    max-width: calc(100% - 44px);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.video-call__label:empty { display: none; }
.video-call__badge {
    right: 6px;
    bottom: 6px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: #ffb4ad;
}
.video-call__badge svg { width: 14px; height: 14px; }

/* The "Video battle" entry on the Play screen: an inline icon in the slot the font icons use. */
.tp-play-mode__svg > svg { display: block; width: 1.15em; height: 1.15em; }

/* "Video battle" on a table in the lobby and on Watch Live: said before a seat is taken. */
.tp-video-battle-badge {
    flex: 0 0 auto;
    justify-self: start;
    align-self: center;
    padding: 1px 7px;
    border: 1px solid color-mix(in srgb, var(--tp-color-primary, #d4a24c) 46%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--tp-color-primary, #d4a24c) 14%, transparent);
    color: var(--tp-color-text, inherit);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .05em;
    line-height: 1.6;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Connection of the call: 3 bars good, 2 fair, 1 weak. The count carries the
   meaning; the colour only repeats it (ui/video-quality.js). */
.video-call__quality {
    position: absolute;
    z-index: 2;
    top: 6px;
    right: 6px;
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 22px;
    padding: 5px 7px;
    border-radius: 999px;
    box-sizing: border-box;
    background: rgba(12, 10, 8, .66);
    color: #fff;
}
.video-call__quality[hidden] { display: none; }
.video-call__quality > i {
    display: block;
    width: 3px;
    border-radius: 1px;
    background: currentColor;
    opacity: .32;
}
.video-call__quality > i:nth-child(1) { height: 5px; }
.video-call__quality > i:nth-child(2) { height: 8px; }
.video-call__quality > i:nth-child(3) { height: 12px; }
.video-call__quality[data-level] > i:nth-child(1),
.video-call__quality[data-level="fair"] > i:nth-child(2),
.video-call__quality[data-level="good"] > i { opacity: 1; }
.video-call__quality[data-level="fair"] { color: #ffd98a; }
.video-call__quality[data-level="poor"] { color: #ffb4ad; }

/* What is live right now, in words. The dot is red only while something is. */
.video-call__live {
    left: 6px;
    top: 6px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: calc(100% - 12px);
    padding: 3px 8px 3px 6px;
    border-radius: 999px;
    box-sizing: border-box;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;
}
.video-call__live > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.video-call__dot {
    flex: 0 0 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .5);
}
:is(.video-call__live, .video-call-chip)[data-live="true"] .video-call__dot {
    background: #ff5146;
    box-shadow: 0 0 0 2px rgba(255, 81, 70, .28);
}
/* Small pictures of what is live, for tiles too narrow for the sentence. */
.video-call__live-icon { display: none; flex: 0 0 12px; width: 12px; height: 12px; }
.video-call__live[data-live-kind^="cam"] .video-call__live-icon--cam,
.video-call__live[data-live-kind$="mic"] .video-call__live-icon--mic { display: block; }
.video-call__tile--self { container-type: inline-size; }
@container (min-width: 170px) {
    .video-call__live[data-live="true"] .video-call__live-icon { display: none; }
}
@container (max-width: 169.98px) {
    .video-call__live[data-live="true"] > span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }
    /* Nothing is live: the struck-through camera in the tile already says so. */
    .video-call__live[data-live="false"] { display: none; }
}

/* The same statement on top of whatever covers the dock: the result card, or
   the "turn your phone upright" notice (z-index 9999999). */
.video-call-chip[hidden] { display: none !important; }
.video-call-chip {
    position: fixed;
    z-index: 10000000;
    top: max(8px, calc(env(safe-area-inset-top, 0px) + 4px));
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 16px);
    padding: 4px 4px 4px 12px;
    box-sizing: border-box;
    border-radius: 999px;
    background: rgba(12, 10, 8, .88);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .5);
}
.video-call-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-call-chip > button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--vc-end, #c4342b);
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
}
.video-call-chip > button svg { width: 20px; height: 20px; }
.video-call-chip > button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── controls ─────────────────────────────────────────────────────────────── */
.video-call__controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 0;
}

.video-call__btn {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: var(--vc-btn);
    height: var(--vc-btn);
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--tp-color-border-strong, rgba(236, 231, 223, .28));
    border-radius: 50%;
    background: var(--tp-color-surface-raised, #232120);
    color: var(--tp-color-text, #ece7df);
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.video-call__btn[hidden] { display: none; }
.video-call__icon { width: 22px; height: 22px; pointer-events: none; }
.video-call__btn .video-call__icon--off,
.video-call__btn[aria-pressed="false"] .video-call__icon--on { display: none; }
.video-call__btn[aria-pressed="false"] .video-call__icon--off { display: block; }
/* Off is said twice: a struck-through icon and a tinted button. */
.video-call__btn[aria-pressed="false"] {
    border-color: color-mix(in srgb, var(--tp-color-danger, #e0776f) 55%, transparent);
    background: color-mix(in srgb, var(--tp-color-danger, #e0776f) 16%, var(--tp-color-surface-raised, #232120));
    color: var(--tp-color-danger, #e0776f);
}
.video-call__btn--end {
    border-color: var(--vc-end);
    background: var(--vc-end);
    color: #fff;
}
.video-call__btn:disabled { opacity: .5; cursor: default; }
.video-call__btn:focus-visible {
    outline: 2px solid var(--tp-color-primary, #d2a75e);
    outline-offset: 2px;
}
@media (hover: hover) {
    .video-call__btn:not(:disabled):hover { filter: brightness(1.08); }
}
@media (prefers-reduced-motion: no-preference) {
    .video-call__btn { transition: transform 100ms ease-out, background-color 140ms ease-out; }
    .video-call__btn:not(:disabled):active { transform: scale(.95); }
}

/* ── the opponent's offer ─────────────────────────────────────────────────── */
.video-call-invite {
    position: fixed;
    z-index: 10015;
    top: calc(max(8px, env(safe-area-inset-top, 0px) + 4px) + 64px);
    left: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 12px;
    align-items: start;
    max-width: 440px;
    margin-inline: auto;
    padding: 14px;
    box-sizing: border-box;
    border: 1px solid var(--tp-color-border-strong, rgba(236, 231, 223, .28));
    border-radius: var(--tp-radius-md, 16px);
    background: var(--tp-color-surface-raised, #232120);
    color: var(--tp-color-text, #ece7df);
    box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .5);
}
.video-call-invite__icon {
    width: 24px;
    height: 24px;
    margin-top: 2px;
    color: var(--tp-color-primary, #d2a75e);
}
.video-call-invite__copy { display: grid; gap: 4px; min-width: 0; }
.video-call-invite__copy strong { font-size: 15px; font-weight: 700; line-height: 1.3; }
.video-call-invite__copy small {
    font-size: 13px;
    line-height: 1.4;
    color: var(--tp-color-text-muted, #ada69b);
}
.video-call-invite__actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.video-call-invite__actions button {
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--tp-color-border-strong, rgba(236, 231, 223, .28));
    border-radius: var(--tp-control-radius, 14px);
    background: transparent;
    color: var(--tp-color-text, #ece7df);
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}
.video-call-invite__actions button.primary {
    border-color: var(--tp-color-primary, #d2a75e);
    background: var(--tp-color-primary, #d2a75e);
    color: var(--tp-color-primary-ink, #171208);
}
.video-call-invite__actions button:focus-visible {
    outline: 2px solid var(--tp-color-primary, #d2a75e);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: no-preference) {
    .video-call-invite:not([hidden]) { animation: video-call-invite-in 220ms cubic-bezier(.23, 1, .32, 1); }
    @keyframes video-call-invite-in {
        from { opacity: 0; transform: translateY(-8px); }
        to { opacity: 1; transform: none; }
    }
}
@media (min-width: 1100px) {
    .video-call-invite { top: 64px; left: auto; right: 28px; width: 380px; margin-inline: 0; }
}

/* ── the menu entry ───────────────────────────────────────────────────────── */
#game-menu-overlay .game-menu-item > .game-menu-item__svg {
    flex: 0 0 22px;
    width: 22px;
    height: 18px;
    color: var(--tp-color-primary, #c49a61);
}

/* ==========================================================================
   Placement on the game screen. Only while a call exists.
   ========================================================================== */

/* ── phone portrait: a row of its own between the player strip and the actions ── */
@media (max-width: 600px) {
    html[data-theme] body.game-active #screen-game.active.video-call-on {
        grid-template-rows: calc(var(--game-bar-offset) + 58px) auto auto minmax(0, 1fr) auto auto auto !important;
    }
    #screen-game.video-call-on > .video-call {
        grid-column: 1;
        grid-row: 6;
        width: calc(100vw - 4px);
        margin-inline: 2px;
    }
    #screen-game.video-call-on > .game-mobile-actions { grid-row: 7; }
    /* The board keeps its own look and simply takes the height that is left. */
    html[data-theme] body.game-active #screen-game.active.video-call-on .board-stage .board-layout { min-height: 0; }
}

/* Short phones: cameras and controls side by side, so the board keeps its height. */
@media (max-width: 600px) and (max-height: 700px) {
    #screen-game.video-call-on { --vc-btn: 44px; --vc-tile-h: 92px; }
    #screen-game.video-call-on > .video-call {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        padding: 0;
    }
    #screen-game.video-call-on .video-call__controls {
        display: grid;
        grid-template-columns: repeat(2, var(--vc-btn));
        gap: 4px;
    }
    #screen-game.video-call-on .video-call__tiles { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
    #screen-game.video-call-on .video-call__avatar { width: 22px; height: 22px; }
    #screen-game.video-call-on .video-call__status { font-size: 11px; }
    /* A tile this small holds the sentence or the silhouette, not both. */
    #screen-game.video-call-on .video-call__tile--peer[data-status="true"] .video-call__avatar { display: none; }
    #screen-game.video-call-on .video-call__tile--peer .video-call__placeholder { padding: 4px 4px 28px; }
}

/* ── tablet portrait ──────────────────────────────────────────────────────── */
@media (min-width: 600.02px) and (max-width: 1099.98px) and (orientation: portrait) {
    /* --vc-chrome: the app bar, both player strips and the status line. */
    #screen-game.video-call-on { --vc-tile-h: 200px; --vc-dock-h: 266px; --vc-chrome: 190px; }
    html[data-theme] body.game-active #screen-game.active.video-call-on {
        grid-template-rows: auto auto auto minmax(0, 1fr) auto auto !important;
        align-content: stretch !important;
    }
    #screen-game.video-call-on > .video-call {
        grid-column: 1;
        grid-row: 6;
        width: min(calc(100vw - 8px), 720px);
        margin-inline: auto;
        padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    }
    html[data-theme] #screen-game.video-call-on .board-layout {
        width: min(calc(100vw - 8px), calc((100dvh - var(--vc-chrome) - var(--vc-dock-h)) * 1.62)) !important;
    }
}
@media (min-width: 600.02px) and (max-width: 767px) and (orientation: portrait) {
    #screen-game.video-call-on { --vc-chrome: 214px; }
}

/* ── wide screens and landscape: a column to the right of the board ───────── */
@media (min-width: 1100px), (min-width: 600.02px) and (max-width: 1099.98px) and (orientation: landscape) {
    #screen-game.video-call-on > .video-call {
        grid-row: 4;
        justify-self: end;
        align-self: center;
        z-index: 2;
        width: var(--vc-side-w);
        max-height: 100%;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: stretch;
    }
    #screen-game.video-call-on .video-call__tiles {
        display: contents;
    }
    #screen-game.video-call-on .video-call__tile--peer {
        grid-column: 1 / -1;
        aspect-ratio: 4 / 3;
    }
    #screen-game.video-call-on .video-call__tile--self { min-height: 92px; }
    #screen-game.video-call-on .video-call__controls {
        display: grid;
        grid-template-columns: repeat(2, 44px);
        gap: 4px;
        --vc-btn: 44px;
        align-content: center;
    }
    html[data-theme] #screen-game.video-call-on #tab-board {
        padding-right: calc(var(--vc-side-w) + 14px) !important;
        box-sizing: border-box !important;
    }
}
@media (min-width: 1100px) {
    #screen-game.video-call-on > .video-call { grid-column: 2; }
}
@media (min-width: 600.02px) and (max-width: 1099.98px) and (orientation: landscape) {
    #screen-game.video-call-on { --vc-side-w: 200px; }
    #screen-game.video-call-on > .video-call { grid-column: 1; margin-right: 4px; }
    html[data-theme] #screen-game.video-call-on .board-layout {
        width: min(calc(100vw - 22px - var(--vc-side-w)), calc((100dvh - 246px) * 1.62)) !important;
    }
}
/* A phone on its side never gets here: the game screen is replaced by the
   "turn your phone upright" notice (#portrait-lock-overlay). The call stays
   up underneath, which is why .video-call-chip is drawn above that notice. */
