/* =====================================================================
   Galeri — public styles
   ================================================================== */

:root {
    --bg: #f6f6f3;
    --surface: #ffffff;
    --surface-2: #f0efea;
    --text: #16171a;
    --muted: #6c7077;
    --line: #e3e2dc;
    --line-strong: #cfcec6;
    --accent: #165dff;
    --accent-ink: #ffffff;
    --danger: #c0392b;
    --folder: #e9e5da;
    --folder-edge: #d8d3c4;
    --shadow-sm: 0 1px 2px rgba(20, 20, 15, .05);
    --shadow-md: 0 12px 30px -12px rgba(20, 20, 15, .22);
    --shadow-lg: 0 30px 70px -24px rgba(0, 0, 0, .45);
    --radius: 12px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    --ease: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0c0d0f;
        --surface: #15161a;
        --surface-2: #1c1e23;
        --text: #f1f2f4;
        --muted: #9aa0aa;
        --line: #26282e;
        --line-strong: #34373f;
        --accent: #6d9bff;
        --accent-ink: #08101f;
        --folder: #23252b;
        --folder-edge: #2d3037;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-md: 0 16px 36px -16px rgba(0, 0, 0, .7);
        --shadow-lg: 0 40px 90px -30px rgba(0, 0, 0, .9);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { letter-spacing: -.022em; line-height: 1.12; }

.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 24px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: 16px; top: -60px; z-index: 200;
    background: var(--text); color: var(--bg);
    padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
    transition: top .2s var(--ease);
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-bottom: 1px solid var(--line);
}
.topbar-inner {
    display: flex; align-items: center; justify-content: space-between;
    gap: 20px; min-height: 66px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 650; font-size: 14.5px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-tools { display: flex; align-items: center; gap: 10px; }
.search {
    position: relative; display: flex; align-items: center;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 9px; height: 36px; padding: 0 10px; gap: 8px;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.search-icon { color: var(--muted); flex: 0 0 auto; }
.search input {
    border: 0; background: transparent; outline: none; color: var(--text);
    width: 210px; font-size: 13.5px; padding: 0;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-kbd {
    font-family: var(--mono); font-size: 10.5px; color: var(--muted);
    border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
    background: var(--surface-2);
}

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; box-shadow: var(--shadow-sm); }
.seg-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 28px; border: 0; border-radius: 6px; background: transparent;
    color: var(--muted); cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------------------------------------------------------------- flash */
.flash-stack { margin-top: 18px; display: grid; gap: 8px; }
.flash {
    padding: 11px 14px; border-radius: 9px; font-size: 13.5px;
    border: 1px solid var(--line); background: var(--surface);
}
.flash-success { border-color: color-mix(in srgb, #1a7f37 35%, var(--line)); background: color-mix(in srgb, #1a7f37 8%, var(--surface)); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }

/* ---------------------------------------------------------------- main */
.main { padding-bottom: 56px; }

.hero {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 40px; padding: 54px 0 30px;
}
.eyebrow {
    text-transform: uppercase; letter-spacing: .14em; font-size: 11px;
    font-weight: 650; color: var(--muted); margin-bottom: 12px;
}
.hero h1 {
    font-size: clamp(2rem, 4.6vw, 3.4rem);
    font-weight: 700; letter-spacing: -.035em;
}
.lede { color: var(--muted); font-size: 15.5px; margin-top: 10px; max-width: 56ch; }
.hero-intro { color: var(--muted); margin-top: 14px; max-width: 60ch; font-size: 14px; }

.hero-stats { display: flex; gap: 30px; margin: 0; flex: 0 0 auto; }
.hero-stats div { display: flex; flex-direction: column; gap: 2px; }
.hero-stats dt { order: 2; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.hero-stats dd { order: 1; margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.section-head h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.section-count { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- folders */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(188px, 1fr)); gap: 30px 22px; }

.folder-card { display: flex; flex-direction: column; gap: 12px; border-radius: 14px; }
.folder-card:hover .folder { transform: translateY(-3px); }
.folder-card:hover .folder-paper img { transform: scale(1.04); }

.folder {
    position: relative; aspect-ratio: 1.28 / 1;
    transition: transform .35s var(--ease);
    filter: drop-shadow(0 10px 18px rgba(30, 28, 20, .10));
}
.folder-tab {
    position: absolute; top: 0; left: 0; width: 47%; height: 26%;
    background: var(--folder-edge); border-radius: 9px 11px 0 0;
}
.folder-paper {
    position: absolute; inset: 11% 5% 6%;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 9px; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}
.folder-paper img {
    width: 100%; height: 100%; object-fit: cover;
    background-size: cover; background-position: center;
    transition: transform .45s var(--ease);
}
.folder-front {
    position: absolute; left: 0; right: 0; bottom: 0; height: 54%;
    background: linear-gradient(180deg, color-mix(in srgb, var(--folder) 82%, #fff) 0%, var(--folder) 55%);
    border: 1px solid var(--folder-edge);
    border-radius: 11px 11px 12px 12px;
    box-shadow: 0 -10px 22px -12px rgba(30, 28, 20, .35);
}
.folder-front::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, .22), transparent 45%);
}
.folder-badge {
    position: absolute; right: 12px; bottom: 10px; z-index: 2;
    background: color-mix(in srgb, var(--text) 82%, transparent);
    color: var(--bg); font-size: 11px; font-weight: 650;
    padding: 2px 7px; border-radius: 20px; font-variant-numeric: tabular-nums;
}
.folder-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 0 2px; }
.folder-name { font-size: 14px; font-weight: 600; letter-spacing: -.008em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-sub { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- empty */
.empty { text-align: center; padding: 80px 20px; border: 1px dashed var(--line-strong); border-radius: 16px; background: color-mix(in srgb, var(--surface) 55%, transparent); }
.empty-mark { width: 62px; height: 62px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.empty h2 { font-size: 19px; margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 42ch; margin: 0 auto 18px; }
.empty-inline { margin-top: 24px; padding: 40px 20px; }

/* ---------------------------------------------------------------- breadcrumb / folder head */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding-top: 30px; }
.crumbs a { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumb-sep { opacity: .55; }
.crumbs [aria-current] { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }

.folder-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; padding: 22px 0 26px; }
.folder-head h1 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); font-weight: 700; letter-spacing: -.03em; }
.folder-meta-line { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.folder-actions { flex: 0 0 auto; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 15px; border-radius: 9px;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
    font-size: 13.5px; font-weight: 550; cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-primary:hover { background: color-mix(in srgb, var(--text) 88%, var(--bg)); border-color: var(--text); }
.btn-note { opacity: .5; font-family: var(--mono); font-size: 11px; }

/* ---------------------------------------------------------------- photos grid */
.list-head { display: none; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 26px 18px; }

.photo-item { position: relative; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.thumb {
    position: relative; display: block; border-radius: 10px; overflow: hidden;
    background: var(--surface-2); aspect-ratio: 4 / 3;
    border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.thumb img {
    width: 100%; height: 100%; object-fit: cover;
    background-size: cover; background-position: center;
    transition: transform .5s var(--ease);
}
.photo-item:hover .thumb img { transform: scale(1.035); }
.thumb.is-broken { display: grid; place-items: center; }
.thumb.is-broken img { display: none; }

.photo-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.photo-name { font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.photo-dims, .photo-size { display: none; }

.photo-dl {
    position: absolute; top: 8px; right: 8px;
    width: 30px; height: 30px; display: grid; place-items: center;
    background: color-mix(in srgb, #0b0c0e 62%, transparent); color: #fff;
    border-radius: 8px; opacity: 0; transform: translateY(-4px);
    transition: opacity .18s var(--ease), transform .18s var(--ease), background .18s var(--ease);
    backdrop-filter: blur(6px);
}
.photo-item:hover .photo-dl, .photo-dl:focus-visible { opacity: 1; transform: none; }
.photo-dl:hover { background: color-mix(in srgb, #0b0c0e 82%, transparent); }

.file-thumb { display: grid; place-items: center; background: var(--surface-2); }
.file-icon {
    display: inline-grid; place-items: center;
    font-family: var(--mono); font-size: 13px; font-weight: 650; letter-spacing: .02em;
    width: 58px; height: 68px; border-radius: 7px;
    background: var(--surface); border: 1px solid var(--line-strong); color: var(--muted);
    box-shadow: 0 8px 14px -10px rgba(0, 0, 0, .35);
}

/* list layout */
.photos[data-layout="list"] { display: block; border-top: 1px solid var(--line); }
.photos[data-layout="list"] .photo-item {
    display: grid; grid-template-columns: 76px minmax(0, 1fr) 120px 100px 40px;
    align-items: center; gap: 16px;
    padding: 9px 4px; border-bottom: 1px solid var(--line);
    border-radius: 0;
}
.photos[data-layout="list"] .thumb { width: 76px; height: 57px; aspect-ratio: auto; border-radius: 7px; }
.photos[data-layout="list"] .photo-dims,
.photos[data-layout="list"] .photo-size { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.photos[data-layout="list"] .photo-sub { display: none; }
.photos[data-layout="list"] .photo-dl { position: static; opacity: 1; transform: none; background: transparent; color: var(--muted); width: 32px; height: 32px; }
.photos[data-layout="list"] .photo-dl:hover { background: var(--surface-2); color: var(--text); }

.photos[data-layout="list"] + .empty-inline { margin-top: 0; }

body.layout-list .list-head {
    display: grid; grid-template-columns: 76px minmax(0, 1fr) 120px 100px 40px;
    gap: 16px; padding: 0 4px 10px; border-bottom: 1px solid var(--line-strong);
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
body.layout-list .col-name { grid-column: 2; }
body.layout-list .col-dims { grid-column: 3; }
body.layout-list .col-size { grid-column: 4; }

@media (max-width: 760px) {
    .photos[data-layout="list"] .photo-item { grid-template-columns: 64px minmax(0, 1fr) 40px; }
    .photos[data-layout="list"] .photo-dims { display: none; }
    body.layout-list .list-head { display: none; }
}

/* ---------------------------------------------------------------- lightbox */
.lightbox {
    position: fixed; inset: 0; z-index: 100;
    display: flex; flex-direction: column;
    background: rgba(6, 7, 9, .965);
    color: #f4f5f7;
    opacity: 0; visibility: hidden;
    transition: opacity .22s var(--ease);
}
.lightbox.is-open { opacity: 1; visibility: visible; }
.lightbox [hidden] { display: none !important; }

.lb-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 22px; }
.lb-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.lb-title strong { font-size: 13.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-counter { font-family: var(--mono); font-size: 11.5px; color: rgba(255, 255, 255, .55); }

.lb-icon-btn {
    width: 38px; height: 38px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 9px; color: #fff; cursor: pointer;
    transition: background .15s var(--ease);
}
.lb-icon-btn:hover { background: rgba(255, 255, 255, .15); }

.lb-stage { position: relative; flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 72px; }
.lb-stage img {
    max-width: 100%; max-height: 100%; object-fit: contain;
    border-radius: 4px; box-shadow: var(--shadow-lg);
    transition: transform .18s var(--ease);
    transform-origin: center;
    cursor: zoom-in;
}
.lb-stage img.is-zoomed { cursor: grab; }

.lb-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 46px; height: 70px; display: grid; place-items: center;
    border: 0; border-radius: 10px; background: rgba(255, 255, 255, .06);
    color: #fff; cursor: pointer; transition: background .15s var(--ease);
}
.lb-nav:hover { background: rgba(255, 255, 255, .14); }
.lb-nav.prev { left: 14px; }
.lb-nav.next { right: 14px; }

.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 22px 20px; }
.lb-meta { display: flex; gap: 14px; font-family: var(--mono); font-size: 11.5px; color: rgba(255, 255, 255, .58); }
.lb-controls { display: flex; align-items: center; gap: 6px; }
.lb-zoom { font-family: var(--mono); font-size: 11.5px; min-width: 42px; text-align: center; color: rgba(255, 255, 255, .7); }
.lb-download {
    display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 15px;
    margin-left: 8px; border-radius: 9px; background: #fff; color: #111;
    font-size: 13px; font-weight: 600;
}
.lb-download:hover { background: #e7e7e7; }

@media (max-width: 640px) {
    .lb-stage { padding: 0 12px; }
    .lb-nav { width: 38px; height: 54px; }
    .lb-nav.prev { left: 6px; }
    .lb-nav.next { right: 6px; }
    .lb-meta { display: none; }
}

/* ---------------------------------------------------------------- footer */
.footer { border-top: 1px solid var(--line); padding: 22px 0; margin-top: 40px; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.footer-links { display: inline-flex; gap: 16px; align-items: center; }
.footer-links a:hover { color: var(--text); }

/* ---------------------------------------------------------------- toast */
.toast {
    position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px);
    background: var(--text); color: var(--bg); padding: 10px 16px;
    border-radius: 9px; font-size: 13px; box-shadow: var(--shadow-md);
    opacity: 0; pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease);
    z-index: 120; max-width: 88vw;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- error */
.error-page { text-align: center; padding: 12vh 20px 16vh; }
.error-code { font-family: var(--mono); font-size: 13px; color: var(--muted); letter-spacing: .2em; }
.error-page h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 14px 0 12px; letter-spacing: -.03em; }
.error-page .lede { margin: 0 auto 22px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
    .hero { flex-direction: column; align-items: flex-start; gap: 26px; padding-top: 40px; }
    .hero-stats { gap: 26px; }
    .folders { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 24px 16px; }
}

@media (max-width: 680px) {
    .wrap { padding: 0 16px; }
    .topbar-inner { min-height: 60px; gap: 12px; }
    .brand-sub { display: none; }
    .search input { width: 100%; }
    .search { flex: 1; }
    .search-kbd { display: none; }
    .topbar-tools { flex: 1; justify-content: flex-end; }
    .folder-head { flex-direction: column; align-items: flex-start; gap: 16px; }
    .folders { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .photos { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 20px 12px; }
    .hero-stats { width: 100%; justify-content: space-between; }
}

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