:root {
    --bg: #111316;
    --bg-elev: #1a1d22;
    --bg-card: #20242a;
    --fg: #e7ebef;
    --muted: #8a93a0;
    --accent: #4f9dff;
    --error: #ff6464;
    --success: #5ec48b;
    --border: #2a2f36;
    --thumb-min: 110px;
    --gap: 4px;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over class rules that set `display`
   (e.g. .jump-panel and .viewer), otherwise those overlays stay visible. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); font-size: 0.9em; }
.error { color: var(--error); }
.success { color: var(--success); }
.status { padding: 8px 0; font-size: 0.9em; }
.status.success { color: var(--success); }
.status.error { color: var(--error); }

/* ---------- Centered card pages (login / admin / setup) ---------- */
.page-center {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    width: 100%;
    max-width: 380px;
    display: grid;
    gap: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.card.wide { max-width: 560px; }
.card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.card label {
    display: grid;
    gap: 6px;
    font-size: 0.9em;
    color: var(--muted);
}
.card label.checkbox {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    color: var(--fg);
}
.card input[type="email"],
.card input[type="password"],
.card input[type="url"],
.card input[type="text"],
.card select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}
.card input:focus, .card select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}
.card .row { display: flex; gap: 8px; }
.card .row > input { flex: 2; }
.card .row > select { flex: 1; min-width: 0; }
.card button, .btn-secondary {
    padding: 10px 16px;
    border-radius: 8px;
    border: 0;
    background: var(--accent);
    color: #fff;
    font: inherit;
    cursor: pointer;
}
.btn-secondary {
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--border);
    display: inline-block;
    text-align: center;
}
.card .actions { display: flex; gap: 8px; align-items: center; }
.card button:hover { filter: brightness(1.1); }

/* ---------- Gallery topbar ---------- */
.page-gallery { padding: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(10px + var(--safe-top)) 14px 10px;
    background: rgba(17,19,22,0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar-left h1 {
    font-size: 1.05rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50vw;
}
.topbar-right { display: flex; align-items: center; gap: 4px; }
.iconbtn {
    background: transparent;
    color: var(--fg);
    border: 0;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.iconbtn:hover { background: var(--bg-card); }

/* ---------- Month sections + thumb grid ---------- */
#gallery {
    padding: 8px 8px calc(40px + var(--safe-bottom));
}
.month-section { margin-bottom: 28px; }
.month-header {
    position: sticky;
    top: calc(58px + var(--safe-top));
    margin: 0;
    padding: 10px 6px;
    background: linear-gradient(to bottom, rgba(17,19,22,0.95), rgba(17,19,22,0.85));
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--fg);
    z-index: 5;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.month-header .count { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 0.85em; }
.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--thumb-min), 1fr));
    gap: var(--gap);
    padding: 4px 0;
}
.thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--bg-card);
    overflow: hidden;
    border-radius: 4px;
    cursor: pointer;
}
.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 200ms ease;
}
.thumb img.loaded { opacity: 1; }
.thumb.is-video .play-icon {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 999px;
    pointer-events: none;
    line-height: 1;
}
.thumb:hover img.loaded { transform: scale(1.02); }
.thumb img { transition: opacity 200ms ease, transform 200ms ease; }

@media (min-width: 700px)  { :root { --thumb-min: 150px; } }
@media (min-width: 1100px) { :root { --thumb-min: 180px; --gap: 6px; } }
@media (min-width: 1600px) { :root { --thumb-min: 210px; } }

/* ---------- Jump panel ---------- */
.jump-panel {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 60;
    display: grid;
    place-items: end center;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.jump-inner {
    background: var(--bg-elev);
    width: 100%;
    max-width: 520px;
    max-height: 70vh;
    border-radius: 14px 14px 0 0;
    display: flex;
    flex-direction: column;
}
@media (min-width: 700px) {
    .jump-panel { place-items: center; padding: 20px; }
    .jump-inner { border-radius: 14px; max-height: 80vh; }
}
.jump-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
#jump-content { overflow-y: auto; padding: 8px 0; }
.jump-year { padding: 6px 16px; }
.jump-year > h3 {
    margin: 0;
    font-size: 1rem;
    padding: 6px 0;
    color: var(--muted);
    letter-spacing: 0.04em;
}
.jump-months {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 4px;
    padding-bottom: 8px;
}
.jump-month {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg-card);
    color: var(--fg);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font: inherit;
}
.jump-month:hover { background: var(--border); }
.jump-month .c { color: var(--muted); font-size: 0.85em; }

/* ---------- Viewer ---------- */
.viewer {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 100;
    display: flex;
    flex-direction: column;
    user-select: none;
    overflow: hidden;
    touch-action: pan-y;
}
.viewer-stage {
    flex: 1;
    min-height: 0;
    position: relative;
    display: grid;
    /* Definite single cell so .viewer-media's max-width/height:100% resolves
       against the stage size instead of the image's natural size. */
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    overflow: hidden;
}
.viewer-media {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 200ms ease;
    will-change: transform;
}
.viewer-media.swipe-anim { transition: none; }
.viewer video.viewer-media { pointer-events: auto; }
.viewer-loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
}

.viewer-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(8px + var(--safe-top)) 12px 8px;
    background: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0));
    color: #fff;
}
.viewer-top .iconbtn { color: #fff; }
.viewer-top .iconbtn:hover { background: rgba(255,255,255,0.1); }
.viewer-counter { font-variant-numeric: tabular-nums; }

.viewer-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    background: rgba(0,0,0,0.5);
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 6;
}
.viewer-arrow:hover { background: rgba(0,0,0,0.75); }
.viewer-arrow.prev { left: 14px; }
.viewer-arrow.next { right: 14px; }
.viewer-arrow:disabled { opacity: 0.3; cursor: default; }

/* Hide arrows on small/touch screens — swipe is the gesture there */
@media (hover: none) and (pointer: coarse) {
    .viewer-arrow { display: none; }
}

.viewer-info {
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    border-top: 1px solid rgba(255,255,255,0.08);
    max-height: 40vh;
    overflow: auto;
}
@media (min-width: 800px) {
    .viewer-info {
        grid-template-columns: 1fr 1fr 220px;
        align-items: start;
    }
}
.viewer-info .date {
    font-size: 1rem;
    line-height: 1.3;
}
.viewer-info .date .filename {
    display: block;
    color: var(--muted);
    font-size: 0.85em;
    margin-top: 2px;
    word-break: break-all;
}
.viewer-info .people {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
}
.person-chip {
    background: rgba(255,255,255,0.1);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.85em;
}
.person-chip.unnamed { color: var(--muted); font-style: italic; }
.viewer-info .map-wrap {
    width: 100%;
    height: 130px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-card);
}
.viewer-info .map-wrap.empty {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 0.85em;
}
#viewer-map { width: 100%; height: 100%; }
.location-text { font-size: 0.85em; color: var(--muted); margin-top: 4px; }
