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

:root {
    --bg:       #f5f5f7;
    --surface:  rgba(255,255,255,0.72);
    --surface2: rgba(255,255,255,0.92);
    --accent:   #0071e3;
    --accent-h: #0077ed;
    --text:     #1d1d1f;
    --text2:    #6e6e73;
    --border:   rgba(0,0,0,0.08);
    --r:        18px;
    --r-sm:     12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
    height: 52px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 200;
    background: rgba(245,245,247,0.82);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    letter-spacing: -.2px;
    transition: opacity .15s;
}
.logo:hover { opacity: .6; }

.login-btn, .logout-btn {
    font-size: .82rem;
    color: var(--text2);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.login-btn:hover, .logout-btn:hover {
    background: rgba(0,0,0,.06);
    color: var(--text);
}

#breadcrumb {
    font-size: .85rem;
    color: var(--text2);
}
#breadcrumb a {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s;
}
#breadcrumb a:hover { opacity: .7; }

/* ── Layout ── */
.screen { display: block; }
.hidden { display: none !important; }

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 56px 24px 80px;
}

/* ── Home ── */
.home-hero {
    text-align: center;
    margin-bottom: 52px;
}
.home-hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 700;
    letter-spacing: -.04em;
    line-height: 1.1;
    background: linear-gradient(135deg, #1d1d1f 0%, #555 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 14px;
}
.home-hero p {
    font-size: 1.1rem;
    color: var(--text2);
    font-weight: 400;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    max-width: 560px;
    margin: 0 auto;
}

.mode-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 36px 28px;
    text-align: left;
    cursor: pointer;
    transition: transform .2s cubic-bezier(.25,.46,.45,.94),
                box-shadow .2s cubic-bezier(.25,.46,.45,.94);
    font-family: inherit;
    color: var(--text);
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    display: block;
    width: 100%;
}
.mode-card:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 20px 40px rgba(0,0,0,.12);
}
.mode-card:active { transform: translateY(-1px) scale(1.005); }

.mode-icon  {
    font-size: 2.8rem;
    margin-bottom: 16px;
    display: block;
}
.mode-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: -.02em;
}
.mode-desc  {
    font-size: .88rem;
    color: var(--text2);
    line-height: 1.4;
}

/* ── Persons ── */
.persons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.person-card {
    background: var(--surface2);
    border-radius: var(--r);
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
    transition: transform .2s cubic-bezier(.25,.46,.45,.94),
                box-shadow .2s cubic-bezier(.25,.46,.45,.94);
    border: 1px solid var(--border);
}
.person-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 24px 48px rgba(0,0,0,.14);
}
.person-card:active { transform: translateY(-2px) scale(1.01); }

.person-cover {
    width: 100%;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: linear-gradient(135deg, #a8d8f0 0%, #0071e3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
}
.person-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .4s ease;
}
.person-card:hover .person-cover img { transform: scale(1.05); }

.person-info { padding: 14px 16px 16px; }
.person-name  {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -.01em;
    margin-bottom: 3px;
}
.person-count {
    font-size: .8rem;
    color: var(--text2);
}

/* ── Gallery header ── */
.gallery-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.gallery-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.03em;
}
.gallery-count {
    font-size: .78rem;
    color: var(--accent);
    background: rgba(0,113,227,.1);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* ── Gallery grid ── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.day-separator {
    grid-column: 1 / -1;
    padding: 28px 0 10px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text2);
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}
.day-separator:first-child { padding-top: 0; }

.gallery-item {
    aspect-ratio: 1;
    border-radius: var(--r-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: #e0e0e5;
    transition: transform .2s cubic-bezier(.25,.46,.45,.94),
                box-shadow .2s cubic-bezier(.25,.46,.45,.94);
}
.gallery-item:hover {
    transform: scale(1.03);
    box-shadow: 0 16px 32px rgba(0,0,0,.18);
    z-index: 2;
}
.gallery-item:hover .item-overlay { opacity: 1; }

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .4s ease;
}
.gallery-item:hover img { transform: scale(1.04); }

.video-thumb {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1c1c1e 0%, #2c2c2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-play-badge {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 44px; height: 44px;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    padding-left: 3px;
    color: #fff;
    pointer-events: none;
    transition: background .2s, transform .2s;
}
.gallery-item:hover .video-play-badge {
    background: rgba(0,0,0,.62);
    transform: translate(-50%, -50%) scale(1.12);
}

.video-duration {
    position: absolute;
    bottom: 8px; right: 8px;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(6px);
    color: #fff;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    padding: 2px 7px;
    border-radius: 6px;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.item-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(transparent 45%, rgba(0,0,0,.72));
    color: #fff;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity .2s;
    gap: 2px;
}
.item-person {
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .01em;
}
.item-date   {
    font-size: .72rem;
    opacity: .75;
}

.gallery-empty {
    text-align: center;
    padding: 100px 0;
    color: var(--text2);
    font-size: 1rem;
}

.gallery-hidden {
    font-size: .78rem;
    color: #ff3b30;
    background: rgba(255,59,48,.1);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* ── Vote button (gallery grid) ── */
.vote-btn {
    position: absolute;
    top: 8px; right: 8px;
    min-width: 26px; height: 26px;
    padding: 0 6px;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(6px);
    border: 1.5px solid rgba(255,255,255,.25);
    border-radius: 13px;
    color: rgba(255,255,255,.8);
    font-size: .72rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    transition: opacity .2s, background .15s, border-color .15s, transform .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    line-height: 1;
}
.gallery-item:hover .vote-btn { opacity: 1; }
.vote-btn.active {
    background: rgba(255,59,48,.8);
    border-color: rgba(255,59,48,.9);
    color: #fff;
    opacity: 1;
}
.vote-btn:hover { transform: scale(1.1); }

/* ── Lightbox ── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lb-in .25s ease;
}
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }

.lb-close {
    position: absolute;
    top: 18px; right: 20px;
    width: 34px; height: 34px;
    background: rgba(255,255,255,.12);
    backdrop-filter: blur(8px);
    border: none;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .15s;
    z-index: 10;
    line-height: 1;
}
.lb-close:hover {
    background: rgba(255,255,255,.22);
    transform: scale(1.1);
}

.lb-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px; height: 50px;
    background: rgba(255,255,255,.1);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,.15);
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .15s;
    z-index: 10;
    user-select: none;
    line-height: 1;
}
.lb-nav:hover {
    background: rgba(255,255,255,.2);
    transform: translateY(-50%) scale(1.08);
}
.lb-nav.dimmed  { opacity: .2; pointer-events: none; }
.lb-prev { left: 20px; }
.lb-next { right: 20px; }

.lb-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: calc(100vw - 140px);
    max-height: 100vh;
    padding: 50px 0 24px;
}

#lb-media {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    flex: 1;
}
#lb-media img,
#lb-media video {
    max-width: calc(100vw - 140px);
    max-height: calc(100vh - 110px);
    object-fit: contain;
    border-radius: var(--r-sm);
    display: block;
    box-shadow: 0 32px 80px rgba(0,0,0,.5);
}

.lb-info {
    display: flex;
    gap: 16px;
    align-items: center;
    font-size: .82rem;
    color: rgba(255,255,255,.5);
    width: 100%;
    padding: 0 6px;
}
#lb-person  {
    color: #fff;
    font-weight: 600;
    font-size: .88rem;
}
#lb-counter {
    margin-left: auto;
    font-size: .78rem;
    opacity: .4;
}

.lb-vote-btn {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    color: rgba(255,255,255,.7);
    border-radius: 20px;
    padding: 4px 14px;
    font-size: .8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.lb-vote-btn:hover { background: rgba(255,255,255,.2); color: #fff; }
.lb-vote-btn.active {
    background: rgba(255,59,48,.7);
    border-color: rgba(255,59,48,.8);
    color: #fff;
}
.lb-vote-btn.active:hover { background: rgba(255,59,48,.9); }

/* ── Loading ── */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(245,245,247,.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}
.spinner {
    width: 32px; height: 32px;
    border: 2.5px solid rgba(0,0,0,.08);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 600px) {
    main { padding: 32px 16px 60px; }
    .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
    .gallery-item { border-radius: 6px; }
    .persons-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .lb-nav { width: 40px; height: 40px; font-size: 1.2rem; }
    .lb-prev { left: 8px; }
    .lb-next { right: 8px; }
    .lb-wrap { max-width: calc(100vw - 100px); }
    #lb-media img, #lb-media video {
        max-width: calc(100vw - 100px);
        max-height: calc(100vh - 100px);
    }
}

/* Scroll sentinel for chunked loading */
.scroll-sentinel {
    height: 1px;
    pointer-events: none;
}
