:root {
    --bg: #f5f5f7;
    --bg2: #ffffff;
    --bg3: #e8eaed;
    --primary: #f97316;
    --primary2: #ea580c;
    --primary-light: #fff7ed;
    --card: #ffffff;
    --card-border: #e5e7eb;
    --text: #1f2937;
    --muted: #6b7280;
    --muted2: #9ca3af;
    --ok: #22c55e;
    --err: #ef4444;
    --danger: #ef4444;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
}

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* ==================== Header / Topbar ==================== */
.topbar {
    padding: 22px 18px 14px;
    text-align: center;
    background: var(--bg2);
    border-bottom: 1px solid var(--card-border);
}
.logo {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--primary);
}
.sub {
    margin-top: 6px;
    font-size: 13px;
    color: var(--muted);
}

/* ==================== Container ==================== */
.container {
    flex: 1;
    padding: 16px 16px 24px;
}

/* ==================== Card ==================== */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 16px;
    box-shadow: var(--shadow);
}

/* ==================== Platform Chips ==================== */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.chip {
    border: 1px solid var(--card-border);
    background: var(--bg);
    color: var(--muted);
    font-size: 13px;
    padding: 7px 13px;
    border-radius: 999px;
    cursor: pointer;
    transition: all .18s ease;
    user-select: none;
}
.chip.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
}

/* ==================== Inputs ==================== */
.url-input {
    width: 100%;
    min-height: 84px;
    resize: none;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    background: var(--bg);
    color: var(--text);
    padding: 12px 14px;
    font-size: 15px;
    line-height: 1.5;
    outline: none;
    transition: border-color .18s ease;
}
.url-input:focus { border-color: var(--primary); }
.url-input::placeholder { color: var(--muted2); }

/* ---- 输入框工具栏 ---- */
.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.input-hint {
    font-size: 12px;
    color: var(--muted2);
}
.copy-text-btn {
    flex-shrink: 0;
    border: 1px solid var(--card-border);
    background: var(--bg2);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
}
.copy-text-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}
.copy-text-btn:active { transform: scale(0.97); }

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1f2937;
    color: #fff;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
    z-index: 9999;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.btn-primary {
    margin-top: 14px;
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    box-shadow: 0 8px 20px rgba(249, 115, 22, 0.35);
    cursor: pointer;
    transition: transform .12s ease, opacity .2s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

/* ==================== Status ==================== */
.status {
    margin-top: 16px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}
.status .spinner {
    width: 22px; height: 22px;
    border: 3px solid rgba(249, 115, 22, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 8px;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== Result ==================== */
.result {
    margin-top: 16px;
}
.result-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.cover {
    width: 100%;
    display: block;
    background: #000;
    max-height: 320px;
    object-fit: cover;
}
.r-title {
    padding: 14px 16px 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}
.r-text-wrap {
    position: relative;
}
.r-desc {
    padding: 6px 16px 0;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}
.btn-copy-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 10px 16px 14px;
    padding: 6px 14px;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    background: var(--bg2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s ease;
}
.btn-copy-text:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}
.btn-copy-text:active { transform: scale(0.97); }
.ptag {
    display: inline-block;
    margin: 12px 16px 0;
    font-size: 12px;
    color: #fff;
    padding: 3px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
}
.actions {
    padding: 14px 16px 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.btn-save {
    flex: 1;
    min-width: 120px;
    text-align: center;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    cursor: pointer;
    text-decoration: none;
    transition: transform .12s ease;
}
.btn-save:active { transform: scale(0.98); }
.btn-save.alt {
    background: #fff;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.video-box { background: #000; }
.video-box video { width: 100%; display: block; max-height: 360px; background: #000; }

/* ==================== Gallery ==================== */
.gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 14px 16px 4px;
}
.gallery .item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--card-border);
    background: var(--bg);
    cursor: pointer;
    aspect-ratio: 1 / 1;
    transition: transform .15s ease;
}
.gallery .item:active { transform: scale(0.97); }
.gallery .item img,
.gallery .item video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}
.gallery .item img.broken { opacity: 0.15; }
.gallery .play-badge {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 42px; height: 42px;
    line-height: 42px;
    text-align: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 16px;
    pointer-events: none;
}
.gallery .kind-tag {
    position: absolute;
    left: 6px; top: 6px;
    font-size: 11px;
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

/* ==================== Modal ==================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.modal-body {
    position: relative;
    z-index: 1;
    width: calc(100% - 32px);
    max-width: 440px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    background: var(--bg2);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: pop .18s ease;
}
@keyframes pop {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}
.modal-media {
    flex: 1;
    min-height: 200px;
    max-height: 66vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}
.modal-media img,
.modal-media video {
    max-width: 100%;
    max-height: 66vh;
    display: block;
    object-fit: contain;
}
.modal-actions {
    display: flex;
    gap: 10px;
    padding: 14px 16px;
}
.modal-actions .btn-save { flex: 1; }
.modal-actions button.btn-save { font-family: inherit; }

/* ==================== Utilities ==================== */
.hidden { display: none !important; }

/* ============================================================
   素材浏览器
   ============================================================ */
.material-browser {
    display: flex; flex-direction: column;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    height: calc(100vh - 280px);
    min-height: 400px;
    margin-bottom: 12px;
}
.material-browser.hidden { display: none; }

.mat-topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    background: var(--bg2);
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
}
.mat-close {
    width: 32px; height: 32px;
    border: none; border-radius: 8px;
    background: var(--bg2);
    font-size: 16px; color: var(--text);
    cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.mat-close:hover { background: #fee; color: var(--danger); }
.mat-tabs {
    display: flex; gap: 4px; flex: 1; overflow-x: auto;
    scrollbar-width: none;
}
.mat-tabs::-webkit-scrollbar { display: none; }
.mat-tab {
    padding: 6px 14px; border: none; border-radius: 8px;
    background: transparent; color: var(--muted);
    font-size: 13px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: all .15s;
}
.mat-tab.active {
    background: var(--primary); color: #fff;
}
.mat-open {
    width: 32px; height: 32px;
    border-radius: 8px; background: var(--bg2);
    color: var(--muted); text-decoration: none;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.mat-open:hover { color: var(--primary); background: var(--primary-light); }
.mat-iframe-wrap {
    flex: 1; position: relative; background: #fff;
}
.mat-iframe-wrap iframe {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    border: none;
}

/* ============================================================
   底部导航
   ============================================================ */
.bottom-nav {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 12px; margin: 0;
    background: var(--bg2);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    position: sticky; bottom: 4px; z-index: 50;
}
.bottom-nav::-webkit-scrollbar { display: none; }
.bn-find {
    padding: 10px 18px; border: none; border-radius: 10px;
    background: var(--primary); color: #fff;
    font-size: 14px; font-weight: 600;
    cursor: pointer; white-space: nowrap; flex-shrink: 0;
    transition: all .15s;
}
.bn-find:hover { filter: brightness(1.1); }
.bn-find.active {
    background: var(--danger);
}
.bn-tabs {
    display: flex; gap: 4px;
}
.bn-tab {
    padding: 8px 14px; border: none; border-radius: 8px;
    background: var(--bg2); color: var(--muted);
    font-size: 13px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: all .15s;
}
.bn-tab:hover { color: var(--text); }
.bn-tab.active {
    background: var(--primary); color: #fff;
}

/* 底部安全区 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-nav { margin-bottom: env(safe-area-inset-bottom); }
}

.foot {
    text-align: center;
    font-size: 12px;
    color: var(--muted2);
    padding: 16px;
    opacity: .8;
}

/* ================================================================ */
/*                     LOGIN / AUTH PANEL                            */
/* ================================================================ */
.auth-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-height: 100vh;
    background: linear-gradient(180deg, #fff7ed 0%, #ffffff 40%, #fefce8 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: #ffffff;
    border: 1px solid #fde8d7;
    border-radius: 24px;
    padding: 36px 28px 28px;
    box-shadow: 0 20px 60px rgba(249, 115, 22, 0.08), 0 4px 16px rgba(0, 0, 0, 0.04);
    text-align: center;
}

.auth-card .logo {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--primary);
    margin-bottom: 4px;
}

.auth-sub {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Tab switcher */
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-radius: 12px;
    overflow: hidden;
    background: #f5f5f7;
    padding: 4px;
}
.auth-tab {
    flex: 1;
    border: none;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-radius: 10px;
    transition: all .22s ease;
}
.auth-tab.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* Form */
.auth-form {
    text-align: left;
}
.auth-form .field {
    margin-bottom: 16px;
}
.auth-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}
.auth-form input {
    width: 100%;
    padding: 13px 15px;
    border-radius: 12px;
    border: 1.5px solid #e5e7eb;
    background: #f9fafb;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: all .18s ease;
}
.auth-form input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.08);
}
.auth-form input::placeholder {
    color: #9ca3af;
}

/* Code row */
.code-row {
    display: flex;
    gap: 10px;
}
.code-row input {
    flex: 1;
}
.code-btn {
    flex-shrink: 0;
    border: 1.5px solid var(--primary);
    border-radius: 12px;
    padding: 0 18px;
    font-size: 13px;
    font-weight: 600;
    background: #ffffff;
    color: var(--primary);
    cursor: pointer;
    white-space: nowrap;
    transition: all .18s ease;
}
.code-btn:hover {
    background: var(--primary-light);
}
.code-btn:active {
    background: var(--primary);
    color: #fff;
}
.code-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Auth tip */
.auth-tip {
    margin-top: 14px;
    font-size: 13px;
    text-align: center;
    color: var(--muted);
    min-height: 20px;
}
.auth-tip.error { color: var(--err); }
.auth-tip.success { color: var(--ok); font-weight: 600; }

/* Submit button */
.auth-form .btn-primary {
    margin-top: 6px;
    border-radius: 14px;
    padding: 15px;
    font-size: 16px;
    letter-spacing: 1px;
}

/* ================================================================ */
/*                     USER BAR (top of main page)                   */
/* ================================================================ */
.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px 12px;
}
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-avatar {
    width: 34px; height: 34px;
    line-height: 34px;
    text-align: center;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 18px;
}
.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* Member badge */
.member-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: .5px;
}
.member-badge.vip {
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
}
.member-badge.free {
    background: #f3f4f6;
    color: var(--muted);
}

.logout-btn {
    border: 1.5px solid #e5e7eb;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all .15s ease;
    font-weight: 600;
}
.logout-btn:active {
    background: #f9fafb;
    color: var(--err);
    border-color: var(--err);
}

/* ================================================================ */
/*                     UPGRADE BANNER                                */
/* ================================================================ */
.upgrade-banner {
    background: linear-gradient(135deg, #fff7ed, #fffbeb);
    border: 1px solid #fed7aa;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.upgrade-text {
    font-size: 13px;
    color: #c2410c;
    line-height: 1.5;
    font-weight: 500;
}
.upgrade-btn {
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #f97316, #ea580c);
    cursor: pointer;
    transition: all .15s ease;
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.3);
}
.upgrade-btn:active { transform: scale(0.97); }
