/* ===== 基础重置与变量 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --background: #0f172a;
    --foreground: #e2e8f0;
    --card: #1e293b;
    --card-foreground: #e2e8f0;
    --border: #334155;
    --muted: #475569;
    --muted-foreground: #94a3b8;
    --primary: #60a5fa;
    --accent: #8b5cf6;
    --destructive: #ef4444;
    --emerald: #10b981;
    --amber: #f59e0b;
    --rose: #f43f5e;
    
    /* 移动端安全区域 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background: var(--background);
    color: var(--foreground);
    font-family: 'Noto Serif SC', serif;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== 星空背景 ===== */
.stars-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle 3s ease-in-out infinite;
    will-change: opacity, transform;
}

.star-bright {
    background: linear-gradient(135deg, #e0f7ff 0%, #a8d8ff 100%);
    box-shadow: 0 0 6px 2px rgba(168, 216, 255, 0.5);
}

@keyframes twinkle {
    0%, 100% { 
        opacity: 0.3; 
        transform: scale(0.8);
    }
    50% { 
        opacity: 1; 
        transform: scale(1.2);
    }
}

/* ===== 风动线条 ===== */
.wind-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.wind-line {
    position: absolute;
    height: 1px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(125, 211, 252, 0.4) 20%, 
        rgba(125, 211, 252, 0.6) 50%, 
        rgba(125, 211, 252, 0.4) 80%, 
        transparent 100%);
    border-radius: 1px;
    animation: wind-sweep 8s linear infinite;
    will-change: transform, opacity;
}

@keyframes wind-sweep {
    0% { 
        transform: translateX(-100%) scaleX(0);
        opacity: 0;
    }
    10% { opacity: 0.6; }
    50% {
        transform: translateX(50%) scaleX(1);
        opacity: 0.3;
    }
    90% { opacity: 0.6; }
    100% { 
        transform: translateX(200%) scaleX(0);
        opacity: 0;
    }
}

/* ===== 月亮组件 ===== */
.moon-container {
    position: fixed;
    top: clamp(20px, 8vh, 60px);
    right: clamp(16px, 5vw, 80px);
    z-index: 1;
    max-width: min(30vw, 120px);
    max-height: min(30vw, 120px);
}

.orbit-star {
    position: absolute;
    top: 50%;
    left: 50%;
    width: clamp(4px, 1.5vw, 8px);
    height: clamp(4px, 1.5vw, 8px);
    background: radial-gradient(circle, #fff 0%, #e0f7ff 100%);
    border-radius: 50%;
    box-shadow: 0 0 4px 1px rgba(255, 255, 255, 0.5);
    animation: orbit-star-orbit var(--orbit-duration) linear infinite, twinkle 3s ease-in-out infinite;
    animation-delay: var(--orbit-delay), 0s;
    will-change: transform;
}

@keyframes orbit-star-orbit {
    0% {
        transform: translate(-50%, -50%) rotate(var(--orbit-angle)) translateX(var(--orbit-radius)) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(calc(var(--orbit-angle) + 360deg)) translateX(var(--orbit-radius)) rotate(-360deg);
    }
}

.moon {
    width: clamp(80px, 25vw, 120px);
    height: clamp(80px, 25vw, 120px);
    position: relative;
    border-radius: 50%;
    background: linear-gradient(135deg, #fff8e7 0%, #f5e6c8 50%, #e8d4a8 100%);
    animation: moon-glow 4s ease-in-out infinite, moon-pulse 6s ease-in-out infinite, moon-rotate 60s linear infinite;
    will-change: transform, box-shadow;
}

.moon::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 15%;
    width: 20%;
    height: 20%;
    border-radius: 50%;
    background: rgba(200, 180, 140, 0.3);
}

.moon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 60%;
    width: 15%;
    height: 15%;
    border-radius: 50%;
    background: rgba(200, 180, 140, 0.2);
}

@keyframes moon-glow {
    0%, 100% { 
        box-shadow: 0 0 40px 10px rgba(255, 220, 130, 0.3),
                    0 0 80px 20px rgba(255, 220, 130, 0.15);
    }
    50% { 
        box-shadow: 0 0 50px 15px rgba(255, 220, 130, 0.4),
                    0 0 100px 30px rgba(255, 220, 130, 0.2);
    }
}

@keyframes moon-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes moon-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== 极光背景 ===== */
.aurora {
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(6, 182, 212, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 60%);
    pointer-events: none;
    animation: aurora-pulse 8s ease-in-out infinite alternate;
    will-change: opacity, transform;
}

@keyframes aurora-pulse {
    0% {
        opacity: 0.6;
        transform: scale(1);
    }
    100% {
        opacity: 1;
        transform: scale(1.05);
    }
}

/* ===== 玻璃卡片 ===== */
.glass-card {
    background: linear-gradient(135deg, 
        rgba(30, 41, 59, 0.7) 0%, 
        rgba(15, 23, 42, 0.5) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(51, 65, 85, 0.3);
    box-shadow: 
        0 8px 32px rgba(15, 23, 42, 0.4),
        inset 0 1px 0 rgba(71, 85, 105, 0.2);
    transition: all 0.3s ease;
    border-radius: clamp(8px, 2vw, 12px);
}

.glass-card:hover {
    border-color: rgba(51, 65, 85, 0.5);
    box-shadow: 
        0 12px 40px rgba(15, 23, 42, 0.5),
        inset 0 1px 0 rgba(100, 116, 139, 0.3);
}

@media (hover: none) {
    .glass-card:hover {
        transform: none;
        border-color: rgba(51, 65, 85, 0.3);
        box-shadow: 0 8px 32px rgba(15, 23, 42, 0.4);
    }
    
    .glass-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* ===== 渐变文字 ===== */
.gradient-text {
    background: linear-gradient(135deg, 
        #7dd3fc 0%, 
        #a78bfa 50%,
        #67e8f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    padding-bottom: 0.1em;
}

/* ===== 节点卡片 ===== */
.node-card {
    position: relative;
    border-radius: clamp(8px, 2vw, 12px);
    padding: clamp(12px, 3vw, 16px);
    transition: all 0.5s ease;
}

.node-card:hover {
    transform: scale(1.02);
}

.node-card.best-node {
    outline: 1px solid rgba(16, 185, 129, 0.5);
    outline-offset: 2px;
}

@media (hover: none) {
    .node-card:hover {
        transform: none;
    }
}

.best-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    padding: 2px 8px;
    background: linear-gradient(to right, #10b981, #14b8a6);
    border-radius: 9999px;
    font-size: clamp(10px, 3vw, 12px);
    font-weight: 500;
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    white-space: nowrap;
    z-index: 10;
}

/* ===== 状态图标 ===== */
.status-icon {
    width: clamp(32px, 10vw, 40px);
    height: clamp(32px, 10vw, 40px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.status-available {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    animation: status-pulse 2s ease-in-out infinite;
}

.status-unavailable {
    background: rgba(244, 63, 94, 0.15);
    color: #f43f5e;
}

@keyframes status-pulse {
    0%, 100% { 
        box-shadow: 0 0 0 0 currentColor;
    }
    50% { 
        box-shadow: 0 0 0 8px transparent;
    }
}

@media (prefers-reduced-motion: reduce) {
    .status-available {
        animation: none;
        box-shadow: 0 0 0 2px currentColor;
    }
}

.status-badge {
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: clamp(10px, 3vw, 12px);
    font-weight: 500;
}

.status-badge.available {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.status-badge.unavailable {
    background: rgba(244, 63, 94, 0.1);
    color: #f43f5e;
}

.time-emerald { color: #10b981; }
.time-amber { color: #f59e0b; }
.time-rose { color: #f43f5e; }

/* ===== 进度条 ===== */
.progress-bar {
    margin-top: 12px;
    height: clamp(3px, 1vw, 4px);
    background: rgba(51, 65, 85, 0.5);
    border-radius: 9999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 9999px;
    transition: all 1s ease;
    will-change: width;
}

.progress-emerald {
    background: linear-gradient(to right, #10b981, #2dd4bf);
}

.progress-amber {
    background: linear-gradient(to right, #f59e0b, #fb923c);
}

.progress-rose {
    background: linear-gradient(to right, #f43f5e, #f472b6);
}

.progress-error {
    background: rgba(244, 63, 94, 0.3);
}

/* ===== 加载 shimmer ===== */
.loading-shimmer {
    background: linear-gradient(90deg,
        rgba(30, 41, 59, 0.5) 0%,
        rgba(51, 65, 85, 0.7) 50%,
        rgba(30, 41, 59, 0.5) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    will-change: background-position;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ===== 旋转动画 ===== */
.animate-spin {
    animation: spin 1s linear infinite;
    will-change: transform;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== 自定义滚动条 ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #0f172a;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

@media (pointer: coarse) {
    ::-webkit-scrollbar {
        width: 0px;
        height: 0px;
    }
    
    body {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
}

/* ===== 模式按钮 ===== */
.mode-btn {
    transition: all 0.2s ease;
    border: 1px solid transparent;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mode-btn:hover {
    opacity: 0.8;
}

.mode-btn.active {
    background: rgba(6, 182, 212, 0.2);
    color: #67e8f9;
    border: 1px solid rgba(6, 182, 212, 0.3);
}

/* ===== 下载按钮 ===== */
.download-btn {
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.12) 0%, 
        rgba(147, 197, 253, 0.18) 100%);
    border-radius: 16px;
    border: 1px solid rgba(147, 197, 253, 0.25);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: min(65%, 280px);
    max-width: 280px;
    justify-content: center;
    box-shadow: 
        0 8px 32px rgba(59, 130, 246, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    min-height: 48px;
    padding: 12px 24px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    touch-action: manipulation;
}

.download-btn svg {
    stroke: url(#btnGradient);
    flex-shrink: 0;
}

.download-btn-text {
    background: linear-gradient(135deg, #7dd3fc 0%, #a78bfa 50%, #67e8f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: clamp(14px, 4vw, 16px);
    white-space: nowrap;
}

.download-btn:hover {
    transform: scale(1.05);
    box-shadow: 
        0 12px 40px rgba(59, 130, 246, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.download-btn:active {
    transform: scale(0.98);
}

@media (hover: none) {
    .download-btn:hover {
        transform: none;
    }
    
    .download-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* ===== 移动端断点优化 ===== */
@media (max-width: 640px) {
    .download-btn {
        width: min(85%, 280px);
        padding: 14px 20px;
    }
    
    .moon-container {
        top: 16px;
        right: 16px;
        opacity: 0.8;
    }
    
    .moon {
        width: 60px;
        height: 60px;
    }
    
    .orbit-star {
        display: none;
    }
    
    .glass-card {
        margin-left: 16px;
        margin-right: 16px;
    }
    
    .node-card {
        padding: 12px;
    }
    
    .best-badge {
        font-size: 10px;
        padding: 2px 6px;
        top: -6px;
        right: -6px;
    }
}

@media (max-width: 380px) {
    .moon-container {
        top: 12px;
        right: 12px;
    }
    
    .moon {
        width: 48px;
        height: 48px;
    }
    
    .download-btn {
        width: 90%;
        min-height: 44px;
    }
    
    .status-icon {
        width: 28px;
        height: 28px;
    }
}

/* ===== 无障碍：减少动画 ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .star,
    .wind-line,
    .orbit-star,
    .moon,
    .aurora,
    .loading-shimmer {
        animation: none !important;
    }
    
    .moon {
        box-shadow: 0 0 30px 5px rgba(255, 220, 130, 0.3);
    }
    
    .status-available {
        animation: none;
        box-shadow: 0 0 0 2px currentColor;
    }
}

/* ===== 横屏模式优化 ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .moon-container {
        top: 12px;
        right: 12px;
    }
    
    .moon {
        width: 50px;
        height: 50px;
    }
    
    .orbit-star {
        display: none;
    }
}

/* ===== 深色模式支持 ===== */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ===== 高对比度模式支持 ===== */
@media (prefers-contrast: high) {
    .glass-card {
        border-width: 2px;
        border-color: rgba(255, 255, 255, 0.5);
    }
    
    .status-badge.available,
    .status-badge.unavailable {
        border: 1px solid currentColor;
    }
    
    .node-card.best-node {
        outline-width: 2px;
        outline-color: #10b981;
    }
}