/* =========================================================================
   Recall theme — 3 of 4: components
   First the Bootstrap components, themed through their own --bs-* variables;
   then Recall's shared components (the partials and repeated patterns).
   ========================================================================= */

/* =========================================================================
   Bootstrap components
   ========================================================================= */

/* ---- Buttons ------------------------------------------------------------- */

.btn {
    --bs-btn-font-family: var(--tvdb-font-ui);
    --bs-btn-font-size: var(--tvdb-text-sm);
    --bs-btn-font-weight: 500;
    --bs-btn-border-radius: var(--tvdb-radius-md);
    --bs-btn-disabled-opacity: 0.55;
}

.btn-sm {
    --bs-btn-font-size: var(--tvdb-text-xs);
    --bs-btn-border-radius: var(--tvdb-radius-md);
}

.btn-lg {
    --bs-btn-font-size: var(--tvdb-text-md);
    --bs-btn-border-radius: var(--tvdb-radius-md);
}

.btn:focus-visible {
    outline: 2px solid var(--tvdb-focus);
    outline-offset: 2px;
    box-shadow: none;
}

.btn-primary {
    --bs-btn-color: var(--tvdb-on-signal);
    --bs-btn-bg: var(--tvdb-signal);
    --bs-btn-border-color: var(--tvdb-signal);
    --bs-btn-hover-color: var(--tvdb-on-signal);
    --bs-btn-hover-bg: var(--tvdb-signal-hover);
    --bs-btn-hover-border-color: var(--tvdb-signal-hover);
    --bs-btn-active-color: var(--tvdb-on-signal);
    --bs-btn-active-bg: var(--tvdb-signal-hover);
    --bs-btn-active-border-color: var(--tvdb-signal-hover);
    --bs-btn-disabled-color: var(--tvdb-on-signal);
    --bs-btn-disabled-bg: var(--tvdb-signal);
    --bs-btn-disabled-border-color: var(--tvdb-signal);
}

.btn-outline-primary {
    --bs-btn-color: var(--tvdb-signal-ink);
    --bs-btn-border-color: var(--tvdb-signal);
    --bs-btn-hover-color: var(--tvdb-on-signal);
    --bs-btn-hover-bg: var(--tvdb-signal);
    --bs-btn-hover-border-color: var(--tvdb-signal);
    --bs-btn-active-color: var(--tvdb-on-signal);
    --bs-btn-active-bg: var(--tvdb-signal);
    --bs-btn-active-border-color: var(--tvdb-signal);
    --bs-btn-disabled-color: var(--tvdb-signal-ink);
    --bs-btn-disabled-border-color: var(--tvdb-signal);
}

.btn-outline-danger {
    --bs-btn-color: var(--tvdb-danger);
    --bs-btn-border-color: var(--tvdb-danger);
    --bs-btn-hover-color: var(--tvdb-on-danger);
    --bs-btn-hover-bg: var(--tvdb-danger);
    --bs-btn-hover-border-color: var(--tvdb-danger);
    --bs-btn-active-color: var(--tvdb-on-danger);
    --bs-btn-active-bg: var(--tvdb-danger);
    --bs-btn-active-border-color: var(--tvdb-danger);
    --bs-btn-disabled-color: var(--tvdb-danger);
    --bs-btn-disabled-border-color: var(--tvdb-danger);
}

.btn-dark {
    --bs-btn-color: var(--tvdb-on-ink);
    --bs-btn-bg: var(--tvdb-ink);
    --bs-btn-border-color: var(--tvdb-ink);
    --bs-btn-hover-color: var(--tvdb-on-ink);
    --bs-btn-hover-bg: var(--tvdb-ink-3);
    --bs-btn-hover-border-color: var(--tvdb-ink-3);
    --bs-btn-active-color: var(--tvdb-on-ink);
    --bs-btn-active-bg: var(--tvdb-ink-3);
    --bs-btn-active-border-color: var(--tvdb-ink-3);
}

.btn-outline-dark,
.btn-outline-secondary {
    --bs-btn-color: var(--tvdb-text);
    --bs-btn-border-color: var(--tvdb-ink-line-strong);
    --bs-btn-hover-color: var(--tvdb-on-ink);
    --bs-btn-hover-bg: var(--tvdb-ink);
    --bs-btn-hover-border-color: var(--tvdb-ink);
    --bs-btn-active-color: var(--tvdb-on-ink);
    --bs-btn-active-bg: var(--tvdb-ink);
    --bs-btn-active-border-color: var(--tvdb-ink);
    --bs-btn-disabled-color: var(--tvdb-text-muted);
    --bs-btn-disabled-border-color: var(--tvdb-ink-line);
}

.btn-outline-secondary {
    --bs-btn-color: var(--tvdb-text-muted);
}

.btn-link {
    --bs-btn-font-weight: 500;
}

/* Only ever inside a confirm modal: the button that actually removes. */
.btn-danger {
    --bs-btn-color: var(--tvdb-on-danger);
    --bs-btn-bg: var(--tvdb-danger);
    --bs-btn-border-color: var(--tvdb-danger);
    --bs-btn-hover-color: var(--tvdb-on-danger);
    --bs-btn-hover-bg: var(--tvdb-danger-ink);
    --bs-btn-hover-border-color: var(--tvdb-danger-ink);
    --bs-btn-active-color: var(--tvdb-on-danger);
    --bs-btn-active-bg: var(--tvdb-danger-ink);
    --bs-btn-active-border-color: var(--tvdb-danger-ink);
}

/* A watched toggle that is on ("Watched Fri, Sep 11"): solid green, and brick
   on hover to say "press to undo". The action itself is a .btn-primary. */
.btn-watch--on {
    --bs-btn-color: var(--tvdb-on-ok);
    --bs-btn-bg: var(--tvdb-ok);
    --bs-btn-border-color: var(--tvdb-ok);
    --bs-btn-hover-color: var(--tvdb-on-danger);
    --bs-btn-hover-bg: var(--tvdb-danger);
    --bs-btn-hover-border-color: var(--tvdb-danger);
    --bs-btn-active-color: var(--tvdb-on-danger);
    --bs-btn-active-bg: var(--tvdb-danger);
    --bs-btn-active-border-color: var(--tvdb-danger);
}

/* ---- Alerts ---------------------------------------------------------------- */

.alert {
    --bs-alert-border-radius: var(--tvdb-radius-md);
}

.alert-warning {
    --bs-alert-color: var(--tvdb-signal-ink);
    --bs-alert-bg: var(--tvdb-signal-tint);
    --bs-alert-border-color: var(--tvdb-signal-edge);
    --bs-alert-link-color: var(--tvdb-signal-ink);
}

.alert-info {
    --bs-alert-color: var(--tvdb-info-ink);
    --bs-alert-bg: var(--tvdb-info-tint);
    --bs-alert-border-color: var(--tvdb-info-edge);
    --bs-alert-link-color: var(--tvdb-info-ink);
}

.alert-success {
    --bs-alert-color: var(--tvdb-ok-ink);
    --bs-alert-bg: var(--tvdb-ok-tint);
    --bs-alert-border-color: var(--tvdb-ok-edge);
    --bs-alert-link-color: var(--tvdb-ok-ink);
}

.alert-danger {
    --bs-alert-color: var(--tvdb-danger-ink);
    --bs-alert-bg: var(--tvdb-danger-tint);
    --bs-alert-border-color: var(--tvdb-danger-edge);
    --bs-alert-link-color: var(--tvdb-danger-ink);
}

/* ---- List group (episode and search rows) ---------------------------------- */

.list-group {
    --bs-list-group-color: var(--tvdb-text);
    --bs-list-group-bg: transparent;
    --bs-list-group-border-color: var(--tvdb-ink-line);
    --bs-list-group-border-radius: var(--tvdb-radius-md);
    --bs-list-group-item-padding-x: var(--tvdb-space-4);
    --bs-list-group-item-padding-y: var(--tvdb-space-3);
}

.list-group-item:hover {
    background: var(--tvdb-wash);
}

.list-group-item.is-watched {
    background: var(--tvdb-ok-wash);
}

/* ---- Forms ------------------------------------------------------------------- */

.form-label {
    margin-bottom: var(--tvdb-space-1);
    font-size: var(--tvdb-text-sm);
    font-weight: 500;
    color: var(--bs-body-color);
}

.form-control {
    background-color: var(--tvdb-paper-dim);
    border-color: var(--tvdb-ink-line-strong);
    border-radius: var(--tvdb-radius-md);
}

.form-control:focus {
    color: var(--bs-body-color);
    background-color: var(--tvdb-paper-dim);
    border-color: var(--tvdb-focus);
    box-shadow: 0 0 0 0.2rem var(--tvdb-focus-halo);
}

.form-control::placeholder {
    color: var(--tvdb-text-muted);
    opacity: 1;
}

.form-control::file-selector-button {
    font-weight: 500;
    border-color: var(--tvdb-ink-line-strong);
}

.form-text {
    font-size: var(--tvdb-text-sm);
}

/* Validation: we draw our own status icon, so drop Bootstrap's background
   image and keep the border colour. */
.form-control.is-valid,
.form-control.is-invalid {
    background-image: none;
    padding-right: 2.5rem;
}

.form-control.is-valid,
.form-control.is-valid:focus {
    border-color: var(--tvdb-ok);
    box-shadow: none;
}

.form-control.is-invalid,
.form-control.is-invalid:focus {
    border-color: var(--tvdb-danger);
    box-shadow: none;
}

.form-control.is-valid:focus { box-shadow: 0 0 0 0.2rem var(--tvdb-ok-tint); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 0.2rem var(--tvdb-danger-tint); }

.field-validation-error {
    display: block;
    margin-top: var(--tvdb-space-1);
    font-size: var(--tvdb-text-sm);
}

/* A form's buttons: one row, the action that saves on the right. */
.tvdb-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--tvdb-space-2);
    margin-top: var(--tvdb-space-5);
}

/* ---- Table --------------------------------------------------------------------- */

.table {
    --bs-table-color: var(--tvdb-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--tvdb-ink-line);
    --bs-table-striped-color: var(--tvdb-text);
    --bs-table-striped-bg: var(--tvdb-wash);
    --bs-table-hover-color: var(--tvdb-text);
    --bs-table-hover-bg: var(--tvdb-wash);

    font-size: var(--tvdb-text-sm);
}

.table > thead th {
    font-size: var(--tvdb-text-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tvdb-text-muted);
    border-bottom-color: var(--tvdb-ink-line-strong);
}

/* ---- Modal --------------------------------------------------------------------- */

.modal {
    --bs-modal-color: var(--tvdb-text);
    --bs-modal-bg: var(--tvdb-paper);
    --bs-modal-border-color: var(--tvdb-ink-line);
    --bs-modal-border-radius: var(--tvdb-radius-lg);
    --bs-modal-inner-border-radius: var(--tvdb-radius-lg);
    --bs-modal-header-border-color: var(--tvdb-ink-line);
    --bs-modal-footer-border-color: var(--tvdb-ink-line);
}

.modal-title {
    font-size: var(--tvdb-text-xl);
}

/* ---- Progress -------------------------------------------------------------------- */

.progress {
    --bs-progress-bg: var(--tvdb-paper-dim);
    --bs-progress-bar-bg: var(--tvdb-signal);
    --bs-progress-border-radius: var(--tvdb-radius-pill);
}

/* =========================================================================
   Recall components
   ========================================================================= */

/* ---- Close button: a Phosphor "x" (toasts and modals) --------------------- */

.tvdb-close {
    appearance: none;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: var(--tvdb-radius-round);
    background: transparent;
    color: inherit;
    font-size: var(--tvdb-text-lg);
    opacity: 0.7;
    cursor: pointer;
    transition: opacity var(--tvdb-ease), background-color var(--tvdb-ease);
}

.tvdb-close:hover,
.tvdb-close:focus-visible {
    opacity: 1;
    background: var(--bs-secondary-bg);
}

/* ---- Empty state (the _EmptyState partial) --------------------------------- */

.tvdb-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--tvdb-space-2);
    max-width: 30rem;
    margin-inline: auto;
    padding: var(--tvdb-space-6) var(--tvdb-space-4);
    text-align: center;
}

.tvdb-empty-state__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    margin-bottom: var(--tvdb-space-2);
    border-radius: var(--tvdb-radius-round);
    background: var(--tvdb-paper-dim);
    border: 1px solid var(--tvdb-ink-line);
    color: var(--tvdb-text-muted);
    font-size: var(--tvdb-text-2xl);
}

.tvdb-empty-state__icon .ph,
.tvdb-empty-state__icon .ph-fill {
    font-size: 1em;
    vertical-align: 0;
}

.tvdb-empty-state__title {
    margin: 0;
    font-size: var(--tvdb-text-xl);
}

h1.tvdb-empty-state__title {
    font-size: var(--tvdb-text-2xl);
}

.tvdb-empty-state__text {
    margin: 0;
    line-height: var(--tvdb-leading-body);
    color: var(--tvdb-text-muted);
}

.tvdb-empty-state__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--tvdb-space-2);
    margin-top: var(--tvdb-space-3);
}

/* A compact one inside a section that already has a heading. */
.tvdb-empty-state--inline {
    padding-block: var(--tvdb-space-5);
}

/* ---- Media frame and status slate (posters and stills on detail pages) ----- */

.tvdb-media {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
    aspect-ratio: 2 / 3;
    min-height: 200px;
    overflow: hidden;
    background: var(--tvdb-media-bg);
    border-radius: var(--tvdb-radius-lg);
}

.tvdb-media.is-wide {
    aspect-ratio: 16 / 9;
}

.tvdb-media img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: cover;
}

/* Shared "nothing to show" placeholder for every artwork frame. */
.tvdb-media.is-empty::after,
.tvdb-series-poster.is-empty::after,
.tvdb-catchup-media.is-empty::after,
.tvdb-fav-episode-art.is-empty::after {
    content: "No image";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--tvdb-space-2);
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-on-ink-faint);
    text-align: center;
}

@media (max-width: 575.98px) {
    /* On a phone the aspect ratio alone decides the height. */
    .tvdb-media { min-height: 0; }
}

/* A still that does not exist yet gets a low strip, not an empty 16:9 box. */
.tvdb-media.is-wide.is-empty {
    aspect-ratio: auto;
    min-height: 0;
    height: 6rem;
}

.tvdb-media.is-wide.is-empty::after {
    content: none;
}

.tvdb-media__placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--tvdb-space-2);
    padding-bottom: var(--tvdb-space-5);
    font-size: var(--tvdb-text-sm);
    color: var(--tvdb-on-ink-faint);
}

.tvdb-slate,
.tvdb-slate--inline {
    display: inline-flex;
    align-items: center;
    gap: var(--tvdb-space-2);
    border: 1px solid var(--tvdb-signal-halo);
    border-radius: var(--tvdb-radius-sm);
    font-family: var(--tvdb-font-mono);
    font-size: var(--tvdb-text-xs);
    letter-spacing: 0.04em;
    color: var(--tvdb-on-ink);
}

.tvdb-slate {
    position: absolute;
    left: var(--tvdb-space-3);
    bottom: var(--tvdb-space-3);
    padding: var(--tvdb-space-1) var(--tvdb-space-2);
    background: var(--tvdb-scrim-strong);
}

.tvdb-slate--inline {
    padding: 0.1rem var(--tvdb-space-2);
    background: var(--tvdb-ink-2);
}

.tvdb-dot {
    flex: none;
    width: 7px;
    height: 7px;
    border-radius: var(--tvdb-radius-round);
    background: var(--tvdb-signal);
    box-shadow: 0 0 6px 1px var(--tvdb-signal-edge);
    animation: tvdb-pulse 2.2s ease-in-out infinite;
}

.tvdb-dot.is-ok {
    background: var(--tvdb-ok);
    box-shadow: 0 0 6px 1px var(--tvdb-ok-edge);
}

@keyframes tvdb-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* Small thumbnail in a list row. */
.tvdb-thumb {
    flex: none;
    width: 56px;
    height: 84px;
    border-radius: var(--tvdb-radius-sm);
    object-fit: cover;
    background: var(--tvdb-ink-2);
}

.tvdb-thumb.is-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-on-ink-faint);
    text-align: center;
}

/* Small round button that holds only an icon ("⋯"). */
.tvdb-icon-button {
    appearance: none;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--tvdb-ink-line-strong);
    border-radius: var(--tvdb-radius-round);
    background: transparent;
    color: var(--tvdb-text);
    font-size: var(--tvdb-text-lg);
    cursor: pointer;
    transition: background var(--tvdb-ease), border-color var(--tvdb-ease);
}

.tvdb-icon-button:hover,
.tvdb-icon-button:focus-visible,
.tvdb-icon-button.show {
    background: var(--tvdb-paper-dim);
    border-color: var(--tvdb-text-muted);
}

/* A removal that is offered quietly: plain text, confirmed in a modal. */
.tvdb-quiet-action {
    appearance: none;
    padding: var(--tvdb-space-1) 0;
    border: 0;
    background: none;
    font-size: var(--tvdb-text-sm);
    color: var(--tvdb-text-muted);
    text-decoration: underline;
    text-decoration-color: var(--tvdb-ink-line-strong);
    text-underline-offset: 0.15em;
    cursor: pointer;
}

.tvdb-quiet-action:hover,
.tvdb-quiet-action:focus-visible {
    color: var(--tvdb-danger);
    text-decoration-color: currentColor;
}

/* A quiet action that destroys something: danger-coloured before it is touched. */
.tvdb-quiet-action--danger {
    color: var(--tvdb-danger);
    text-decoration-color: var(--tvdb-danger-edge);
}

.tvdb-quiet-action--danger:hover,
.tvdb-quiet-action--danger:focus-visible {
    color: var(--tvdb-danger-ink);
}

/* A setting in a facts list: what it is now, and the button that changes it. */
.tvdb-setting {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--tvdb-space-2) var(--tvdb-space-4);
}

.tvdb-setting__state {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

/* A row of quiet actions (Profile: Sign out, Delete my account). */
.tvdb-quiet-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--tvdb-space-2) var(--tvdb-space-5);
}

/* Secondary facts as a quiet label–value list. */
.tvdb-facts-quiet {
    display: flex;
    flex-direction: column;
    gap: var(--tvdb-space-1);
    margin: 0;
    font-size: var(--tvdb-text-sm);
    color: var(--tvdb-text-muted);
}

.tvdb-facts-quiet > div {
    display: flex;
    gap: var(--tvdb-space-3);
}

.tvdb-facts-quiet dt {
    flex: 0 0 6.5rem;
    font-weight: 500;
}

.tvdb-facts-quiet dd {
    margin: 0;
    color: var(--tvdb-text);
}

/* The last line of a detail page: where the data comes from. */
.tvdb-source-line {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tvdb-space-2) var(--tvdb-space-5);
    margin: var(--tvdb-space-6) 0 0;
    padding-top: var(--tvdb-space-3);
    border-top: 1px solid var(--tvdb-ink-line);
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-text-muted);
}

/* ---- Badges ----------------------------------------------------------------- */

.tvdb-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--tvdb-space-1);
    padding: 0.2rem var(--tvdb-space-2);
    border: 1px solid transparent;
    border-radius: var(--tvdb-radius-pill);
    font-size: var(--tvdb-text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: var(--tvdb-leading-snug);
    text-transform: uppercase;
}

.tvdb-badge--amber {
    color: var(--tvdb-signal-ink);
    background: var(--tvdb-signal-tint-strong);
    border-color: var(--tvdb-signal-edge);
}

.tvdb-badge--ok {
    color: var(--tvdb-ok-ink);
    background: var(--tvdb-ok-tint);
    border-color: var(--tvdb-ok-edge);
}

.tvdb-badge--info {
    color: var(--tvdb-info-ink);
    background: var(--tvdb-info-tint);
    border-color: var(--tvdb-info-edge);
}

.tvdb-badge--neutral {
    color: var(--tvdb-text-muted);
    background: var(--tvdb-paper-dim);
    border-color: var(--tvdb-ink-line);
}

.tvdb-badge--danger {
    color: var(--tvdb-danger-ink);
    background: var(--tvdb-danger-tint);
    border-color: var(--tvdb-danger-edge);
}

.tvdb-genre-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tvdb-space-2);
}

/* Role pill on the profile page: neutral, amber for an admin. */
.tvdb-role-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--tvdb-space-2);
    padding: var(--tvdb-space-1) var(--tvdb-space-3);
    border-radius: var(--tvdb-radius-pill);
    font-size: var(--tvdb-text-sm);
    font-weight: 600;
    background: var(--tvdb-paper-dim);
    border: 1px solid var(--tvdb-ink-line);
    color: var(--tvdb-text);
}

.tvdb-role-badge--admin {
    background: var(--tvdb-signal-tint);
    border-color: var(--tvdb-signal-edge);
    color: var(--tvdb-signal-ink);
}

/* ---- Metadata list (dl.row) -------------------------------------------------- */

/* No gutter: the rule under each value then ends where the text column ends. */
dl.row {
    --bs-gutter-x: 0;
}

dl.row dt {
    padding-block: var(--tvdb-space-2);
    padding-right: var(--tvdb-space-3);
    font-size: var(--tvdb-text-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tvdb-text-muted);
}

dl.row dd {
    padding-block: var(--tvdb-space-2);
    font-size: var(--tvdb-text-sm);
    border-bottom: 1px solid var(--tvdb-ink-line);
}

/* Links. In running text a link is underlined (Bootstrap's default). A link
   that stands on its own in a list or a card (an episode title, a person's
   name, a card title) is .tvdb-link-plain: no underline until hover or focus. */
.tvdb-link-plain {
    color: inherit;
    text-decoration: none;
}

.tvdb-link-plain:hover,
.tvdb-link-plain:focus-visible {
    color: var(--tvdb-signal-text);
    text-decoration: underline;
}

/* A link that is part of a value: ink-coloured with a quiet underline. */
dl.row dd a,
.tvdb-metalink {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--tvdb-ink-line-strong);
    text-underline-offset: 0.15em;
    transition: color var(--tvdb-ease), text-decoration-color var(--tvdb-ease);
}

dl.row dd a:hover,
dl.row dd a:focus-visible,
.tvdb-metalink:hover,
.tvdb-metalink:focus-visible {
    color: var(--tvdb-signal-text);
    text-decoration-color: currentColor;
}

/* Phosphor "arrow-up-right" after a link that leaves the site. */
dl.row dd a[target="_blank"]::after,
.tvdb-metalink[target="_blank"]::after {
    content: "\e092";
    display: inline-block;
    margin-left: 0.25em;
    font-family: "Phosphor";
    font-size: 0.9em;
    color: var(--tvdb-text-muted);
    text-decoration: none;
}

/* Small "Edit" chip next to a value. */
.tvdb-inline-edit {
    padding: 0.1rem var(--tvdb-space-2);
    border: 1px solid var(--tvdb-ink-line-strong);
    border-radius: var(--tvdb-radius-pill);
    font-size: var(--tvdb-text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
}

dl.row dd a.tvdb-inline-edit {
    color: var(--tvdb-signal-text);
    text-decoration: none;
}

.tvdb-inline-edit:hover,
.tvdb-inline-edit:focus-visible {
    border-color: var(--tvdb-signal-text);
}

/* ---- Ratings ------------------------------------------------------------------ */

.tvdb-rating {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 var(--tvdb-space-2);
}

.tvdb-rating-star {
    align-self: center;
    color: var(--tvdb-signal);
}

.tvdb-rating-score {
    font-family: var(--tvdb-font-mono);
    white-space: nowrap;
}

.tvdb-rating-score strong {
    font-size: 1.1em;
    font-weight: 500;
    color: var(--tvdb-text);
}

.tvdb-rating-votes {
    font-size: var(--tvdb-text-sm);
    color: var(--tvdb-text-muted);
}

/* Everything rating-related on an episode, in one tile. */
.tvdb-rating-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--tvdb-space-2) var(--tvdb-space-5);
    padding: var(--tvdb-space-3) var(--tvdb-space-4);
    background: var(--tvdb-paper-dim);
    border: 1px solid var(--tvdb-ink-line);
    border-radius: var(--tvdb-radius-md);
}

/* "Your rating": ten pills, each a submit button (the _RatingWidget partial).
   One row of ten; two rows of five on a phone. "Clear" sits beside them. */
.tvdb-rating-picker {
    display: flex;
    flex-direction: column;
    gap: var(--tvdb-space-2);
}

.tvdb-rating-picker-label {
    font-size: var(--tvdb-text-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tvdb-text-muted);
}

.tvdb-rating-picker-row {
    display: flex;
    align-items: center;
    gap: var(--tvdb-space-3);
}

.tvdb-rating-pills {
    display: grid;
    grid-template-columns: repeat(10, 36px);
    gap: var(--tvdb-space-2);
}

@media (max-width: 575.98px) {
    .tvdb-rating-pills {
        grid-template-columns: repeat(5, 36px);
    }
}

.tvdb-rating-pill {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--tvdb-radius-round);
    border: 1px solid var(--tvdb-ink-line-strong);
    background: var(--tvdb-paper-dim);
    color: var(--tvdb-text-muted);
    font-family: var(--tvdb-font-mono);
    font-size: var(--tvdb-text-sm);
    cursor: pointer;
    transition: color var(--tvdb-ease), border-color var(--tvdb-ease), background var(--tvdb-ease);
}

.tvdb-rating-pill:hover,
.tvdb-rating-pill:focus-visible {
    border-color: var(--tvdb-signal);
    color: var(--tvdb-signal-ink);
}

/* Every pill up to the current rating is tinted; the rating itself is solid. */
.tvdb-rating-pill.is-filled {
    background: var(--tvdb-signal-tint-strong);
    border-color: var(--tvdb-signal-edge);
    color: var(--tvdb-signal-ink);
}

.tvdb-rating-pill.is-current {
    background: var(--tvdb-signal);
    border-color: var(--tvdb-signal);
    color: var(--tvdb-on-signal);
    font-weight: 500;
}

.tvdb-rating-clear {
    appearance: none;
    padding: var(--tvdb-space-1) 0;
    border: 0;
    background: none;
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-text-muted);
    text-decoration: underline;
    cursor: pointer;
}

.tvdb-rating-clear:hover,
.tvdb-rating-clear:focus-visible {
    color: var(--tvdb-danger);
}

/* ---- Like (the _LikeToggle partial) ---------------------------------------------- */

.tvdb-like-form {
    display: inline-flex;
}

.tvdb-heart {
    appearance: none;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--tvdb-radius-round);
    border: 1px solid var(--tvdb-ink-line-strong);
    background: var(--tvdb-paper-dim);
    color: var(--tvdb-text-muted);
    font-size: var(--tvdb-text-lg);
    cursor: pointer;
    transition: color var(--tvdb-ease), border-color var(--tvdb-ease), background var(--tvdb-ease);
}

.tvdb-heart .ph,
.tvdb-heart .ph-fill {
    font-size: 1em;
    vertical-align: 0;
}

.tvdb-heart:hover,
.tvdb-heart:focus-visible {
    color: var(--tvdb-like);
    border-color: var(--tvdb-like);
}

.tvdb-heart--on {
    color: var(--tvdb-like);
    border-color: var(--tvdb-like-edge);
    background: var(--tvdb-like-tint);
}

/* ---- Watched controls ------------------------------------------------------------- */

/* The one watched control of an episode row: an empty ring until watched. */
.tvdb-watch-dot {
    appearance: none;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--tvdb-radius-round);
    border: 1px solid var(--tvdb-text-muted);
    background: transparent;
    color: transparent;
    font-size: var(--tvdb-text-md);
    line-height: 1;
    cursor: pointer;
    transition: background var(--tvdb-ease), border-color var(--tvdb-ease), color var(--tvdb-ease);
}

.tvdb-watch-dot .ph {
    font-size: 1em;
    vertical-align: 0;
}

.tvdb-watch-dot:hover,
.tvdb-watch-dot:focus-visible {
    border-color: var(--tvdb-ok);
    color: var(--tvdb-ok-ink);
}

/* Not aired yet: not a button, a clock (the row says when it airs). */
.tvdb-watch-dot--upcoming {
    border-style: dashed;
    border-color: var(--tvdb-ink-line-strong);
    color: var(--tvdb-text-muted);
    cursor: default;
}

.tvdb-watch-dot--upcoming:hover {
    border-color: var(--tvdb-ink-line-strong);
    color: var(--tvdb-text-muted);
}

.tvdb-watch-dot--on {
    background: var(--tvdb-ok);
    border-color: var(--tvdb-ok);
    color: var(--tvdb-on-ok);
}

.tvdb-watch-dot--on:hover,
.tvdb-watch-dot--on:focus-visible {
    background: var(--tvdb-danger);
    border-color: var(--tvdb-danger);
    color: var(--tvdb-on-danger);
}

/* Round "mark watched" button that sits on top of a still. */
.tvdb-watch-badge {
    appearance: none;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--tvdb-radius-round);
    border: 1px solid var(--tvdb-on-ink-faint);
    background: var(--tvdb-scrim);
    backdrop-filter: blur(3px);
    color: var(--tvdb-on-ink);
    font-size: var(--tvdb-text-md);
    line-height: 1;
    cursor: pointer;
    transition: background var(--tvdb-ease), border-color var(--tvdb-ease), color var(--tvdb-ease);
}

.tvdb-watch-badge:hover,
.tvdb-watch-badge:focus-visible {
    background: var(--tvdb-ok);
    border-color: var(--tvdb-ok);
    color: var(--tvdb-on-ok);
}

.tvdb-watch-badge:focus-visible {
    outline-color: var(--tvdb-on-ink);
    outline-offset: -4px;
}

/* The same round button holding a "⋯" menu: it opens something, it does not
   mark anything, so it does not turn green. */
.tvdb-watch-badge--menu {
    font-size: var(--tvdb-text-lg);
}

.tvdb-watch-badge--menu:hover,
.tvdb-watch-badge--menu:focus-visible,
.tvdb-watch-badge--menu.show {
    background: var(--tvdb-scrim-strong);
    border-color: var(--tvdb-on-ink);
    color: var(--tvdb-on-ink);
}

/* ---- Filter bar --------------------------------------------------------------------- */

/* A page heading with its one action on the same line, right-aligned. */
.tvdb-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--tvdb-space-2) var(--tvdb-space-4);
    margin-bottom: var(--tvdb-space-4);
}

/* Phones: keep them on one line, so the button gives up its icon and some padding. */
@media (max-width: 575.98px) {
    .tvdb-page-head {
        flex-wrap: nowrap;
        gap: var(--tvdb-space-2);
    }

    .tvdb-page-head > h1 {
        min-width: 0;
    }

    .tvdb-page-head > .btn {
        flex: none;
        --bs-btn-padding-x: var(--tvdb-space-3);
    }

    .tvdb-page-head > .btn > i {
        display: none;
    }
}

/* One of a page's sections (an h2 and what belongs to it). Sections are a
   step of space-6 apart on every page; the heading sits space-3 above its
   content (the h2 rule in base.css). */
.tvdb-page-section {
    margin-bottom: var(--tvdb-space-6);
}

.tvdb-page-section:last-child {
    margin-bottom: 0;
}

/* A text page (Privacy): the same rhythm between its headed parts. */
.tvdb-text-page h2 {
    margin-top: var(--tvdb-space-6);
}

/* ---- Titles in lists and on cards ---------------------------------------------------
   Two styles and no others. A row in a list (episode, search result, import
   row, notification) has a title at body size; a card (poster, upcoming,
   liked episode, person) has one a step smaller. Both are the UI face,
   semibold. */
.tvdb-episode__title,
.tvdb-result__title,
.tvdb-import-row__title,
.tvdb-bar-list__name,
.tvdb-notification__title {
    font-family: var(--tvdb-font-ui);
    font-size: var(--tvdb-text-md);
    font-weight: 600;
    letter-spacing: 0;
    line-height: var(--tvdb-leading-snug);
}

.tvdb-upcoming-series,
.tvdb-series-title,
.tvdb-fav-episode-show,
.tvdb-person__name {
    font-size: var(--tvdb-text-sm);
    font-weight: 600;
    line-height: var(--tvdb-leading-snug);
}

/* A group inside a section, under an h3 (the Library's "Haven't watched in a
   while" inside Watching). From 576px its body is a Bootstrap collapse behind
   the "Show N" button; on a phone it is always there, as a scrolling row.
   The Library's Stopped section uses the same toggle and body under its h2. */
.tvdb-subgroup {
    margin-top: var(--tvdb-space-5);
    padding-top: var(--tvdb-space-4);
    border-top: 1px solid var(--tvdb-ink-line);
    scroll-margin-top: var(--tvdb-space-4);
}

.tvdb-subgroup__toggle[aria-expanded="true"] .ph {
    transform: rotate(180deg);
}

@media (max-width: 575.98px) {
    .tvdb-subgroup__body.collapse:not(.show) {
        display: block;
    }
}

/* A one-time offer on a page (the Dashboard's weekly-email card): an icon,
   what is offered, and the two answers. */
.tvdb-offer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--tvdb-space-3) var(--tvdb-space-4);
    padding: var(--tvdb-space-3) var(--tvdb-space-4);
    background: var(--tvdb-signal-tint);
    border: 1px solid var(--tvdb-signal-edge);
    border-radius: var(--tvdb-radius-lg);
}

.tvdb-offer__icon {
    flex: none;
    font-size: var(--tvdb-text-xl);
    color: var(--tvdb-signal-ink);
}

.tvdb-offer__text {
    flex: 1 1 16rem;
    min-width: 0;
}

.tvdb-offer__title {
    margin: 0 0 var(--tvdb-space-1);
    font-family: var(--tvdb-font-ui);
    font-size: var(--tvdb-text-md);
    font-weight: 600;
    letter-spacing: 0;
    line-height: var(--tvdb-leading-snug);
}

.tvdb-offer__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tvdb-space-2);
}

/* A section heading with a quiet link at the far end ("See all"). */
.tvdb-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--tvdb-space-3);
    margin-bottom: var(--tvdb-space-3);
}

.tvdb-section-head__link {
    flex: none;
    font-size: var(--tvdb-text-sm);
    font-weight: 600;
    text-decoration: none;
}

.tvdb-section-head__link:hover,
.tvdb-section-head__link:focus-visible {
    text-decoration: underline;
}

/* The filter's own line under the page head, set apart by a rule. */
.tvdb-filter-row {
    margin-bottom: var(--tvdb-space-5);
    padding-bottom: var(--tvdb-space-3);
    border-bottom: 1px solid var(--tvdb-ink-line);
}

.tvdb-filter-bar {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--tvdb-space-2);
}

.tvdb-filter-btn--series i { color: var(--tvdb-signal-text); }
.tvdb-filter-btn--movie i { color: var(--tvdb-info); }

/* ---- Poster card and grid (the _SeriesCard partial) --------------------------------- */

/* One row of posters and no more: six across on a desktop; narrower, a row
   that scrolls sideways with the next poster peeking in. */
.tvdb-poster-row {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: clamp(0.75rem, 2vw, 1.5rem);
}

@media (max-width: 991.98px) {
    .tvdb-poster-row {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        margin-inline: calc(-1 * var(--tvdb-shell-pad));
        padding-inline: var(--tvdb-shell-pad);
        scroll-padding-inline: var(--tvdb-shell-pad);
        /* Room for the cards' hover lift and focus ring inside the scroller. */
        padding-block: var(--tvdb-space-1);
    }

    .tvdb-poster-row > .tvdb-series-card-wrap {
        flex: 0 0 clamp(7rem, 30%, 9rem);
        scroll-snap-align: start;
    }
}

/* Two posters across on a phone: big enough to recognise, with room for the
   title and two short lines under each. */
.tvdb-series-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--tvdb-space-4) clamp(0.75rem, 2vw, 1.5rem);
}

@media (min-width: 576px) { .tvdb-series-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 768px) { .tvdb-series-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 992px) { .tvdb-series-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* On a phone, a section of posters as one row that scrolls sideways, sized so
   the next poster peeks in at the edge (the cast row's pattern). From 576px it
   is the ordinary grid. */
@media (max-width: 575.98px) {
    .tvdb-series-grid--row-on-phone {
        display: flex;
        gap: var(--tvdb-space-3);
        overflow-x: auto;
        scroll-snap-type: x proximity;
        margin-inline: calc(-1 * var(--tvdb-shell-pad));
        padding-inline: var(--tvdb-shell-pad);
        scroll-padding-inline: var(--tvdb-shell-pad);
        /* Room for the cards' hover lift and focus ring inside the scroller. */
        padding-block: var(--tvdb-space-1);
    }

    .tvdb-series-grid--row-on-phone > .tvdb-series-card-wrap {
        flex: 0 0 calc((100% - 2 * var(--tvdb-space-3)) / 2.4);
        scroll-snap-align: start;
    }
}

/* In the narrow panel there is room for four. */
.tvdb-shell--narrow .tvdb-series-grid {
    grid-template-columns: repeat(3, 1fr);
}

@media (min-width: 576px) {
    .tvdb-shell--narrow .tvdb-series-grid { grid-template-columns: repeat(4, 1fr); }
}

.tvdb-series-card-wrap {
    position: relative;
    display: block;
}

.tvdb-series-card {
    display: flex;
    flex-direction: column;
    color: var(--tvdb-text);
    text-decoration: none;
}

.tvdb-series-card:hover,
.tvdb-series-card:focus-visible {
    color: var(--tvdb-text);
    text-decoration: none;
}

.tvdb-series-poster {
    position: relative;
    display: block;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    background: var(--tvdb-media-bg);
    border: 1px solid var(--tvdb-ink-line);
    border-radius: var(--tvdb-radius-md);
    transition: transform var(--tvdb-ease), box-shadow var(--tvdb-ease), border-color var(--tvdb-ease);
}

.tvdb-series-card:hover .tvdb-series-poster,
.tvdb-series-card:focus-visible .tvdb-series-poster {
    transform: translateY(-2px);
    border-color: var(--tvdb-signal-edge);
    box-shadow: var(--tvdb-shadow-md);
}

.tvdb-series-poster img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Watch progress along the poster's bottom edge: amber in progress, green
   when every aired episode is watched. */
.tvdb-series-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    overflow: hidden;
    background: var(--tvdb-scrim);
}

.tvdb-series-progress-fill {
    display: block;
    height: 100%;
    min-width: 3px;
    background: var(--tvdb-signal);
}

.tvdb-series-progress.is-complete .tvdb-series-progress-fill {
    background: var(--tvdb-ok);
}

.tvdb-series-title {
    display: -webkit-box;
    margin-top: var(--tvdb-space-2);
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.tvdb-series-card:hover .tvdb-series-title,
.tvdb-series-card:focus-visible .tvdb-series-title {
    color: var(--tvdb-signal-text);
    text-decoration: underline;
}

/* "6 of 16 · S05": where the viewer is, in words (the bar on the poster is the glance). */
.tvdb-series-progress-text {
    display: block;
    margin-top: 0.15rem;
    font-family: var(--tvdb-font-mono);
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-text);
}

/* "Series · 2008", "Movie · watched Sep 25". */
.tvdb-series-year {
    display: block;
    margin-top: 0.15rem;
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-text-muted);
}

/* The heart overlaid on a poster's top-right corner. */
.tvdb-series-card-like {
    position: absolute;
    top: var(--tvdb-space-2);
    right: var(--tvdb-space-2);
    z-index: 2;
}

.tvdb-series-card-like .tvdb-heart {
    width: 36px;
    height: 36px;
    border-color: transparent;
    background: var(--tvdb-scrim);
    color: var(--tvdb-on-ink);
    font-size: var(--tvdb-text-md);
    backdrop-filter: blur(2px);
}

.tvdb-series-card-like .tvdb-heart:hover,
.tvdb-series-card-like .tvdb-heart:focus-visible,
.tvdb-series-card-like .tvdb-heart--on {
    color: var(--tvdb-like);
    border-color: transparent;
    background: var(--tvdb-scrim-strong);
}

.tvdb-series-card-like .tvdb-heart:focus-visible {
    outline-color: var(--tvdb-on-ink);
    outline-offset: -3px;
}

/* ---- Catch-up card (the _CatchUpCard partial) ----------------------------------------- */

.tvdb-catchup-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(0.75rem, 2vw, 1.25rem);
}

@media (min-width: 576px) { .tvdb-catchup-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 992px) { .tvdb-catchup-grid { grid-template-columns: repeat(3, 1fr); } }

.tvdb-catchup-media {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--tvdb-media-bg);
    border: 1px solid var(--tvdb-ink-line);
    border-radius: var(--tvdb-radius-lg);
    transition: box-shadow var(--tvdb-ease), border-color var(--tvdb-ease);
}

.tvdb-catchup-card:hover .tvdb-catchup-media,
.tvdb-catchup-card:focus-within .tvdb-catchup-media {
    border-color: var(--tvdb-signal-edge);
    box-shadow: var(--tvdb-shadow-md);
}

.tvdb-catchup-media img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.tvdb-catchup-card:hover .tvdb-catchup-media img {
    transform: scale(1.03);
}

/* The whole still opens the episode; the caption and button sit above it. */
.tvdb-catchup-hit {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.tvdb-catchup-hit:focus-visible {
    outline-color: var(--tvdb-on-ink);
    outline-offset: -4px;
}

.tvdb-catchup-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    /* The top padding is the fade; the right padding clears the round button.
       The shade only sits behind the text (a short fade above it), and stops
       short of black, so a dark still or dark background art keeps its detail;
       the text shadow carries the caption over a bright one. */
    padding: var(--tvdb-space-6) 3.5rem var(--tvdb-space-3) var(--tvdb-space-3);
    background: linear-gradient(to top, var(--tvdb-scrim-caption), var(--tvdb-scrim) 55%, transparent);
    text-shadow: var(--tvdb-text-shadow-on-art);
    pointer-events: none;
}

/* The dark placeholder is dark enough already. */
.tvdb-catchup-media.is-empty .tvdb-catchup-caption {
    background: none;
}

/* The caption names the episode; "No image" in the middle adds nothing. */
.tvdb-catchup-media.is-empty::after {
    content: none;
}

.tvdb-catchup-show {
    align-self: flex-start;
    max-width: 100%;
    overflow: hidden;
    font-size: var(--tvdb-text-md);
    font-weight: 600;
    line-height: var(--tvdb-leading-snug);
    color: var(--tvdb-on-ink);
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: auto;
}

.tvdb-catchup-show:hover,
.tvdb-catchup-show:focus-visible {
    color: var(--tvdb-signal);
    text-decoration: underline;
}

.tvdb-catchup-slate {
    font-family: var(--tvdb-font-mono);
    font-size: var(--tvdb-text-xs);
    letter-spacing: 0.04em;
    color: var(--tvdb-on-ink);
}

.tvdb-catchup-ep {
    overflow: hidden;
    font-size: var(--tvdb-text-sm);
    line-height: var(--tvdb-leading-snug);
    color: var(--tvdb-on-ink);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tvdb-catchup-check {
    position: absolute;
    right: var(--tvdb-space-3);
    bottom: var(--tvdb-space-3);
    z-index: 3;
    margin: 0;
}

/* The card's "⋯" menu, in the corner opposite the caption. One step above the
   other controls so its open menu covers the next card's button too. */
.tvdb-catchup-menu {
    position: absolute;
    top: var(--tvdb-space-3);
    right: var(--tvdb-space-3);
    z-index: 4;
}

/* ---- Upcoming card (the _UpcomingEpisodeCard partial) ----------------------------------
   Compact: a small poster, the episode, then the date with its countdown. Two
   columns of cards from tablet width up. */

.tvdb-upcoming-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--tvdb-space-2);
}

@media (min-width: 768px) {
    .tvdb-upcoming-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Left edge: green when the viewer is caught up on the series, amber otherwise. */
.tvdb-upcoming-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--tvdb-space-3);
    padding: var(--tvdb-space-2);
    background: var(--tvdb-paper-dim);
    border: 1px solid var(--tvdb-ink-line);
    border-left: 3px solid var(--tvdb-signal);
    border-radius: var(--tvdb-radius-md);
    transition: box-shadow var(--tvdb-ease);
}

.tvdb-upcoming-card.is-current {
    border-left-color: var(--tvdb-ok);
}

.tvdb-upcoming-card:hover,
.tvdb-upcoming-card:focus-within {
    box-shadow: var(--tvdb-shadow-sm);
}

.tvdb-upcoming-hit {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
}

.tvdb-upcoming-card .tvdb-thumb {
    position: relative;
    z-index: 0;
    width: 40px;
    height: 60px;
}

/* The date comes after the episode it belongs to, as a secondary line:
   right-aligned and stacked on wide cards, the last line of the text column
   on a phone (see the media query below). */
.tvdb-upcoming-when {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
    text-align: right;
    pointer-events: none;
}

.tvdb-upcoming-date {
    font-size: var(--tvdb-text-sm);
    line-height: var(--tvdb-leading-snug);
    color: var(--tvdb-text-muted);
    white-space: nowrap;
}

.tvdb-upcoming-sep {
    display: none;
}

.tvdb-upcoming-countdown {
    font-family: var(--tvdb-font-mono);
    font-size: var(--tvdb-text-xs);
    line-height: var(--tvdb-leading-snug);
    color: var(--tvdb-text-muted);
    white-space: nowrap;
}

/* Clicks fall through the text to the card link; the series name opts back in. */
.tvdb-upcoming-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    pointer-events: none;
}

.tvdb-upcoming-series {
    position: relative;
    z-index: 2;
    align-self: flex-start;
    max-width: 100%;
    overflow: hidden;
    color: var(--tvdb-text);
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: auto;
}

.tvdb-upcoming-series:hover,
.tvdb-upcoming-series:focus-visible {
    color: var(--tvdb-signal-text);
    text-decoration: underline;
}

/* "S02 • E06  Episode name" on one line; the name gives way first. */
.tvdb-upcoming-episode {
    display: flex;
    align-items: baseline;
    gap: var(--tvdb-space-2);
    min-width: 0;
    font-size: var(--tvdb-text-sm);
    line-height: var(--tvdb-leading-snug);
}

.tvdb-upcoming-episode .tvdb-slate--inline {
    flex: none;
}

.tvdb-upcoming-epname {
    min-width: 0;
    overflow: hidden;
    color: var(--tvdb-text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tvdb-upcoming-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tvdb-space-1);
    padding-top: 0.15rem;
}

/* Phones: everything beside the poster is one text column, the date line last
   ("Sun, Oct 4 · in 2 days"). */
@media (max-width: 575.98px) {
    .tvdb-upcoming-card {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-content: center;
        column-gap: var(--tvdb-space-3);
        row-gap: 0.15rem;
    }

    .tvdb-upcoming-card .tvdb-thumb {
        grid-row: 1 / span 2;
        align-self: center;
    }

    .tvdb-upcoming-body {
        align-self: end;
    }

    .tvdb-upcoming-card > .tvdb-upcoming-body:last-child {
        grid-row: 1 / span 2;
        align-self: center;
    }

    .tvdb-upcoming-when {
        grid-column: 2;
        align-self: start;
        flex-direction: row;
        align-items: baseline;
        gap: var(--tvdb-space-1);
        text-align: left;
    }

    .tvdb-upcoming-sep {
        display: inline;
        color: var(--tvdb-text-muted);
    }
}

/* ---- Liked-episode card (the _FavoriteEpisodeCard partial) ---------------------------- */

.tvdb-fav-episode-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--tvdb-space-4) clamp(0.75rem, 2vw, 1.25rem);
}

@media (min-width: 576px) { .tvdb-fav-episode-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 992px) { .tvdb-fav-episode-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tvdb-fav-episode {
    display: flex;
    flex-direction: column;
    min-width: 0;
    color: var(--tvdb-text);
    text-decoration: none;
}

.tvdb-fav-episode:hover,
.tvdb-fav-episode:focus-visible {
    color: var(--tvdb-text);
    text-decoration: none;
}

.tvdb-fav-episode-art {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    margin-bottom: var(--tvdb-space-2);
    overflow: hidden;
    background: var(--tvdb-media-bg);
    border: 1px solid var(--tvdb-ink-line);
    border-radius: var(--tvdb-radius-md);
    transition: border-color var(--tvdb-ease), box-shadow var(--tvdb-ease);
}

.tvdb-fav-episode:hover .tvdb-fav-episode-art,
.tvdb-fav-episode:focus-visible .tvdb-fav-episode-art {
    border-color: var(--tvdb-signal-edge);
    box-shadow: var(--tvdb-shadow-sm);
}

.tvdb-fav-episode-art img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tvdb-fav-episode-show {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tvdb-fav-episode:hover .tvdb-fav-episode-show,
.tvdb-fav-episode:focus-visible .tvdb-fav-episode-show {
    color: var(--tvdb-signal-text);
    text-decoration: underline;
}

.tvdb-fav-episode-meta {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 0.15rem;
    font-size: var(--tvdb-text-sm);
    line-height: var(--tvdb-leading-snug);
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.tvdb-fav-episode-date {
    margin-top: 0.15rem;
    font-size: var(--tvdb-text-xs);
    color: var(--tvdb-text-muted);
}

/* ---- Cast and crew (the _CastList partial) ---------------------------------------------
   Collapsed until "Show all" is pressed (tvdb-cast.js decides whether the
   button is needed). Cast: portrait cards, one full row; on phones one row
   that scrolls sideways. Crew (--compact): name and jobs beside a small round
   photo, in columns, showing the first few rows. */

.tvdb-cast {
    margin-top: var(--tvdb-space-6);
}

.tvdb-cast__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--tvdb-space-3);
    margin-bottom: var(--tvdb-space-3);
}

/* Rows beyond the first get no height and are clipped, so the collapsed list
   is always exactly one full row whatever the width. */
.tvdb-cast__list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
    grid-template-rows: auto;
    grid-auto-rows: 0;
    column-gap: var(--tvdb-space-3);
    margin: 0;
    overflow: hidden;
}

.tvdb-cast.is-expanded .tvdb-cast__list {
    grid-auto-rows: auto;
}

.tvdb-cast.is-expanded .tvdb-cast__toggle .ph {
    transform: rotate(180deg);
}

.tvdb-person {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding-bottom: var(--tvdb-space-4);
}

.tvdb-person__photo {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 5;
    margin-bottom: var(--tvdb-space-2);
    border-radius: var(--tvdb-radius-md);
    object-fit: cover;
    object-position: center 20%;
    background: var(--tvdb-ink-2);
}

.tvdb-person__photo--initials {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--tvdb-font-display);
    font-size: var(--tvdb-text-2xl);
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--tvdb-on-ink-muted);
}

.tvdb-person__name {
    overflow-wrap: anywhere;
}

.tvdb-person__detail {
    font-size: var(--tvdb-text-xs);
    line-height: var(--tvdb-leading-snug);
    color: var(--tvdb-text-muted);
    overflow-wrap: anywhere;
}

/* The crew: a 40px round photo (or initials) with name and jobs beside it. */
.tvdb-cast--compact .tvdb-cast__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, auto);
    column-gap: var(--tvdb-space-5);
}

.tvdb-cast--compact .tvdb-person {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    column-gap: var(--tvdb-space-3);
    align-content: center;
    align-items: center;
    padding-bottom: var(--tvdb-space-3);
}

.tvdb-cast--compact .tvdb-person__photo {
    grid-row: 1 / span 2;
    width: 40px;
    height: 40px;
    aspect-ratio: auto;
    margin-bottom: 0;
    border-radius: var(--tvdb-radius-round);
}

.tvdb-cast--compact .tvdb-person__photo--initials {
    font-family: var(--tvdb-font-ui);
    font-size: var(--tvdb-text-sm);
    font-weight: 600;
    letter-spacing: 0;
}

.tvdb-cast--compact .tvdb-person__name,
.tvdb-cast--compact .tvdb-person__detail {
    grid-column: 2;
}

/* A person with no job listed: the name centres on the avatar. */
.tvdb-cast--compact .tvdb-person__name:last-child {
    grid-row: 1 / span 2;
}

@media (min-width: 992px) {
    .tvdb-cast--compact .tvdb-cast__list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 575.98px) {
    .tvdb-cast:not(.tvdb-cast--compact) .tvdb-cast__list {
        display: flex;
        gap: var(--tvdb-space-3);
        overflow-x: auto;
        scroll-snap-type: x proximity;
        /* Bleed to the panel's edge so the row visibly continues. */
        margin-inline: calc(-1 * var(--tvdb-shell-pad));
        padding-inline: var(--tvdb-shell-pad);
        scroll-padding-inline: var(--tvdb-shell-pad);
    }

    /* Three and a bit cards across, so the fourth always peeks in at the edge
       and says the row scrolls. */
    .tvdb-cast:not(.tvdb-cast--compact) .tvdb-person {
        flex: 0 0 clamp(4.75rem, calc((100% - 3 * var(--tvdb-space-3)) / 3.4), 6.5rem);
        scroll-snap-align: start;
    }

    .tvdb-cast:not(.tvdb-cast--compact) .tvdb-cast__toggle {
        display: none;
    }

    .tvdb-cast--compact .tvdb-cast__list {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: repeat(6, auto);
    }
}

/* ---- Toasts (the _ToastMessages partial) --------------------------------------------------
   A fixed stack at the bottom right, dark so it reads over any page. A toast
   that closes itself has a countdown bar along its bottom edge; the bar's
   animation is the timer (js/tvdb-toasts.js closes the toast when it ends). */

.tvdb-toast-stack {
    position: fixed;
    z-index: 1080;
    right: var(--tvdb-space-4);
    bottom: var(--tvdb-space-4);
    display: flex;
    flex-direction: column;
    gap: var(--tvdb-space-2);
    width: min(380px, calc(100vw - 2rem));
    pointer-events: none;
}

.tvdb-toast-stack .alert {
    --bs-alert-color: var(--tvdb-on-ink);
    --bs-alert-bg: var(--tvdb-ink-2);
    --bs-alert-border-color: var(--tvdb-line);
    --bs-alert-padding-x: var(--tvdb-space-3);
    --bs-alert-padding-y: var(--tvdb-space-3);
    --bs-alert-margin-bottom: 0;
    --bs-secondary-bg: var(--tvdb-ink-3);
    --tvdb-focus: var(--tvdb-signal);

    display: flex;
    align-items: center;
    gap: var(--tvdb-space-3);
    border-left-width: 4px;
    font-size: var(--tvdb-text-sm);
    box-shadow: var(--tvdb-shadow-lg);
    pointer-events: auto;
    animation: tvdb-toast-in 0.25s ease-out;

    /* The countdown bar is clipped to the rounded corners. */
    overflow: hidden;
    border-left-color: var(--tvdb-toast-accent);
}

/* The countdown: full width at the start, nothing when the time is up. It only
   runs once the script has taken charge (data-toast-running), so a page
   without script keeps its toasts. */
.tvdb-toast-timer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--tvdb-toast-accent);
    transform-origin: left center;
}

.tvdb-toast[data-toast-running] .tvdb-toast-timer {
    animation: tvdb-toast-countdown var(--tvdb-toast-duration) linear forwards;
}

/* Paused while the toast is being read or used, and while the tab is hidden. */
.tvdb-toast:hover .tvdb-toast-timer,
.tvdb-toast:focus-within .tvdb-toast-timer,
.tvdb-toast-stack[data-toast-paused] .tvdb-toast-timer {
    animation-play-state: paused;
}

@keyframes tvdb-toast-countdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.tvdb-toast-icon {
    flex: none;
    font-size: var(--tvdb-text-lg);
}

.tvdb-toast-text {
    flex: 1 1 auto;
    min-width: 0;
}

/* The accent of each kind: its left edge and its countdown bar. */
.tvdb-toast-stack .alert-success { --tvdb-toast-accent: var(--tvdb-ok); }
.tvdb-toast-stack .alert-success .tvdb-toast-icon { color: var(--tvdb-ok); }
/* "You've finished ..." gets the trophy in amber. */
.tvdb-toast-stack .alert-success .tvdb-toast-icon--finished { color: var(--tvdb-signal); }
.tvdb-toast-stack .alert-danger { --tvdb-toast-accent: var(--tvdb-danger); }
.tvdb-toast-stack .alert-danger .tvdb-toast-icon { color: var(--tvdb-danger-on-ink); }
.tvdb-toast-stack .alert-warning { --tvdb-toast-accent: var(--tvdb-signal); }
.tvdb-toast-stack .alert-warning .tvdb-toast-icon { color: var(--tvdb-signal); }
.tvdb-toast-stack .alert-info { --tvdb-toast-accent: var(--tvdb-info); }
.tvdb-toast-stack .alert-info .tvdb-toast-icon { color: var(--tvdb-info-on-ink); }

/* "Undo" and friends: amber, so it stands out on the dark toast. */
.tvdb-toast-action {
    appearance: none;
    flex: none;
    padding: var(--tvdb-space-1) var(--tvdb-space-3);
    border: 1px solid var(--tvdb-signal);
    border-radius: var(--tvdb-radius-md);
    background: transparent;
    color: var(--tvdb-signal);
    font-size: var(--tvdb-text-sm);
    font-weight: 600;
    text-decoration: none;   /* it is a link in the "Rate it" toast */
    cursor: pointer;
    transition: background var(--tvdb-ease), color var(--tvdb-ease);
}

.tvdb-toast-action:hover,
.tvdb-toast-action:focus-visible {
    background: var(--tvdb-signal);
    color: var(--tvdb-on-signal);
}

@keyframes tvdb-toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 480px) {
    .tvdb-toast-stack {
        left: var(--tvdb-space-4);
        width: auto;
    }

    /* A caught-up toast with actions ("Rate it", "Undo") says more than fits
       beside them on a phone: the sentence gets the first line to itself and
       the actions go under it. */
    .tvdb-toast-stack .alert[data-toast-kind][data-toast-actions] {
        flex-wrap: wrap;
    }

    .tvdb-toast-stack .alert[data-toast-kind][data-toast-actions] .tvdb-toast-text {
        flex-basis: calc(100% - 3rem);
    }

    .tvdb-toast-stack .alert[data-toast-kind][data-toast-actions] .tvdb-close {
        margin-left: auto;
    }
}

/* ---- Motion ------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .tvdb-dot,
    .tvdb-toast-stack .alert {
        animation: none;
    }

    /* The bar is not shown, but it still keeps the time: its animation runs
       (and pauses) as usual, and the toast closes when it ends. */
    .tvdb-toast-timer {
        opacity: 0;
    }

    .tvdb-series-poster,
    .tvdb-catchup-media img {
        transition: none;
    }

    .tvdb-series-card:hover .tvdb-series-poster,
    .tvdb-series-card:focus-visible .tvdb-series-poster,
    .tvdb-catchup-card:hover .tvdb-catchup-media img {
        transform: none;
    }
}
