/* 2048 游戏样式表 - 2048 Styles */

/* CSS 变量定义 - 支持主题切换 */
:root {
    /* 浅色主题 */
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --container-bg: white;
    --container-shadow: 0 10px 40px rgba(0,0,0,0.2);
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #888;
    --text-light: rgba(255,255,255,0.9);
    --border-color: #333;
    --primary-color: #667eea;
    --primary-hover: #5568d3;
    --success-color: #48bb78;
    --warning-color: #ed8936;
    --danger-color: #ff6b6b;
    --overlay-bg: rgba(0,0,0,0.5);

    /* 2048 游戏板颜色 */
    --board-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.35);
    --cell-text: #776e65;

    /* 数字方块颜色 */
    --tile-2: #eee4da;
    --tile-4: #ede0c8;
    --tile-8: #f2b179;
    --tile-16: #f59563;
    --tile-32: #f67c5f;
    --tile-64: #f65e3b;
    --tile-128: #edcf72;
    --tile-256: #edcc61;
    --tile-512: #edc850;
    --tile-1024: #edc53f;
    --tile-2048: #edc22e;
    --tile-super: #3c3a32;
}

/* 深色主题 */
[data-theme="dark"] {
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --container-bg: #2d3748;
    --container-shadow: 0 10px 40px rgba(0,0,0,0.5);
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #4a5568;
    --primary-color: #667eea;
    --primary-hover: #5a67d8;
    --overlay-bg: rgba(0,0,0,0.8);

    --board-bg: #4a4a5a;
    --cell-bg: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    transition: background 0.3s ease;
}

h1 {
    color: white;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 36px;
}

.back-btn {
    position: absolute;
    left: 20px;
    top: 20px;
    padding: 10px 20px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    transition: all 0.3s;
}

.back-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateX(-3px);
}

/* 顶部控制按钮 */
.top-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 100;
}

.control-btn {
    padding: 10px 15px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
}

.control-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

.control-btn.muted {
    opacity: 0.6;
}

/* 游戏容器 */
.game-container {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--container-shadow);
    max-width: 500px;
    width: 100%;
    transition: all 0.3s ease;
}

/* 分数区域 */
.score-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
}

.score-box {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    padding: 15px 25px;
    border-radius: 12px;
    min-width: 100px;
    text-align: center;
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.score-label {
    font-size: 12px;
    text-transform: uppercase;
    opacity: 0.9;
    margin-bottom: 5px;
}

.score-value {
    font-size: 24px;
    font-weight: bold;
}

/* 游戏板 */
.game-board {
    background: var(--board-bg);
    border-radius: 10px;
    padding: 10px;
    position: relative;
    margin: 0 auto 25px;
    width: fit-content;
    touch-action: none;
    overflow: hidden;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 80px);
    grid-template-rows: repeat(4, 80px);
    gap: 10px;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 5px;
    width: 80px;
    height: 80px;
}

/* 数字方块容器 */
#tile-container {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 350px;
    height: 350px;
    pointer-events: none;
}

/* 数字方块样式 */
.tile {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    font-weight: bold;
    transition: all 0.15s ease;
    animation: appear 0.2s ease;
}

@keyframes appear {
    0% { opacity: 0; transform: scale(0); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.tile.merged {
    animation: pop 0.2s ease;
}

/* 数字颜色 */
.tile-2 { background: var(--tile-2); color: #776e65; }
.tile-4 { background: var(--tile-4); color: #776e65; }
.tile-8 { background: var(--tile-8); color: #f9f6f2; }
.tile-16 { background: var(--tile-16); color: #f9f6f2; }
.tile-32 { background: var(--tile-32); color: #f9f6f2; }
.tile-64 { background: var(--tile-64); color: #f9f6f2; }
.tile-128 { background: var(--tile-128); color: #f9f6f2; font-size: 24px; box-shadow: 0 0 10px rgba(243, 215, 116, 0.3); }
.tile-256 { background: var(--tile-256); color: #f9f6f2; font-size: 24px; box-shadow: 0 0 10px rgba(243, 215, 116, 0.4); }
.tile-512 { background: var(--tile-512); color: #f9f6f2; font-size: 24px; box-shadow: 0 0 10px rgba(243, 215, 116, 0.5); }
.tile-1024 { background: var(--tile-1024); color: #f9f6f2; font-size: 20px; box-shadow: 0 0 15px rgba(243, 215, 116, 0.6); }
.tile-2048 { background: var(--tile-2048); color: #f9f6f2; font-size: 20px; box-shadow: 0 0 20px rgba(237, 194, 46, 0.7); }
.tile-super { background: var(--tile-super); color: #f9f6f2; font-size: 18px; }

/* 控制按钮 */
.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

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

/* 操作说明 */
.help-text {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.8;
}

.help-text kbd {
    background: rgba(102, 126, 234, 0.1);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--primary-color);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

/* 移动端控制按钮 */
.mobile-controls {
    display: none;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

/* 覆盖层和消息 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay.show {
    display: flex;
}

.message {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: none;
}

.message.show {
    display: block;
    animation: fadeInUp 0.3s ease;
}

.message h2 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 28px;
}

.message p {
    color: var(--text-secondary);
    margin-bottom: 25px;
    line-height: 1.6;
    white-space: pre-line;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 游戏结束和胜利覆盖层 */
.game-over-overlay, .win-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    z-index: 100;
}

.game-over-overlay.show, .win-overlay.show {
    display: flex;
}

.game-over-overlay h2 {
    color: #ff6b6b;
    font-size: 36px;
    margin-bottom: 20px;
}

.win-overlay h2 {
    color: #edc22e;
    font-size: 36px;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(237, 194, 46, 0.5);
}

.win-overlay p {
    color: white;
    margin-bottom: 20px;
}

/* 统计面板 */
.stats-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--container-bg);
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: none;
    z-index: 1001;
}

.stats-panel.show {
    display: block;
    animation: fadeInUp 0.3s ease;
}

.stats-panel h2 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: rgba(102, 126, 234, 0.1);
    padding: 15px;
    border-radius: 12px;
    text-align: center;
}

.stat-card h3 {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.stat-card .value {
    color: var(--primary-color);
    font-size: 24px;
    font-weight: bold;
}

/* 排行榜 */
.leaderboard {
    background: rgba(102, 126, 234, 0.05);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
}

.leaderboard h3 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 15px;
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard th,
.leaderboard td {
    padding: 10px;
    text-align: center;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
}

.leaderboard th {
    font-weight: bold;
    color: var(--text-primary);
}

/* 网易新闻伪装暂停页面 */
.news-masquerade {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f5;
    display: none;
    flex-direction: column;
    z-index: 999;
}

.news-masquerade.show {
    display: flex;
}

.news-header {
    height: 50px;
    background: #c52e26;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    flex-shrink: 0;
}

.news-logo {
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 2px;
}

.news-nav {
    display: flex;
    gap: 20px;
    flex: 1;
}

.news-nav span {
    font-size: 14px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 3px;
    transition: background 0.2s;
}

.news-nav span:hover {
    background: rgba(255,255,255,0.2);
}

.back-to-game {
    background: white;
    color: #c52e26;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
}

.back-to-game:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
}

.news-iframe-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#news-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Excel 伪装暂停页面 */
.excel-masquerade {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f5;
    display: none;
    flex-direction: column;
    z-index: 999;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

.excel-masquerade.show {
    display: flex;
}

/* Excel 标题栏 */
.excel-header {
    background: #217346;
    color: white;
    flex-shrink: 0;
}

.excel-title-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 12px;
    -webkit-app-region: drag;
}

.excel-icon {
    font-size: 20px;
}

.excel-filename {
    flex: 1;
    font-size: 14px;
    opacity: 0.95;
}

.excel-window-controls {
    display: flex;
    gap: 16px;
    font-size: 14px;
}

.excel-window-controls span {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.excel-window-controls span:hover {
    background: rgba(255,255,255,0.2);
}

/* Excel 工具栏 */
.excel-toolbar {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    background: #f3f2f1;
    border-bottom: 1px solid #d1d1d1;
}

.excel-menu-item {
    padding: 6px 14px;
    color: #333;
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.excel-menu-item:hover {
    background: #e1e1e1;
}

/* Excel 公式栏 */
.excel-formula-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: white;
    border-bottom: 1px solid #d1d1d1;
    gap: 12px;
}

.excel-name-box {
    width: 60px;
    padding: 6px 10px;
    background: #f3f2f1;
    border: 1px solid #d1d1d1;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    text-align: center;
}

.excel-formula-input {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid #d1d1d1;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    background: white;
}

/* Excel 内容区 */
.excel-content {
    flex: 1;
    overflow: auto;
    background: white;
    display: flex;
    flex-direction: column;
}

.excel-row-header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
}

.excel-corner {
    width: 50px;
    height: 24px;
    background: #f3f2f1;
    border-right: 1px solid #d1d1d1;
    border-bottom: 1px solid #d1d1d1;
    flex-shrink: 0;
}

.excel-col-headers {
    display: flex;
    flex: 1;
}

.excel-col-headers div {
    width: 80px;
    height: 24px;
    background: #f3f2f1;
    border-right: 1px solid #d1d1d1;
    border-bottom: 1px solid #d1d1d1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
    flex-shrink: 0;
}

.excel-grid-container {
    display: flex;
    flex: 1;
}

.excel-row-numbers {
    width: 50px;
    flex-shrink: 0;
}

.excel-row-numbers div {
    height: 24px;
    background: #f3f2f1;
    border-right: 1px solid #d1d1d1;
    border-bottom: 1px solid #d1d1d1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
}

.excel-cells {
    display: flex;
    flex-direction: column;
}

.excel-cell-row {
    display: flex;
}

.excel-cell {
    width: 80px;
    height: 24px;
    border-right: 1px solid #e1e1e1;
    border-bottom: 1px solid #e1e1e1;
    display: flex;
    align-items: center;
    padding: 0 6px;
    font-size: 12px;
    color: #333;
    background: white;
    flex-shrink: 0;
}

.excel-cell.selected {
    background: #e8f0e8;
    border: 2px solid #217346;
    margin: -1px;
    z-index: 5;
}

/* Excel 状态栏 */
.excel-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    background: #217346;
    color: white;
    font-size: 12px;
    flex-shrink: 0;
}

.excel-status-right {
    display: flex;
    gap: 20px;
}

.excel-status-right span {
    cursor: pointer;
}

/* Excel 返回按钮 */
.excel-back-btn {
    position: absolute;
    top: 100px;
    right: 20px;
    background: #217346;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 1000;
    transition: all 0.2s;
}

.excel-back-btn:hover {
    background: #1e6b40;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.pause-hint {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    background: rgba(0,0,0,0.5);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
}

/* 移动端透明暂停按钮 */
.mobile-pause-btn {
    display: none;
    position: fixed;
    top: 50px;
    right: 10px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    backdrop-filter: blur(4px);
}

.mobile-pause-btn:active {
    background: rgba(255, 255, 255, 0.5);
}

/* 响应式设计 */
@media (max-width: 600px) {
    /* 显示移动端暂停按钮 */
    .mobile-pause-btn { display: flex; align-items: center; justify-content: center; }

    /* 增强返回游戏按钮 */
    .back-to-game {
        padding: 12px 20px !important;
        font-size: 16px !important;
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        z-index: 99999 !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
    }

    .excel-back-btn {
        bottom: 80px !important;
    }

    body {
        padding: 8px;
    }

    h1 {
        font-size: 22px;
        margin-top: 45px;
        margin-bottom: 8px;
    }

    .back-btn {
        top: 8px;
        left: 8px;
        padding: 5px 10px;
        font-size: 11px;
    }

    .top-controls {
        top: 8px;
        right: 8px;
        gap: 5px;
    }

    .control-btn {
        padding: 5px 8px;
        font-size: 13px;
    }

    .game-container {
        padding: 8px;
    }

    /* 分数显示 - 紧凑横向布局 */
    .score-container {
        display: flex;
        justify-content: center;
        gap: 8px;
        margin-bottom: 10px;
    }

    .score-box {
        padding: 5px 12px;
        min-width: 55px;
        border-radius: 6px;
    }

    .score-label {
        font-size: 9px;
        margin-bottom: 1px;
    }

    .score-value {
        font-size: 14px;
    }

    /* 游戏板 - 增大尺寸，减少边框 */
    .game-board {
        padding: 4px;
        margin-bottom: 10px;
    }

    .grid-container {
        grid-template-columns: repeat(4, 80px);
        grid-template-rows: repeat(4, 80px);
        gap: 3px;
    }

    .grid-cell {
        width: 80px;
        height: 80px;
        border-radius: 3px;
    }

    #tile-container {
        width: 332px;  /* 4*80 + 3*3 = 320 + 9 = 332 */
        height: 332px;
    }

    .tile {
        width: 80px;
        height: 80px;
        font-size: 28px;
        border-radius: 3px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 22px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 18px;
    }

    .tile-super {
        font-size: 14px;
    }

    /* 隐藏虚拟方向按钮 */
    .mobile-controls {
        display: none !important;
    }

    /* 控制按钮 - 紧凑 */
    .controls {
        gap: 6px;
        margin-bottom: 8px;
    }

    .btn {
        padding: 6px 14px;
        font-size: 12px;
        border-radius: 18px;
    }

    .help-text {
        font-size: 10px;
        display: none;
    }
}

@media (max-width: 400px) {
    .grid-container {
        grid-template-columns: repeat(4, 72px);
        grid-template-rows: repeat(4, 72px);
        gap: 3px;
    }

    .grid-cell {
        width: 72px;
        height: 72px;
    }

    #tile-container {
        width: 300px;  /* 4*72 + 3*3 = 288 + 9 = 300 */
        height: 300px;
    }

    .tile {
        width: 72px;
        height: 72px;
        font-size: 24px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 18px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 15px;
    }

    .tile-super {
        font-size: 12px;
    }

    /* 分数更紧凑 */
    .score-box {
        padding: 4px 10px;
        min-width: 48px;
    }

    .score-label {
        font-size: 8px;
    }

    .score-value {
        font-size: 12px;
    }
}
