/* =============================================
   XinLuo 小游戏 - 样式表 (v0.6.1 - 回退稳定版)
   简洁线框风格 / 移动端优先
   ============================================= */

/* ========== 基础 ========== */
.games-body {
    min-height: 100vh;
    background: var(--bg-body);
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overscroll-behavior: none;
    touch-action: manipulation;
}

/* ========== 小游戏主页 ========== */
.games-hub {
    padding: 100px 0 60px;
    background: var(--section-alt-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 28px;
    max-width: 960px;
    margin: 0 auto;
}

/* 简洁线框卡片 */
.game-card {
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 16px;
    padding: 40px 28px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.game-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
}

.game-card:active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.game-card-icon {
    font-size: 56px;
    margin-bottom: 16px;
    line-height: 1;
}

.game-card h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.game-card p {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.game-card-footer {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* 简洁标签 */
.game-tag {
    display: inline-block;
    padding: 4px 14px;
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

/* ========== 全屏游戏容器 ========== */
.game-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ========== 顶部栏 ========== */
.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    height: 44px;
    gap: 6px;
}

/* 返回按钮 */
.game-back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: transparent;
    border: 1.5px solid var(--border-card);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    white-space: nowrap;
    min-height: 36px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.game-back-btn:hover,
.game-back-btn:active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.game-topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 暂停按钮 */
.game-pause-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1.5px solid var(--border-card);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.game-pause-btn:hover,
.game-pause-btn:active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.game-pause-btn .icon-play { display: none; }
.game-pause-btn.paused .icon-pause { display: none; }
.game-pause-btn.paused .icon-play { display: block; }

/* 标题 */
.game-title-bar {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 分数条 */
.game-score-bar {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    min-width: 60px;
    text-align: right;
}

/* ========== 游戏区域 ========== */
.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: var(--bg-body);
    padding: 8px;
    touch-action: none;
}

/* ========== 覆盖层（开始/暂停/结束面板） ========== */
.game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10;
    touch-action: none;
}

.game-overlay.hidden { display: none; }

/* 简洁线框面板 */
.game-start-panel {
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 16px;
    padding: 28px 32px;
    text-align: center;
    max-width: 340px;
    animation: fadeInUp 0.3s ease;
    margin: 12px;
    user-select: none;
    -webkit-user-select: none;
}

.game-start-panel h2 {
    font-size: 22px;
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 700;
}

.game-start-panel p {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 4px;
    line-height: 1.6;
}

.game-start-panel .btn { margin-top: 14px; }

/* ========== 难度/地图选择器 ========== */
.difficulty-selector,
.map-size-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 12px 0 4px;
    flex-wrap: wrap;
}

.difficulty-selector label,
.map-size-selector label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    width: 100%;
    text-align: center;
    margin-bottom: 2px;
}

/* 简洁线框按钮 */
.diff-btn {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    border: 1.5px solid var(--border-input);
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    min-width: 48px;
    min-height: 32px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.diff-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.diff-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ========== 恐龙游戏画布 ========== */
#dino-canvas {
    display: block;
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    max-width: 100%;
    touch-action: none;
}

/* ========== 俄罗斯方块 ========== */
.tetris-layout {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: center;
}

#tetris-canvas {
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    max-width: 100%;
    touch-action: none;
}

.tetris-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 100px;
}

.tetris-sidebar h4 {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.tetris-sidebar > div {
    background: var(--bg-card);
    border: 1.5px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 10px;
    text-align: center;
}

#tetris-score, #tetris-level {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

#tetris-next {
    display: block;
    margin: 0 auto;
    background: var(--bg-surface);
    border-radius: 6px;
}

/* ========== 贪吃蛇 ========== */
.snake-layout {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: center;
}

#snake-canvas {
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    max-width: 100%;
    touch-action: none;
}

.snake-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 100px;
}

.snake-sidebar h4 {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.snake-sidebar > div {
    background: var(--bg-card);
    border: 1.5px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 10px;
    text-align: center;
}

#snake-score, #snake-length {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

/* ========== 2048 ========== */
.game2048-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.game2048-info {
    display: flex;
    gap: 16px;
    align-items: center;
}

.game2048-score-box {
    background: var(--bg-card);
    border: 1.5px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 16px;
    text-align: center;
    min-width: 80px;
}

.game2048-score-box h4 {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 2px;
}

.game2048-score-box div {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

.game2048-board-wrap {
    padding: 6px;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
}

#game2048-canvas {
    display: block;
    border-radius: 8px;
    touch-action: none;
}

/* ========== 扫雷 ========== */
.minesweeper-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.minesweeper-info {
    display: flex;
    gap: 16px;
    align-items: center;
}

.ms-info-box {
    background: var(--bg-card);
    border: 1.5px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 16px;
    text-align: center;
    min-width: 80px;
}

.ms-info-box h4 {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 2px;
}

.ms-info-box div {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

.minesweeper-board-wrap {
    padding: 6px;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
}

#minesweeper-canvas {
    display: block;
    border-radius: 8px;
    touch-action: none;
}

/* ========== 五子棋 ========== */
.gomoku-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.gomoku-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.gomoku-turn {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    transition: color 0.3s;
}

.gomoku-score {
    display: flex;
    gap: 16px;
    font-size: 14px;
    color: var(--text-muted);
}

.gomoku-score b {
    color: var(--primary);
    font-weight: 700;
    margin-left: 2px;
}

.gomoku-board-wrap {
    padding: 6px;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
}

#gomoku-canvas {
    display: block;
    border-radius: 8px;
    touch-action: none;
}

/* ========== 游戏结束信息 ========== */
.game-over-msg {
    font-size: 26px;
    font-weight: 900;
    color: #ef4444;
    margin-bottom: 4px;
}

.game-final-score {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* ========== 退出确认弹窗 ========== */
#exit-confirm-overlay {
    animation: fadeIn 0.2s ease;
}

#exit-confirm-overlay .game-start-panel {
    animation: fadeInUp 0.3s ease;
}

#exit-cancel:hover {
    border-color: var(--text-muted) !important;
    color: var(--text-primary) !important;
}

#exit-confirm:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* ========== 虚拟 D-pad（移动端十字键） ========== */
.dpad-container {
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 2100;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.dpad-container.show {
    opacity: 1;
    pointer-events: auto;
}

.dpad-cluster {
    position: relative;
    width: 144px;
    height: 144px;
    margin-bottom: 10px;
}

/* D-pad 按钮 - 只变色不移动 */
.dpad-btn {
    position: absolute;
    width: 46px;
    height: 46px;
    border: 2px solid var(--border-card);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.1s, border-color 0.1s, color 0.1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    padding: 0;
    transform: none !important;
}

/* 激活状态：只变蓝色，不缩放不位移 */
.dpad-btn:active,
.dpad-btn.active {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
    transform: none !important;
}

.dpad-up    { top: 0;    left: 50%; margin-left: -23px; }
.dpad-down  { bottom: 0; left: 50%; margin-left: -23px; }
.dpad-left  { left: 0;    top: 50%; margin-top: -23px; }
.dpad-right { right: 0;   top: 50%; margin-top: -23px; }

.dpad-center {
    top: 50%; left: 50%;
    margin: -20px 0 0 -20px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-subtle);
    cursor: default;
}

/* 动作按钮 */
.dpad-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2.5px solid var(--primary);
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
    cursor: pointer;
    transition: background-color 0.1s, color 0.1s, border-color 0.1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    padding: 0;
    margin-left: 36px;
    transform: none !important;
}

.dpad-action-btn:active,
.dpad-action-btn.active {
    background: var(--primary) !important;
    color: #fff !important;
    transform: none !important;
}

.dpad-action-icon { font-size: 16px; line-height: 1; }
.dpad-action-text { font-size: 9px; margin-top: 1px; font-weight: 600; }

/* ========== 动画 ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

/* ========== 响应式 ========== */

/* 平板 */
@media (max-width: 900px) {
    .tetris-layout, .snake-layout,
    .game2048-layout, .minesweeper-layout, .gomoku-layout {
        flex-direction: column;
        align-items: center;
    }
    .tetris-sidebar, .snake-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        min-width: unset;
        gap: 6px;
    }
    .tetris-sidebar > div, .snake-sidebar > div {
        min-width: 64px;
        padding: 6px 10px;
    }
}

/* 手机 */
@media (max-width: 768px) {
    .games-hub { padding: 80px 0 40px; }
    .games-grid { gap: 16px; padding: 0 14px; }

    .game-topbar { padding: 4px 8px; height: 42px; }
    .game-title-bar { font-size: 14px; }
    .game-score-bar { font-size: 12px; min-width: 52px; }
    .game-back-btn { padding: 5px 10px; font-size: 12px; min-height: 32px; }
    .game-pause-btn { width: 32px; height: 32px; }

    .game-start-panel { padding: 22px 18px; }
    .game-start-panel h2 { font-size: 19px; }

    /* D-Pad 手机尺寸 */
    .dpad-container.show { opacity: 1; }
    .dpad-cluster { width: 126px; height: 126px; margin-bottom: 8px; }
    .dpad-btn { width: 40px; height: 40px; }
    .dpad-up    { margin-left: -20px; }
    .dpad-down  { margin-left: -20px; }
    .dpad-left  { margin-top: -20px; }
    .dpad-right { margin-top: -20px; }
    .dpad-center { width: 34px; height: 34px; margin: -17px 0 0 -17px; }
    .dpad-action-btn { width: 52px; height: 52px; margin-left: 30px; }
    .dpad-action-icon { font-size: 14px; }
    .dpad-action-text { font-size: 8px; }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .games-grid { grid-template-columns: 1fr; }
    .game-card { padding: 32px 20px; }

    .dpad-container { bottom: 10px; left: 10px; }
    .dpad-cluster { width: 108px; height: 108px; }
    .dpad-btn { width: 34px; height: 34px; }
    .dpad-up    { margin-left: -17px; }
    .dpad-down  { margin-left: -17px; }
    .dpad-left  { margin-top: -17px; }
    .dpad-right { margin-top: -17px; }
    .dpad-center { width: 28px; height: 28px; margin: -14px 0 0 -14px; }
    .dpad-action-btn { width: 46px; height: 46px; margin-left: 24px; }
}

/* 横屏优化 */
@media (max-height: 500px) and (orientation: landscape) {
    .dpad-container { bottom: 6px; left: 6px; }
    .dpad-cluster { width: 96px; height: 96px; margin-bottom: 4px; }
    .dpad-btn { width: 30px; height: 30px; }
    .dpad-up    { margin-left: -15px; }
    .dpad-down  { margin-left: -15px; }
    .dpad-left  { margin-top: -15px; }
    .dpad-right { margin-top: -15px; }
    .dpad-center { width: 26px; height: 26px; margin: -13px 0 0 -13px; }
    .dpad-action-btn { width: 42px; height: 42px; }
    .game-topbar { height: 36px; padding: 3px 6px; }
    .games-hub { padding: 50px 0 20px; }
}
