/* Theme preview switcher (demo site only): a "Themes" tab docked to a screen
   edge that opens a panel away from that edge with one button per theme,
   stacked. Uses the active theme's tokens (radius follows theme.radius).
   Placement comes from data-position = "<edge>-<slot>" (setting
   demosite.themeSwitcher.position); the defaults below are "right-bottom":
   right edge, centered at 85% of the viewport height (docked to the bottom on
   small screens). Slots along an edge sit at 15% / 50% / 85%. */
.conn-demo-themes {
    --conn-demo-radius: var(--conn-radius, 0.75rem);
    /* Which corners are rounded (1) or square (0, against the screen edge): TL TR BR BL */
    --conn-demo-tl: 1;
    --conn-demo-tr: 0;
    --conn-demo-br: 0;
    --conn-demo-bl: 1;
    --conn-demo-panel-from: translateX(0.5rem);
    position: fixed;
    top: 85%;
    right: 0;
    z-index: 1045; /* above navbar (1030), below offcanvas/modals */
    transform: translateY(-50%);
    background: var(--conn-surface, #fff);
    border: 1px solid var(--conn-border, rgba(0, 0, 0, 0.1));
    border-right: 0;
    border-radius:
        calc(var(--conn-demo-radius) * var(--conn-demo-tl))
        calc(var(--conn-demo-radius) * var(--conn-demo-tr))
        calc(var(--conn-demo-radius) * var(--conn-demo-br))
        calc(var(--conn-demo-radius) * var(--conn-demo-bl));
    box-shadow: 0 4px 16px rgb(0 0 0 / 12%);
    font-size: 0.8125rem;
}

/* ── Edge ── */
.conn-demo-themes[data-position^="left-"] {
    --conn-demo-tl: 0;
    --conn-demo-tr: 1;
    --conn-demo-br: 1;
    --conn-demo-bl: 0;
    --conn-demo-panel-from: translateX(-0.5rem);
    right: auto;
    left: 0;
    border-right: 1px solid var(--conn-border, rgba(0, 0, 0, 0.1));
    border-left: 0;
}

.conn-demo-themes[data-position^="top-"],
.conn-demo-themes[data-position^="bottom-"] {
    right: auto;
    transform: translateX(-50%);
    border-right: 1px solid var(--conn-border, rgba(0, 0, 0, 0.1));
}

.conn-demo-themes[data-position^="top-"] {
    --conn-demo-tl: 0;
    --conn-demo-tr: 0;
    --conn-demo-br: 1;
    --conn-demo-bl: 1;
    --conn-demo-panel-from: translateY(-0.5rem);
    top: 0;
    border-top: 0;
}

.conn-demo-themes[data-position^="bottom-"] {
    --conn-demo-tl: 1;
    --conn-demo-tr: 1;
    --conn-demo-br: 0;
    --conn-demo-bl: 0;
    --conn-demo-panel-from: translateY(0.5rem);
    top: auto;
    bottom: 0;
    border-bottom: 0;
}

/* ── Slot along the edge ── */
.conn-demo-themes[data-position$="-top"] { top: 15%; }
.conn-demo-themes[data-position$="-middle"] { top: 50%; }
.conn-demo-themes[data-position$="-left"] { left: 15%; }
.conn-demo-themes[data-position$="-center"] { left: 50%; }
.conn-demo-themes[data-position$="-right"] { left: 85%; }

/* ── Toggle: narrow edge tile — icon, short horizontal caption, count ── */
.conn-demo-themes__toggle {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    min-width: 3.5rem;
    padding: 0.65rem 0.5rem 0.6rem;
    /* Not "inherit": in Chrome the <summary> sits in the <details> shadow slot, so it
       would inherit the slot's square corners. Inner radius = outer minus the border. */
    --conn-demo-inner-radius: max(0px, calc(var(--conn-demo-radius) - 1px));
    border-radius:
        calc(var(--conn-demo-inner-radius) * var(--conn-demo-tl))
        calc(var(--conn-demo-inner-radius) * var(--conn-demo-tr))
        calc(var(--conn-demo-inner-radius) * var(--conn-demo-br))
        calc(var(--conn-demo-inner-radius) * var(--conn-demo-bl));
    color: var(--conn-text, inherit);
    font-weight: 600;
    line-height: 1;
    transition: background-color 0.2s ease;
    white-space: nowrap;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.conn-demo-themes__toggle:hover,
.conn-demo-themes[open] .conn-demo-themes__toggle {
    background: color-mix(in srgb, var(--conn-demo-current, #6366f1) 10%, transparent);
}

.conn-demo-themes__toggle::-webkit-details-marker {
    display: none;
}

.conn-demo-themes__toggle:focus-visible {
    outline: 2px solid var(--conn-demo-current, var(--conn-accent, currentColor));
    outline-offset: 2px;
}

.conn-demo-themes__icon {
    flex: none;
    width: 1.375rem;
    height: 1.375rem;
    color: var(--conn-demo-current, var(--conn-accent, currentColor));
}

/* Horizontal caption: readable without tilting your head, still narrow */
.conn-demo-themes__label {
    font-size: 0.625rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.conn-demo-themes__count {
    min-width: 1.25rem;
    margin-top: 0.15rem;
    padding: 0.2rem 0.4rem;
    border-radius: var(--conn-radius-pill, 999px);
    background: var(--conn-demo-current, var(--conn-accent, #6366f1));
    color: #fff;
    font-size: 0.6875rem;
    text-align: center;
}

/* Attention cue while closed: a ring pulses out of the toggle and the palette
   icon wiggles, every few seconds. Stops once the visitor has opened the
   switcher (.is-seen, remembered by theme-switcher.js) and for reduced motion. */
.conn-demo-themes:not([open]):not(.is-seen) .conn-demo-themes__toggle::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius:
        calc(var(--conn-demo-radius) * var(--conn-demo-tl))
        calc(var(--conn-demo-radius) * var(--conn-demo-tr))
        calc(var(--conn-demo-radius) * var(--conn-demo-br))
        calc(var(--conn-demo-radius) * var(--conn-demo-bl));
    pointer-events: none;
    animation: conn-demo-themes-pulse 3.5s ease-out 1.5s infinite;
}

.conn-demo-themes:not([open]):not(.is-seen) .conn-demo-themes__icon {
    animation: conn-demo-themes-wiggle 3.5s ease-in-out 1.5s infinite;
}

@keyframes conn-demo-themes-pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--conn-demo-current, #6366f1) 55%, transparent); }
    45%, 100% { box-shadow: 0 0 0 12px transparent; }
}

@keyframes conn-demo-themes-wiggle {
    0%, 30%, 100% { transform: rotate(0); }
    6% { transform: rotate(-18deg) scale(1.1); }
    12% { transform: rotate(14deg) scale(1.1); }
    18% { transform: rotate(-8deg); }
    24% { transform: rotate(4deg); }
}

/* ── Panel: opens away from the docked edge. Default (right edge, low on the
   screen): to the left of the tab, bottom-aligned so it grows upwards ── */
.conn-demo-themes__panel {
    position: absolute;
    right: calc(100% + 0.5rem);
    bottom: 0;
    max-height: min(75vh, 36rem);
    padding: 0.5rem;
    background: var(--conn-surface, #fff);
    border: 1px solid var(--conn-border, rgba(0, 0, 0, 0.1));
    border-radius: var(--conn-demo-radius);
    box-shadow: 0 4px 16px rgb(0 0 0 / 12%);
    overflow-y: auto;
    overscroll-behavior: contain;
}

[data-position^="left-"] .conn-demo-themes__panel {
    right: auto;
    left: calc(100% + 0.5rem);
}

/* Left/right edge: high on the screen grows downwards, middle grows both ways */
[data-position$="-top"] .conn-demo-themes__panel {
    top: 0;
    bottom: auto;
}

[data-position$="-middle"] .conn-demo-themes__panel {
    top: 50%;
    bottom: auto;
    translate: 0 -50%;
}

/* Top/bottom edge: below/above the tab, aligned with it towards the screen center */
[data-position^="top-"] .conn-demo-themes__panel,
[data-position^="bottom-"] .conn-demo-themes__panel {
    inset: auto;
}

[data-position^="top-"] .conn-demo-themes__panel { top: calc(100% + 0.5rem); }
[data-position^="bottom-"] .conn-demo-themes__panel { bottom: calc(100% + 0.5rem); }
[data-position$="-left"] .conn-demo-themes__panel { left: 0; }
[data-position$="-right"] .conn-demo-themes__panel { right: 0; }

[data-position$="-center"] .conn-demo-themes__panel {
    left: 50%;
    translate: -50% 0;
}

.conn-demo-themes[open]:not(.is-restored) .conn-demo-themes__panel {
    animation: conn-demo-themes-open 0.2s ease-out;
}

@keyframes conn-demo-themes-open {
    from { opacity: 0; transform: var(--conn-demo-panel-from); }
    to { opacity: 1; transform: none; }
}

.conn-demo-themes__list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.conn-demo-themes .conn-demo-themes__theme {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.7rem 0.3rem 0.45rem;
    border: 1px solid var(--conn-border-strong, rgba(0, 0, 0, 0.2));
    border-radius: var(--conn-radius-pill, 999px);
    color: var(--conn-text, inherit);
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

/* No animated hover underline (t3kit-base theme.linkHoverEffect, very specific selector). */
.conn-demo-themes .conn-demo-themes__theme::before,
.conn-demo-themes .conn-demo-themes__theme::after {
    content: none !important;
}

.conn-demo-themes .conn-demo-themes__theme:hover,
.conn-demo-themes .conn-demo-themes__theme:focus-visible {
    border-color: var(--conn-demo-swatch);
    color: var(--conn-text, inherit);
}

.conn-demo-themes .conn-demo-themes__theme.is-active {
    border-color: var(--conn-demo-swatch);
    box-shadow: inset 0 0 0 1px var(--conn-demo-swatch);
    font-weight: 600;
}

.conn-demo-themes__swatch {
    flex: none;
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 50%;
    background: var(--conn-demo-swatch, currentColor);
}

/* Small screens: compact tab (icon + count, no caption); low on a left/right edge
   it is docked to the bottom. The panel keeps the full theme names but may not
   run past the opposite edge. */
@media (max-width: 767.98px) {
    .conn-demo-themes[data-position="right-bottom"],
    .conn-demo-themes[data-position="left-bottom"] {
        top: auto;
        bottom: 1rem;
        transform: none;
    }

    .conn-demo-themes__toggle {
        gap: 0.25rem;
        min-width: 2.5rem;
        padding: 0.45rem 0.35rem 0.4rem;
    }

    .conn-demo-themes__icon {
        width: 1.125rem;
        height: 1.125rem;
    }

    .conn-demo-themes__label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .conn-demo-themes__count {
        margin-top: 0;
        padding: 0.15rem 0.3rem;
        font-size: 0.625rem;
    }

    .conn-demo-themes__panel {
        max-width: calc(100vw - 4rem);
        padding: 0.375rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .conn-demo-themes *,
    .conn-demo-themes *::after {
        animation: none !important;
    }
}
