/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* The hidden attribute must always win, even over display:flex/grid rules */
[hidden] { display: none !important; }

/* ── Variables ── */
:root {
    --bg:           #f5f7fb;
    --surface:      #ffffff;
    --border:       #d9e2ec;
    --border-2:     #e2e8f0;
    --text:         #1f2937;
    --text-muted:   #475569;
    --text-faint:   #94a3b8;
    --accent:       #0f172a;
    --radius-sm:    6px;
    --radius-md:    12px;
    --radius-lg:    20px;
    --shadow-sm:    0 2px 8px rgba(15,23,42,.06);
    --shadow-md:    0 8px 24px rgba(15,23,42,.08);
    --shadow-lg:    0 18px 42px rgba(15,23,42,.10);
    --toolbar-h:    52px;
    --mobile-toolbar-space: 0px;
}

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Layout ── */
.wrap {
    max-width: 1220px;
    margin: 0 auto;
    padding: 0 20px calc(52px + var(--mobile-toolbar-space));
}

.landing-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
}

/* ── Card ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 22px;
}

/* ── Hero ── */
.hero {
    text-align: center;
    padding: 34px 36px;
    background:
        radial-gradient(circle at top, rgba(148,163,184,.12), transparent 46%),
        linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    width: 100%;
}

/* Landing page: narrow centered card; gallery page hero spans the full wrap */
.landing-wrap .hero {
    max-width: 640px;
}

.hero h1 {
    font-size: clamp(26px, 5vw, 40px);
    line-height: 1.05;
    letter-spacing: -.03em;
    margin-bottom: 14px;
}

.hero-title-link { color: inherit; text-decoration: none; }
.hero-title-link:hover { color: #334155; }

.hero-nav {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.hero-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    padding: 7px 12px;
    border: 1px solid var(--border-2);
    border-radius: 999px;
    background: rgba(255,255,255,.9);
    transition: background .15s, border-color .15s;
}

.hero-nav a:hover { background: #fff; border-color: var(--border); color: #334155; }

/* Language switch */
.language-switch {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-faint);
}

.language-switch a { color: var(--text-muted); text-decoration: none; }
.language-switch a:hover { color: var(--accent); }
.language-switch .is-active { color: var(--accent); font-weight: 600; }

/* Hero copy */
.hero-copy { max-width: 520px; margin: 20px auto 0; }
.hero-copy p { margin: 0; }
.hero-copy p + p { margin-top: 10px; }
.hero-message { font-size: clamp(18px, 3vw, 24px); font-weight: 600; color: var(--accent); letter-spacing: -.02em; }
.hero-submessage { color: var(--text-muted); font-size: 15px; line-height: 1.65; }
.requested-id-note { color: var(--text-muted); font-size: 14px; margin-top: 10px; }

/* Gallery summary pill */
.gallery-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.gallery-summary-pill {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 13px;
    box-shadow: var(--shadow-sm);
}

.gallery-summary-pill strong { color: var(--accent); margin-left: 6px; font-weight: 600; }

/* Gallery note */
.gallery-note {
    max-width: 480px;
    margin: 16px auto 0;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
    text-align: left;
}

/* Gallery ID form */
.gallery-id-form {
    margin: 24px auto 0;
    width: 100%;
    max-width: 480px;
    display: flex;
    gap: 10px;
    align-items: stretch;
    flex-wrap: wrap;
}

.gallery-id-label {
    position: absolute; width: 1px; height: 1px; padding: 0;
    margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.gallery-id-input {
    flex: 1 1 220px;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.gallery-id-input:focus { border-color: #94a3b8; box-shadow: 0 0 0 3px rgba(148,163,184,.2); }

/* Action buttons */
.primary-action {
    height: 44px;
    padding: 0 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s;
}

.primary-action:hover { opacity: .88; }

.secondary-action {
    display: inline-flex;
    align-items: center;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s;
}

.secondary-action:hover { background: #f1f5f9; }

/* Landing actions */
.landing-actions { margin-top: 20px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* Folder list panel */
.folder-list-panel { margin-top: 24px; text-align: left; }

.folder-list-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    margin-bottom: 10px;
}

.folder-list-items { display: flex; flex-direction: column; gap: 2px; }

.folder-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-md);
    background: var(--surface);
    text-decoration: none;
    color: inherit;
    transition: background .12s, border-color .12s;
}

.folder-list-item:hover { background: #f8fafc; border-color: var(--border); }
.folder-list-item.is-child { margin-left: 18px; }

.folder-list-item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.folder-list-item-name { font-size: 14px; font-weight: 500; color: var(--text); }
.folder-list-item-meta { font-size: 12px; color: var(--text-faint); }
.folder-list-item-arrow { font-size: 12px; color: var(--text-faint); white-space: nowrap; flex-shrink: 0; }

.compact-note { font-size: 13px; color: var(--text-faint); padding: 10px 0; }

/* ── Toolbar (gallery app) ── */
.toolbar {
    position: sticky;
    top: 0;
    z-index: 200;
    min-height: var(--toolbar-h);
    background: rgba(245,247,251,.93);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(15,23,42,.06);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.toolbar-group select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

/* View toggle */
.view-toggle { display: flex; gap: 2px; }

.view-toggle-button {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background .12s;
}

.view-toggle-button svg { width: 16px; height: 16px; }
.view-toggle-button:hover { background: #f1f5f9; }
.view-toggle-button.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Bulk buttons */
.bulk-download-all-button,
.bulk-download-button,
.bulk-deselect-button {
    height: 32px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s, background .12s;
}

.bulk-download-all-button {
    background: var(--accent);
    color: #fff;
    border: none;
}

.bulk-download-button {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.bulk-deselect-button {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-2);
}

.bulk-download-all-button:hover { opacity: .88; }
.bulk-download-button:hover { background: #f1f5f9; }
.bulk-deselect-button:hover { background: #f1f5f9; }
.bulk-download-all-button:disabled { opacity: .5; cursor: default; }

/* Archive status */
.archive-latest {
    font-size: 12px;
    color: var(--text-faint);
    white-space: nowrap;
}

.archive-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.archive-status-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--text-muted);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

.archive-debug {
    font-size: 11px;
    color: #dc2626;
    padding: 4px 12px;
    background: #fef2f2;
    border-bottom: 1px solid #fecaca;
}

/* ── Grid ── */
.grid {
    columns: 2;
    column-gap: 8px;
    margin-top: 12px;
}

@media (min-width: 480px)  { .grid { columns: 3; } }
@media (min-width: 720px)  { .grid { columns: 4; } }
@media (min-width: 960px)  { .grid { columns: 5; } }
@media (min-width: 1200px) { .grid { columns: 6; } }

.photo {
    break-inside: avoid;
    margin-bottom: 8px;
    position: relative;
    background: var(--border-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow .2s ease;
}

.photo:hover { box-shadow: 0 6px 20px rgba(15,23,42,.14); }

.photo.is-selected::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid #3b82f6;
    border-radius: var(--radius-sm);
    pointer-events: none;
}

/* List view */
.grid.is-list-view { columns: 1; }

.grid.is-list-view .photo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-2);
    background: var(--surface);
    margin-bottom: 4px;
}

.grid.is-list-view .photo-button {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.grid.is-list-view .photo-button img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    display: block;
}

.grid.is-list-view .photo-meta { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.grid.is-list-view .photo-meta h3 { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Photo button */
.photo-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0;
    border: none;
    background: var(--surface-2, #f1f5f9);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    aspect-ratio: 4 / 3;
    overflow: hidden;
}

/* v1 parity: portraits letterbox inside the 4/3 cell instead of cropping */
.photo-button img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: opacity .2s, transform .25s ease;
}

.photo:hover .photo-button img {
    transform: scale(1.03);
}

.photo-button[data-ready="0"] img { opacity: 0; }
.photo-button[data-ready="1"] img { opacity: 1; }

.grid.is-list-view .photo-button {
    aspect-ratio: unset;
}

/* Photo meta (grid view) */
.grid:not(.is-list-view) .photo-meta {
    padding: 6px 8px 8px;
    background: var(--surface);
}

.photo-meta h3 {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.photo-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.photo-download { font-size: 11px; color: #3b82f6; text-decoration: none; }
.photo-download:hover { text-decoration: underline; }
.photo-size { font-size: 11px; color: var(--text-faint); }
.photo-extra { margin-top: 3px; }
.photo-extra-line { font-size: 11px; color: var(--text-faint); }

/* Select button overlay */
.photo-select {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,.8);
    background: rgba(0,0,0,.25);
    cursor: pointer;
    z-index: 2;
    transition: background .12s, border-color .12s;
}

.photo-select:hover { background: rgba(59,130,246,.6); border-color: #3b82f6; }
.photo.is-selected .photo-select { background: #3b82f6; border-color: #3b82f6; }

.grid.is-list-view .photo-select { position: static; flex-shrink: 0; }

/* ── Loading / Empty ── */
.grid-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: 14px;
}

.grid-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--text-muted);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.gallery-empty {
    margin: 12px 0;
    padding: 32px 24px;
    border: 1px dashed var(--border);
    background: var(--surface);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-align: center;
}

.gallery-empty-title { color: var(--accent); font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.gallery-empty-hint { font-size: 14px; line-height: 1.6; }

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,.88);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex;
    align-items: stretch;
}

.modal[hidden] { display: none; }

.modal-dialog {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.modal-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(0,0,0,.6);
    flex-shrink: 0;
}

.modal-title {
    font-size: 13px;
    font-weight: 500;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.modal-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.modal-select,
.modal-close,
.modal-link {
    height: 32px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.modal-select { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #e2e8f0; }
.modal-select.is-selected { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.modal-link { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #e2e8f0; }
.modal-close { background: transparent; border: none; color: #94a3b8; font-size: 16px; }
.modal-close:hover { color: #fff; }

.modal-viewport {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 0;
}

.modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    transition: opacity .2s;
}

.modal-image.is-loading { opacity: 0; }

.modal-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-loader[hidden] { display: none; }

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255,255,255,.2);
    border-top-color: rgba(255,255,255,.8);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.3);
    border: none;
    color: rgba(255,255,255,.8);
    font-size: 28px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background .12s;
    z-index: 1;
}

.modal-nav:hover { background: rgba(0,0,0,.6); color: #fff; }
.modal-nav.prev { left: 8px; }
.modal-nav.next { right: 8px; }

.modal-footer {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(0,0,0,.5);
    flex-shrink: 0;
}

.modal-footer-counter { font-size: 12px; color: #94a3b8; }
.modal-footer-text { font-size: 11px; color: #64748b; }

/* ── Download overlay ── */
.download-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.download-overlay[hidden] { display: none; }

.download-overlay-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px 36px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.download-overlay-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 0 auto 16px;
}

.download-overlay-text { font-size: 16px; font-weight: 600; color: var(--accent); margin-bottom: 8px; }
.download-overlay-subtext { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ── Access code ── */
.access-code-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.access-code-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.access-code-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 20px; }

.access-code-card input[type="text"],
.access-code-card input[type="password"] {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color .15s;
}

.access-code-card input:focus { border-color: #94a3b8; }
.access-code-card button[type="submit"] { width: 100%; }
.access-code-error { color: #dc2626; font-size: 13px; margin-bottom: 10px; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }

/* ── modal-open body lock ── */
body.modal-open { overflow: hidden; }

/* ── Mobile adjustments ── */
@media (max-width: 480px) {
    .hero { padding: 24px 20px; }
    .wrap { padding: 0 12px calc(52px + var(--mobile-toolbar-space)); }
    .card { padding: 20px; border-radius: var(--radius-md); }
    .toolbar { padding: 6px 10px; gap: 6px; }
    .bulk-download-all-button,
    .bulk-download-button { font-size: 12px; padding: 0 10px; }
}

@media (max-width: 720px) {
    .grid { columns: 2; }
    .modal-nav { display: none; }
}
