/* Shared sheet + modal chrome. sheet.js adds the classes:
 *   html.tg-sheet-lock    background scroll lock while any layer is open
 *   .tg-sheet-overlay     every registered overlay
 *   .tg-sheet-panel       its panel
 *   .tg-sheet-docked      the panel sits on the bottom edge (a real sheet)
 *   .tg-sheet-dragging    a drag is in progress
 * --tg-sheet-progress (0..1) fades the backdrop as the sheet is pulled down.
 * --tg-vvh / --tg-kb come from visualViewport while a layer is open. */

html.tg-sheet-lock,
html.tg-sheet-lock body {
    overflow: hidden !important;
    overscroll-behavior: none;
}

.tg-sheet-overlay {
    overscroll-behavior: contain;
    -webkit-tap-highlight-color: transparent;
}
/* Backdrop follows the drag: the scrim lightens as the sheet goes down. */
.tg-sheet-overlay.tg-sheet-docked {
    opacity: 1;
    transition: background-color var(--tg-sheet-fade, 0.22s) ease, backdrop-filter var(--tg-sheet-fade, 0.22s) ease;
}
.tg-sheet-overlay.tg-sheet-docked.tg-sheet-dragging { transition: none; }
.tg-sheet-overlay.tg-sheet-docked[style*="--tg-sheet-progress"] {
    background-color: rgba(36, 24, 20, calc(0.45 * (1 - var(--tg-sheet-progress, 0))));
    -webkit-backdrop-filter: blur(calc(6px * (1 - var(--tg-sheet-progress, 0))));
    backdrop-filter: blur(calc(6px * (1 - var(--tg-sheet-progress, 0))));
}

.tg-sheet-panel {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    outline: none;
}
.tg-sheet-panel:focus-visible { outline: none; }

/* One look for every bottom sheet: same radius, handle, shadow, safe area. */
html body .tg-sheet-panel.tg-sheet-docked {
    border-radius: 28px 28px 0 0;
    box-shadow: 0 -10px 28px rgba(36, 24, 20, 0.16);
    padding-bottom: calc(1.15rem + env(safe-area-inset-bottom, 0px));
    max-height: min(92vh, 92dvh, calc(var(--tg-vvh, 100dvh) - 24px - env(safe-area-inset-top, 0px)));
    touch-action: pan-y;
    will-change: transform;
    animation: tg-sheet-in 0.34s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
html body .tg-sheet-panel.tg-sheet-docked.tg-sheet-dragging { user-select: none; -webkit-user-select: none; }
html body .tg-sheet-panel.tg-sheet-docked > .sheet-grab,
html body .tg-sheet-panel.tg-sheet-docked > .credits-sheet-grab {
    display: block;
    width: 42px;
    height: 5px;
    border-radius: 99px;
    background: rgba(27, 42, 74, 0.22);
    margin: 0.2rem auto 0.7rem;
    flex-shrink: 0;
    touch-action: none;
    position: relative;
}
/* Bigger invisible hit area on the handle. */
html body .tg-sheet-panel.tg-sheet-docked > .sheet-grab::before,
html body .tg-sheet-panel.tg-sheet-docked > .credits-sheet-grab::before {
    content: '';
    position: absolute;
    inset: -14px -40px;
}
html[data-daypart="night"] body .tg-sheet-panel.tg-sheet-docked > .sheet-grab,
html[data-daypart="night"] body .tg-sheet-panel.tg-sheet-docked > .credits-sheet-grab {
    background: rgba(255, 246, 234, 0.32);
}

/* Keyboard open: the overlay lifts the sheet above it. */
html.tg-sheet-kb .tg-sheet-overlay.tg-sheet-docked {
    padding-bottom: var(--tg-kb, 0px);
}
html.tg-sheet-kb body .tg-sheet-panel.tg-sheet-docked {
    padding-bottom: 1rem;
}

@keyframes tg-sheet-in {
    from { transform: translate3d(0, 100%, 0); }
    to { transform: translate3d(0, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
    html body .tg-sheet-panel.tg-sheet-docked { animation: none; will-change: auto; }
    .tg-sheet-overlay.tg-sheet-docked { transition: none; }
}
html.face-reduced body .tg-sheet-panel.tg-sheet-docked { animation: none; }

/* Contributor breakdown was a floating card stuck to the bottom edge;
   it is a sheet like the rest now. */
#contributor-analytics-overlay .contributor-analytics-dialog {
    max-width: 480px;
    width: 100%;
    border-radius: 28px 28px 0 0;
    background: var(--cream);
    color: var(--ink);
    padding: 0.35rem 1.15rem calc(1.15rem + env(safe-area-inset-bottom, 0px));
    max-height: min(92vh, 92dvh);
}

/* Desktop: every sheet is a centered card, like Your plan already was. */
@media (min-width: 1024px) {
    html body .credits-overlay.tg-sheet-overlay,
    html body .lib-detail-overlay.tg-sheet-overlay,
    html body .story-detail-overlay.tg-sheet-overlay {
        align-items: center;
        padding: 2rem 1rem;
    }
    html body .credits-overlay.tg-sheet-overlay > .tg-sheet-panel,
    html body .lib-detail-overlay.tg-sheet-overlay > .tg-sheet-panel,
    html body .story-detail-overlay.tg-sheet-overlay > .tg-sheet-panel {
        border-radius: 28px;
        max-height: min(86vh, 780px);
        box-shadow: 0 24px 64px rgba(27, 42, 74, 0.16), 0 4px 16px rgba(27, 42, 74, 0.08);
        animation: dialog-pop-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    html body .tg-sheet-overlay > .tg-sheet-panel:not(.tg-sheet-docked) > .sheet-grab,
    html body .tg-sheet-overlay > .tg-sheet-panel:not(.tg-sheet-docked) > .credits-sheet-grab {
        visibility: hidden;
        height: 0.4rem;
        margin: 0;
    }
}
