/* Browse Gallery: grid + image viewer (public/slideshow/gallery.js).
   Uses the colour tokens and caption (.ss-overlay / .ov-*) styles from
   slideshow.css. */

body.no-scroll { overflow: hidden; }

/* ── Grid ─────────────────────────────────────────────────────────────── */

.gallery { min-height: 100vh; padding: 0 16px 48px; }

.g-head {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 14px 0;
    background: rgba(10, 13, 24, 0.94);
    backdrop-filter: blur(6px);
}
.g-head h1 { margin: 0; font-size: 1.3em; font-weight: 600; flex: 1; min-width: 140px; }
.g-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid rgba(74, 158, 255, 0.7);
    border-radius: 50%;
    background: rgba(10, 13, 24, 0.45);
}
.g-back:hover { background: rgba(74, 158, 255, 0.35); }
.g-back svg { width: 22px; height: 22px; fill: #fff; }

.g-search {
    flex: 0 1 340px;
    min-width: 0;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 0.95em;
}
.g-search:focus { outline: none; border-color: var(--accent); }

.g-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    max-width: 1400px;
    margin: 0 auto;
}
@media (max-width: 480px) {
    .g-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

.g-card {
    display: block;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.2s, transform 0.2s;
}
.g-card:hover, .g-card:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: none; }

.g-thumb {
    position: relative;
    aspect-ratio: 4 / 5;
    background: #0d1124;
    overflow: hidden;
}
.g-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.g-thumb.loaded img { opacity: 1; }

.g-badge {
    position: absolute;
    top: 8px;
    z-index: 1;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7em;
    pointer-events: none;
}
.g-count  { right: 8px; background: rgba(0, 0, 0, 0.65); color: #7ec8ff; border: 1px solid rgba(74, 158, 255, 0.4); }
.g-mosaic { left: 8px; background: rgba(240, 160, 48, 0.85); color: #1a1200; font-weight: 600; }
.g-4k     { top: auto; bottom: 8px; right: 8px; background: rgba(74, 158, 255, 0.85); color: #04101f; font-weight: 700; letter-spacing: 0.04em; }

.g-title {
    margin: 0;
    padding: 9px 10px 11px;
    font-size: 0.85em;
    font-weight: 500;
    line-height: 1.3;
}

.g-none { text-align: center; color: var(--muted); padding: 40px 0; }

/* ── Viewer ───────────────────────────────────────────────────────────── */

.gm {
    position: fixed;
    inset: 0;
    z-index: 20;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
}

.gm-stage {
    position: relative;
    height: 100vh;
    height: 100dvh;
    background: #000;
    overflow: hidden;
}

.gm-img {
    position: absolute;
    max-width: none;
    transform-origin: center center;
    transition: opacity 0.3s ease;
    user-select: none;
    -webkit-user-drag: none;
}
.gm.loading .gm-img,
.gm.loading .ss-overlay { opacity: 0; }
.gm.loading .gm-stage::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(74, 158, 255, 0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: gm-spin 1s linear infinite;
}
.gm.no-overlay .ss-overlay { opacity: 0; }
.gm.busy { cursor: progress; }
@keyframes gm-spin { to { transform: rotate(360deg); } }

.gm-ctl { position: absolute; z-index: 5; }
.gm-top-left  { top: 16px; left: 16px; }
.gm-top-right { top: 16px; right: 16px; display: flex; align-items: center; gap: 10px; }
.gm-counter {
    position: absolute;
    top: 24px;
    left: 50%;
    z-index: 5;
    transform: translateX(-50%);
    padding: 3px 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.5);
    color: #9aa0a6;
    font-size: 0.8em;
    pointer-events: none;
}
.gm-counter:empty { display: none; }

.gm-more {
    position: absolute;
    left: 50%;
    bottom: 6px;
    z-index: 5;
    transform: translateX(-50%);
    padding: 2px 10px;
    border: 0;
    background: none;
    cursor: pointer;
    opacity: 0.55;
}
.gm-more:hover { opacity: 1; }
.gm-more svg { width: 26px; height: 26px; fill: #fff; display: block; }

/* Download menu */
.gm-menu {
    position: absolute;
    top: 72px;
    right: 16px;
    z-index: 6;
    min-width: 230px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #141a33;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
.gm-menu h4 {
    margin: 0;
    padding: 9px 14px 6px;
    font-size: 0.72em;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    background: #10152b;
}
.gm-menu button {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 10px;
    padding: 9px 14px 9px 18px;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.88em;
    text-align: left;
    cursor: pointer;
}
.gm-menu button:hover { background: var(--panel-hi); }
.gm-menu button[hidden], .gm-menu h4[hidden] { display: none; }
.gm-menu .hint { margin-left: auto; color: var(--muted); font-size: 0.85em; }

/* Information window (the i button): object details + the image's line */
.gm-panel {
    position: absolute;
    top: 72px;
    right: 16px;
    z-index: 6;
    width: min(460px, calc(100% - 32px));
    max-height: calc(100% - 96px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(20, 26, 51, 0.96);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    scrollbar-width: thin;
}
.gm-panel-close {
    position: sticky;
    top: 6px;
    float: right;
    width: 32px;
    height: 32px;
    margin: 6px 6px 0 0;
    border: 0;
    border-radius: 50%;
    background: rgba(10, 13, 24, 0.6);
    color: #fff;
    font-size: 1.4em;
    line-height: 1;
    cursor: pointer;
}
.gm-panel-close:hover { background: rgba(74, 158, 255, 0.4); }
.gm-panel .gm-info { max-width: none; margin: 0; padding: 18px 20px 16px; }
.gm-panel .gm-imgline {
    justify-content: flex-start;
    padding: 12px 20px 16px;
    border-bottom: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

/* Filmstrip, image line, info */
.gm-strip {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    background: #070912;
    scrollbar-width: thin;
}
.gm-thumb {
    flex-shrink: 0;
    width: 54px;
    height: 68px;
    padding: 0;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 4px;
    background: #000;
    opacity: 0.5;
    cursor: pointer;
    transition: opacity 0.15s, border-color 0.15s;
}
.gm-thumb:hover { opacity: 0.85; }
.gm-thumb.active { opacity: 1; border-color: var(--accent); }
.gm-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.gm-imgline {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 16px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.8em;
    color: #9aa0a6;
}
.gm-imgline .g-lbl     { color: #6e7681; }
.gm-imgline .g-caption { color: #c9d1d9; font-style: italic; }
.gm-imgline .g-palette { color: #7ec8ff; font-weight: 600; }
.gm-imgline .g-mosaic-tag { color: #f0a030; }

.gm-info {
    max-width: 820px;
    margin: 0 auto;
    padding: 22px 20px 60px;
}
.gm-title { margin: 0 0 14px; font-size: 1.25em; font-weight: 600; }
.gm-blurb { margin: 0 0 12px; line-height: 1.65; color: #c9d1d9; font-size: 0.95em; }
.gm-facts {
    margin: 14px 0 0;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    color: #8b949e;
    font-size: 0.88em;
    font-style: italic;
    line-height: 1.55;
}
.gm-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.gm-link {
    padding: 5px 13px;
    border: 1px solid rgba(74, 158, 255, 0.3);
    border-radius: 14px;
    background: rgba(74, 158, 255, 0.1);
    color: #7ec8ff;
    font-size: 0.82em;
    text-decoration: none;
}
.gm-link:hover { background: rgba(74, 158, 255, 0.22); border-color: var(--accent); color: #fff; }

/* Reordering -- only when run locally (window.GALLERY_EDIT, gallery.js) */
.g-edit-status {
    padding: 4px 10px;
    border: 1px dashed var(--line);
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.8em;
    white-space: nowrap;
    cursor: help;
}
.g-card.can-drag { cursor: grab; }
.gm-thumb.can-drag { cursor: grab; }
.g-card.dragging, .gm-thumb.dragging { opacity: 0.35; }
.g-card.drop-before, .gm-thumb.drop-before { box-shadow: -4px 0 0 0 var(--accent); }
.g-card.drop-after,  .gm-thumb.drop-after  { box-shadow:  4px 0 0 0 var(--accent); }
.g-card.just-moved { border-color: #3fb950; }
.g-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 100;
    max-width: calc(100vw - 32px);
    padding: 8px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(18, 24, 49, 0.96);
    color: var(--text);
    font-size: 0.9em;
    opacity: 0;
    transform: translate(-50%, 10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.g-toast.show { opacity: 1; transform: translate(-50%, 0); }
.g-toast.saved { border-color: #3fb950; }
.g-toast.error { border-color: #f85149; color: #ffb4ae; }

@media (max-width: 600px) {
    .gm-top-left  { top: 10px; left: 10px; }
    .gm-top-right { top: 10px; right: 10px; gap: 8px; }
    .gm-menu { top: 60px; right: 10px; left: 10px; min-width: 0; }
    .gm-panel { top: 60px; right: 10px; left: 10px; width: auto; max-height: calc(100% - 76px); }
}
