/* ============================================
   WebApp Container v2.0 - Modern UI Styles
   ============================================ */

/* === CSS 变量 === */
:root {
    --bg-primary: #0a0a14;
    --bg-secondary: #12121f;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.4);
    --accent-start: #667eea;
    --accent-end: #764ba2;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success: #4ade80;
    --error: #f87171;
    --warning: #fbbf24;
    --info: #60a5fa;
    --border: rgba(255, 255, 255, 0.08);
    --nav-bg: rgba(10, 10, 20, 0.85);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
}

/* === 全局重置 === */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    overscroll-behavior: none;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(ellipse at 20% 0%, rgba(102, 126, 234, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(118, 75, 162, 0.12) 0%, transparent 50%),
        linear-gradient(180deg, #0f0f1a 0%, #0a0a14 100%);
    z-index: -1;
    pointer-events: none;
}

/* === HOME 页面 === */
#home {
    padding: max(60px, env(safe-area-inset-top)) 20px max(40px, env(safe-area-inset-bottom));
    min-height: 100vh;
    min-height: 100dvh;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    display: flex;
    flex-direction: column;
}

#home.hidden {
    visibility: hidden;
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
    position: fixed;
    inset: 0;
}

.home-header {
    margin-bottom: 32px;
    max-width: 800px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.brand-icon {
    font-size: 32px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px rgba(102, 126, 234, 0.4));
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(102, 126, 234, 0.4)); }
    50% { filter: drop-shadow(0 0 30px rgba(118, 75, 162, 0.6)); }
}

.brand-text {
    background: linear-gradient(135deg, #fff 0%, rgba(255,255,255,0.8) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.3px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.icon-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    transform: rotate(180deg);
}

.icon-btn:active {
    transform: rotate(180deg) scale(0.9);
}

/* === 应用列表 === */
#list-container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
}

#list {
    display: flex;
    flex-wrap: wrap;
    gap: 24px 16px;
    justify-content: flex-start;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 12px 8px 10px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    -webkit-user-drag: none;
    width: calc(25% - 12px);
    min-width: 80px;
    max-width: 100px;
}

.card:active {
    transform: scale(0.92);
}

.card:hover .card-icon-wrap {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.3);
}

.card-icon-wrap {
    position: relative;
    width: 68px;
    height: 68px;
    border-radius: 18px;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(102,126,234,0.2), rgba(118,75,162,0.2));
    box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 10px;
}

.card-icon-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.app-name {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.3;
}

.app-desc {
    color: var(--text-tertiary);
    font-size: 11px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.app-version-tag {
    position: absolute;
    top: 4px;
    right: 0;
    font-size: 9px;
    color: var(--accent-start);
    background: rgba(102, 126, 234, 0.15);
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 600;
    font-family: "SF Mono", "Fira Code", monospace;
    letter-spacing: -0.3px;
}

/* === 骨架屏 === */
.loading-skeleton {
    display: flex;
    flex-wrap: wrap;
    gap: 24px 16px;
}

.skeleton-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    width: calc(25% - 12px);
    min-width: 80px;
    max-width: 100px;
}

.skeleton-icon {
    width: 68px;
    height: 68px;
    border-radius: 18px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    margin-bottom: 10px;
}

.skeleton-name {
    width: 50px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

/* === 空状态 === */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    color: var(--text-tertiary);
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-desc {
    font-size: 14px;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* === 按钮 === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    gap: 8px;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

/* === APP 容器 === */
#app-container {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 100;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

#app-container.visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

/* 悬浮胶囊按钮（仿微信小程序） */
#capsule {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(30, 30, 47, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 34px;
    padding: 4px 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease;
}

#capsule.hidden {
    opacity: 0;
    pointer-events: none;
}

.capsule-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: background 0.2s ease;
}

.capsule-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.capsule-btn:active {
    transform: scale(0.93);
}

.capsule-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 2px;
}

.capsule-title {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
    display: none;
}

.capsule-version {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    font-family: "SF Mono", "Fira Code", monospace;
    padding-right: 8px;
}

/* === iframe 包装（全屏） === */
.frame-wrap {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--bg-primary);
}

#app-frame {
    border: none;
    background: white;
    width: 100%;
    height: 100%;
    position: static;
    left: auto;
    margin-left: 0;
    top: auto;
}

/* === 加载界面 === */
#loading {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(15,15,26,0.98) 0%, rgba(10,10,20,0.99) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 299;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

#loading.visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.loader-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loader-ring {
    position: relative;
    width: 64px;
    height: 64px;
    margin-bottom: 24px;
}

.ring {
    position: absolute;
    border-radius: 50%;
    border: 3px solid transparent;
    animation: loader-spin 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.ring-1 {
    inset: 0;
    border-top-color: var(--accent-start);
    border-right-color: var(--accent-start);
    animation-duration: 1.5s;
    filter: drop-shadow(0 0 10px rgba(102,126,234,0.5));
}

.ring-2 {
    inset: 8px;
    border-bottom-color: var(--accent-end);
    border-left-color: var(--accent-end);
    animation-duration: 1.2s;
    animation-direction: reverse;
    filter: drop-shadow(0 0 10px rgba(118,75,162,0.5));
}

.ring-3 {
    inset: 16px;
    border-top-color: rgba(255,255,255,0.3);
    animation-duration: 2s;
}

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

.loader-text {
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: breathe 2s ease-in-out infinite;
}

.loader-sub {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 6px;
    min-height: 16px;
}

@keyframes breathe {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* === Toast 通知 === */
#toast-container {
    position: fixed;
    top: max(20px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: rgba(30, 30, 45, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    max-width: calc(100vw - 40px);
}

.toast.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.toast-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--error); }
.toast-info .toast-icon { color: var(--info); }

.toast-msg {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === 更新弹窗 === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.visible .modal-card {
    transform: scale(1) translateY(0);
}

.modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(102,126,234,0.15), rgba(118,75,162,0.15));
    color: var(--accent-start);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--text-primary);
}

.modal-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 24px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-actions .btn {
    flex: 1;
    padding: 12px 20px;
}

/* === 响应式适配 === */
@media (min-width: 768px) {
    .card {
        width: calc(16.666% - 17px);
        max-width: 110px;
    }
    
    .skeleton-card {
        width: calc(16.666% - 17px);
        max-width: 110px;
    }
    
    .card-icon-wrap {
        width: 76px;
        height: 76px;
        border-radius: 20px;
    }
    
    .app-name {
        font-size: 14px;
    }
}

@media (max-width: 380px) {
    .card {
        width: calc(33.333% - 11px);
        min-width: 70px;
    }
    
    .skeleton-card {
        width: calc(33.333% - 11px);
        min-width: 70px;
    }
    
    .card-icon-wrap {
        width: 60px;
        height: 60px;
        border-radius: 16px;
    }
    
    .brand {
        font-size: 24px;
    }
}

/* === 深色/浅色模式自动适配（可选） === */
@media (prefers-color-scheme: light) {
    /* 保持深色主题，不做浅色模式 */
}

/* === 滚动条美化 === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* === 选中样式 === */
::selection {
    background: rgba(102, 126, 234, 0.3);
    color: white;
}

/* 隐藏版本号标签 */
.app-version-tag,
.capsule-version {
    display: none !important;
}

/* 底部备案信息 */
.site-footer {
    text-align: center;
    padding: 18px 20px 0px;
    font-size: 12px;
    color: rgba(255,255,255,0.35);
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 0px;
    letter-spacing: 0.3px;
    line-height: 1.8;
}
.site-footer a {
    color: rgba(255,255,255,0.35);
    text-decoration: none;
    transition: color 0.2s;
}
.site-footer a:hover {
    color: rgba(255,255,255,0.65);
}
.site-footer .sep {
    margin: 0 8px;
    color: rgba(255,255,255,0.15);
}
.site-footer img {
    vertical-align: middle;
    margin-right: 4px;
    width: 16px;
    height: 16px;
}

