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

:root {
    --bg: #0a0a0a;
    --bg-elevated: #141414;
    --text: #e0e0e0;
    --text-muted: #666;
    --accent: #4a9eff;
    --border: #222;
}

[data-theme="light"] {
    --bg: #f5f5f5;
    --bg-elevated: #ffffff;
    --text: #1a1a1a;
    --text-muted: #666;
    --accent: #0066cc;
    --border: #ddd;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent); }

/* Header */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.brand {
    font-weight: 600;
    letter-spacing: 0.5px;
}

#breadcrumb-path { color: var(--text-muted); }
#breadcrumb-path a { color: var(--text-muted); }
#breadcrumb-path a:hover { color: var(--text); }

#search-form { display: flex; }
#search-input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 12px;
    color: var(--text);
    width: 200px;
    font-size: 13px;
}
#search-input:focus { outline: none; border-color: var(--accent); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#theme-toggle,
#frame-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

#theme-toggle:hover,
#frame-toggle:hover {
    border-color: var(--accent);
}

/* Main Content */
#app {
    margin-top: 48px;
    min-height: calc(100vh - 48px);
    padding: 16px;
}

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

.grid-item {
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 4px;
    cursor: pointer;
    background: var(--bg-elevated);
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s, opacity 0.2s;
}

.grid-item:hover img {
    transform: scale(1.05);
    opacity: 0.85;
}

/* Album Grid */
.albums-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.album-card {
    display: block;
    background: var(--bg-elevated);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    container-type: inline-size; /* Enable container queries */
}

.album-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.album-card:hover .album-cover::after {
    background: rgba(0, 0, 0, 0.2);
}

.album-cover {
    position: relative;
    aspect-ratio: 16 / 10;
    background-color: var(--border);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center; /* Center vertically for better impact */
    justify-content: center;
}

.album-cover::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4); /* Slightly darker for better contrast */
    transition: background 0.2s;
}

.album-cover .no-cover {
    position: relative;
    z-index: 2;
    color: var(--text-muted);
    font-size: 12px;
}

.album-info {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.album-name {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 800;
    /* text-transform: uppercase; */
    font-size: clamp(24px, 12cqw, 48px);
    line-height: 1.1; /* Increased from 0.85 to prevent clipping */
    margin: 0;
    padding: 0.2em 0; /* Added padding for tall script ascenders/descenders */
    color: #fff;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.8);
    word-break: normal; /* Prevent mid-word breaking */
    overflow-wrap: anywhere; /* Wrap only when absolutely necessary */
    width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.album-count {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.3);
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    margin-top: 12px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Section Headers */
.section-header {
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-header:first-child { margin-top: 0; }

.section-header a { color: var(--text-muted); }
.section-header a:hover { color: var(--text); }

.section-header .count {
    font-size: 11px;
    opacity: 0.6;
    margin-left: 8px;
}

/* Photo View */
.photo-view {
    position: fixed;
    inset: 48px 0 0 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.photo-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.photo-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.photo-container img.framed {
    max-width: 94%;
    max-height: 94%;
    box-sizing: border-box;
    border: 1vmin solid #fcfcfc;
    border-radius: 3px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .photo-container img.framed {
    border-color: #050505;
    box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.2);
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 48px;
    cursor: pointer;
    padding: 20px;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.nav-btn:hover { opacity: 1; }
.nav-btn.prev { left: 0; }
.nav-btn.next { right: 0; }
.nav-btn:disabled { display: none; }

.photo-meta {
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.actions {
    display: flex;
    align-items: center;
    margin-left: 12px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.action-btn:hover {
    color: var(--text);
    background: var(--border);
}

.action-btn svg {
    display: block;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    background: rgba(74, 158, 255, 0.15);
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
}

.tag:hover {
    background: rgba(74, 158, 255, 0.25);
}

.exif {
    display: flex;
    gap: 16px;
    margin-left: auto;
}

.exif span { white-space: nowrap; }

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty State */
.empty {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    .albums-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
    .nav-btn { font-size: 36px; padding: 16px; }
}

/* Responsive - Mobile */
@media (max-width: 600px) {
    #header {
        padding: 0 12px;
        gap: 8px;
    }

    .breadcrumb {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .brand {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #breadcrumb-path {
        display: none;
    }

    .header-actions {
        gap: 8px;
        flex-shrink: 0;
    }

    #search-form {
        display: none;
    }

    #theme-toggle,
    #frame-toggle {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #app {
        padding: 12px;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .grid-item {
        border-radius: 2px;
    }

    .grid-item:hover img {
        transform: none;
        opacity: 1;
    }

    .albums-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .album-card:hover {
        transform: none;
    }

    .album-cover {
        aspect-ratio: 16 / 9;
    }

    .album-info {
        padding: 10px 12px;
    }

    .photo-view {
        inset: 48px 0 0 0;
    }

    .photo-container img.framed {
        max-width: 92%;
        max-height: 92%;
        border-width: 2vmin;
    }

    .nav-btn {
        font-size: 32px;
        padding: 12px;
        opacity: 0.5;
    }

    .nav-btn.prev { left: 0; }
    .nav-btn.next { right: 0; }

    .photo-meta {
        padding: 10px 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .tags {
        gap: 4px;
    }

    .tag {
        padding: 4px 8px;
        font-size: 10px;
    }

    .exif {
        margin-left: 0;
        flex-wrap: wrap;
        gap: 8px 12px;
    }

    .exif span {
        font-size: 11px;
    }

    .section-header {
        margin: 16px 0 10px;
        font-size: 11px;
    }
}

/* Responsive - Small Mobile */
@media (max-width: 380px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }

    #app {
        padding: 8px;
    }

    .nav-btn {
        font-size: 28px;
        padding: 8px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .grid-item:hover img {
        transform: none;
        opacity: 1;
    }

    .album-card:hover {
        transform: none;
        box-shadow: none;
    }

    .nav-btn {
        opacity: 0.6;
    }

    .nav-btn:active {
        opacity: 1;
    }
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
    .photo-meta {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    #header {
        padding-left: calc(16px + env(safe-area-inset-left));
        padding-right: calc(16px + env(safe-area-inset-right));
    }

    @media (max-width: 600px) {
        #header {
            padding-left: calc(12px + env(safe-area-inset-left));
            padding-right: calc(12px + env(safe-area-inset-right));
        }
    }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #333; }
