:root {
    color-scheme: light;
    --color-canvas: #f7f6fb;
    --color-surface: #ffffff;
    --color-surface-soft: #f0eef8;
    --color-text: #1b1923;
    --color-text-muted: #716d7d;
    --color-border: #e8e5ef;
    --color-brand: #6757d9;
    --color-brand-strong: #5646c8;
    --color-brand-soft: #eeebff;
    --color-favorite: #f3b51b;
    --color-danger: #d94868;
    --shadow-card: 0 6px 22px rgba(43, 36, 74, 0.08);
    --shadow-floating: 0 10px 30px rgba(43, 36, 74, 0.15);
    --radius-small: 12px;
    --radius-medium: 18px;
    --radius-large: 24px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --bottom-nav-height: 68px;
    --content-max-width: 960px;
    --transition-fast: 160ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body,
#app {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: transparent;
}

html,
body,
button,
input {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(103, 87, 217, 0.3);
    outline-offset: 2px;
}

.main-layout {
    width: 100%;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
}

.nav-content { display: contents; }

.app-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
    background:
        radial-gradient(circle at 100% 0, rgba(103, 87, 217, 0.08), transparent 34%),
        var(--color-canvas);
}

.screen-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.screen-scroll::-webkit-scrollbar {
    display: none;
}

h1[tabindex="-1"] {
    outline: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Library header */
.library-header {
    flex: 0 0 auto;
    padding: max(18px, env(safe-area-inset-top)) var(--space-5) var(--space-4);
    background: rgba(247, 246, 251, 0.94);
    border-bottom: 1px solid rgba(232, 229, 239, 0.7);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 20;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: min(100%, var(--content-max-width));
    margin: 0 auto var(--space-4);
}

.brand-mark {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    object-fit: cover;
    border-radius: 14px;
    box-shadow: 0 5px 16px rgba(67, 54, 130, 0.18);
}

.brand-row h1 {
    margin: 0;
    color: var(--color-text);
    font-size: 25px;
    font-weight: 780;
    letter-spacing: -0.6px;
    line-height: 1.1;
}

.brand-row p {
    margin: 3px 0 0;
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 500;
}

.search-field {
    position: relative;
    display: flex;
    align-items: center;
    width: min(100%, var(--content-max-width));
    height: 50px;
    margin: 0 auto;
    color: var(--color-text-muted);
}

.search-field svg {
    position: absolute;
    left: 16px;
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    pointer-events: none;
}

.search-field input {
    width: 100%;
    height: 100%;
    padding: 0 16px 0 47px;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    outline: none;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 16px;
    box-shadow: 0 3px 14px rgba(43, 36, 74, 0.05);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

.search-field input::placeholder {
    color: #918d9b;
}

.search-field input:focus {
    border-color: rgba(103, 87, 217, 0.55);
    box-shadow: 0 0 0 4px rgba(103, 87, 217, 0.1);
}

/* Library sections */
.library-content {
    padding: var(--space-6) 0 calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 28px);
}

.own-photo-section {
    width: min(100%, var(--content-max-width));
    margin: 0 auto var(--space-6);
    padding: 0 var(--space-5);
}

.own-photo-cta {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 86px;
    padding: 14px 16px;
    border: 1px solid rgba(103, 87, 217, 0.2);
    border-radius: 22px;
    background: linear-gradient(135deg, #6757d9, #806ee8);
    color: #fff;
    box-shadow: 0 10px 26px rgba(74, 57, 168, 0.22);
    text-align: left;
    cursor: pointer;
}

.own-photo-cta:active { transform: scale(.985); }
.own-photo-cta:disabled { cursor: default; opacity: .7; }

.own-photo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border-radius: 17px;
    background: rgba(255, 255, 255, .16);
}

.own-photo-icon svg,
.own-photo-chevron {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.own-photo-icon svg { width: 29px; height: 29px; }
.own-photo-chevron { width: 24px; height: 24px; opacity: .8; }
.own-photo-copy { min-width: 0; }
.own-photo-copy strong { display: block; font-size: 17px; font-weight: 780; }
.own-photo-copy small { display: block; margin-top: 4px; color: rgba(255,255,255,.78); font-size: 12px; line-height: 1.35; }
.recent-photo-section { margin-bottom: var(--space-8); }
.user-image-artwork { background: #e8e6ed; }
.user-image-artwork .card-image { padding: 0; object-fit: cover; }
.user-image-card { position: relative; }

.user-image-delete {
    position: absolute;
    top: 13px;
    right: 13px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid rgba(232, 229, 239, .9);
    border-radius: 50%;
    background: rgba(255,255,255,.94);
    color: var(--color-danger);
    box-shadow: 0 3px 12px rgba(43,36,74,.12);
}

.user-image-delete svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.user-image-delete:active { transform: scale(.9); }

.category-section,
.loading-section {
    width: min(100%, var(--content-max-width));
    margin: 0 auto var(--space-8);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 var(--space-5);
    margin-bottom: var(--space-3);
}

.section-heading h2 {
    margin: 0;
    color: var(--color-text);
    font-size: 20px;
    font-weight: 750;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.section-heading p {
    margin: 3px 0 0;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 550;
}

.text-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px 0 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--color-brand);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.text-button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.text-button:active {
    background: var(--color-brand-soft);
}

.image-rail {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: clamp(148px, 41vw, 184px);
    gap: var(--space-3);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding: 2px var(--space-5) 10px;
}

.image-rail::-webkit-scrollbar {
    display: none;
}

.image-rail-item {
    min-width: 0;
    scroll-snap-align: start;
}

/* Image cards */
.image-card {
    position: relative;
    width: 100%;
    min-width: 0;
}

.image-card-main {
    display: block;
    width: 100%;
    padding: 8px 8px 12px;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-medium);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-card);
    text-align: left;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.image-card-main:active {
    transform: scale(0.975);
    border-color: rgba(103, 87, 217, 0.28);
    box-shadow: 0 3px 12px rgba(43, 36, 74, 0.08);
}

.image-card-artwork {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 13px;
    background: #fdfdfd;
}

.card-image {
    display: block;
    width: 100%;
    height: 100%;
    padding: 7px;
    object-fit: contain;
    pointer-events: none;
}

.card-image.image-load-error {
    opacity: 0.15;
}

.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #aaa6b3;
    background: var(--color-surface-soft);
}

.image-placeholder svg {
    width: 38px;
    height: 38px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.image-card-title {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 0 4px;
    overflow: hidden;
    color: var(--color-text);
    font-size: 13px;
    font-weight: 650;
    line-height: 20px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorite-btn {
    position: absolute;
    top: 13px;
    right: 13px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid rgba(232, 229, 239, 0.9);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    color: #9d99a7;
    box-shadow: 0 3px 12px rgba(43, 36, 74, 0.11);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    transition: color var(--transition-fast), transform var(--transition-fast), background var(--transition-fast);
}

.favorite-btn svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.favorite-btn.is-favorite {
    color: var(--color-favorite);
    background: #fffaf0;
}

.favorite-btn.is-favorite svg {
    fill: currentColor;
}

.favorite-btn:active {
    transform: scale(0.9);
}

/* App top bar */
.app-top-bar {
    position: relative;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    align-items: center;
    gap: var(--space-2);
    min-height: calc(76px + env(safe-area-inset-top));
    padding: max(14px, env(safe-area-inset-top)) var(--space-4) 12px;
    border-bottom: 1px solid rgba(232, 229, 239, 0.75);
    background: rgba(247, 246, 251, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 20;
}

.top-bar-icon-button,
.top-bar-icon-placeholder {
    width: 48px;
    height: 48px;
}

.top-bar-icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 15px;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: 0 3px 12px rgba(43, 36, 74, 0.06);
    cursor: pointer;
}

.top-bar-icon-button svg {
    width: 25px;
    height: 25px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.top-bar-icon-button:active {
    background: var(--color-brand-soft);
    color: var(--color-brand);
    transform: scale(0.96);
}

.top-bar-copy {
    min-width: 0;
    text-align: center;
}

.top-bar-copy h1 {
    margin: 0;
    overflow: hidden;
    color: var(--color-text);
    font-size: 22px;
    font-weight: 760;
    letter-spacing: -0.4px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-bar-copy p {
    margin: 4px 0 0;
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 550;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Grids */
.grid-content {
    width: min(100%, var(--content-max-width));
    margin: 0 auto;
    padding: var(--space-5);
}

.grid-content.with-bottom-navigation {
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 28px);
}

.image-grid,
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

/* Bottom navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(100%, 720px);
    min-height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding: 7px max(18px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-right));
    border-top: 1px solid rgba(226, 222, 235, 0.9);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 -8px 28px rgba(43, 36, 74, 0.08);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    transform: translateX(-50%);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 54px;
    padding: 5px 18px;
    border: 0;
    border-radius: 17px;
    background: transparent;
    color: #898491;
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.nav-item.active {
    background: var(--color-brand-soft);
    color: var(--color-brand);
}

.nav-item:active {
    transform: scale(0.97);
}

.nav-icon {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-item.active .nav-icon {
    stroke-width: 2.1;
}

.nav-label {
    overflow: hidden;
    font-size: 11px;
    font-weight: 650;
    line-height: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Empty, loading and action states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 58vh;
    padding: 52px 24px;
    color: var(--color-text);
    text-align: center;
}

.empty-state-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    margin-bottom: var(--space-5);
    border-radius: 28px;
    background: var(--color-brand-soft);
    color: var(--color-brand);
}

.empty-state-icon svg {
    width: 40px;
    height: 40px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.empty-state h2 {
    margin: 0 0 var(--space-2);
    font-size: 22px;
    font-weight: 760;
    letter-spacing: -0.3px;
}

.empty-state p {
    max-width: 330px;
    margin: 0 0 var(--space-6);
    color: var(--color-text-muted);
    font-size: 15px;
    line-height: 1.5;
}

.primary-button {
    min-height: 48px;
    padding: 0 24px;
    border: 0;
    border-radius: 16px;
    background: var(--color-brand);
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 7px 20px rgba(103, 87, 217, 0.24);
    cursor: pointer;
}

.primary-button:active {
    background: var(--color-brand-strong);
    transform: scale(0.98);
}

.skeleton-card {
    padding: 8px 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-medium);
    background: var(--color-surface);
}

.skeleton-artwork,
.skeleton-line,
.skeleton-heading {
    position: relative;
    overflow: hidden;
    background: #eceaf1;
}

.skeleton-artwork::after,
.skeleton-line::after,
.skeleton-heading::after {
    position: absolute;
    inset: 0;
    content: "";
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.72), transparent);
    transform: translateX(-100%);
    animation: skeleton-shimmer 1.35s infinite;
}

.skeleton-artwork {
    aspect-ratio: 1;
    border-radius: 13px;
}

.skeleton-line {
    width: 68%;
    height: 11px;
    margin: 14px auto 0;
    border-radius: 999px;
}

.skeleton-heading {
    width: 150px;
    height: 24px;
    border-radius: 8px;
}

@keyframes skeleton-shimmer {
    100% { transform: translateX(100%); }
}

@media (hover: hover) and (pointer: fine) {
    .image-card-main:hover {
        border-color: rgba(103, 87, 217, 0.24);
        box-shadow: 0 10px 28px rgba(43, 36, 74, 0.12);
        transform: translateY(-2px);
    }

    .favorite-btn:hover,
    .top-bar-icon-button:hover {
        color: var(--color-brand);
    }

    .text-button:hover,
    .nav-item:hover {
        background: var(--color-brand-soft);
        color: var(--color-brand);
    }
}

@media (min-width: 700px) {
    .library-header {
        padding-right: var(--space-8);
        padding-left: var(--space-8);
    }

    .section-heading,
    .image-rail {
        padding-right: var(--space-8);
        padding-left: var(--space-8);
    }

    .image-rail {
        grid-auto-columns: 196px;
        gap: var(--space-4);
    }

    .grid-content {
        padding: var(--space-6) var(--space-8);
    }

    .image-grid,
    .skeleton-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--space-4);
    }
}

@media (min-width: 1024px) {
    .image-grid,
    .skeleton-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 360px) {
    .library-header {
        padding-right: var(--space-4);
        padding-left: var(--space-4);
    }

    .brand-mark {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .brand-row h1 {
        font-size: 23px;
    }

    .section-heading,
    .image-rail {
        padding-right: var(--space-4);
        padding-left: var(--space-4);
    }

    .grid-content {
        padding-right: var(--space-4);
        padding-left: var(--space-4);
    }

    .favorite-btn {
        top: 11px;
        right: 11px;
        width: 40px;
        height: 40px;
    }
}

.image-grid > div {
    contain: layout style;
}

.category-section.is-deferred {
    content-visibility: auto;
    contain-intrinsic-size: auto none auto 16rem;
}

.mobile-load-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: var(--space-6) 0 var(--space-4);
    text-align: center;
}

.mobile-load-more-status {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 550;
}

.mobile-load-more-btn {
    padding: 0 var(--space-4);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
