/**
 * Top bar coach — tablet (768–1180px), navegador y PWA.
 * Misma UX que desktop; safe-area y densidad como en PWA instalada.
 */
@media (min-width: 768px) and (max-width: 1180px) {
    :root {
        --app-top-bar-offset: calc(var(--app-top-bar-height) + env(safe-area-inset-top, 0px));
    }

    .app-top-bar {
        padding: env(safe-area-inset-top, 0px) max(10px, env(safe-area-inset-right, 0px)) 0
            max(12px, env(safe-area-inset-left, 0px));
        gap: 8px;
        height: var(--app-top-bar-offset);
        min-height: var(--app-top-bar-offset);
        align-items: center;
        box-sizing: border-box;
    }

    #app-top-bar-brand {
        flex-shrink: 0;
    }

    .rtp-brand--topbar {
        margin-right: 2px;
    }

    .rtp-brand--topbar svg {
        width: min(160px, 20vw);
        max-width: 160px;
    }

    #vue-top-bar-app.top-bar-vue-mount {
        position: relative;
        flex: 1;
        min-width: 0;
        width: 100%;
        gap: 4px 8px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr);
        grid-template-areas: "left center right";
        align-items: center;
    }

    #vue-top-bar-app .top-bar-left {
        grid-area: left;
        justify-self: start;
    }

    #vue-top-bar-app .top-bar-right {
        grid-area: right;
        justify-self: end;
    }

    .top-bar-left,
    .top-bar-right {
        gap: 6px;
        min-width: 0;
        position: relative;
        z-index: 2;
        overflow: visible;
    }

    .top-bar-nav-vue {
        max-width: min(240px, 36vw);
        min-width: 8.75rem;
    }

    .top-bar-nav-trigger {
        min-width: 8.75rem;
        padding: 7px 10px 7px 12px;
        font-size: 0.74rem;
        gap: 6px;
    }

    .top-bar-nav-menu {
        min-width: max(100%, 16.25rem);
        padding: 7px;
    }

    .top-bar-nav-item {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .topbar-players-btn {
        padding: 6px 10px;
        font-size: 0.66rem;
        gap: 5px;
        flex-shrink: 0;
    }

    /* Centro en columna propia: no solapa nav ni JUGADORES (dominio tablet) */
    #vue-top-bar-app .top-bar-center {
        grid-area: center;
        position: static;
        left: auto;
        top: auto;
        transform: none;
        z-index: 1;
        justify-self: center;
        width: max-content;
        max-width: min(28vw, 220px);
        margin: 0 auto;
        padding: 0 4px;
        pointer-events: none;
    }

    #vue-top-bar-app .top-bar-center:has(.top-bar-team-mode) ~ .top-bar-right .top-bar-coach-name {
        display: none;
    }

    /* Pizarra en vivo: más espacio a la izquierda (nav + JUGADORES visibles) */
    #vue-top-bar-app:has(#topbar-players-btn:not([style*="display: none"])) {
        grid-template-columns: minmax(0, 1.2fr) minmax(0, auto) minmax(0, 0.8fr);
    }

    #vue-top-bar-app:has(#topbar-players-btn:not([style*="display: none"])) .top-bar-center {
        max-width: min(24vw, 190px);
    }

    .top-bar-team-mode {
        display: block;
        width: 100%;
        font-size: clamp(0.66rem, 1.5vw, 0.78rem);
        line-height: 1.2;
    }

    .top-bar-coach-name {
        max-width: min(20vw, 120px);
        font-size: clamp(0.66rem, 1.5vw, 0.78rem);
    }

    .top-bar-coach-name--center {
        max-width: min(34vw, 280px);
        font-size: clamp(0.72rem, 1.8vw, 0.86rem);
    }

    .topbar-room-badge {
        padding: 5px 9px;
        gap: 6px;
        flex-shrink: 0;
    }

    .topbar-room-badge__label {
        font-size: 0.56rem;
        letter-spacing: 0.03em;
    }

    .topbar-projection-btn--solo {
        margin-right: 2px;
    }

    .topbar-projection-btn {
        width: 34px;
        height: 34px;
        flex-shrink: 0;
    }

    /* Contenido coach alineado bajo la barra efectiva (igual PWA / Safari) */
    #lobby {
        top: var(--app-top-bar-offset);
    }

    #game-screen {
        top: var(--app-top-bar-offset);
    }

    #coach-menu-container {
        top: calc(var(--app-top-bar-offset) + 12px);
    }

    .game-container {
        min-height: calc(100vh - var(--app-top-bar-offset));
    }

    .game-workshop-shell {
        min-height: calc(100vh - var(--app-top-bar-offset));
    }

    .game-workshop-shell.creation-workshop-open {
        height: calc(100vh - var(--app-top-bar-offset));
        min-height: calc(100vh - var(--app-top-bar-offset));
    }

    .creation-editor-panel {
        top: var(--app-top-bar-offset);
    }

    .creation-defense-toggle {
        top: calc(var(--app-top-bar-offset) + 12px);
    }

    .creation-defense-panel {
        top: calc(var(--app-top-bar-offset) + 56px);
    }

    .auth-screen,
    .dashboard-screen {
        top: var(--app-top-bar-offset);
    }
}
