:root {
    --primary-color: #3f2068;
    --primary-hover: #2f1552;
    --accent-color: #7f5bb4;
    --bg-color: #534d69;
    --card-bg: rgba(255, 255, 255, 0.78);
    --card-solid: #ffffff;
    --text-main: #1f2030;
    --text-muted: #6b6879;
    --border-color: rgba(63, 32, 104, 0.14);
    --danger: #b42335;
    --success: #176b45;
    --shadow: 0 22px 60px rgba(31, 21, 57, 0.18);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    padding: clamp(24px, 5vw, 64px) 18px;
    color: var(--text-main);
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.72), transparent 30%),
        linear-gradient(135deg, #f8fbff 0%, var(--bg-color) 100%);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.container {
    width: min(100%, 820px);
    min-height: calc(100vh - clamp(48px, 10vw, 128px));
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 10px 14px 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(31, 21, 57, 0.08);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.login-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
}

.header-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(63, 32, 104, 0.12);
    border-radius: 999px;
    padding: 9px 15px;
    color: var(--primary-color);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 20px rgba(63, 32, 104, 0.08);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.header-link:hover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 12px 24px rgba(63, 32, 104, 0.12);
    transform: translateY(-1px);
}

.header-button {
    border: 1px solid rgba(63, 32, 104, 0.12);
    background: rgba(255, 255, 255, 0.82);
    cursor: pointer;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    margin: 0;
    padding: 7px 10px 7px 8px;
    border: 1px solid rgba(63, 32, 104, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.28);
    box-shadow: 0 8px 18px rgba(31, 21, 57, 0.05);
    color: var(--primary-color);
    font-size: clamp(1.15rem, 2.5vw, 1.48rem);
    font-weight: 700;
    letter-spacing: -0.5px;
    text-decoration: none;
}

.brand-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: none;
    border-radius: 12px;
    background: rgba(63, 32, 104, 0.06);
    box-shadow: inset 0 0 0 1px rgba(63, 32, 104, 0.04);
}

.brand-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.download-card,
.admin-card {
    border: 0;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 26px 60px rgba(31, 21, 57, 0.14);
    backdrop-filter: blur(18px);
}

.download-card {
    padding: clamp(28px, 6vw, 52px);
    text-align: center;
    border: 1px solid rgba(63, 32, 104, 0.06);
}

.file-icon {
    width: 82px;
    height: 82px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 22px;
    border-radius: 24px;
    background: #f0f7ff;
}

.file-icon svg { width: 42px; height: 42px; color: var(--primary-color); }

.eyebrow {
    margin: 0 0 7px;
    color: var(--accent-color);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.file-name {
    margin: 0 0 8px;
    font-size: clamp(1.12rem, 3vw, 1.55rem);
    font-weight: 700;
    letter-spacing: -0.3px;
    overflow-wrap: anywhere;
}

.file-info { margin: 0 0 28px; color: var(--text-muted); font-size: 0.9rem; }

.download-button {
    width: 100%;
    min-height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 14px;
    padding: 15px 22px;
    color: white;
    background: linear-gradient(135deg, var(--primary-color), #4c2a7b);
    font-size: 0.96rem;
    font-weight: 700;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.download-button:hover {
    box-shadow: 0 12px 28px rgba(63, 32, 104, 0.22);
    filter: brightness(1.02);
}

.download-button:active { transform: scale(0.985); }
.download-button:disabled { cursor: wait; opacity: 0.65; }
.download-button svg { flex: 0 0 auto; }

.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 22px;
    padding: 10px 12px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

.footer-divider { opacity: 0.5; }

.footer-link {
    color: var(--primary-color);
    font-weight: 700;
    text-decoration: none;
}
.footer-link:hover { text-decoration: underline; }
.footer-button {
    border: 0;
    padding: 0;
    background: transparent;
}

.form-message {
    margin: 10px 0 0;
    color: var(--danger);
    font-size: 0.82rem;
    font-weight: 600;
}

.stack-form {
    display: grid;
    gap: 14px;
    width: 100%;
}

.stack-form label {
    display: grid;
    gap: 8px;
    text-align: left;
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 600;
}

.stack-form input,
.stack-form select {
    width: 100%;
    min-height: 44px;
    border: 1px solid rgba(63, 32, 104, 0.18);
    border-radius: 11px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-main);
}

.stack-form input:focus,
.stack-form select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(127, 91, 180, 0.12);
    outline: none;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(19, 12, 31, 0.42);
    z-index: 30;
}

.modal-backdrop[hidden] { display: none; }

.modal {
    width: min(100%, 430px);
    position: relative;
    border: 0;
    border-radius: 24px;
    padding: clamp(22px, 4vw, 30px);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 30px 80px rgba(23, 12, 44, 0.28);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: rgba(63, 32, 104, 0.08);
    color: var(--primary-color);
    font-size: 1.2rem;
}

.modal-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.modal-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: var(--primary-color);
    background: #f0eaf8;
}

.modal-copy {
    margin: 0 0 18px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.admin-page .container { width: min(100%, 980px); }

.admin-container { justify-content: flex-start; }

.admin-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.admin-header .brand { align-self: flex-start; margin: 0; }

.admin-title {
    margin: 0 0 6px;
    color: var(--primary-color);
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    letter-spacing: -0.04em;
}

.admin-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 22px;
}

.nav-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid rgba(63, 32, 104, 0.16);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--primary-color);
    background: rgba(52, 75, 102, 0.66);
    font-size: .82rem;
    font-weight: 700;
    text-decoration: none;
}

.nav-button.primary {
    color: rgba(21, 36, 54, 0.66);
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

#upload { grid-column: 1; grid-row: 1; }
#icon-settings { grid-column: 1; grid-row: 2; }
#users { grid-column: 2; grid-row: 1 / span 2; }
#file-settings { grid-column: 1; grid-row: 3; }
#files { grid-column: 2; grid-row: 3; }

.admin-card {
    padding: 14px 13px;
}

.admin-card h2 {
    margin: 0 0 8px;
    font-size: 1.12rem;
    color: var(--text-main);
}

.card-description {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.5;
}

.settings-actions {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, .7fr);
    align-items: stretch;
    gap: 8px;
}

.copy-link-button {
    min-height: 44px;
    border: 0;
    border-radius: 11px;
    padding: 10px 12px;
    color: #286044;
    background: #ccebd8;
    font-size: .82rem;
    font-weight: 700;
}

.copy-link-button:disabled {
    color: #8e9991;
    background: #e4e8e5;
    cursor: not-allowed;
}

.drop-zone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 125px;
    border: 1.5px dashed rgba(63, 32, 104, .33);
    border-radius: 15px;
    padding: 14px;
    color: var(--text-muted);
    background: rgba(52, 75, 102, 0.75);
    text-align: center;
    transition: border-color .2s, background .2s;
}

.drop-zone.is-dragging,
.drop-zone:hover {
    border-color: var(--accent-color);
    background: rgba(20, 41, 71, 0.75);
}

.drop-zone input,
.icon-drop-zone input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.drop-zone svg { width: 30px; height: 30px; }

.icon-drop-zone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 78px;
    border: 1px dashed rgba(63, 32, 104, .24);
    border-radius: 12px;
    color: var(--text-muted);
    background: rgba(250, 248, 255, .6);
    font-size: .78rem;
    text-align: center;
}

.icon-drop-zone.is-dragging,
.icon-drop-zone:hover {
    border-color: var(--accent-color);
    background: #f6f1fc;
}

body.dark-theme .icon-drop-zone {
    border-color: rgba(201, 178, 238, 0.2);
    background: rgba(29, 24, 40, 0.62);
}

body.dark-theme .icon-drop-zone.is-dragging,
body.dark-theme .icon-drop-zone:hover {
    background: rgba(127, 91, 180, 0.2);
}

.checkbox-row {
    display: flex !important;
    align-items: center;
    min-height: 44px;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid rgba(63, 32, 104, .12);
    border-radius: 11px;
    background: rgba(250, 248, 255, .6);
    gap: 7px !important;
}

.checkbox-row input {
    width: auto;
    min-height: 0;
    margin: 0;
    accent-color: var(--accent-color);
}

.upload-progress {
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.progress-track {
    height: 7px;
    overflow: hidden;
    margin-top: 7px;
    border-radius: 99px;
    background: #e7e1ef;
}

.progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent-color);
    transition: width .2s;
}

.icon-preview {
    width: 64px;
    height: 64px;
    overflow: hidden;
    margin: 0 auto 10px;
    border-radius: 16px;
    background: #f0eaf8;
}

.icon-preview img { width: 100%; height: 100%; object-fit: cover; }

.file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid rgba(63, 32, 104, .1);
    border-radius: 12px;
    padding: 10px 12px;
    background: rgba(255,255,255,.68);
    min-height: 57px;
    padding: 8px 9px 8px 13px;
}

.file-row-icon {
    flex: 0 0 auto;
    width: 33px;
    height: 33px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: var(--primary-color);
    background: #f0eaf8;
}

.file-action {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 9px;
    color: var(--text-muted);
    background: transparent;
    opacity: .2;
    transition: opacity .2s, background .2s, color .2s;
}

.file-action:hover {
    opacity: 1;
    background: rgba(63, 32, 104, 0.08);
    color: var(--primary-color);
}

.file-action svg { width: 17px; height: 17px; }

.toast {
    position: fixed;
    z-index: 30;
    right: 18px;
    bottom: 18px;
    max-width: min(390px, calc(100vw - 36px));
    border: 1px solid rgba(23, 107, 69, .15);
    border-radius: 12px;
    padding: 12px 15px;
    color: var(--success);
    background: white;
    box-shadow: var(--shadow);
    font-size: .83rem;
    font-weight: 700;
}

.toast.error {
    border-color: rgba(180, 35, 53, .16);
    color: var(--danger);
}

body.dark-theme {
    --primary-color: #c9b2ee;
    --primary-hover: #e0d2f7;
    --accent-color: #c2a3ef;
    --bg-color: #171421;
    --card-bg: rgba(38, 31, 52, 0.9);
    --card-solid: #261f34;
    --text-main: #f2eef8;
    --text-muted: #b9b0c8;
    --border-color: rgba(201, 178, 238, 0.2);
    --danger: #ff9ca8;
    --success: #8be0b5;
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
    background:
        radial-gradient(circle at 12% 10%, rgba(127, 91, 180, 0.2), transparent 30%),
        linear-gradient(135deg, #242031 0%, #111018 100%);
}

body.dark-theme .site-header,
body.dark-theme .header-link,
body.dark-theme .header-button {
    border-color: rgba(201, 178, 238, 0.2);
    background: rgba(38, 31, 52, 0.82);
}

body.dark-theme .download-card,
body.dark-theme .admin-card,
body.dark-theme .modal {
    background: rgba(38, 31, 52, 0.92);
    border-color: rgba(201, 178, 238, 0.14);
}

body.dark-theme .brand,
body.dark-theme .stack-form input,
body.dark-theme .stack-form select {
    border-color: rgba(201, 178, 238, 0.18);
    background: rgba(29, 24, 40, 0.78);
}

body.dark-theme .stack-form input,
body.dark-theme .stack-form select,
body.dark-theme .modal-close {
    color: var(--text-main);
}

body.dark-theme .file-icon,
body.dark-theme .modal-icon,
body.dark-theme .icon-preview,
body.dark-theme .file-row-icon {
    background: rgba(127, 91, 180, 0.2);
}

body.dark-theme .checkbox-row {
    border-color: rgba(201, 178, 238, .18);
    background: rgba(29, 24, 40, .62);
}

body.dark-theme .file-row {
    border-color: rgba(201, 178, 238, 0.16);
    background: rgba(29, 24, 40, 0.62);
}

body.dark-theme .progress-track { background: #3b3249; }
body.dark-theme .toast { background: #261f34; }

@media (max-width: 720px) {
    .site-header {
        flex-wrap: wrap;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .admin-header { flex-direction: column; }
    .admin-header .brand { align-self: auto; order: -1; }
    .download-card { padding: 28px 19px; }
    .footer { line-height: 1.8; flex-wrap: wrap; }
    .admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #upload, #icon-settings, #users, #file-settings, #files { grid-column: auto; grid-row: auto; }
}

@media (max-width: 520px) {
    .admin-grid { grid-template-columns: 1fr; }
    .settings-actions { grid-template-columns: 1fr; }
}
