:root {
    color-scheme: light dark;
}

/* Cross-fade between pages on same-origin navigation (home ⇄ device feed). */
@view-transition {
    navigation: auto;
}

/* Shared-element morph: the image addressed by the URL fragment (the one the
   homepage thumbnail linked to) is paired with the thumbnail tagged `hero`,
   so it grows into place instead of cross-fading with the rest of the page. */
#image-list img:target {
    view-transition-name: hero;
}

body {
    font-family: monospace;
    margin: 0;
}

monocam-add {
    position: fixed;
    top: max(1rem, env(safe-area-inset-top));
    right: 1rem;
    z-index: 10;
}

form#create,
form#token {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 1em;
}

/* Fullscreen camera capture overlay. */
.monocam-camera {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: light-dark(#e8e8e8, #111);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

/* Full-page tap target: shown on QR-scan/`?start` entry and as the
   open-failure fallback. The tap supplies the user gesture that camera +
   fullscreen require. The whole overlay is the target — the "+" is decorative. */
.monocam-prompt {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: light-dark(#e8e8e8, #111);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
}

.monocam-prompt .monocam-plus {
    width: 40vmin;
    height: 40vmin;
    color: light-dark(rgba(0, 0, 0, 0.5), rgba(255, 255, 255, 0.5));
}

.monocam-camera canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

/* The raw video stays in the DOM (so frames keep decoding) but hidden —
   the dithered canvas is what's shown. */
.monocam-camera .monocam-video {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.monocam-camera button,
.monocam-prompt button {
    position: absolute;
    border: 1px solid light-dark(rgba(0, 0, 0, 0.2), rgba(255, 255, 255, 0.15));
    background: light-dark(#111, #eee);
    color: light-dark(#fff, #111);
    cursor: pointer;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.monocam-close {
    top: max(1rem, env(safe-area-inset-top));
    right: 1rem;
    width: 3.5rem;
    height: 3.5rem;
}

.monocam-switch {
    top: max(1rem, env(safe-area-inset-top));
    left: 1rem;
    width: 3.5rem;
    height: 3.5rem;
}

.monocam-hint {
    position: absolute;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    color: light-dark(rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.45));
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
}

/* Full-screen image feed — soft snap: scroll freely, settle when nearby. */
html {
    scroll-snap-type: y proximity;
}

#image-list {
    display: block;
}

/* Each image is a full-screen, snapping panel with a ~4% border. */
#image-list img {
    display: block;
    width: 100%;
    height: 100vh; /* fallback */
    height: 100svh; /* more stable for scroll-driven animations */
    box-sizing: border-box;
    padding: 4%;
    object-fit: contain;
    image-rendering: pixelated; /* keep the 1-bit dither crisp when upscaled */
    scroll-snap-align: start;
}

/* Scroll-driven scale: image grows toward center of view, shrinks at the
   edges. Pure CSS, compositor-driven (transform + view() timeline). */
@keyframes scroll-grow {
    0% {
        transform: scale(0.2);
    }
    30%,
    60% {
        transform: scale(1);
    }
    100% {
        transform: scale(0.2);
    }
}

@supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
        #image-list img {
            animation: scroll-grow ease-in-out both;
            animation-timeline: view();
        }
    }
}

/* Optimistic upload: pulse until the server confirms (replaces scroll-grow
   via higher specificity; auto timeline so it runs on time, not scroll). */
@keyframes pulse {
    to {
        opacity: 0.4;
    }
}

#image-list img.uploading {
    animation: pulse 0.8s ease-in-out infinite alternate;
    animation-timeline: auto;
}

/* Pinned to the tapped image: client.js sets `top` to the image panel's
   bottom edge; the translate pulls the button up inside it. */
monocam-actions {
    position: absolute;
    display: block;
    left: max(1rem, env(safe-area-inset-left));
    z-index: 10;
    transform: translateY(calc(-100% - 1rem));
}

/* "Scroll for more" hint over the top image of a multi-image feed. */
.scroll-hint {
    position: fixed;
    bottom: max(1rem, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    pointer-events: none;
    color: light-dark(rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.45));
}

@keyframes hint-bounce {
    0%,
    100% {
        transform: translate(-50%, 0);
    }
    50% {
        transform: translate(-50%, -0.4rem);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .scroll-hint {
        animation: hint-bounce 1.6s ease-in-out infinite;
    }
}

/* Homepage: device index with recent-image thumbnails. */
main.home {
    max-width: 60rem;
    margin: 0 auto;
    padding: 0.75rem;
}

main.home h1 {
    font-size: 1.2rem;
    margin: 0 0 0.75rem;
}

.home-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.about-link {
    font-size: 0.85rem;
    color: inherit;
}

.device-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.device {
    margin-bottom: 0.75rem;
}

.device-name {
    display: inline-block;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    font-weight: bold;
    color: inherit;
    text-decoration: none;
}

.device-name:hover {
    text-decoration: underline;
}

.thumbs {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.thumb {
    flex: 0 0 auto;
}

.thumb img {
    height: 4rem;
    width: auto;
    object-fit: contain;
    background: light-dark(#fff, #000);
    border-radius: 5px;
}

.thumbs-empty {
    color: light-dark(rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.45));
    font-size: 0.8rem;
}

/* Homepage "Your photos": images this browser holds delete tokens for. */
.my-images {
    margin-top: 2rem;
}

.my-images h2 {
    font-size: 0.9rem;
    margin: 0 0 0.25rem;
}

.my-images-hint {
    margin: 0 0 0.5rem;
    color: light-dark(rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.45));
    font-size: 0.8rem;
}

.my-thumb {
    position: relative;
    display: inline-block;
}

.my-thumb img {
    height: 4rem;
    width: auto;
    object-fit: contain;
    background: light-dark(#fff, #000);
    border-radius: 5px;
}

.my-del {
    position: absolute;
    top: -0.4rem;
    right: -0.4rem;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    border: 1px solid light-dark(rgba(0, 0, 0, 0.2), rgba(255, 255, 255, 0.15));
    background: light-dark(#111, #eee);
    color: light-dark(#fff, #111);
    font-size: 0.7rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.my-del:disabled {
    opacity: 0.4;
    cursor: default;
}

/* About page. */
main.about {
    max-width: 34rem;
    margin: 0 auto;
    padding: 0.75rem;
    line-height: 1.6;
}

main.about h1 {
    font-size: 1.2rem;
    margin: 0 0 0.75rem;
}

main.about a {
    color: inherit;
}

/* Admin page. */
main.admin {
    max-width: 60rem;
    margin: 0 auto;
    padding: 0.75rem;
}

main.admin h1 {
    font-size: 1.2rem;
}

main.admin h2 {
    font-size: 1rem;
    margin-top: 1.5rem;
}

.admin-devices {
    border-collapse: collapse;
}

.admin-devices td {
    padding: 0.3rem 1rem 0.3rem 0;
}

.admin-devices a {
    color: inherit;
}

button.danger {
    color: light-dark(#c00, #f66);
}

.admin-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

#sel-count {
    font-size: 0.8rem;
    opacity: 0.6;
}

.admin-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.admin-grid .pick {
    position: relative;
    cursor: pointer;
}

.admin-grid .pick input {
    position: absolute;
    top: 0.3rem;
    left: 0.3rem;
    z-index: 1;
}

.admin-grid .pick img {
    display: block;
    height: 6rem;
    width: auto;
    object-fit: contain;
    background: light-dark(#fff, #000);
    border-radius: 5px;
}

.admin-grid .pick:has(:checked) img {
    outline: 3px solid light-dark(#06c, #4af);
}

.admin-grid .pick.is-flagged img {
    opacity: 0.5;
}

.pick-meta {
    display: block;
    font-size: 0.7rem;
    opacity: 0.6;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-grid .pick.is-flagged .pick-meta {
    color: light-dark(#c00, #f66);
    opacity: 1;
}

/* Gallery preview — the composited board frame, pixel-for-pixel */
.gallery {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 1rem;
}

.gallery canvas {
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    border: 1px solid light-dark(#ccc, #444);
    background: #fff;
}
