/* ══════════════════════════════════════════════════════════════════════════
   The common gallery core — shared/css/gallery.css (spec v12 §5.0 row 9)

   The viewer's chrome and the frame affordance, styled ONLY through the
   --gallery-* custom properties below. A surface overrides the subset it
   wants in its own stylesheet, after this file is linked. This file carries
   no world token, no image URL and no importance-overriding declaration.

   Focus rings are INSET box-shadows, not outlines: every control here carries
   a clip-path chamfer, and clip-path clips an outline away.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens — the default skin ───────────────────────────────────────────── */

:root {
    --gallery-backdrop: rgba(12, 18, 16, 0.92);
    --gallery-ink: #f6faf8;
    --gallery-surface: rgba(255, 255, 255, 0.10);
    --gallery-edge: rgba(255, 255, 255, 0.30);
    --gallery-focus: #ffffff;
    --gallery-chamfer: 0px;
    --gallery-stage-max: calc(100dvh - 150px);
}

/* ── The frame affordance ────────────────────────────────────────────────── */

.cg-frame[data-cg-viewer] {
    cursor: pointer;
}

.cg-frame[data-cg-viewer]::before {
    content: "Zvětšit";
    position: absolute;
    z-index: 2;
    right: 14px;
    bottom: 14px;
    padding: 8px 14px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.85rem;
    line-height: 1;
    letter-spacing: 0.04em;
    color: var(--gallery-ink);
    background: var(--gallery-backdrop);
    border: 1px solid var(--gallery-edge);
    box-shadow: 0 6px 18px -8px rgba(12, 18, 16, 0.45);
    pointer-events: none;
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.cg-frame[data-cg-viewer]:hover::before,
.cg-frame[data-cg-viewer]:focus-visible::before {
    background: var(--gallery-ink);
    color: var(--gallery-backdrop);
    border-color: var(--gallery-ink);
}

/* A visible focus ring on the frame itself — inset, so it stays inside the
   frame's own clip region. */
.cg-frame[data-cg-viewer]:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px var(--gallery-focus);
}

/* ── The viewer — a fixed overlay covering the viewport ──────────────────── */

/* `hidden` must win over the flex layout below: the one dialog is reused, and
   it is hidden between openings. */
.cg-viewer[hidden] {
    display: none;
}

/* `inset: 0` with no width/height pair, and no side offsets beyond zero: the
   overlay cannot push the document wider than the viewport. */
.cg-viewer {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--gallery-backdrop);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--gallery-ink);
    transition: opacity 160ms ease;
}

/* The photograph area takes the room the chrome leaves behind. */
.cg-viewer-stage {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cg-viewer-picture {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
}

/* The image fits the viewport: the height budget is the surface's stage token.
   Never cropped, never letterboxed. */
.cg-viewer-img {
    display: block;
    max-width: 100%;
    max-height: var(--gallery-stage-max);
    width: auto;
    height: auto;
    object-fit: contain;
    border: 1px solid var(--gallery-edge);
}

/* The control bar — one cut line. */
.cg-viewer-bar {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 14px;
    padding: 14px 0 2px;
    border-top: 1px solid var(--gallery-edge);
    clip-path: polygon(calc(100% - var(--gallery-chamfer)) 0, 100% var(--gallery-chamfer),
            100% 100%, var(--gallery-chamfer) 100%,
            0 calc(100% - var(--gallery-chamfer)), 0 0);
}

/* ── The controls ────────────────────────────────────────────────────────── */

/* Every control is at least 44×44. */
.cg-viewer-btn {
    flex: 0 0 auto;
    min-width: 52px;
    min-height: 52px;
    padding: 10px 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--gallery-ink);
    background: var(--gallery-surface);
    border: 1px solid var(--gallery-edge);
    cursor: pointer;
    clip-path: polygon(calc(100% - var(--gallery-chamfer)) 0, 100% var(--gallery-chamfer),
            100% 100%, var(--gallery-chamfer) 100%,
            0 calc(100% - var(--gallery-chamfer)), 0 0);
    transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.cg-viewer-btn:hover {
    color: var(--gallery-backdrop);
    background: var(--gallery-ink);
    border-color: var(--gallery-ink);
}

.cg-viewer-btn:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px var(--gallery-focus);
}

/* The close control: the largest of the three, in the top-right corner. */
.cg-viewer-close {
    z-index: 2;
    min-width: 56px;
    min-height: 56px;
    padding: 12px 16px;
    font-size: 1.3rem;
    background: var(--gallery-backdrop);
}

.cg-viewer-close:hover {
    color: var(--gallery-backdrop);
    background: var(--gallery-ink);
}

/* A clamped control is disabled and visibly reduced. */
.cg-viewer-btn:disabled {
    opacity: 0.32;
    cursor: default;
    pointer-events: none;
}

/* ── The position indicator ──────────────────────────────────────────────── */

.cg-viewer-position {
    flex: 1 1 auto;
    margin: 0;
    min-width: 4.5em;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.95rem;
    line-height: 1.2;
    letter-spacing: 0.08em;
    text-align: center;
    color: var(--gallery-ink);
    font-variant-numeric: tabular-nums;
    clip-path: polygon(calc(100% - var(--gallery-chamfer)) 0, 100% var(--gallery-chamfer),
            100% 100%, var(--gallery-chamfer) 100%,
            0 calc(100% - var(--gallery-chamfer)), 0 0);
}

/* ── 768 px and below — the primary device ───────────────────────────────── */

@media (max-width: 768px) {
    .cg-viewer {
        padding: 12px;
    }

    /* The chrome on a phone is taller: the close control and the bar both
       take their own row, so the image budget shrinks with them. */
    .cg-viewer-img {
        max-height: calc(var(--gallery-stage-max) - 40px);
    }

    .cg-viewer-bar {
        gap: 10px;
        margin-top: 10px;
    }

    .cg-viewer-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 8px 14px;
    }

    .cg-viewer-close {
        min-width: 52px;
        min-height: 52px;
    }

    /* The chip stays inside the narrower frame. */
    .cg-frame[data-cg-viewer]::before {
        right: 10px;
        bottom: 10px;
        padding: 7px 12px;
        min-height: 44px;
        font-size: 0.8rem;
    }
}

/* ── Reduced motion — nothing moves unless the user has asked for motion ── */

@media (prefers-reduced-motion: reduce) {
    .cg-viewer,
    .cg-viewer-btn,
    .cg-frame[data-cg-viewer]::before {
        transition: none;
    }
}
