:root {
    --bg-main: #f4f3f8;
    --bg-card: #ffffff;
    --purple-main: #6d5bd0;
    --purple-soft: #efeefe;
    --purple-dark: #5344b8;
    --accent-pink: #ec4899;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --border-soft: #e8e5f8;
    --shadow-soft: 0 12px 26px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    -webkit-tap-highlight-color: transparent;
    background:
        radial-gradient(1200px 600px at 10% -10%, #efeafe 0%, transparent 60%),
        radial-gradient(1000px 600px at 90% 0%, #ffe7f2 0%, transparent 55%),
        linear-gradient(180deg, #f4f3f8 0%, #ffffff 100%);
}

h1, h2, h3 {
    margin-top: 0;
    font-family: 'Syne', sans-serif;
}

a { color: var(--purple-dark); text-decoration: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 62px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
    background: linear-gradient(90deg, var(--purple-main), var(--accent-pink));
    box-shadow: 0 10px 24px rgba(67, 56, 202, 0.25);
}

.topbar nav {
    display: flex;
    gap: 10px;
    align-items: center;
}

.topbar nav a {
    color: #fff;
    padding: 6px 10px;
    border-radius: 999px;
}

.topbar nav a:hover { background: rgba(255,255,255,0.18); }

.brand {
    color: #fff;
    text-decoration: none;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    letter-spacing: 0.6px;
    font-size: 1.1rem;
}

.container {
    max-width: 1100px;
    margin: 18px auto;
    padding: 0 14px calc(40px + env(safe-area-inset-bottom));
}

.hero-card {
    background: linear-gradient(135deg, #312e81, #7c3aed 58%, #ec4899);
    color: #fff;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 16px 34px rgba(49, 46, 129, 0.25);
    margin-bottom: 12px;
}

.hero-card p { margin: 0; color: rgba(255,255,255,0.92); }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 12px;
}

.upload-card { margin-top: 12px; }

label {
    display: block;
    margin-bottom: 6px;
    color: var(--purple-main);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.35px;
    text-transform: uppercase;
}

input, select {
    width: 100%;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: #f9f9fd;
    padding: 10px;
    font-size: 0.9rem;
    min-height: 44px;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--purple-main);
    background: #fff;
}

button, .btn-link {
    border: none;
    border-radius: 999px;
    padding: 11px 16px;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--purple-main), var(--accent-pink));
    box-shadow: 0 6px 16px rgba(109, 91, 208, 0.35);
    min-height: 44px;
}

.btn-link {
    text-decoration: none;
    display: inline-block;
}

.ghost-btn {
    border: 1px solid var(--border-soft);
    background: #fff;
    color: var(--purple-dark);
    box-shadow: none;
}
.ghost-btn:hover {
    background: #f8f7ff;
}

.stack-form {
    display: grid;
    gap: 10px;
}
.share-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
}
.share-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-height: 18px;
}

.toolbar-form {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
}

.page-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.page-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.upload-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    min-height: 36px;
    border-radius: 10px;
    border: 1px solid #d9d2ff;
    background: linear-gradient(180deg, #faf8ff, #f3efff);
    color: #4c1d95;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
}
.upload-page-link:hover {
    background: #f1ebff;
}
.view-size-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.view-size-toggle .size-btn {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 0.78rem;
}
.view-size-toggle .size-btn.active {
    background: #ede9fe;
    border-color: #c4b5fd;
    color: #5b21b6;
}

.gallery-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.gallery-grid-dynamic.size-large {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.gallery-grid-dynamic.size-medium {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.gallery-grid-dynamic.size-small {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.gallery-grid-dynamic.size-small .media-card,
.gallery-grid-dynamic.size-medium .media-card {
    padding: 10px;
}
.gallery-grid-dynamic.size-small .media-card h3 {
    font-size: 0.86rem;
}
.gallery-grid-dynamic.size-small .media-card .subtle {
    display: none;
}
.gallery-grid-dynamic.size-small .row-actions {
    gap: 6px;
}
.gallery-grid-dynamic.size-small .row-actions .btn-link,
.gallery-grid-dynamic.size-small .row-actions .ghost-btn {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.74rem;
}

.media-card h3 {
    margin-bottom: 6px;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-box {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #f7f6ff;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    overflow: hidden;
    margin-bottom: 10px;
}

.preview-box img,
.preview-box video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.preview-link {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-tile {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: var(--purple-dark);
}

.subtle {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin: 0 0 5px 0;
}
.media-meta-line {
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-top: 8px;
    gap: 6px;
}

.media-view-card {
    padding: 12px;
}
.media-view-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.back-btn {
    min-height: 36px;
    padding: 8px 12px;
}
.media-view-actions .btn-link {
    min-height: 36px;
    padding: 8px 12px;
}
.media-view-body {
    margin-top: 10px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-soft);
    background: #f7f6ff;
    height: calc(100svh - 230px);
    min-height: 46vh;
    display: grid;
    place-items: center;
}
.media-view-image,
.media-view-video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    background: #111;
}

@media (max-width: 640px) {
    .media-view-body {
        height: calc(100svh - 210px);
    }
}
.icon-btn {
    width: 32px;
    height: 32px;
    min-height: 32px;
    border-radius: 9px;
    border: 1px solid var(--border-soft);
    background: #fff;
    color: var(--purple-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: none;
    padding: 0;
}
.icon-btn-primary {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
}
.icon-btn-danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.inline-form { display: inline; }

.flash-wrap { margin-bottom: 10px; display: grid; gap: 8px; }
.flash {
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.flash.success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

.auth-wrap {
    max-width: 760px;
    margin: 0 auto;
}
.auth-login-wrap {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 14px;
}
.auth-hero-card {
    border-radius: 16px;
    padding: 20px;
    color: #fff;
    background:
        radial-gradient(circle at 20% 10%, rgba(255,255,255,0.26), transparent 40%),
        linear-gradient(135deg, #191970, #6d5bd0 55%, #ec4899);
    box-shadow: 0 18px 36px rgba(39, 26, 102, 0.35);
}
.auth-chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.35);
    margin-bottom: 10px;
}
.auth-hero-card h1 {
    margin: 0 0 8px 0;
    font-size: 2.4rem;
    letter-spacing: 0.5px;
}
.auth-hero-card p {
    margin: 0;
    color: rgba(255,255,255,0.94);
}
.auth-login-card h2 {
    font-size: 1.4rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.pagination {
    margin-top: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
}

.upload-queue {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.queue-item {
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 8px 10px;
    background: #faf9ff;
}

.queue-name {
    font-size: 0.86rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.queue-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.queue-bar {
    margin-top: 6px;
    width: 100%;
    height: 7px;
    border-radius: 999px;
    background: #ece9ff;
    overflow: hidden;
}

.queue-bar span {
    display: block;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--purple-main), var(--accent-pink));
    transition: width 0.2s ease;
}

.queue-state {
    margin-top: 5px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.queue-item.done {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.queue-item.failed {
    border-color: #fecaca;
    background: #fef2f2;
}

@media (max-width: 720px) {
    .topbar {
        height: auto;
        min-height: 58px;
        padding: 10px 12px;
        gap: 10px;
    }

    .brand {
        font-size: 0.92rem;
    }

    .topbar nav {
        gap: 6px;
    }

    .topbar nav a {
        padding: 6px 8px;
        font-size: 0.86rem;
    }

    .container {
        margin-top: 12px;
        padding-left: 10px;
        padding-right: 10px;
    }
    .card {
        padding: 10px;
        margin-bottom: 10px;
    }
    .preview-box {
        margin-bottom: 8px;
    }
    .media-card h3 {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }
    .subtle {
        font-size: 0.76rem;
        margin-bottom: 4px;
    }
    .media-meta-line {
        font-size: 0.7rem;
    }

    .toolbar-form { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .page-head-row { flex-wrap: wrap; }
    .page-head-actions { width: 100%; justify-content: space-between; }
    .view-size-toggle .size-btn {
        min-height: 32px;
        padding: 6px 9px;
        font-size: 0.72rem;
    }
    .gallery-grid-dynamic.size-large {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .gallery-grid-dynamic.size-medium {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .gallery-grid-dynamic.size-small {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .row-actions {
        gap: 5px;
    }
    .icon-btn {
        width: 30px;
        height: 30px;
        min-height: 30px;
        border-radius: 8px;
    }
    .auth-login-wrap {
        grid-template-columns: 1fr;
    }
}
