/* Shared Theme - 统一的 CSS 变量和基础样式 */

/* === CSS Variables === */
:root {
    /* 主色调 */
    --c-primary: #6366f1;
    --c-primary-hover: #4f46e5;
    --c-primary-light: rgba(99, 102, 241, 0.1);
    --c-primary2: #a78bfa;
    
    /* 状态颜色 */
    --c-success: #10b981;
    --c-error: #ef4444;
    --c-warning: #f59e0b;
    
    /* 背景和卡片 */
    --c-bg: #f8f7ff;
    --c-card: rgba(255, 255, 255, 0.72);
    --c-card-hover: #faf9ff;
    
    /* 文本颜色 */
    --c-text: #1e1b2e;
    --c-text2: #6b7280;
    
    /* 边框和输入 */
    --c-border: rgba(255, 255, 255, 0.45);
    --c-input-bg: #f9fafb;
    
    /* 遮罩和徽章 */
    --c-overlay: rgba(0, 0, 0, 0.5);
    --c-badge: #eef2ff;
    
    /* 圆角和阴影 */
    --radius: 12px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(99, 102, 241, 0.08);
    --shadow-lg: 0 8px 32px rgba(99, 102, 241, 0.1);
    
    /* 模糊效果 */
    --blur: 20px;
}

/* === Dark Theme === */
[data-theme="dark"] {
    --c-primary: #818cf8;
    --c-primary-hover: #6366f1;
    --c-primary-light: rgba(129, 140, 248, 0.12);
    --c-primary2: #c4b5fd;
    
    --c-success: #34d399;
    --c-error: #f87171;
    --c-warning: #fbbf24;
    
    --c-bg: #08080f;
    --c-card: rgba(24, 22, 38, 0.72);
    --c-card-hover: #282540;
    
    --c-text: #eae8f2;
    --c-text2: #9ca3af;
    
    --c-border: rgba(255, 255, 255, 0.06);
    --c-input-bg: #161425;
    
    --c-overlay: rgba(0, 0, 0, 0.7);
    --c-badge: #2d2a3e;
    
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* === Base Styles === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'SF Pro Display', 'Segoe UI', 'Microsoft YaHei', system-ui, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    min-height: 100vh;
    min-height: 100dvh;
    transition: background .5s, color .4s;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* === Animated Background === */
.bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-mesh {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 600px 400px at 20% 30%, rgba(99, 102, 241, 0.15), transparent),
        radial-gradient(ellipse 500px 500px at 80% 70%, rgba(167, 139, 250, 0.12), transparent),
        radial-gradient(ellipse 400px 300px at 50% 50%, rgba(16, 185, 129, 0.08), transparent);
    animation: meshShift 25s ease-in-out infinite alternate;
}

@keyframes meshShift {
    0% { background-position: 0% 0%, 100% 100%, 50% 50%; }
    50% { background-position: 30% 20%, 70% 80%, 40% 60%; }
    100% { background-position: 10% 40%, 90% 30%, 60% 40%; }
}

.bg-grain {
    position: absolute;
    inset: 0;
    opacity: .03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 128px;
}

[data-theme="dark"] .bg-mesh {
    background:
        radial-gradient(ellipse 600px 400px at 20% 30%, rgba(99, 102, 241, 0.08), transparent),
        radial-gradient(ellipse 500px 500px at 80% 70%, rgba(167, 139, 250, 0.06), transparent),
        radial-gradient(ellipse 400px 300px at 50% 50%, rgba(16, 185, 129, 0.04), transparent);
}

/* === Page Layout === */
.page {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    padding: 48px 20px calc(40px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* === Animations === */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Common Components === */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--c-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--c-primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--c-primary-light);
    color: var(--c-primary);
}

.btn-secondary:hover {
    background: var(--c-border);
}

.btn-danger {
    background: #fef2f2;
    color: var(--c-error);
}

[data-theme="dark"] .btn-danger {
    background: #2d1a1a;
}

.btn-danger:hover {
    background: #fee2e2;
}

/* Icon Buttons */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--c-text2);
    transition: background .2s, color .2s;
    position: relative;
    cursor: pointer;
    border: none;
    background: none;
}

.icon-btn:hover {
    background: var(--c-primary-light);
    color: var(--c-primary);
}

/* Cards */
.card {
    background: var(--c-card);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: all .3s cubic-bezier(.25, .46, .45, .94);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Toast */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    opacity: 1;
    transition: opacity .3s;
    pointer-events: auto;
    white-space: nowrap;
}

.toast-success {
    background: var(--c-success);
    color: #fff;
}

.toast-error {
    background: var(--c-error);
    color: #fff;
}

.toast-info {
    background: var(--c-primary);
    color: #fff;
}

/* Floating Back Button */
.floating-back {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--c-border);
    background: var(--c-card);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    z-index: 90;
    transition: all .25s;
    color: var(--c-text2);
}

.floating-back:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.2);
    border-color: var(--c-primary);
    color: var(--c-primary);
}

@media(max-width: 480px) {
    .floating-back {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

/* Loading Spinner */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* Theme Toggle Button */
.theme-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--c-card);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    font-size: 18px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all .25s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border: 1px solid var(--c-border);
}

.theme-btn:hover {
    transform: scale(1.1) rotate(20deg);
}

/* Form Elements */
input, textarea, select {
    background: var(--c-input-bg);
    color: var(--c-text);
    border: 2px solid var(--c-border);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 15px;
    width: 100%;
    transition: border-color .2s;
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--c-primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--c-primary-light);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: var(--c-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn .15s ease;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--c-card);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: scaleIn .2s ease;
}

/* Responsive */
@media (prefers-reduced-motion: reduce) {
    .bg-mesh,
    .bg-grain {
        animation: none;
    }
    
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--c-primary);
    color: white;
    padding: 8px 16px;
    z-index: 100;
    transition: top 0.3s;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    font-size: 14px;
}

.skip-link:focus {
    top: 0;
}
