/* Device Loader gallery — demo page styles (not part of the library) */

:root {
    --bg: #f5f5f7;
    --card: #ffffff;
    --ink: #1d1d1f;
    --muted: #6e6e73;
    --line: #e3e3e8;
    --accent: #0071e3;
    --frame: 300px;
    --gap: 20px;
    --gutter: clamp(16px, 4vw, 48px);
    --radius: 22px;
    --ease: cubic-bezier(.2, .8, .2, 1);
    color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

code { font: .85em ui-monospace, SFMono-Regular, Menlo, monospace; }

/* --- Page header --------------------------------------------------------- */
.page-head {
    padding: 48px var(--gutter) 24px;
    max-width: 900px;
}
.page-head h1 { font-size: clamp(28px, 4vw, 40px); letter-spacing: -.02em; }
.page-head p { color: var(--muted); margin-top: 6px; }
.page-head nav {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px;
}
.page-head nav a {
    padding: 6px 14px; border-radius: 999px;
    background: var(--card); border: 1px solid var(--line);
    color: var(--ink); text-decoration: none; font-weight: 500;
}
.page-head nav a:hover { border-color: var(--ink); }

/* --- Groups -------------------------------------------------------------- */
.group { padding: 32px 0 24px; scroll-margin-top: 16px; }
.group-head {
    display: flex; align-items: baseline; gap: 12px;
    margin: 0 var(--gutter) 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.group-head h2 { font-size: 28px; letter-spacing: -.015em; }
.group-head p { color: var(--muted); }
.carousel-nav { margin-left: auto; align-self: center; display: flex; gap: 8px; }
.carousel-nav button {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
    font-size: 22px; line-height: 1; cursor: pointer;
    transition: opacity .2s, border-color .2s;
}
.carousel-nav button:hover:not(:disabled) { border-color: var(--ink); }
.carousel-nav button:disabled { opacity: .35; cursor: default; }

/* --- Carousel: one snap stop per device ---------------------------------- */
.carousel {
    list-style: none;
    display: flex;
    gap: var(--gap);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--gutter);
    padding: 4px var(--gutter) 16px;
    scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }

.slide {
    flex: 0 0 var(--frame);
    scroll-snap-align: start;
}

.frame {
    position: relative;
    width: var(--frame);
    height: var(--frame);
    padding: 20px;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.04);
    display: grid;
    place-items: center;
    container-type: size;
    transition: box-shadow .25s var(--ease), transform .25s var(--ease);
}
.frame:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0,0,0,.05), 0 16px 36px rgba(0,0,0,.08);
}

/* The figure is sized to the device's own aspect ratio (--ar is set once it
   renders), so its box IS the device — that's what the zoom animates from. */
.frame figure.device,
.lb-device {
    --ar: 1;
    aspect-ratio: var(--ar);
    width: min(100cqw, 100cqh * var(--ar));
    margin: 0;
}
.frame figure.device:not([data-state="loaded"]) {
    width: 60cqw;
    border-radius: 14px;
    background: linear-gradient(100deg, #f0f0f3 30%, #f8f8fa 50%, #f0f0f3 70%) 0 0 / 200% 100%;
    animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.frame figure.device > svg,
.lb-device > svg {
    display: block;
    width: 100%;
    height: 100%;
}
/* Fold module keeps its own flex layout — just fill the box */
.frame figure.device > .fold-stage,
.lb-device > .fold-stage {
    width: 100%;
    height: 100%;
    /* The module's fixed 1200px perspective exaggerates at large sizes —
       scale it with the device so the zoomed fold matches the card */
    perspective: calc(min(100cqw, 100cqh * var(--ar)) * 4.5);
}

.zoom {
    position: absolute; inset: 0;
    border: 0; background: none;
    border-radius: inherit;
    cursor: zoom-in;
}
.zoom:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.caption {
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 4px 0;
    font-size: 13px;
}
.caption strong { font-size: 15px; font-weight: 600; }
.caption span { color: var(--muted); }

/* --- Lightbox ------------------------------------------------------------- */
.lightbox {
    position: fixed; inset: 0;
    width: 100vw; height: 100dvh;
    max-width: none; max-height: none;
    border: 0; padding: 0;
    background: transparent;
    color: var(--ink);
    overflow: hidden;
}
.lightbox::backdrop { background: transparent; }

.lb-inner {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: 64px 1fr 64px;
    grid-template-rows: 1fr auto;
    background: rgba(245, 245, 247, 0);
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    transition: background .35s var(--ease), backdrop-filter .35s var(--ease), -webkit-backdrop-filter .35s var(--ease);
}
.lightbox.is-open .lb-inner {
    background: rgba(245, 245, 247, .9);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

.lb-stage {
    grid-column: 2; grid-row: 1;
    display: grid; place-items: center;
    padding: 56px 0 16px;
    min-height: 0;
    container-type: size;
}
.lb-device { will-change: transform; transform-origin: 0 0; }

.lb-close, .lb-prev, .lb-next {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    border-radius: 50%;
    width: 44px; height: 44px;
    font-size: 26px; line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .25s var(--ease), border-color .2s;
}
.lb-close:hover, .lb-prev:hover:not(:disabled), .lb-next:hover:not(:disabled) { border-color: var(--ink); }
.lb-prev:disabled, .lb-next:disabled { visibility: hidden; }
.lb-close { position: absolute; top: 16px; right: 16px; z-index: 2; }
.lb-prev { grid-column: 1; grid-row: 1; align-self: center; justify-self: center; }
.lb-next { grid-column: 3; grid-row: 1; align-self: center; justify-self: center; }

.lb-info {
    grid-column: 1 / -1; grid-row: 2;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px 16px;
    align-items: start;
    width: min(820px, 100% - 32px);
    margin: 0 auto 24px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.lb-title h2 { font-size: 20px; letter-spacing: -.01em; }
.lb-title p { color: var(--muted); }
.lb-count { color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 4px; }

.lb-options { grid-column: 1 / -1; min-height: 58px; }
.lb-code { grid-column: 1 / -1; position: relative; }
.lb-code summary { cursor: pointer; color: var(--accent); font-weight: 500; width: max-content; }
.lb-code pre {
    margin-top: 8px;
    max-height: 22vh; overflow: auto;
    padding: 14px 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 13px;
}
.lb-copy {
    position: absolute; right: 8px; top: 36px;
    border: 1px solid var(--line); background: var(--bg);
    border-radius: 8px; padding: 4px 10px; font: inherit; font-size: 12px;
    cursor: pointer;
}

.lightbox.is-open :is(.lb-close, .lb-prev, .lb-next) { opacity: 1; }
.lightbox.is-open .lb-info { opacity: 1; transform: none; }

/* Source card fades while its device is "lifted" into the lightbox.
   opacity (not visibility/display) so shared gradient defs keep resolving. */
.slide.is-lifted figure.device { opacity: 0; }

@media (max-width: 640px) {
    :root { --frame: min(300px, 78vw); }
    .lb-inner { grid-template-columns: 0 1fr 0; }
    .lb-stage { padding: 72px 20px 16px; }
    .lb-prev, .lb-next { position: absolute; bottom: 50%; }
    .lb-prev { left: 8px; } .lb-next { right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
