/* ============================================================
   Viewer skin — smoked-glass override (desktop only)
   Consumes hooks defined upstream in 360-VIEWER:
     --p360-sidebar-bg / -backdrop-filter / -border-left
     --p360-toolbar-bg / -border-bottom / -backdrop-filter
     --p360-info-bar-bg / -border / -backdrop-filter
     --p360-toggle-btn-bg / -border / -backdrop-filter
   No-op defaults upstream preserve mobile and other consumers.
   See docs/THEMING.md in the viewer repo for the override-slot
   convention.
   ============================================================ */

@media (min-width: 769px) {
    /* ----- Sidebar surface ----- */
    .p360-sidebar[data-theme="dark"] {
        --p360-sidebar-bg: rgba(12, 14, 20, 0.62);
        --p360-sidebar-backdrop-filter: blur(28px) saturate(160%);
        --p360-sidebar-border-left: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    }
    .p360-sidebar[data-theme="light"] {
        --p360-sidebar-bg: rgba(248, 250, 252, 0.68);
        --p360-sidebar-backdrop-filter: blur(24px) saturate(140%);
        --p360-sidebar-border-left: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 8px 32px rgba(15, 23, 42, 0.18);

        /* Boost light-mode text contrast.
           Upstream slate-500/400 greys read as washed-out on the glass
           background. Override the token layer so section headings,
           count pills, chevrons, and toolbar icons all go darker in
           one shot without hunting individual selectors. */
        --p360-text: #0a0a0a;
        --p360-text-muted: #1f2937;   /* section titles, toolbar icons */
        --p360-text-dim: #374151;     /* count pill text, chevrons */
        --p360-border: rgba(0, 0, 0, 0.18);
        --p360-border-strong: rgba(0, 0, 0, 0.32);
        --p360-hover-bg: rgba(0, 0, 0, 0.09);
    }

    /* ----- Toolbar (top of sidebar) -----
       Inherits the sidebar's blur — keep its own background transparent
       so it reads as one continuous glass surface. The bottom border
       softens to a hairline divider. */
    .p360-sidebar[data-theme="dark"] .p360-toolbar {
        --p360-toolbar-bg: transparent;
        --p360-toolbar-border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }
    .p360-sidebar[data-theme="light"] .p360-toolbar {
        --p360-toolbar-bg: transparent;
        --p360-toolbar-border-bottom: 1px solid rgba(15, 23, 42, 0.06);
    }

    /* ----- Info bar (bottom prev/next) -----
       Independent floating bar (not inside sidebar) — gets its own
       glass treatment so it visually rhymes with the sidebar. */
    body .p360-info-bar {
        --p360-info-bar-bg: rgba(12, 14, 20, 0.55);
        --p360-info-bar-backdrop-filter: blur(20px) saturate(150%);
        --p360-info-bar-border: 1px solid rgba(255, 255, 255, 0.08);
    }

    /* ----- Toggle button (floating top-right) -----
       Same glass language, smaller blur for the smaller surface. */
    .p360-sidebar-toggle {
        --p360-toggle-btn-bg: rgba(12, 14, 20, 0.55);
        --p360-toggle-btn-border: 1px solid rgba(255, 255, 255, 0.12);
        --p360-toggle-btn-backdrop-filter: blur(16px) saturate(150%);
    }
}

/* When the sidebar is collapsed, the toggle becomes a circular
   "open sidebar" affordance (both desktop + mobile). The icon class
   swap to `ph-sidebar-simple` is handled by gallery-integration.js
   so the glyph reads as "reveal panel from the right" rather than a
   generic hamburger. Viewer's base rule is 44x44 so border-radius
   alone is enough to render a perfect circle; expanded state keeps
   the viewer's native 8px rounded-rect. */
.p360-sidebar-toggle[aria-expanded="false"] {
    border-radius: 9999px !important;
}

/* ============================================================
   Info bar — fully pilled shape (all screen sizes)
   Vendor default is border-radius 14px on the bar and 8px on
   the prev/next nav buttons; override to a true pill + circular
   buttons. The dropup trigger (.p360-dropup-trigger) is styled
   in dropup-menu.css and gets the same circular treatment.
   ============================================================ */

/* Desktop only — on mobile the bar is docked flat (border-radius: 0
   from the vendor's mobile rule). */
@media (min-width: 481px) {
    body .p360-info-bar {
        border-radius: 9999px !important;
    }
}
body .p360-info-bar .p360-info-nav {
    border-radius: 50% !important;
}

/* ============================================================
   Fullscreen — hide gallery-level overlays
   Mirrors the viewer's own :fullscreen rules in phong-360-ui.css
   so the auth chip, report button, and reaction picker vanish
   when the user double-clicks to enter fullscreen mode.
   ============================================================ */

:fullscreen #gallery-top-bar,
:fullscreen #reaction-picker-mount {
    display: none !important;
}

/* On mobile, the gallery-top-bar (auth chip + hamburger menu) is
   pinned at z-index:10000 — well above the sidebar (z-index:200).
   When the sidebar is opened on mobile it should fully cover the
   viewport, so hide the top-bar while the sidebar is open. Desktop
   is unaffected (sidebar opens alongside, not over). */
@media (max-width: 768px) {
    body:has(.p360-sidebar.p360-sidebar--open) #gallery-top-bar {
        display: none !important;
    }
}

/* ============================================================
   Responsive sidebar width + grid density (desktop only)
   Mobile (≤480) and tablet (481–768) keep the viewer's own
   responsive rules. Desktop bumps width and grid min-tile-size
   in tiers so the auto-fill grid flips to 2 columns naturally
   once (sidebar - padding) / min-tile ≥ 2.
   ============================================================ */

@media (min-width: 769px) and (max-width: 1279px) {
    .p360-sidebar {
        --p360-sidebar-width: 360px;
    }
}

@media (min-width: 1280px) and (max-width: 1599px) {
    .p360-sidebar {
        --p360-sidebar-width: 440px;
    }
    .p360-sidebar .p360-grid {
        --p360-grid-min-width: 200px;
    }
}

@media (min-width: 1600px) {
    .p360-sidebar {
        --p360-sidebar-width: 520px;
    }
    .p360-sidebar .p360-grid {
        --p360-grid-min-width: 220px;
    }
}

/* ============================================================
   Discover header — glassmorphic title pill

   Pill style matches the title <h2> wherever it lives — either
   inside `.p360-header` (engine default markup) or inside
   `.p360-toolbar` (after gallery-integration.js relocates it).
   The `:is(.p360-header, .p360-toolbar) > .p360-header-title`
   selector covers both. Profile pages nest the title under
   .p360-header-profile > .p360-header-info, so the `>`
   combinator excludes them and they keep their native styling.

   No glow/shadow per project rule (memory:
   feedback_no_glow_effects). The pill uses border +
   backdrop-filter for depth — no insets, no bloom.
   ============================================================ */

/* When JS relocates the title into the toolbar, .p360-header
   becomes empty — collapse it. Applies at all widths so mobile
   doesn't render a phantom empty row either. */
.p360-sidebar .p360-header[data-empty="true"] {
    display: none;
}

/* Tighten the discover header — sized for title+subtitle, but we now
   only carry the pill. :has() scopes this to the discover layout
   (direct-child title) so profile headers, which nest the title under
   .p360-header-profile, keep their original generous padding.
   Border-bottom dropped entirely so the pill floats clean against the
   sections below. */
.p360-sidebar .p360-header:has(> .p360-header-title) {
    padding: 4px 12px 6px;
    border-bottom: none;
}

.p360-sidebar :is(.p360-header, .p360-toolbar) > .p360-header-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 8px 8px;
    margin: 0;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
    line-height: 1;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.96);
    text-decoration: none;
    cursor: pointer;

    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.10);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.p360-sidebar :is(.p360-header, .p360-toolbar) > a.p360-header-title:hover {
    background: rgba(0, 0, 0, 0.42);
    border-color: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.p360-sidebar :is(.p360-header, .p360-toolbar) > a.p360-header-title:active {
    transform: scale(0.97);
    background: rgba(0, 0, 0, 0.55);
}

.p360-sidebar :is(.p360-header, .p360-toolbar) > a.p360-header-title:focus-visible {
    outline: 2px solid var(--p360-accent, #e13e13);
    outline-offset: 2px;
}

.p360-sidebar :is(.p360-header, .p360-toolbar) > .p360-header-title::before {
    content: "";
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background-image: url('/static/img/360-hextile-logo.png');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.p360-sidebar[data-theme="light"] :is(.p360-header, .p360-toolbar) > .p360-header-title {
    color: rgba(15, 23, 42, 0.92);
    background:
        linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.55) 0%,
            rgba(255, 255, 255, 0.30) 40%,
            rgba(255, 255, 255, 0.20) 62%,
            rgba(255, 255, 255, 0.40) 100%
        );
    border-color: rgba(15, 23, 42, 0.10);
}

.p360-sidebar[data-theme="light"] :is(.p360-header, .p360-toolbar) > .p360-header-title::before {
    filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.20));
}

/* ============================================================
   Toolbar one-row layout (when title pill lives inside it)

   Activates only when JS has marked the toolbar with
   data-gallery-relocated="true" — so we don't accidentally
   restyle the toolbar before the title relocation runs, and
   so contexts where relocation isn't applied keep the engine
   default toolbar layout.

   Right-padding clears the floating .p360-sidebar-toggle caret
   (top:12 right:12, 44px wide). The actions group is pushed
   to the right by margin-left:auto, leaving space between the
   title pill and the action buttons.
   ============================================================ */

.p360-sidebar .p360-toolbar[data-gallery-relocated="true"] {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 13px 64px 12px 12px;
    position: relative; /* anchor for the mobile dropdown */
}

.p360-sidebar .p360-toolbar[data-gallery-relocated="true"] .gallery-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* Kebab + dropdown wrapper — present at all widths in the DOM, but the
   wrapper is hidden on desktop so actions render inline in the toolbar. */
.p360-sidebar .gallery-toolbar-kebab-wrap {
    position: relative;
    margin-left: auto;
    display: inline-flex;
}

@media (min-width: 769px) {
    .p360-sidebar .gallery-toolbar-kebab-wrap {
        display: none;
    }
}

/* ============================================================
   Mobile (≤768px) — engine action bar hidden, replaced by a
   labeled menu inside the dropdown. JS builds the menu rows
   in gallery-integration.js (_renderMobileMenu).
   ============================================================ */

@media (max-width: 768px) {
    /* Hide the engine action bar on mobile — labeled menu replaces it. */
    .p360-sidebar .p360-toolbar[data-gallery-relocated="true"] .gallery-toolbar-actions {
        display: none;
    }

    .p360-sidebar .gallery-toolbar-kebab {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border-radius: 999px;
        background: rgba(0, 0, 0, 0.28);
        border: 1px solid rgba(255, 255, 255, 0.10);
        color: rgba(255, 255, 255, 0.85);
        font-size: 20px;
        cursor: pointer;
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        transition: background 0.15s ease, color 0.15s ease;
    }

    .p360-sidebar .gallery-toolbar-kebab:hover {
        color: #fff;
        background: rgba(0, 0, 0, 0.45);
    }

    .p360-sidebar .gallery-toolbar-dropdown {
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        z-index: 5;
        padding: 6px;
        border-radius: 14px;
        background: rgba(0, 0, 0, 0.55);
        border: 1px solid rgba(255, 255, 255, 0.10);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
    }

    .p360-sidebar .gallery-toolbar-dropdown[hidden] {
        display: none;
    }

    /* Labeled menu — replaces the icon-button stack. */
    .p360-sidebar .gallery-toolbar-menu {
        list-style: none;
        margin: 0;
        padding: 0;
        min-width: 220px;
    }

    .p360-sidebar .gallery-toolbar-menu li {
        display: flex;
        align-items: center;
        gap: 12px;
        height: 44px;
        padding: 0 14px;
        border-radius: 10px;
        color: rgba(255, 255, 255, 0.92);
        font-size: 14px;
        cursor: pointer;
        transition: background 0.12s ease;
        white-space: nowrap;
    }

    .p360-sidebar .gallery-toolbar-menu li:hover,
    .p360-sidebar .gallery-toolbar-menu li:active {
        background: rgba(255, 255, 255, 0.08);
    }

    .p360-sidebar .gallery-toolbar-menu li > i:first-child {
        font-size: 18px;
        opacity: 0.85;
        flex-shrink: 0;
        width: 20px;
        text-align: center;
    }

    .p360-sidebar .gallery-toolbar-menu .label {
        flex: 1;
    }

    .p360-sidebar .gallery-toolbar-menu .value {
        opacity: 0.65;
        font-size: 13px;
    }

    .p360-sidebar .gallery-toolbar-menu .caret {
        font-size: 14px;
        opacity: 0.55;
        transition: transform 0.15s ease;
    }

    .p360-sidebar .gallery-toolbar-menu li[data-expanded="true"] .caret {
        transform: rotate(180deg);
    }

    /* Inline submenu (resolution chooser) */
    .p360-sidebar .gallery-toolbar-submenu {
        list-style: none;
        margin: 2px 0 4px;
        padding: 0;
    }

    .p360-sidebar .gallery-toolbar-submenu li {
        display: flex;
        align-items: center;
        height: 36px;
        padding: 0 14px 0 46px;
        border-radius: 8px;
        font-size: 13px;
        color: rgba(255, 255, 255, 0.78);
        cursor: pointer;
        transition: background 0.12s ease;
    }

    .p360-sidebar .gallery-toolbar-submenu li:hover,
    .p360-sidebar .gallery-toolbar-submenu li:active {
        background: rgba(255, 255, 255, 0.06);
    }

    .p360-sidebar .gallery-toolbar-submenu li[aria-current="true"] {
        color: rgba(255, 255, 255, 1);
        font-weight: 600;
    }

    /* Light theme parity for the kebab + dropdown surfaces. */
    .p360-sidebar[data-theme="light"] .gallery-toolbar-kebab {
        background: rgba(255, 255, 255, 0.55);
        border-color: rgba(15, 23, 42, 0.10);
        color: rgba(15, 23, 42, 0.80);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-kebab:hover {
        color: rgba(15, 23, 42, 0.95);
        background: rgba(255, 255, 255, 0.75);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-menu li {
        color: rgba(15, 23, 42, 0.92);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-menu li:hover,
    .p360-sidebar[data-theme="light"] .gallery-toolbar-menu li:active {
        background: rgba(15, 23, 42, 0.06);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-submenu li {
        color: rgba(15, 23, 42, 0.78);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-submenu li[aria-current="true"] {
        color: rgba(15, 23, 42, 1);
    }

    .p360-sidebar[data-theme="light"] .gallery-toolbar-dropdown {
        background: rgba(248, 250, 252, 0.80);
        border-color: rgba(15, 23, 42, 0.10);
    }
}

/* ============================================================
   Gallery avatar chip (inside .p360-info-bar)
   Injected as a child of the viewer's info bar by
   gallery-integration.js. Positioned between the prev nav
   arrow and the title/subtitle text block. Inherits the info
   bar's glass background and its fullscreen hiding for free
   (no extra :fullscreen rule needed here — see info-bar-avatar
   plan, Stage-level decision 9).
   ============================================================ */

.p360-info-bar .gallery-avatar-chip {
    display: inline-flex;
    align-items: center;
    /* The info bar is a flex row (set by the viewer's own stylesheet). The
       chip is a flex child, so lock it against shrinking/stretching so the
       avatar stays round and the name doesn't squash when the bar narrows. */
    align-self: center;
    flex-shrink: 0;
    gap: 8px;
    height: 40px;
    padding: 0 14px 0 6px;
    margin: 0 6px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    max-width: 160px;
    transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.p360-info-bar .gallery-avatar-chip:hover,
.p360-info-bar .gallery-avatar-chip:focus-visible {
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
    outline: none;
}

.p360-info-bar .gallery-avatar-chip__img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
}

.p360-info-bar .gallery-avatar-chip__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Light-theme counterpart — mirrors the info bar's light treatment */
.p360-info-bar[data-theme="light"] .gallery-avatar-chip,
body[data-theme="light"] .p360-info-bar .gallery-avatar-chip {
    border-color: rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.04);
    color: rgba(15, 23, 42, 0.70);
}

.p360-info-bar[data-theme="light"] .gallery-avatar-chip:hover,
body[data-theme="light"] .p360-info-bar .gallery-avatar-chip:hover {
    border-color: rgba(15, 23, 42, 0.22);
    background: rgba(15, 23, 42, 0.08);
    color: rgba(15, 23, 42, 0.95);
}

/* ============================================================
   Info-bar action buttons — react (smiley) + config download
   Same glass language as the avatar chip. Circular icon-only
   buttons sit between the title/subtitle and the next arrow.
   Hidden in fullscreen via the existing .p360-info-bar rule.
   ============================================================ */

.p360-info-bar .gallery-infobar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin: 0 2px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.75);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.p360-info-bar .gallery-infobar-btn:hover,
.p360-info-bar .gallery-infobar-btn:focus-visible {
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
    outline: none;
}

.p360-info-bar .gallery-infobar-btn:active {
    transform: scale(0.94);
}

.p360-info-bar .gallery-infobar-btn--react:hover {
    color: #fbbf24;
}

.p360-info-bar .gallery-infobar-btn--config:hover {
    color: #e13e13;
}

.p360-info-bar[data-theme="light"] .gallery-infobar-btn,
body[data-theme="light"] .p360-info-bar .gallery-infobar-btn {
    border-color: rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.04);
    color: rgba(15, 23, 42, 0.70);
}

.p360-info-bar[data-theme="light"] .gallery-infobar-btn:hover,
body[data-theme="light"] .p360-info-bar .gallery-infobar-btn:hover {
    border-color: rgba(15, 23, 42, 0.22);
    background: rgba(15, 23, 42, 0.08);
    color: rgba(15, 23, 42, 0.95);
}

/* ============================================================
   Inline reaction chips — Discord-style emoji + count pills
   Rendered to the right of the React button by
   gallery-integration.js (_buildReactionStrip). Clicking a
   chip routes through the shared Alpine reactionPicker so
   optimistic updates and the 3-per-user cap are enforced
   in one place.
   ============================================================ */

.p360-info-bar .gallery-reaction-strip {
    display: inline-flex;
    align-items: center;
    align-self: center;
    flex-shrink: 1;
    min-width: 0;
    gap: 6px;
    margin: 0 2px;
    overflow: hidden;
}

.p360-info-bar .gallery-reaction-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    gap: 6px;
    height: 40px;
    padding: 0 12px 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.p360-info-bar .gallery-reaction-chip:hover,
.p360-info-bar .gallery-reaction-chip:focus-visible {
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.98);
    outline: none;
}

.p360-info-bar .gallery-reaction-chip:active {
    transform: scale(0.94);
}

.p360-info-bar .gallery-reaction-chip__emoji {
    font-size: 17px;
    line-height: 1;
}

.p360-info-bar .gallery-reaction-chip__count {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* Active = viewer has reacted with this emoji. Brand-orange tint
   so the "you already voted for this" signal is unmistakable. */
.p360-info-bar .gallery-reaction-chip--active {
    border-color: rgba(225, 62, 19, 0.45);
    background: rgba(225, 62, 19, 0.12);
    color: rgba(255, 255, 255, 0.98);
}

.p360-info-bar .gallery-reaction-chip--active:hover,
.p360-info-bar .gallery-reaction-chip--active:focus-visible {
    border-color: rgba(225, 62, 19, 0.65);
    background: rgba(225, 62, 19, 0.18);
}

/* Light theme */
.p360-info-bar[data-theme="light"] .gallery-reaction-chip,
body[data-theme="light"] .p360-info-bar .gallery-reaction-chip {
    border-color: rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.04);
    color: rgba(15, 23, 42, 0.75);
}

.p360-info-bar[data-theme="light"] .gallery-reaction-chip:hover,
body[data-theme="light"] .p360-info-bar .gallery-reaction-chip:hover {
    border-color: rgba(15, 23, 42, 0.22);
    background: rgba(15, 23, 42, 0.08);
    color: rgba(15, 23, 42, 0.95);
}

.p360-info-bar[data-theme="light"] .gallery-reaction-chip--active,
body[data-theme="light"] .p360-info-bar .gallery-reaction-chip--active {
    border-color: rgba(225, 62, 19, 0.55);
    background: rgba(225, 62, 19, 0.14);
    color: rgba(15, 23, 42, 0.98);
}

/* ============================================================
   Info-bar — uniform 40px module height
   Overrides the viewer's 28×28 prev/next nav arrows to match the
   gallery's 40px module height so every interactive child of
   .p360-info-bar sits on a single horizontal baseline.
   ============================================================ */

body .p360-info-bar .p360-info-nav {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 18px;
}

/* Prev + Next are repositioned by JS into a left-anchored paired
   cluster. Tighter internal gap reads as one control. */
.p360-info-bar .gallery-nav-cluster {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-right: 4px;
    flex-shrink: 0;
}

/* ============================================================
   View-count pill — read-only 👁 count indicator
   Same pill shape as reaction chips but non-interactive and
   de-emphasized so it reads as meta, not an action.
   ============================================================ */

.p360-info-bar .gallery-viewcount-pill {
    display: inline-flex;
    align-items: center;
    align-self: center;
    flex-shrink: 0;
    gap: 6px;
    height: 40px;
    padding: 0 12px 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
    color: rgba(255, 255, 255, 0.55);
    font-size: 13px;
    line-height: 1;
    cursor: default;
    pointer-events: auto;
}

.p360-info-bar .gallery-viewcount-pill__icon {
    font-size: 16px;
}

.p360-info-bar .gallery-viewcount-pill__count {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.p360-info-bar[data-theme="light"] .gallery-viewcount-pill,
body[data-theme="light"] .p360-info-bar .gallery-viewcount-pill {
    border-color: rgba(15, 23, 42, 0.08);
    background: rgba(15, 23, 42, 0.03);
    color: rgba(15, 23, 42, 0.55);
}

/* ============================================================
   Copy-share-URL button — brand-orange flash on successful copy
   Reuses .gallery-infobar-btn base (40×40 circle). The --copied
   modifier is applied for 1500ms after clipboard.writeText resolves.
   ============================================================ */

.p360-info-bar .gallery-infobar-btn--share:hover {
    color: rgba(255, 255, 255, 0.95);
}

.p360-info-bar .gallery-infobar-btn--copied {
    border-color: rgba(225, 62, 19, 0.55);
    background: rgba(225, 62, 19, 0.14);
    color: #fff;
}

/* ============================================================
   Selected thumbnail — neutral outline per theme
   Upstream uses --p360-accent (brand orange) for the selected
   outline. In the gallery we want a neutral contrast ring:
   bright white on dark, near-black on light.
   ============================================================ */

/* Cancel the upstream outline (which paints outside the box and
   visually enlarges the thumbnail). Draw the selection ring +
   lighten overlay on a ::after layer that sits above the <img>
   and strictly inside the thumbnail's clipped box. */
.p360-thumbnail--selected {
    outline: none;
}

.p360-thumbnail--selected::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 2px solid transparent;
    border-radius: inherit;
    box-sizing: border-box;
}

.p360-sidebar[data-theme="dark"] .p360-thumbnail--selected::after {
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.18);
}

.p360-sidebar[data-theme="light"] .p360-thumbnail--selected::after {
    border-color: #111111;
    background: rgba(255, 255, 255, 0.32);
}

/* ============================================================
   Section teaser row
   A 4-thumbnail preview strip that sits directly under a
   collapsed section's heading. Vanishes when the section is
   expanded (the real grid takes over). Mirrors the main
   thumbnail's 2:1 aspect and radius, at a reduced scale.
   ============================================================ */

.gallery-teaser-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 0 12px 10px;
    margin-top: -4px;
    max-height: 120px;
    opacity: 1;
    overflow: hidden;
    transition:
        max-height 0.3s ease,
        opacity 0.2s ease,
        padding 0.3s ease,
        margin 0.3s ease;
}

/* Hide the teaser when the section is expanded — the full grid
   already shows everything, the teaser would be redundant. */
.p360-section:not(.p360-section--collapsed) > .gallery-teaser-row {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    pointer-events: none;
}

.gallery-teaser-thumb {
    all: unset;
    position: relative;
    display: block;
    aspect-ratio: 2 / 1;
    border-radius: calc(var(--p360-thumbnail-radius, 6px) - 2px);
    overflow: hidden;
    cursor: pointer;
    background: var(--p360-hover-bg, rgba(255, 255, 255, 0.06));
    transition: transform 0.18s ease, outline-color 0.18s ease;
    outline: 1px solid transparent;
    outline-offset: 0;
}

.gallery-teaser-thumb:hover {
    transform: scale(1.04);
    z-index: 1;
}

.gallery-teaser-thumb:focus-visible {
    outline-width: 2px;
}

.p360-sidebar[data-theme="dark"] .gallery-teaser-thumb:hover,
.p360-sidebar[data-theme="dark"] .gallery-teaser-thumb:focus-visible {
    outline-color: rgba(255, 255, 255, 0.85);
}

.p360-sidebar[data-theme="light"] .gallery-teaser-thumb:hover,
.p360-sidebar[data-theme="light"] .gallery-teaser-thumb:focus-visible {
    outline-color: rgba(17, 17, 17, 0.85);
}

.gallery-teaser-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ============================================================
   Creator avatar username nametag
   Upstream renders .p360-avatar-name below the circle as plain
   text. We reposition it as a compact badge that overlaps the
   bottom-center of the avatar circle — tiny but readable, with
   a solid 2px drop shadow offset so it reads like a pinned tag.
   ============================================================ */

.p360-avatar-row .p360-avatar-item {
    position: relative;
    /* Give the badge room below so it doesn't get clipped by
       the row's overflow or collide with the next item. */
    padding-bottom: 14px;
    gap: 0;
}

.p360-avatar-row .p360-avatar-name {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    max-width: 72px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.p360-sidebar[data-theme="dark"] .p360-avatar-row .p360-avatar-name {
    background: #ffffff;
    color: #111111;
    box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.75);
}

.p360-sidebar[data-theme="light"] .p360-avatar-row .p360-avatar-name {
    background: #111111;
    color: #ffffff;
    box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.35);
}

/* ============================================================
   Help modal
   Triggered by the viewer's toolbar '?' button via the
   p360-help CustomEvent. Glass panel that rhymes with the
   sidebar — theme inherited from <html data-theme>.
   ============================================================ */

.gallery-help {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.18s ease;
}

.gallery-help[hidden] { display: none; }

.gallery-help.gallery-help--open { opacity: 1; }

.gallery-help-panel {
    width: 100%;
    max-width: 460px;
    padding: 28px 28px 22px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(18, 20, 26, 0.78);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
    color: #f4f4f5;
    transform: translateY(8px) scale(0.985);
    transition: transform 0.22s ease;
}

.gallery-help--open .gallery-help-panel {
    transform: none;
}

.gallery-help-title {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.gallery-help-list {
    list-style: none;
    margin: 0 0 22px;
    padding: 0;
    display: grid;
    gap: 10px;
    font-size: 14px;
    line-height: 1.45;
    color: rgba(244, 244, 245, 0.92);
}

.gallery-help-list li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.gallery-help-list i {
    flex-shrink: 0;
    width: 22px;
    text-align: center;
    font-size: 18px;
    line-height: 1.4;
    color: #e13e13;
}

.gallery-help-list strong {
    font-weight: 600;
    color: #ffffff;
}

.gallery-help-divider {
    height: 1px;
    margin: 4px 0 16px;
    background: rgba(255, 255, 255, 0.1);
}

.gallery-help-setting {
    margin-bottom: 22px;
}

.gallery-help-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.gallery-help-switch-text {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
}

.gallery-help-switch-text i {
    width: 22px;
    text-align: center;
    font-size: 18px;
    color: #e13e13;
}

.gallery-help-switch-control {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.gallery-help-switch-control input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.gallery-help-switch-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    transition: background 0.18s ease;
}

.gallery-help-switch-track::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.18s ease;
}

.gallery-help-switch-control input:checked + .gallery-help-switch-track {
    background: #e13e13;
}

.gallery-help-switch-control input:checked + .gallery-help-switch-track::before {
    transform: translateX(18px);
}

.gallery-help-switch-control input:focus-visible + .gallery-help-switch-track {
    outline: 2px solid rgba(225, 62, 19, 0.7);
    outline-offset: 2px;
}

.gallery-help-setting-desc {
    margin: 8px 0 0;
    padding-left: 32px;
    font-size: 12.5px;
    line-height: 1.4;
    color: rgba(244, 244, 245, 0.62);
}

.gallery-help-close {
    all: unset;
    display: block;
    width: 100%;
    padding: 11px 0;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #ffffff;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.gallery-help-close:hover {
    background: rgba(225, 62, 19, 0.18);
    border-color: rgba(225, 62, 19, 0.45);
}

/* Light-theme variant — key off <html data-theme> set by the
   pre-paint script + gallery-integration. */
[data-theme="light"] .gallery-help {
    background: rgba(255, 255, 255, 0.55);
}

[data-theme="light"] .gallery-help-panel {
    background: rgba(250, 250, 252, 0.82);
    border-color: rgba(15, 23, 42, 0.12);
    color: #0a0a0a;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
}

[data-theme="light"] .gallery-help-list {
    color: rgba(10, 10, 10, 0.88);
}

[data-theme="light"] .gallery-help-list strong {
    color: #000000;
}

[data-theme="light"] .gallery-help-close {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.18);
    color: #0a0a0a;
}

[data-theme="light"] .gallery-help-close:hover {
    background: rgba(225, 62, 19, 0.12);
    border-color: rgba(225, 62, 19, 0.55);
}

[data-theme="light"] .gallery-help-divider {
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .gallery-help-switch-track {
    background: rgba(0, 0, 0, 0.22);
}

[data-theme="light"] .gallery-help-switch-control input:checked + .gallery-help-switch-track {
    background: #e13e13;
}

[data-theme="light"] .gallery-help-setting-desc {
    color: rgba(10, 10, 10, 0.6);
}

/* ============================================================
   Mobile (≤ 480px): tighten gallery-specific children of the
   info bar to fit the docked layout from the vendor.
   - Avatar chip stays visible with the user's name.
   - Reaction chips are collapsed under the React (smiley) button,
     which gets a count badge. Tap the smiley to open the picker.
   ============================================================ */
@media (max-width: 480px) {
    /* Pull the floating top-bar (hamburger + auth chip) and the
       sidebar toggle closer to the top and side edges. Tailwind
       defaults to top-4 left-4 (16px); 6px reads as snug-to-edge
       without being clipped by rounded phone corners. */
    #gallery-top-bar {
        top: 6px;
        left: 6px;
    }
    .p360-sidebar-toggle {
        top: 6px;
        right: 6px;
    }

    /* Bar layout: drop space-between so the title (flex: 1) handles
       spacing, pushing the smiley + dropup to the right edge. */
    body .p360-info-bar {
        justify-content: flex-start;
    }

    /* Avatar chip — tighter padding but keep the name. */
    .p360-info-bar .gallery-avatar-chip {
        height: 36px;
        padding: 0 10px 0 4px;
        margin: 0;
        gap: 6px;
        max-width: 140px;
        font-size: 12px;
    }
    .p360-info-bar .gallery-avatar-chip__img {
        width: 28px;
        height: 28px;
    }

    /* Re-show the title block (vendor mobile rule hides it). The
       text fills the gap between the avatar and the right-side
       smiley + dropup buttons. */
    .p360-info-bar .p360-info-text {
        display: flex;
        text-align: left;
        padding: 0 8px;
        min-width: 0;
    }
    .p360-info-bar .p360-info-title {
        font-size: 12px;
    }
    .p360-info-bar .p360-info-subtitle {
        font-size: 10px;
    }

    /* Action buttons: 40 → 36 */
    .p360-info-bar .gallery-infobar-btn {
        width: 36px;
        height: 36px;
        margin: 0;
        font-size: 18px;
    }

    /* Hide the inline reaction strip — its data is summarized as a
       count badge on the smiley button (see _updateReactionStrip). */
    .p360-info-bar .gallery-reaction-strip {
        display: none;
    }

    /* Float prev/next out of the bar's flex flow and span them
       across its full width, ~8px above the top edge. The bar is
       position:fixed so the cluster anchors relative to it. */
    .p360-info-bar .gallery-nav-cluster {
        position: absolute;
        left: 8px;
        right: 8px;
        bottom: calc(100% + 8px);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0;
        margin: 0;
        padding: 0;
        pointer-events: none;
        z-index: 1;
    }

    /* Each floating arrow gets its own glass surface — they're no
       longer inside the bar's pane so they need standalone backing. */
    .p360-info-bar .gallery-nav-cluster .p360-info-nav {
        pointer-events: auto;
        width: 36px;
        height: 36px;
        background: rgba(12, 14, 20, 0.55);
        backdrop-filter: blur(16px) saturate(150%);
        -webkit-backdrop-filter: blur(16px) saturate(150%);
        border: 1px solid rgba(255, 255, 255, 0.12);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    }

    body[data-theme="light"] .p360-info-bar .gallery-nav-cluster .p360-info-nav {
        background: rgba(248, 250, 252, 0.80);
        border-color: rgba(15, 23, 42, 0.10);
    }
}

/* ============================================================
   Reaction-count badge on the React (smiley) button
   Visible on mobile (where the inline strip is hidden) and as a
   subtle indicator on desktop too. Set via JS:
     react.dataset.reactionCount = "3"   → shows badge
     delete react.dataset.reactionCount  → hides badge
   ============================================================ */
.p360-info-bar .gallery-infobar-btn--react {
    position: relative;
}
.p360-info-bar .gallery-infobar-btn--react[data-reaction-count]::after {
    content: attr(data-reaction-count);
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #e13e13;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 0 0 2px rgba(12, 14, 20, 0.85);
}
body[data-theme="light"] .p360-info-bar .gallery-infobar-btn--react[data-reaction-count]::after {
    box-shadow: 0 0 0 2px rgba(248, 250, 252, 0.95);
}
