:root {
    --bg: #05050c;
    --glass: rgba(255, 255, 255, 0.055);
    --glass-hi: rgba(255, 255, 255, 0.10);
    --border: rgba(255, 255, 255, 0.12);
    --border-hi: rgba(255, 255, 255, 0.22);
    --text: #f5f6fa;
    --text-dim: rgba(245, 246, 250, 0.62);
    --text-faint: rgba(245, 246, 250, 0.38);
    --accent-1: #7b5cff;
    --accent-2: #b06ef2;
    --accent-3: #4facfe;
    --danger: #ff5b6e;
    --radius: 22px;
    --radius-sm: 14px;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
            "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100dvh;
}

body.locked { overflow: hidden auto; }

/* ================= Background ================= */
.bg {
    position: fixed; inset: 0; z-index: 0;
    overflow: hidden; pointer-events: none;
}
.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(110px);
    opacity: 0.5;
    will-change: transform;
}
.blob-1 { width: 48vmax; height: 48vmax; background: #6d4bff; top: -16vmax; left: -12vmax; animation: float1 20s ease-in-out infinite; }
.blob-2 { width: 42vmax; height: 42vmax; background: #ff4b9d; bottom: -16vmax; right: -10vmax; opacity: 0.35; animation: float2 24s ease-in-out infinite; }
.blob-3 { width: 36vmax; height: 36vmax; background: #2ad4ff; bottom: 15%; left: 28%; opacity: 0.28; animation: float3 28s ease-in-out infinite; }

@keyframes float1 { 50% { transform: translate(8vmax, 6vmax) scale(1.12); } }
@keyframes float2 { 50% { transform: translate(-9vmax, -5vmax) scale(1.08); } }
@keyframes float3 { 50% { transform: translate(4vmax, -7vmax) scale(1.18); } }

/* ================= Glass ================= */
.glass {
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ================= Views ================= */
.view { position: relative; z-index: 1; }
.hidden { display: none !important; }

/* ================= Gate ================= */
.gate-view {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.gate-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 32px 28px;
    animation: cardIn 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.brand { text-align: center; margin-bottom: 28px; }

.logo {
    width: 60px; height: 60px;
    margin: 0 auto 18px;
    display: grid; place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2) 55%, var(--accent-3));
    color: #fff;
    box-shadow: 0 12px 40px rgba(123, 92, 255, 0.45);
}
.logo svg { width: 30px; height: 30px; }

.brand h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.4px;
    background: linear-gradient(120deg, #fff, #c9bcff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.sub {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-dim);
    letter-spacing: 0.2px;
}

.field { display: block; margin-bottom: 18px; }
.field span {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
    margin-bottom: 8px;
}
.field input {
    width: 100%;
    padding: 14px 16px;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
    letter-spacing: 1px;
}
.field input::placeholder { color: var(--text-faint); letter-spacing: 0.3px; }
.field input:focus {
    border-color: rgba(123, 92, 255, 0.65);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 4px rgba(123, 92, 255, 0.14);
}

.msg {
    font-size: 13px;
    text-align: center;
    min-height: 18px;
    margin-top: 12px;
    color: var(--danger);
    opacity: 0;
    transition: opacity 0.2s;
}
.msg.show { opacity: 1; }

.foot {
    margin-top: 22px;
    text-align: center;
    font-size: 11.5px;
    color: var(--text-faint);
}
.foot a { color: var(--text-dim); text-decoration: none; }
.foot a:hover { color: var(--text); }

/* ================= Buttons ================= */
.btn {
    font-family: var(--font);
    font-size: 14.5px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    padding: 13px 20px;
    cursor: pointer;
    transition: all 0.18s ease;
    letter-spacing: 0.1px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 20px; font-size: 15.5px; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; border-radius: 10px; }

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2) 60%, var(--accent-3));
    background-size: 200% 200%;
    box-shadow: 0 10px 30px rgba(123, 92, 255, 0.35);
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 14px 38px rgba(123, 92, 255, 0.5);
    background-position: 100% 50%;
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-ghost {
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hi);
}

/* ================= App layout ================= */
.app-view {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    max-width: 780px;
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-radius: 18px;
    position: sticky;
    top: 12px;
    z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: #38e07b;
    box-shadow: 0 0 12px #38e07b;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; transform: scale(0.85); } }
.topbar-title { font-size: 14.5px; font-weight: 700; letter-spacing: -0.2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border);
    color: var(--text-dim);
    letter-spacing: 0.4px;
}
.pill-accent {
    background: linear-gradient(135deg, rgba(123, 92, 255, 0.25), rgba(79, 172, 254, 0.2));
    border-color: rgba(123, 92, 255, 0.4);
    color: #d9d0ff;
}

.main { display: flex; flex-direction: column; gap: 18px; flex: 1; }

.card { padding: 22px; }

.card-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.2px;
    margin-bottom: 16px;
    color: var(--text);
}

/* ================= Dropzone ================= */
.dropzone {
    border: 1.5px dashed rgba(255, 255, 255, 0.18);
    border-radius: 18px;
    padding: 42px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.22s ease;
    background: rgba(255, 255, 255, 0.02);
}
.dropzone:hover,
.dropzone.drag {
    border-color: rgba(123, 92, 255, 0.7);
    background: rgba(123, 92, 255, 0.08);
    transform: translateY(-2px);
}
.dz-icon {
    width: 52px; height: 52px;
    margin: 0 auto 16px;
    display: grid; place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(123, 92, 255, 0.28), rgba(79, 172, 254, 0.18));
    border: 1px solid rgba(123, 92, 255, 0.35);
    color: #c9bcff;
}
.dz-icon svg { width: 26px; height: 26px; }
.dz-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.dz-sub { font-size: 12.5px; color: var(--text-faint); }

.preview-wrap { position: relative; border-radius: 18px; overflow: hidden; }
.preview-wrap img {
    display: block;
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.35);
}
.preview-overlay {
    position: absolute;
    inset: auto 0 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
}
.preview-info { font-size: 12px; color: var(--text-dim); }

/* ================= Modes ================= */
.modes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.mode {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px 14px 13px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-family: var(--font);
    text-align: left;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}
.mode:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--border-hi); }
.mode.active {
    background: linear-gradient(135deg, rgba(123, 92, 255, 0.28), rgba(79, 172, 254, 0.16));
    border-color: rgba(123, 92, 255, 0.65);
    box-shadow: 0 8px 26px rgba(123, 92, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.mode-badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.8px;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-dim);
}
.mode.active .mode-badge {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
    color: #fff;
}
.mode-name { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; }
.mode-desc { font-size: 10.5px; color: var(--text-faint); }

/* ================= Loading ================= */
.loading-card { text-align: center; padding: 38px 24px; }
.spinner {
    width: 58px; height: 58px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, var(--accent-1), var(--accent-2), var(--accent-3), transparent);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    animation: spin 0.95s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 15px; font-weight: 600; }
.loading-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 8px; }

/* ================= Result / Compare ================= */
.result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.result-head .card-title { margin: 0; }

.compare {
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    background: #000;
    user-select: none;
    touch-action: none;
    cursor: ew-resize;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.img-before, .img-after {
    display: block;
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    background: #000;
}
.compare-after {
    position: absolute;
    inset: 0;
    clip-path: inset(0 calc(100% - var(--pos)) 0 0);
    will-change: clip-path;
}
.img-after {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}
.handle {
    position: absolute;
    top: 0; bottom: 0;
    left: var(--pos);
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.handle-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.5);
}
.handle-grip {
    position: relative;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1.5px solid rgba(255, 255, 255, 0.55);
    color: #fff;
    box-shadow: 0 6px 26px rgba(0, 0, 0, 0.4);
}
.handle-grip svg { width: 20px; height: 20px; }

.tag {
    position: absolute;
    top: 12px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 5px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}
.tag-before { left: 12px; }
.tag-after { right: 12px; background: rgba(123, 92, 255, 0.45); border-color: rgba(123, 92, 255, 0.7); }

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
    font-size: 12px;
    color: var(--text-dim);
}
.result-meta span {
    padding: 6px 11px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
}

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.result-actions .btn { flex: 1; min-width: 140px; }

/* ================= Footer & Toast ================= */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 4px 4px;
    font-size: 11.5px;
    color: var(--text-faint);
}
.footer a { color: var(--text-dim); text-decoration: none; }
.footer a:hover { color: var(--text); }

.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 30px);
    padding: 13px 22px;
    border-radius: 14px;
    background: rgba(20, 20, 28, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-hi);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 100;
    max-width: calc(100vw - 40px);
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 91, 110, 0.5); }

/* ================= Responsive ================= */
@media (max-width: 520px) {
    .app-view { padding: 14px; gap: 14px; }
    .card { padding: 18px; }
    .modes { grid-template-columns: 1fr; }
    .mode { flex-direction: row; align-items: center; gap: 12px; padding: 12px 14px; }
    .mode-desc { margin-left: auto; }
    .gate-card { padding: 32px 24px 24px; }
    .brand h1 { font-size: 21px; }
}