/* ==========================================================================
   Mobile contextual TabBar — States 2 / 3 / 4 styling
   harnessing-iphone-flotilla S2 — Modal Parity Wave 1
   --------------------------------------------------------------------------
   Pairs with mobile-modal-states.js. The bottom band's shell (height,
   safe-area, border-top, z-index 11000) is owned by mobile-tab-bar.css; this
   file styles the state-specific payload that lands inside it.

   States:
     state-2-story  — playback scrubber + chapter nav + speed + close
     state-3-bio    — playback scrubber + chapter nav + Read|Listen + close
     state-4-umi    — 5 outward affordances (Heart Principle canonical)

   The bar's outer height grows for States 2/3 so the elide row +
   scrubber row + control row all fit comfortably above the safe-area inset.
   State 4 stays at the canonical 56pt content height (single row of
   evenly-distributed 5 affordances).
   ========================================================================== */

@media (max-width: 767px) {

    /* ── Stateful bar — kill State-1's flexbox row layout ── */
    .mobile-tab-bar.mobile-tab-bar-stateful {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        padding: 0;
        background: rgba(18, 18, 22, 0.97);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        color: #f5f6f8;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
    }

    /* ── State 2 + 3 (playback) — three-row band ── */
    .mobile-tab-bar.mobile-tab-bar-state-2-story,
    .mobile-tab-bar.mobile-tab-bar-state-3-bio {
        height: calc(140px + var(--mobile-safe-area-bottom, 0px));
        padding-bottom: var(--mobile-safe-area-bottom, 0px);
    }

    /* Subtle warm-amber accent treatment so the user reads it as a
       temporal-context state, distinct from State-1's neutral surface. */
    .mobile-tab-bar.mobile-tab-bar-state-2-story::before,
    .mobile-tab-bar.mobile-tab-bar-state-3-bio::before {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(180deg, rgba(255, 204, 0, 0.04) 0%, rgba(255, 204, 0, 0) 60%);
        pointer-events: none;
    }

    .mobile-tab-bar.mobile-tab-bar-state-3-bio::before {
        /* Bio state — slightly warmer tint to differentiate visually */
        background: linear-gradient(180deg, rgba(167, 139, 250, 0.05) 0%, rgba(167, 139, 250, 0) 60%);
    }

    .ctxbar-row {
        display: flex;
        align-items: center;
        position: relative;
        z-index: 1;
        padding: 0 12px;
        min-height: 0;
    }

    .ctxbar-row-elide {
        height: 26px;
        font-size: 12px;
        line-height: 1.2;
        color: rgba(245, 246, 248, 0.78);
        letter-spacing: 0.01em;
        font-feature-settings: 'tnum';
    }

    .ctxbar-elide-text {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ctxbar-elide-text strong {
        color: #f5f6f8;
        font-weight: 600;
    }

    .ctxbar-row-scrub {
        height: 38px;
        gap: 8px;
    }

    .ctxbar-time {
        font-size: 11px;
        font-variant-numeric: tabular-nums;
        font-feature-settings: 'tnum';
        color: rgba(245, 246, 248, 0.7);
        min-width: 32px;
        text-align: center;
    }

    .ctxbar-scrubber {
        flex: 1;
        appearance: none;
        -webkit-appearance: none;
        height: 4px;
        background: rgba(255, 255, 255, 0.18);
        border-radius: 2px;
        outline: none;
        margin: 0;
        padding: 0;
    }

    .ctxbar-scrubber::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: #ffcc00;
        border: 2px solid rgba(0, 0, 0, 0.35);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
        cursor: pointer;
    }

    .ctxbar-scrubber::-moz-range-thumb {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: #ffcc00;
        border: 2px solid rgba(0, 0, 0, 0.35);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
        cursor: pointer;
    }

    .mobile-tab-bar-state-3-bio .ctxbar-scrubber::-webkit-slider-thumb,
    .mobile-tab-bar-state-3-bio .ctxbar-scrubber::-moz-range-thumb {
        background: #a78bfa; /* indigo for Bio state */
    }

    .ctxbar-row-controls {
        height: 64px;
        gap: 4px;
        justify-content: space-around;
    }

    .ctxbar-row-controls .ctxbar-btn {
        flex: 1 1 0;
    }

    /* ── State 4 (UMI) — single 56pt row of 6 evenly-distributed affordances ──
       2026-05-10 (meticulous-tailoring-canvas S3): added Constellation slot
       per UMI Heart Principle clause #4 (Issue #5). flex basis 0 so 6 buttons
       distribute equally regardless of label width. */
    .mobile-tab-bar.mobile-tab-bar-state-4-umi {
        flex-direction: row;
        align-items: stretch;
        justify-content: space-around;
        padding: 0;
    }
    .mobile-tab-bar.mobile-tab-bar-state-4-umi .ctxbar-btn {
        flex: 1 1 0;
        min-width: 0;
    }
    .mobile-tab-bar.mobile-tab-bar-state-4-umi .ctxbar-btn .ctxbar-label {
        font-size: 9px;
    }

    /* ── Common ctxbar-btn (shared across States 2/3/4) ── */
    .ctxbar-btn {
        appearance: none;
        background: none;
        border: none;
        color: rgba(245, 246, 248, 0.85);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 44px;
        min-width: 44px;
        padding: 4px 6px;
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.02em;
        position: relative;
    }
    .ctxbar-btn:active {
        background: rgba(255, 255, 255, 0.08);
        border-radius: 8px;
    }
    .ctxbar-btn[disabled],
    .ctxbar-btn[aria-disabled="true"] {
        opacity: 0.4;
        cursor: not-allowed;
    }
    .ctxbar-btn .ctxbar-ico {
        width: 24px;
        height: 24px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .ctxbar-btn .ctxbar-ico svg {
        width: 24px;
        height: 24px;
    }
    .ctxbar-btn .ctxbar-label {
        font-size: 10px;
        line-height: 1;
        letter-spacing: 0.02em;
        max-height: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    /* Play button — outsize the icon as the visual anchor of the controls row */
    .ctxbar-row-controls .ctxbar-play .ctxbar-ico,
    .ctxbar-row-controls .ctxbar-play .ctxbar-ico svg {
        width: 30px;
        height: 30px;
    }
    .ctxbar-play {
        color: #ffcc00;
    }
    .mobile-tab-bar-state-3-bio .ctxbar-play {
        color: #a78bfa;
    }

    /* Speed slot — show value (1.0×, 1.25×, 1.5×, 2.0×) prominently */
    .ctxbar-speed-value {
        font-size: 13px;
        font-weight: 700;
        color: #ffcc00;
        line-height: 1;
        font-variant-numeric: tabular-nums;
    }

    /* Read|Listen toggle — indigo accent (Bio state) */
    .ctxbar-readlisten {
        color: #a78bfa;
    }
    .ctxbar-readlisten .ctxbar-ico svg {
        color: #a78bfa;
    }

    /* Back-stack badge (depth > 1) */
    .ctxbar-back-stack {
        position: relative;
    }
    .ctxbar-back-stack .ctxbar-badge {
        position: absolute;
        top: 2px;
        right: 6px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: #ef4444;
        color: #ffffff;
        font-size: 11px;
        font-weight: 700;
        line-height: 18px;
        text-align: center;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    }

    /* Close — slightly muted vs other affordances */
    .ctxbar-close {
        color: rgba(245, 246, 248, 0.65);
    }

    /* ── Stateful bar hides MCP slots since they live in State 1 ── */
    .mobile-tab-bar.mobile-tab-bar-stateful .mcp-slot,
    .mobile-tab-bar.mobile-tab-bar-stateful .mcp-bookend,
    .mobile-tab-bar.mobile-tab-bar-stateful .mcp-cancel-btn,
    .mobile-tab-bar.mobile-tab-bar-stateful .mcp-done-btn,
    .mobile-tab-bar.mobile-tab-bar-stateful .mobile-tab-item {
        display: none !important;
    }
}

/* Desktop never renders contextual states */
@media (min-width: 768px) {
    .mobile-tab-bar.mobile-tab-bar-stateful {
        display: none !important;
    }
}
