/*
 * Forum/topic theater rail integration.
 *
 * The current Tides of War phpBB shell places #page-body directly inside
 * .tow-main-wrap. Earlier theater-context rules assumed an extra .wrap inside
 * #page-body, which no longer exists. Keep the shared portal activity component,
 * but lay it out against the DOM phpBB actually renders.
 */
body.section-viewforum:has(.tow-theater-context) #page-body,
body.section-viewtopic:has(.tow-theater-context) #page-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 286px;
    column-gap: 30px;
    align-items: start;
}

body.section-viewforum:has(.tow-theater-context) #page-body > .tow-theater-context,
body.section-viewtopic:has(.tow-theater-context) #page-body > .tow-theater-context {
    grid-column: 1 / -1;
}

.tow-theater-context-activity-host {
    position: static;
    z-index: auto;
    grid-column: 2;
    grid-row: 2 / span 20;
    width: 286px !important;
    min-width: 0;
    align-self: start;
}

.tow-theater-context-activity-host .tow-theater-destination {
    background: transparent;
}

.tow-theater-context-activity-host .tow-theater-activity {
    position: sticky;
    top: 20px;
    width: 100%;
}

body.section-viewforum:has(.tow-theater-context) #page-body > :not(.tow-theater-context):not(.tow-theater-context-activity-host),
body.section-viewtopic:has(.tow-theater-context) #page-body > :not(.tow-theater-context):not(.tow-theater-context-activity-host) {
    grid-column: 1;
    min-width: 0;
    width: 100%;
}

/* The forum header and controls should not inherit a stale reduced width from
 * the first-generation absolute-rail implementation. */
body.section-viewforum:has(.tow-theater-context) .tow-forum-header,
body.section-viewforum:has(.tow-theater-context) .tow-topic-controls,
body.section-viewforum:has(.tow-theater-context) .tow-topic-directory,
body.section-viewforum:has(.tow-theater-context) .tow-topic-directory-footer,
body.section-viewforum:has(.tow-theater-context) .tow-forum-online,
body.section-viewtopic:has(.tow-theater-context) #page-body > :not(.tow-theater-context):not(.tow-theater-context-activity-host) {
    max-width: none;
}

@media (max-width: 980px) {
    body.section-viewforum:has(.tow-theater-context) #page-body,
    body.section-viewtopic:has(.tow-theater-context) #page-body {
        display: block;
    }

    .tow-theater-context-activity-host {
        position: static;
        width: 100% !important;
        margin: -8px 0 26px;
    }

    .tow-theater-context-activity-host .tow-theater-activity {
        position: static;
        width: 100%;
    }

    body.section-viewforum:has(.tow-theater-context) #page-body > :not(.tow-theater-context):not(.tow-theater-context-activity-host),
    body.section-viewtopic:has(.tow-theater-context) #page-body > :not(.tow-theater-context):not(.tow-theater-context-activity-host) {
        width: 100%;
    }
}
