:root {
    --bg: #f8f8f6;
    --surface: #ffffff;
    --surface-subtle: #efefec;
    --ink: #141413;
    --ink-muted: #6c6c68;
    --border: rgba(20, 20, 19, 0.08);
    --border-strong: rgba(20, 20, 19, 0.14);
    --accent: #181817;
    --radius: 8px;
    --radius-sm: 6px;
    --header-height: 52px;
    --max-width: 1440px;
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
}

/* Boot screen */
.app-boot {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
}

.app-boot-brand {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.app-boot-status {
    font-size: 0.875rem;
    color: var(--ink-muted);
}

/* App Shell & Frosted Mobile Header */
.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(248, 248, 246, 0.86);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.site-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    height: var(--header-height);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.96875rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    white-space: nowrap;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--accent);
    color: #ffffff;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--surface-subtle);
    border-radius: 999px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 13px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-muted);
    transition: color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
}

.nav-link:hover {
    color: var(--ink);
}

.nav-link.active {
    color: var(--ink);
    background-color: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Main Content */
.app-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 10px calc(10px + env(safe-area-inset-right)) 36px calc(10px + env(safe-area-inset-left));
}

/* Gallery Toolbar & New Photos Pill */
.gallery-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    padding: 2px 2px 0;
}

.gallery-heading-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.gallery-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--ink);
}

.gallery-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--surface-subtle);
    color: var(--ink-muted);
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.btn-ghost,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}

.btn-ghost {
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-muted);
    padding: 0 10px;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-subtle);
    color: var(--ink);
}

.btn-ghost:active:not(:disabled),
.btn-secondary:active {
    transform: scale(0.97);
}

.btn-ghost:disabled {
    opacity: 0.55;
    cursor: default;
}

.refresh-btn.is-refreshing .icon-refresh {
    animation: spin 0.9s linear infinite;
}

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

.btn-secondary {
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
}

.btn-secondary:hover {
    background: var(--surface-subtle);
}

.new-photos-banner {
    position: sticky;
    top: calc(var(--header-height) + env(safe-area-inset-top) + 10px);
    z-index: 15;
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
    pointer-events: none;
    animation: slideDown 0.22s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.new-photos-pill {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(24, 24, 23, 0.9);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    color: #ffffff;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}

.new-photos-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
}

/* Mobile-First Photo Grid (2 columns on narrow mobile) */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    align-items: start;
}

.photo-grid-item {
    min-width: 0;
}

.photo-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.14s ease, border-color 0.16s ease;
}

.photo-card:active {
    transform: scale(0.985);
}

.photo-link {
    position: relative;
    display: block;
    width: 100%;
    background: var(--surface-subtle);
    overflow: hidden;
}

.photo-thumb {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1.015);
    transition: opacity 0.28s ease, transform 0.35s ease;
}

.photo-thumb.is-loaded {
    opacity: 1;
    transform: scale(1);
}

@media (hover: hover) {
    .photo-card:hover {
        border-color: var(--border-strong);
    }

    .photo-link:hover .photo-thumb.is-loaded {
        transform: scale(1.025);
    }
}

.photo-placeholder,
.photo-skeleton {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: linear-gradient(90deg, #ecece8 25%, #f5f5f2 50%, #ecece8 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite linear;
}

.photo-placeholder {
    position: absolute;
    inset: 0;
    aspect-ratio: auto;
}

.photo-skeleton {
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.photo-broken {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--ink-muted);
    font-size: 0.75rem;
    background: var(--surface-subtle);
}

/* Gallery Footer & Infinite Scroll Sentinel */
.gallery-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 28px 0 12px;
}

.load-more-status,
.end-of-gallery {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--ink-muted);
}

.load-more-error {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--ink-muted);
}

.scroll-sentinel {
    width: 100%;
    height: 1px;
}

/* State Messages & Prose Pages */
.state-message {
    max-width: 440px;
    margin: 48px auto;
    padding: 28px 24px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.state-title {
    margin: 0 0 8px;
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.015em;
}

.state-body {
    margin: 0 0 18px;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--ink-muted);
}

.prose-page {
    max-width: 620px;
    margin: 20px auto;
    padding: 24px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.prose-page h1 {
    margin: 0 0 14px;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.prose-page p {
    margin: 0 0 14px;
    font-size: 0.9375rem;
    line-height: 1.65;
    color: var(--ink-muted);
}

.prose-actions {
    margin-top: 20px;
    margin-bottom: 0;
}

/* Immersive Darkroom Photo Viewer */
.viewer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #0a0a0b;
    color: #f5f5f4;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    outline: none;
    animation: viewerFadeIn 0.18s ease-out;
}

@keyframes viewerFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.viewer-loading {
    align-items: center;
    justify-content: center;
}

.viewer-loading-text {
    font-size: 0.9375rem;
    color: #a8a8a3;
}

.viewer-backdrop .state-message {
    background: #161618;
    border-color: rgba(255, 255, 255, 0.1);
    color: #f5f5f4;
}

.viewer-backdrop .state-body {
    color: #a8a8a3;
}

.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    min-height: 56px;
    background: linear-gradient(to bottom, rgba(10, 10, 11, 0.72), transparent);
}

.viewer-icon-btn,
.viewer-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.1);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: #f5f5f4;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background-color 0.15s ease, transform 0.12s ease;
}

.viewer-icon-btn:hover,
.viewer-download-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.viewer-icon-btn:active,
.viewer-download-btn:active {
    transform: scale(0.96);
}

.viewer-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
}

.viewer-media-frame {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-thumb-preview,
.viewer-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 2px;
    user-select: none;
}

.viewer-thumb-preview {
    position: absolute;
    filter: blur(10px);
    opacity: 0.65;
}

.viewer-image {
    position: relative;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.viewer-image.is-loaded {
    opacity: 1;
}

.viewer-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(16, 16, 18, 0.56);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #f5f5f4;
    transition: background-color 0.15s ease, transform 0.12s ease;
}

.viewer-nav-prev {
    left: 10px;
}

.viewer-nav-next {
    right: 10px;
}

.viewer-nav-btn:hover {
    background: rgba(34, 34, 38, 0.85);
}

.viewer-nav-btn:active {
    transform: translateY(-50%) scale(0.94);
}

.viewer-meta {
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(to top, rgba(10, 10, 11, 0.94), rgba(10, 10, 11, 0.8));
}

.viewer-title {
    margin: 0 0 4px;
    font-size: 0.9375rem;
    font-weight: 500;
}

.viewer-description {
    margin: 0 0 6px;
    font-size: 0.8375rem;
    color: #b8b8b2;
    line-height: 1.45;
}

.viewer-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.75rem;
    color: #8f8f89;
    font-variant-numeric: tabular-nums;
}

.viewer-error {
    text-align: center;
    max-width: 340px;
    padding: 20px;
}

.viewer-error-title {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 600;
}

.viewer-error-body {
    margin: 0 0 14px;
    font-size: 0.875rem;
    color: #a8a8a3;
}

.viewer-preload {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Blazor error UI */
#blazor-error-ui {
    background: #181817;
    color: #ffffff;
    bottom: 0;
    display: none;
    left: 0;
    padding: 12px 16px;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: 0.875rem;
}

#blazor-error-ui .reload {
    margin-left: 12px;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 12px;
    top: 10px;
    background: transparent;
    border: none;
    color: #ffffff;
}

/* Tablet Layout */
@media (min-width: 640px) {
    .site-header-inner {
        padding: 0 20px;
    }

    .app-main {
        padding: 16px calc(20px + env(safe-area-inset-right)) 44px calc(20px + env(safe-area-inset-left));
    }

    .photo-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
    }

    .viewer-stage {
        padding: 12px 24px;
    }
}

@media (min-width: 768px) {
    .photo-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 14px;
    }
}

/* Desktop Layout */
@media (min-width: 1024px) {
    .photo-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
    }

    .viewer-stage {
        padding: 16px 76px;
    }

    .viewer-nav-prev {
        left: 20px;
    }

    .viewer-nav-next {
        right: 20px;
    }
}

@media (min-width: 1280px) {
    .photo-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (min-width: 1536px) {
    .photo-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}
