.iiif-sc {
    position: relative;
}

.iiif-sc__bg {
    position: relative;
    overflow: hidden;
    background: #111;
    color: #fff
}

.iiif-sc__slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity .8s ease;
    display: block;
    color: inherit;
    text-decoration: none;
    pointer-events: none
}

.iiif-sc__slide.is-active {
    opacity: 1;
    pointer-events: auto
}

.iiif-sc__slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.iiif-sc__caption {
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    background: rgba(0, 0, 0, .4);
    padding: .5rem .75rem;
    border-radius: .25rem;
    color: #fff;
    box-sizing: border-box;
}

.iiif-sc__overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
    padding: 1rem
}

.iiif-sc__search {
    pointer-events: auto;
    background: rgba(255, 255, 255, .9);
    padding: 1rem;
    border-radius: .5rem;
    display: flex;
    gap: 0 !important;
    width: 100%;
    /* Scale with viewport: narrower on small/medium, capped on large */
    max-width: clamp(320px, 60vw, 720px);
    box-sizing: border-box;
    align-items: flex-start !important;
    flex-wrap: wrap;
    flex-direction: column;
}

/* Prevent line breaks between radio and label text */
.iiif-sc__search .multi-search-logic,
.iiif-sc__search .search-form__logic {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.iiif-sc__search .logic-option {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    white-space: nowrap;
}

/* Visually disabled logic option (kept visible) */
.iiif-sc__search .logic-option.is-disabled {
    opacity: .5;
    cursor: not-allowed;
}

.iiif-sc__search .logic-option.is-disabled input[disabled] {
    pointer-events: none;
}

.iiif-sc__search input {
    flex: 1 1 auto;
    min-width: 0;
    padding: .5rem;
    margin: 0;
    box-sizing: border-box
}

.iiif-sc__search button {
    padding: .5rem .75rem;
    cursor: pointer;
    margin: 0;
    flex: 0 0 auto
}

/* Controls row: input + radio + button on one line */
.iiif-sc__controls {
    display: flex;
    gap: .5rem;
    align-items: stretch;
    /* match tallest child (input) */
    width: 100%;
}

.iiif-sc__controls .search-form__input {
    flex: 1 1 auto;
    min-width: 0;
}

.iiif-sc__controls .multi-search-logic,
.iiif-sc__controls .search-form__logic {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
}

.iiif-sc__controls .button {
    flex: 0 0 auto;
    align-self: stretch;
    /* match input height */
    display: inline-flex;
    align-items: center;
    /* center label vertically */
}

/* Tablet: keep controls on one line, compress gaps */
@media (max-width: 900px) {
    .iiif-sc__controls {
        flex-wrap: nowrap;
        gap: .4rem;
    }

    .iiif-sc__controls .search-form__input {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Mobile: tighten gaps a bit */
@media (max-width: 600px) {
    .iiif-sc__controls {
        gap: .3rem;
    }

    .iiif-sc__controls .search-form__input {
        /* Allow input to shrink to share space with the button */
        flex: 1 1 0%;
        max-width: none;
        min-width: 0;
    }

    .iiif-sc__controls .multi-search-logic,
    .iiif-sc__controls .search-form__logic {
        gap: .3rem;
        white-space: nowrap;
        justify-content: flex-start;
    }

    .iiif-sc__controls .logic-option {
        font-size: .85em;
    }

    .iiif-sc__controls .button {
        padding: .35rem .5rem;
        font-size: .95em;
        margin-left: auto;
        /* push button to the right edge */
    }
}

/* Extra small devices (e.g., 360px width) */
@media (max-width: 380px) {
    .iiif-sc__controls {
        gap: .25rem;
    }

    .iiif-sc__controls .search-form__input {
        /* Allow input to shrink further on very narrow screens */
        flex: 1 1 0%;
        max-width: none;
    }

    .iiif-sc__controls .multi-search-logic,
    .iiif-sc__controls .search-form__logic {
        gap: .25rem;
    }

    .iiif-sc__controls .logic-option {
        font-size: .8em;
    }

    .iiif-sc__controls .button {
        padding: .3rem .45rem;
        font-size: .9em;
        margin-left: auto;
        /* ensure right alignment on very small screens */
    }
}

/* Medium adjustments */
@media (max-width: 900px) {
    .iiif-sc__search {
        max-width: clamp(280px, 70vw, 640px);
    }
}

/* Examples under the input inside the form */
.iiif-sc__inputwrap {
    width: 100%;
}

.iiif-sc__examples {
    --iiif-ex-gap: .75rem;
    /* default gap for examples */
    margin-top: .4rem;
    font-size: .9em;
    color: #333;
    line-height: 1.4;
    display: flex;
    flex-wrap: wrap;
    column-gap: var(--iiif-ex-gap);
    row-gap: .5rem;
    /* Disable 'palt' only for this block to avoid glyph width changes */
    font-feature-settings: normal !important;
    -webkit-font-feature-settings: normal !important;
    font-variant-ligatures: none !important;
}

.iiif-sc__examples-label {
    color: #444;
    margin-right: .25rem;
}


.iiif-sc__example:hover,
.iiif-sc__example:focus {
    text-decoration: underline;
}

.iiif-sc__examples .iiif-sc__example::after {
    /* No trailing punctuation; spacing is handled by gaps above */
    content: "";
    color: #666;
    margin-right: 0;
}

/* Remove gap only between the label and the first example */
.iiif-sc__examples-label {
    margin-right: 0;
    /* label shouldn't add extra margin */
}

.iiif-sc__examples-label+.iiif-sc__example {
    /* Always keep a small fixed gap between the label and the first example.
       This ensures consistent spacing (.25rem) across all viewport sizes. */
    margin-left: .25rem;
}

/* Limit visible examples by viewport width */
/* Desktop: show up to 5 examples (plus label) */
.iiif-sc__examples .iiif-sc__example:nth-child(n+7) {
    display: none;
}

/* Tablet: show up to 4 */
@media (max-width: 900px) {
    .iiif-sc__examples {
        column-gap: .5rem;
        row-gap: .35rem;
    }
}

/* Narrower tablet breakpoint for limiting to 4 examples */
@media (max-width: 820px) {

    /* Tablet: show up to 4 examples (plus label) */
    .iiif-sc__examples .iiif-sc__example:nth-child(n+6) {
        display: none;
    }
}

/* Mobile: show up to 3 */
@media (max-width: 600px) {
    .iiif-sc__examples {
        column-gap: .4rem;
        row-gap: .25rem;
    }

    /* Mobile: show up to 3 examples (plus label) */
    .iiif-sc__examples .iiif-sc__example:nth-child(n+5) {
        display: none;
    }
}

/* Prevent label and first example from being too tight on small/medium screens */
@media (max-width: 1024px) {
    .iiif-sc__examples {
        /* make gap slightly tighter on small/medium screens (about one half-width space) */
        column-gap: calc(var(--iiif-ex-gap) - 0.25rem);
    }
}

/* Ensure examples appear on their own row below the controls */
.iiif-sc__examples-row {
    flex: 1 1 100%;
    margin-top: 0;
}

.iiif-sc__search.search-form.search-form--inline label {
    line-height: 1;
    /* standard line-height to align with inputs/buttons */
}

/* Tools row between controls and examples */
.iiif-sc__tools-row {
    width: 100%;
    /* Use Grid so the single child can be reliably right-aligned across browsers */
    display: grid;
    justify-items: end;
    /* Fallback alignment in case Grid is overridden */
    text-align: right;
    /* Ensure parent layouts allow this to expand full width */
    min-width: 0;
    margin-top: .5rem;
    /* add visual gap between row1 and row2 */
}

.iiif-sc__advanced-link {
    /* Slightly smaller font size per request */
    font-size: .85em;
    color: #0366d6;
    text-decoration: none;
}

.iiif-sc__advanced-link:hover,
.iiif-sc__advanced-link:focus {
    text-decoration: underline;
}

/* Extra small font for the advanced link on narrow screens */
@media (max-width: 600px) {
    .iiif-sc__advanced-link {
        font-size: .8em;
    }
}

/* Align logic radios to the left (no auto-centering) */
.iiif-sc__controls .multi-search-logic,
.iiif-sc__controls .search-form__logic {
    margin: auto;
    justify-content: flex-start;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .iiif-sc__overlay {
        padding: .5rem;
    }

    .iiif-sc__search {
        flex-direction: row;
        gap: 0;
        padding: .5rem;
        /* Allow wider form on small screens to prevent button overflow */
        max-width: clamp(220px, 96vw, 560px);
        font-size: .9rem;
    }

    .iiif-sc__search input {
        padding: .4rem;
    }

    .iiif-sc__search button {
        padding: .4rem .6rem;
        white-space: nowrap;
    }

    /* Keep the caption box away from the right edge, symmetric to the left */
    .iiif-sc__caption {
        max-width: calc(100% - 2rem);
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Ensure flex container can shrink children properly */
    .iiif-sc__controls {
        min-width: 0;
    }
}

/* Small screens: keep input and button on one row via Grid (input grows, button auto) */
@media (max-width: 640px) {

    /*
    .iiif-sc__controls {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: .3rem;
        align-items: stretch;
        width: 100%;
    }
*/
    .iiif-sc__controls .search-form__input {
        min-width: 0;
        max-width: none !important;
        width: auto;
    }

    .iiif-sc__controls .button {
        justify-self: end;
        margin-left: 0;
    }
}