:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --gradient-0: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-1: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-2: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-3: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    --gradient-4: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    --gradient-5: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

body.dark-mode {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.25), 0 2px 4px -2px rgb(0 0 0 / 0.25);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
}

.search-container {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

/* Theme Toggle */
.theme-toggle {
    position: relative;
    width: 50px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.theme-toggle.active {
    background: var(--primary-color);
}

.theme-toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle.active .theme-toggle-slider {
    transform: translateX(26px);
}

/* Filter Bar */
.filter-bar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
}

.filter-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.filter-tag {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    font-size: 0.8125rem;
    background: var(--bg-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.filter-tag:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.filter-tag.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Main Content */
.main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* 列表样式：将卡片网格改为纯文本行列表 */
.games-list {
    display: block;
    margin-top: 1rem;
    list-style: none;
    padding: 0;
}

/* Game Card */
.game-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.game-card:hover {
    background: rgba(0, 0, 0, 0.02);
}

/* 卡片头部已简化，移除占位高度 */
.game-card-header {
    display: none;
}

.game-card-bg {
    width: 100%;
    height: 100%;
    display: block;
    align-items: center;
    justify-content: center;
    color: inherit;
    position: relative;
    overflow: hidden;
    background: transparent !important;
    /* 去掉彩色背景，极简风格 */
}

.game-card-bg::before {
    display: none;
    /* 隐藏装饰性伪元素 */
}

.game-card-bg::after {
    display: none;
    /* 隐藏动画效果 */
}

/* 图标已移除，列表以纯文字展示 */
.game-icon {
    display: none;
}

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

    to {
        transform: rotate(360deg);
    }
}

.game-card-content {
    padding: 0;
    flex: 1;
}

.game-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.game-card-category {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.game-card-tags {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
}

.tag {
    padding: 0.25rem 0.5rem;
    background: var(--bg-color);
    color: var(--text-secondary);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

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

.phone-modal {
    background: var(--card-bg);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    position: relative;
    border: 1px solid var(--border-color);
    /* Default landscape - 1334x750 */
    width: 1334px;
    height: 750px;
    max-width: min(95vw, 1334px);
    max-height: min(90vh, 750px);
}

.phone-modal.portrait {
    /* Portrait - 调整为更窄的竖屏比例 */
    width: 450px;
    height: 800px;
    max-width: min(80vw, 450px);
    max-height: min(90vh, 800px);
}

.modal-overlay.active .phone-modal {
    transform: scale(1) translateY(0);
}

.phone-screen {
    width: 100%;
    height: 100%;
    background: var(--card-bg);
    position: relative;
    display: flex;
    flex-direction: column;
    border-radius: inherit;
    /* 继承父容器的圆角 */
}

.game-toolbar {
    height: 50px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    flex-shrink: 0;
}

.game-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    opacity: 0.7;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
}

.toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
    transform: scale(1.05);
}

.toolbar-btn.close-btn {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
    transition: all 0.2s ease;
}

.toolbar-btn.close-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.3);
    transform: scale(1.05);
}

.toolbar-btn.close-btn:active {
    transform: scale(0.95);
    background: rgba(239, 68, 68, 0.35);
}

/* 深色模式下的关闭按钮 */
body.dark-mode .toolbar-btn.close-btn {
    background: rgba(248, 113, 113, 0.12);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.15);
}

body.dark-mode .toolbar-btn.close-btn:hover {
    background: rgba(248, 113, 113, 0.2);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.25);
}

body.dark-mode .toolbar-btn.close-btn:active {
    background: rgba(248, 113, 113, 0.3);
}

.toolbar-btn.rotate-btn {
    background: rgba(59, 130, 246, 0.15);
    color: #2563eb;
    border: 1px solid rgba(59, 130, 246, 0.2);
    transition: all 0.2s ease;
}

.toolbar-btn.rotate-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    color: #1d4ed8;
    border-color: rgba(59, 130, 246, 0.3);
    transform: scale(1.05);
}

.toolbar-btn.rotate-btn:active {
    transform: scale(0.95);
    background: rgba(59, 130, 246, 0.35);
}

/* 深色模式下的旋转按钮 */
body.dark-mode .toolbar-btn.rotate-btn {
    background: rgba(96, 165, 250, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.15);
}

body.dark-mode .toolbar-btn.rotate-btn:hover {
    background: rgba(96, 165, 250, 0.2);
    color: #93c5fd;
    border-color: rgba(96, 165, 250, 0.25);
}

body.dark-mode .toolbar-btn.rotate-btn:active {
    background: rgba(96, 165, 250, 0.3);
}

.phone-header {
    display: none;
}

.close-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 2px 8px rgba(255, 107, 107, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.close-btn:hover {
    background: linear-gradient(135deg, #ff5252 0%, #e53e3e 100%);
    transform: scale(1.1);
    box-shadow:
        0 4px 12px rgba(255, 107, 107, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.close-btn:active {
    transform: scale(0.95);
}

.close-btn::before,
.close-btn::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 2px;
    background: white;
    border-radius: 1px;
    transform-origin: center;
}

.close-btn::before {
    transform: rotate(45deg);
}

.close-btn::after {
    transform: rotate(-45deg);
}

.game-iframe {
    width: 100%;
    flex: 1;
    border: none;
}

/* Loading States */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    text-align: center;
}

.loading-spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading-text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.loading-hint {
    font-size: 0.875rem;
    opacity: 0.7;
    max-width: 400px;
    line-height: 1.4;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.loading-pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* 改进滚动性能 */
.games-list {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 改进触摸交互 */
.game-card,
.filter-tag,
.toolbar-btn,
.theme-toggle {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

/* 改进过渡效果 */
.game-card,
.filter-tag,
.toolbar-btn,
.theme-toggle,
.btn,
.search-input {
    transition: color 0.3s ease, background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

/* Responsive */
@media (max-width: 1200px) {
    .main {
        padding: 1.5rem;
    }

    .header,
    .filter-bar {
        padding: 1rem 1.5rem;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .search-container {
        order: 1;
        max-width: none;
    }

    .filter-bar {
        padding: 1rem;
    }

    .filter-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .filter-tags {
        width: 100%;
        justify-content: flex-start;
    }

    .main {
        padding: 1rem;
    }

    /* 移动端：列表式展示，紧凑间距 */
    .games-list {
        margin-top: 0.5rem;
    }

    .game-card {
        padding: 0.5rem 0.75rem;
    }

    .game-card-title {
        font-size: 0.95rem;
    }

    /* phone-screen 在移动端应该和 phone-modal 保持一致 */
    .phone-screen {
        width: 100%;
        height: 100%;
    }

    .modal-overlay {
        padding: 0.5rem;
    }

    .phone-modal {
        width: calc(100vw - 1rem);
        height: calc(100dvh - 1rem);
        max-width: none;
        max-height: none;
    }

    /* 移动端不需要 portrait 特殊设置，统一使用响应式布局 */

    /* 移动端隐藏旋转按钮 */
    .toolbar-btn.rotate-btn {
        display: none;
    }

    /* 移动端全屏适配 */
    .phone-modal {
        width: 95vw;
        height: 90vh;
        max-width: none;
        max-height: none;
    }

    /* 根据设备方向自动调整 - 使用动态视口高度 */
    @media (orientation: portrait) {
        .phone-modal {
            width: 95vw;
            height: 85dvh;
            /* 调整为85%，让高度更合适 */
        }
    }

    @media (orientation: landscape) {
        .phone-modal {
            width: 90vw;
            height: 88dvh;
            /* 调整为88%，稍微缩短一点 */
        }
    }

    /* 对不支持dvh的浏览器回退 */
    @supports not (height: 100dvh) {
        @media (orientation: portrait) {
            .phone-modal {
                height: calc(100vh - 6rem);
                /* 调整为6rem，给更多空间 */
            }
        }

        @media (orientation: landscape) {
            .phone-modal {
                height: calc(100vh - 3rem);
                /* 调整为3rem */
            }
        }
    }

    /* 移动端工具栏优化 */
    .game-toolbar {
        height: 44px;
        padding: 0 0.75rem;
    }

    .game-title {
        font-size: 0.8rem;
    }

    .toolbar-btn.close-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* iOS Safari 安全区域适配 */
    @supports (padding: max(0px)) {
        .modal-overlay {
            padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
        }

        .phone-modal {
            width: calc(100vw - max(1rem, env(safe-area-inset-left)) - max(1rem, env(safe-area-inset-right)));
            height: calc(85dvh - max(1rem, env(safe-area-inset-top)) - max(1rem, env(safe-area-inset-bottom)));
            /* 与上面的85dvh保持一致 */
        }

        @media (orientation: landscape) {
            .phone-modal {
                height: calc(88dvh - max(0.5rem, env(safe-area-inset-top)) - max(0.5rem, env(safe-area-inset-bottom)));
                /* 与上面的88dvh保持一致 */
            }
        }
    }

    /* 移动端统一尺寸，不需要 portrait 特殊处理 */

    /* 针对小屏幕设备进一步优化 */
    @media (max-height: 600px) {
        .phone-modal {
            height: calc(100dvh - 0.5rem) !important;
        }

        .modal-overlay {
            padding: 0.25rem !important;
        }
    }

    /* 对于非常小的屏幕，使用更激进的优化 */
    @media (max-height: 500px) {
        .phone-modal {
            height: 100dvh !important;
            border-radius: 0 !important;
        }

        .modal-overlay {
            padding: 0 !important;
        }
    }
}