/* Shared profile FAB: circle = pill height, shoulder/torso icon */
:root {
    --sg-toolbar-btn-h: 46px;
    --sg-pill-h: var(--sg-toolbar-btn-h);
}

@media (max-width: 768px) {
    :root {
        --sg-toolbar-btn-h: 44px;
        --sg-pill-h: var(--sg-toolbar-btn-h);
    }
}

/* Shared top toolbar — Cast, Chapters header, overlays (FRONTEND_DESIGN_SYSTEM.md) */
.inv-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: clamp(6px, 2vw, 12px);
    align-items: center;
    width: 100%;
    min-height: var(--sg-toolbar-btn-h);
    padding-inline-end: max(6px, env(safe-area-inset-right, 0px));
    scroll-padding-inline-end: max(10px, env(safe-area-inset-right, 0px));
}

.inv-toolbar::-webkit-scrollbar {
    display: none;
}

/* Back — solid pink circle + white arrow (idle); gray shimmer via .sg-btn-deleting */
button.inv-back-btn {
    flex: 0 0 auto;
    width: var(--sg-toolbar-btn-h);
    min-width: var(--sg-toolbar-btn-h);
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
    padding: 0;
    border-radius: 50%;
    border: 2px solid #ec4899;
    background-color: #ec4899;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M15 6l-6 6 6 6' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 42%;
    cursor: pointer;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

button.inv-back-btn:hover:not(:disabled):not(.sg-btn-deleting) {
    background-color: #db2777;
    border-color: #db2777;
}

button.inv-back-btn:focus-visible {
    outline: 2px solid #ec4899;
    outline-offset: 2px;
}

button.inv-back-btn:disabled:not(.sg-btn-deleting) {
    opacity: 0.85;
    cursor: wait;
}

button.inv-back-btn.inv-back-btn--compact {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
}

/* Close — same pink circle, white X (overlays that dismiss, not navigate) */
button.inv-back-btn.inv-back-btn--close {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-size: 46%;
}

.inv-toolbar .inv-back-btn,
.profile-toolbar-row .inv-back-btn {
    touch-action: manipulation;
}

/* All toolbar pills + icon buttons: one shared height */
.inv-toolbar .btn-big.inv-txt,
.inv-toolbar .btn-big.btn-big--solid-pink,
.inv-toolbar .btn-big.inv-toolbar-cta {
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
    padding-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
    font-size: 0.95rem;
    line-height: 1.15;
}

.inv-toolbar .btn-big.inv-txt {
    flex: 0 0 auto;
    min-width: clamp(64px, 14vw, 88px);
    padding: 10px clamp(8px, 2.5vw, 18px);
}

@media (min-width: 769px) {
    .inv-toolbar .btn-big.inv-txt,
    .inv-toolbar .btn-big.btn-big--solid-pink,
    .inv-toolbar .btn-big.inv-toolbar-cta {
        font-size: 1rem;
    }

    .inv-toolbar .btn-big.inv-txt {
        flex: 1 1 0;
        min-width: 72px;
        padding: 12px 18px;
    }

    #navEpisodeRow .btn-big.inv-txt {
        flex: 0 0 auto;
        min-width: clamp(72px, 10vw, 96px);
    }
}

.inv-toolbar .header-profile-btn,
.actions-row-with-profile .header-profile-btn {
    margin-left: auto;
    flex: 0 0 auto;
    width: var(--sg-toolbar-btn-h);
    min-width: var(--sg-toolbar-btn-h);
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
}

.inv-toolbar .btn-ico {
    flex: 0 0 auto;
    width: var(--sg-toolbar-btn-h);
    min-width: var(--sg-toolbar-btn-h);
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
    padding: 0;
    box-sizing: border-box;
}

.inv-toolbar .btn-ico.sparkles {
    width: var(--sg-toolbar-btn-h);
    min-width: var(--sg-toolbar-btn-h);
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
}

.inv-toolbar .scene-view-switcher {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 1.5vw, 8px);
    min-width: 0;
}

/* Primary action (CREATE, NEW EPISODE) — pinned right before profile when row fits */
.inv-toolbar .inv-toolbar-cta {
    margin-left: auto;
    flex: 0 0 auto !important;
}

/* Help or profile after CTA: keep trailing cluster together */
.inv-toolbar .inv-toolbar-cta + .header-profile-btn,
.inv-toolbar .inv-toolbar-cta + .header-help-btn {
    margin-left: auto;
}
.inv-toolbar .header-help-btn + .header-profile-btn {
    margin-left: 0;
}

.inv-ico-group {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: clamp(4px, 1.5vw, 8px);
    flex: 0 0 auto;
    align-items: center;
}

.projects-shell {
    --sg-toolbar-btn-h: 46px;
    --sg-pill-h: var(--sg-toolbar-btn-h);
}

@media (max-width: 768px) {
    .projects-shell {
        --sg-toolbar-btn-h: 44px;
        --sg-pill-h: var(--sg-toolbar-btn-h);
    }
}

button.header-profile-btn {
    flex: 0 0 var(--sg-pill-h);
    width: var(--sg-pill-h);
    height: var(--sg-pill-h);
    min-width: var(--sg-pill-h);
    min-height: var(--sg-pill-h);
    padding: 0;
    border-radius: 50%;
    border: 2px solid #f3a6c7;
    background: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    overflow: hidden;
}

/* Help — purple square > white square > upright “i” (left of profile) */
button.header-help-btn {
    flex: 0 0 auto;
    width: calc(var(--sg-pill-h) + 4px);
    height: calc(var(--sg-pill-h) + 4px);
    min-width: calc(var(--sg-pill-h) + 4px);
    min-height: calc(var(--sg-pill-h) + 4px);
    padding: 7px;
    margin: 0;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
button.header-help-btn .header-help-btn-inner {
    width: 100%;
    height: 100%;
    border-radius: 5px;
    border: 2px solid #fff;
    background: transparent;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: calc(var(--sg-pill-h) * 0.38);
    font-weight: 800;
    font-style: normal;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    box-sizing: border-box;
}
button.header-help-btn:hover {
    filter: brightness(1.06);
}
button.header-help-btn:focus-visible {
    outline: 2px solid #ec4899;
    outline-offset: 2px;
}
.inv-toolbar .header-help-btn,
.actions-row-with-profile .header-help-btn {
    margin-left: auto;
}
.inv-toolbar .header-help-btn + .header-profile-btn,
.actions-row-with-profile .header-help-btn + .header-profile-btn {
    margin-left: 0;
}
.projects-header-row .header-help-btn {
    margin-left: 0;
}

.sg-profile-btn-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    line-height: 1;
    pointer-events: none;
}

button.header-profile-btn svg {
    width: calc(var(--sg-pill-h) * 0.38);
    height: calc(var(--sg-pill-h) * 0.38);
    display: block;
    color: #9d174d;
    flex-shrink: 0;
    transform: translateY(-2px);
}

.sg-profile-credits {
    font-size: clamp(9px, 1.85vw, 11px);
    font-weight: 800;
    color: #9d174d;
    letter-spacing: -0.03em;
    line-height: 1;
    margin-top: -1px;
    max-width: calc(var(--sg-pill-h) - 8px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sg-profile-credits[hidden] {
    display: none;
}

button.header-profile-btn.sg-profile-has-credits svg {
    width: calc(var(--sg-pill-h) * 0.34);
    height: calc(var(--sg-pill-h) * 0.34);
    transform: translateY(-3px);
}

button.header-profile-btn:hover {
    background: #fff7fb;
    border-color: #ec4899;
}

button.header-profile-btn:focus-visible {
    outline: 2px solid #ec4899;
    outline-offset: 2px;
}

@keyframes sg-profile-attention {
    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(236, 72, 153, 0);
    }
    33% {
        transform: scale(1.06);
        box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.35);
    }
    66% {
        transform: scale(1.03);
        box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.2);
    }
}

@keyframes sg-profile-attention-soft {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.65;
    }
}

.header-profile-btn.sg-profile-attention-active {
    animation: sg-profile-attention 0.48s ease-in-out 3;
}

@media (prefers-reduced-motion: reduce) {
    .header-profile-btn.sg-profile-attention-active {
        animation: sg-profile-attention-soft 0.6s ease-in-out 3;
    }
}

.actions-row-with-profile {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    width: 100%;
}

.top-actions.actions-row-with-profile {
    flex-direction: row;
}

.actions-row-with-profile .btn-big {
    flex: 1 1 auto;
    min-width: 0;
}

.profile-toolbar-row .btn-big,
.projects-header-row .btn-big {
    height: var(--sg-toolbar-btn-h);
    min-height: var(--sg-toolbar-btn-h);
    max-height: var(--sg-toolbar-btn-h);
    padding-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
}

/* Profile button user display */
.sg-profile-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ec4899;
    color: #fff;
    font-size: 0.88rem;
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0;
}

.projects-profile-btn .sg-profile-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}

.sg-profile-name-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: 1.1;
    min-width: 0;
    overflow: hidden;
}

.sg-profile-home-credits {
    font-size: 0.72rem;
    font-weight: 700;
    color: #9d174d;
    letter-spacing: 0.02em;
    text-transform: none;
    margin-top: 2px;
    line-height: 1.1;
}

.sg-profile-home-credits[hidden] {
    display: none;
}

.projects-profile-btn.sg-profile-home-has-credits {
    padding-top: 8px;
    padding-bottom: 8px;
}

@media (max-width: 768px) {
    .projects-profile-btn .sg-profile-name {
        max-width: 88px;
    }
}
