/**
 * UI Overhaul - 主菜单、对局 HUD、结算页重构
 * 加载顺序在 main.css 之后，覆盖旧样式
 */

/* ========== CSS 变量补充 ========== */
:root {
    --hud-bg: rgba(18, 18, 24, 0.92);
    --hud-border: rgba(212, 168, 67, 0.12);
    --hud-gold-glow: 0 0 20px rgba(212, 168, 67, 0.15);
    --turn-glow: 0 0 16px rgba(212, 168, 67, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ========== Screen 基础调整 ========== */
#game-screen.screen {
    overflow: hidden;
    background: var(--bg-primary);
}

#main-menu.screen {
    display: flex;
    flex-direction: column;
    padding: 0;
    padding-top: env(safe-area-inset-top);
    overflow: hidden;
}

/* ========== 主菜单 ========== */
.menu-hero {
    padding: 28px 20px 16px;
    text-align: center;
    flex-shrink: 0;
}

.menu-brand {
    margin-bottom: 12px;
}

.menu-logo {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 12px rgba(212, 168, 67, 0.25));
}

.menu-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent-gold);
    letter-spacing: 4px;
    margin: 0;
}

.menu-tagline {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 1px;
}

.menu-player-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-panel);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    padding: 4px 14px;
    font-size: 0.8rem;
}

.menu-lv {
    color: var(--accent-gold);
    font-weight: 700;
}

.menu-exp-track {
    width: 80px;
    height: 5px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
}

.menu-exp-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-gold-dark), var(--accent-gold));
    border-radius: 3px;
    transition: width 0.5s ease;
}

.menu-exp-text {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

/* 菜单主体 */
.menu-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    padding: 0 20px;
    overflow-y: auto;
    min-height: 0;
}

.menu-primary-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.menu-btn.primary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 22px;
    background: linear-gradient(135deg, rgba(212,168,67,0.08), rgba(139,90,43,0.04));
    border: 1px solid rgba(212, 168, 67, 0.2);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    backdrop-filter: blur(4px);
}

.menu-btn.primary:hover {
    background: linear-gradient(135deg, rgba(212,168,67,0.15), rgba(139,90,43,0.08));
    border-color: rgba(212, 168, 67, 0.4);
    transform: translateY(-2px);
    box-shadow: var(--hud-gold-glow);
}

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

.menu-btn.primary .btn-icon {
    font-size: 1.8rem;
    width: 44px;
    text-align: center;
    flex-shrink: 0;
}

.menu-btn.primary .btn-text-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.menu-btn.primary .btn-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.menu-btn.primary .btn-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.menu-btn.primary .btn-arrow {
    font-size: 1.4rem;
    color: var(--accent-gold);
    opacity: 0.5;
    transition: opacity 0.2s;
}

.menu-btn.primary:hover .btn-arrow {
    opacity: 1;
}

/* 次要按钮 */
.menu-secondary-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.menu-btn.compact {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    background: var(--bg-panel);
    border: 1px solid rgba(212, 168, 67, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
}

.menu-btn.compact:hover {
    background: var(--bg-secondary);
    border-color: rgba(212, 168, 67, 0.25);
    transform: translateY(-2px);
}

.menu-btn.compact .btn-icon {
    font-size: 1.5rem;
}

.menu-btn.compact .btn-text {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* 菜单底部工具栏 */
.menu-footer {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 12px 20px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.menu-tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.menu-tool-btn:hover {
    border-color: rgba(212, 168, 67, 0.25);
    color: var(--text-secondary);
    background: rgba(212, 168, 67, 0.05);
}

/* ========== 设置弹窗 ========== */
.settings-panel {
    max-width: 480px;
    width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.settings-panel .modal-panel-body {
    overflow-y: auto;
    padding: 0;
}

.settings-group {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.settings-group:last-child {
    border-bottom: none;
}

.settings-group h4 {
    margin: 0 0 12px 0;
    font-size: 0.85rem;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
}

.setting-row label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.setting-row input,
.setting-row select {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid rgba(212, 168, 67, 0.12);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    min-width: 120px;
    transition: border-color 0.2s;
}

input[type="text"],
input[type="number"],
select {
    min-height: 44px;
}

.setting-row input:focus,
.setting-row select:focus {
    border-color: var(--accent-gold);
}

.setting-row.slider-row {
    gap: 10px;
}

.setting-row.slider-row input[type="range"] {
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    height: 44px;
    background: transparent;
    border-radius: 2px;
    border: none;
    padding: 0;
}

.setting-row.slider-row input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
}

.setting-row.slider-row input[type="range"]::-moz-range-track {
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
}

.setting-row.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-gold);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -6px;
}

/* ========== 通用弹窗面板 ========== */
.modal-panel {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--hud-border);
    box-shadow: var(--shadow-elevated);
    position: relative;
    z-index: 251;
    max-width: 90vw;
}

.modal-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.modal-panel-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
}

/* ========== 暂停菜单 ========== */
.pause-panel {
    width: 320px;
    max-width: 90vw;
}

.pause-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 20px 20px;
}

.pause-action-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    text-align: left;
}

.pause-action-btn:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(212, 168, 67, 0.2);
}

.pause-action-btn.primary {
    background: linear-gradient(135deg, rgba(212,168,67,0.15), rgba(139,90,43,0.08));
    border-color: rgba(212, 168, 67, 0.3);
    font-weight: 600;
}

.pause-action-btn.primary:hover {
    background: linear-gradient(135deg, rgba(212,168,67,0.22), rgba(139,90,43,0.12));
    border-color: rgba(212, 168, 67, 0.45);
}

.pause-action-btn.danger {
    color: var(--lose-color);
    border-color: rgba(198, 40, 40, 0.15);
}

.pause-action-btn.danger:hover {
    background: rgba(198, 40, 40, 0.08);
    border-color: rgba(198, 40, 40, 0.3);
}

.pause-action-btn span:first-child {
    font-size: 1.3rem;
    width: 28px;
    text-align: center;
}

/* ========== 对局 HUD ========== */
.hud-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0) 100%);
    z-index: 20;
    pointer-events: none;
}

.hud-topbar > * {
    pointer-events: auto;
}

.hud-menu-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}

.hud-menu-btn:hover {
    border-color: rgba(212, 168, 67, 0.35);
    color: var(--accent-gold);
}

.hud-match-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    padding: 6px 16px;
    backdrop-filter: blur(8px);
}

.hud-wind {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-gold);
    color: #1a1a1a;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
}

.hud-round {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.hud-deck-info {
    display: flex;
    align-items: baseline;
    gap: 2px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    padding: 6px 14px;
    backdrop-filter: blur(8px);
}

.hud-deck-count {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-gold);
    font-variant-numeric: tabular-nums;
}

.hud-deck-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.turn-timer-display {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    padding: 6px 14px;
    backdrop-filter: blur(8px);
    color: var(--text-primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: all 0.3s ease;
}

.turn-timer-display.hidden {
    display: none;
}

.turn-timer-display.urgent {
    border-color: rgba(244, 67, 54, 0.5);
    background: rgba(244, 67, 54, 0.15);
    color: #ff5252;
    animation: timerPulse 1s ease-in-out infinite;
}

.turn-timer-icon {
    font-size: 0.85rem;
}

.turn-timer-value {
    font-size: 1rem;
    color: var(--accent-gold);
    min-width: 20px;
    text-align: center;
}

.turn-timer-display.urgent .turn-timer-value {
    color: #ff5252;
}

/* 动作反馈 */
.action-feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    pointer-events: none;
    font-size: 3rem;
    font-weight: 800;
    color: var(--accent-gold);
    text-shadow: 0 0 40px rgba(212, 168, 67, 0.6);
    opacity: 0;
    transition: opacity 0.3s;
}

.action-feedback.show {
    opacity: 1;
    animation: actionFeedbackPop calc(0.8s * var(--anim-speed, 1)) ease forwards;
}

@keyframes actionFeedbackPop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    60% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* 牌桌布局调整 */
#game-screen .game-table {
    display: grid;
    grid-template-areas:
        ". top ."
        "left center right"
        ". bottom .";
    grid-template-columns: clamp(92px, 8vw, 132px) minmax(0, 1fr) clamp(92px, 8vw, 132px);
    grid-template-rows: clamp(116px, 14vh, 144px) minmax(0, 1fr) clamp(158px, 23vh, 220px);
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    gap: 8px;
    padding: max(56px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)) 14px;
    box-sizing: border-box;
    overflow: hidden;
}

/* 玩家区域 */
.player-area {
    position: relative !important;
    inset: auto !important;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    overflow: visible;
    z-index: 5;
    transform: none !important;
}

.player-area.top {
    grid-area: top;
    align-self: stretch;
    justify-self: stretch;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow: hidden;
}

.player-area.left {
    grid-area: left;
    align-self: stretch;
    justify-self: center;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.player-area.right {
    grid-area: right;
    align-self: stretch;
    justify-self: center;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.player-area.bottom {
    grid-area: bottom;
    align-self: end;
    justify-self: stretch;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    overflow: hidden;
}

.player-info {
    position: relative;
    padding: 6px 14px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    backdrop-filter: blur(8px);
    gap: 10px;
}

.player-area.current-turn .player-info {
    box-shadow: var(--turn-glow);
    border-color: rgba(212, 168, 67, 0.4);
}

.player-score {
    font-variant-numeric: tabular-nums;
    min-width: 40px;
    text-align: right;
}

.player-area.top .hand-area,
.player-area.bottom .hand-area {
    max-width: 100%;
    min-width: 0;
    justify-content: center;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.player-area.top .hand-area::-webkit-scrollbar,
.player-area.bottom .hand-area::-webkit-scrollbar {
    display: none;
}

/* 覆盖 game.css 的大屏固定牌高，避免 720p 窗口中对家手牌挤出顶部区域。 */
#game-screen .player-area.top .mahjong-tile,
#game-screen .player-area.top .mahjong-tile.back {
    min-width: 0;
    min-height: 0;
    width: clamp(34px, 3.5vw, 48px);
    height: clamp(46px, 7vh, 64px);
}

.player-area.left .hand-area,
.player-area.right .hand-area {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    max-height: calc(100% - 38px);
    justify-content: flex-start;
    overflow: hidden;
}

.melds-area:empty {
    display: none;
}

.player-area.left .melds-area,
.player-area.right .melds-area {
    max-height: 30%;
    overflow: hidden;
}

#game-screen .player-area.left .player-info,
#game-screen .player-area.right .player-info {
    width: 100%;
    max-width: 100%;
    padding: 4px;
    gap: 4px;
    justify-content: center;
}

#game-screen .player-area.left .player-avatar,
#game-screen .player-area.right .player-avatar {
    display: none;
}

#game-screen .player-area.left .player-name,
#game-screen .player-area.right .player-name {
    max-width: clamp(42px, 4vw, 64px);
}

#game-screen .player-area.left .player-score,
#game-screen .player-area.right .player-score {
    min-width: 30px;
}

#game-screen .player-area.left .mahjong-tile,
#game-screen .player-area.right .mahjong-tile,
#game-screen .player-area.left .mahjong-tile.back,
#game-screen .player-area.right .mahjong-tile.back {
    min-width: 0;
    min-height: 0;
    width: clamp(22px, 2.4vw, 32px);
    height: clamp(26px, 2.8vh, 32px);
    border-radius: 7px;
}

#game-screen .player-area.left .mahjong-tile .tile-face,
#game-screen .player-area.right .mahjong-tile .tile-face {
    font-size: clamp(1rem, 1.8vw, 1.45rem);
}

/* 侧家最多会短暂持有 14 张；轻微叠放可确保 720p 窗口也完整显示。 */
#game-screen .player-area.left .hand-area .mahjong-tile + .mahjong-tile,
#game-screen .player-area.right .hand-area .mahjong-tile + .mahjong-tile {
    margin-top: -5px;
}

#game-screen .table-center {
    position: relative;
    inset: auto;
    grid-area: center;
    align-self: stretch;
    justify-self: stretch;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    transform: none !important;
}

#game-screen .game-table.three-player {
    grid-template-areas:
        ". . ."
        "left center right"
        ". bottom .";
    grid-template-columns: clamp(84px, 7vw, 116px) minmax(0, 1fr) clamp(84px, 7vw, 116px);
    grid-template-rows: clamp(40px, 7vh, 64px) minmax(0, 1fr) clamp(158px, 23vh, 220px);
}

/* 回合指示器 */
.turn-indicator {
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    background: var(--accent-gold);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s;
    box-shadow: 0 0 8px rgba(212, 168, 67, 0.6);
}

.turn-indicator.active {
    opacity: 1;
    animation: turnPulse 1.5s ease infinite;
}

@keyframes turnPulse {
    0%, 100% { transform: translateX(-50%) scale(1); opacity: 1; }
    50% { transform: translateX(-50%) scale(1.4); opacity: 0.7; }
}

/* 3人模式：已由 game.css grid 布局统一处理 */
.game-table.three-player .player-area.top {
    display: none !important;
}

/* 弃牌堆 */
.discard-pile {
    width: min(48vw, 260px);
    height: min(28vh, 160px);
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(212, 168, 67, 0.08);
}

/* 动作按钮栏 */
.action-bar {
    position: absolute;
    bottom: clamp(128px, 19vh, 190px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 15;
    padding: 6px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: var(--radius-md);
    backdrop-filter: blur(12px);
}

.action-btn {
    min-width: 56px;
    height: 48px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(212,168,67,0.12), rgba(139,90,43,0.05));
    border: 1px solid rgba(212, 168, 67, 0.2);
    border-radius: var(--radius-sm);
    color: var(--accent-gold);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}

.action-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(212,168,67,0.2), rgba(139,90,43,0.1));
    border-color: rgba(212, 168, 67, 0.4);
}

@media (hover: hover) and (pointer: fine) {
    .action-btn:hover:not(:disabled) {
        transform: translateY(-2px);
    }
}

.action-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.94);
    transition: transform 0.05s ease;
}

.action-btn:focus-visible:not(:disabled) {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.25);
}

.action-btn:not(:disabled)::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    background: radial-gradient(circle at center, rgba(212,168,67,0.25) 0%, transparent 70%);
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.action-btn:not(:disabled):hover::after {
    opacity: 1;
}

.action-btn.highlight:not(:disabled) {
    animation: btnPulse 2s ease-in-out infinite;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 12px rgba(212, 168, 67, 0.2); }
    50% { box-shadow: 0 0 24px rgba(212, 168, 67, 0.4); }
}

.action-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
    filter: grayscale(0.6);
}

.action-btn.secondary {
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.08);
    color: var(--text-muted);
    font-weight: 500;
}

.action-btn.secondary:hover:not(:disabled) {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.15);
    color: var(--text-secondary);
}

.action-btn.highlight {
    background: linear-gradient(135deg, rgba(212,168,67,0.3), rgba(200,150,50,0.18));
    border-color: rgba(212, 168, 67, 0.55);
    box-shadow: 0 0 20px rgba(212, 168, 67, 0.2);
}

.action-btn.highlight:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(212,168,67,0.4), rgba(200,150,50,0.25));
    box-shadow: 0 0 30px rgba(212, 168, 67, 0.35);
}

/* 移除旧的游戏控制栏 */
.game-controls {
    display: none !important;
}

/* ========== 结算页 ========== */
#game-result.screen {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-primary);
    overflow-y: auto;
}

.result-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 30%, rgba(212,168,67,0.06) 0%, transparent 60%);
    pointer-events: none;
}

.result-content {
    position: relative;
    z-index: 2;
    max-width: 440px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.result-header {
    text-align: center;
    padding: 20px 0 8px;
}

.result-icon {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 16px rgba(212, 168, 67, 0.3));
}

.result-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-primary);
}

.result-title.win {
    color: var(--accent-gold);
}

.result-title.lose {
    color: var(--lose-color);
}

.result-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 6px 0 0;
}

/* 结算玩家列表 */
.result-players {
    background: var(--bg-panel);
    border: 1px solid var(--hud-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.result-player-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.result-player-row:last-child {
    border-bottom: none;
}

.result-player-row.winner {
    background: linear-gradient(90deg, rgba(212,168,67,0.06), transparent);
}

.result-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.result-rank.gold {
    background: linear-gradient(135deg, #FFD700, #FFA000);
    color: #1a1a1a;
}

.result-rank.silver {
    background: linear-gradient(135deg, #C0C0C0, #808080);
    color: #1a1a1a;
}

.result-rank.bronze {
    background: linear-gradient(135deg, #CD7F32, #8B4513);
    color: #1a1a1a;
}

.result-rank.normal {
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
}

.result-p-avatar {
    font-size: 1.4rem;
}

.result-p-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
}

.result-p-score {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
}

.result-p-score.positive {
    color: var(--win-color);
}

.result-p-score.negative {
    color: var(--lose-color);
}

/* 结算奖励 */
.result-rewards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.result-reward-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(212, 168, 67, 0.08);
    border: 1px solid rgba(212, 168, 67, 0.15);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--accent-gold);
    animation: rewardPop 0.4s ease backwards;
}

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

/* 结算操作按钮 */
.result-actions {
    display: flex;
    gap: 10px;
    padding-top: 8px;
}

.result-btn {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.result-btn.primary {
    background: linear-gradient(135deg, var(--accent-gold-dark), var(--accent-gold));
    color: #1a1a1a;
}

.result-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(212, 168, 67, 0.3);
}

.result-btn.secondary {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-secondary);
}

.result-btn.secondary:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.18);
}

/* ========== Modal 覆盖层 ========== */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 250;
}

.modal.hidden {
    display: none !important;
}

.modal:not(.hidden) {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 250;
}

.tile-name-label {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.55rem;
    color: var(--text-muted);
    pointer-events: none;
    line-height: 1;
}

.mahjong-tile {
    position: relative;
}

/* Toggle Switch */
.toggle-row {
    justify-content: space-between;
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.1);
    border-radius: 24px;
    transition: 0.2s;
    border: 1px solid rgba(255,255,255,0.1);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: rgba(212,168,67,0.25);
    border-color: rgba(212,168,67,0.4);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--accent-gold);
}
.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(212,168,67,0.2);
}

/* ========== 移动端适配 ========== */
@media (max-width: 560px) {
    .menu-hero {
        padding: 16px 16px 10px;
    }
    .menu-logo {
        font-size: 2.5rem;
    }
    .menu-title {
        font-size: 1.4rem;
        letter-spacing: 2px;
    }
    .menu-body {
        padding: 0 14px;
        gap: 12px;
    }
    .menu-btn.primary {
        padding: 14px 16px;
    }
    .menu-btn.primary .btn-icon {
        font-size: 1.4rem;
        width: 36px;
    }
    .menu-btn.primary .btn-text {
        font-size: 1rem;
    }
    .menu-secondary-actions {
        gap: 8px;
    }
    .menu-btn.compact {
        padding: 10px 4px;
    }

    .settings-panel {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
    }
    .setting-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }
    .setting-row input,
    .setting-row select {
        width: 100%;
        min-width: 0;
    }
    .setting-row.slider-row {
        display: grid;
        grid-template-columns: minmax(64px, auto) 1fr auto;
        align-items: center;
        gap: 8px;
    }
    .setting-row.slider-row label {
        grid-column: 1;
    }
    .setting-row.slider-row input[type="range"] {
        grid-column: 2;
        width: 100%;
    }
    .setting-row.slider-row .slider-value {
        grid-column: 3;
        min-width: 42px;
        text-align: right;
    }
    .toggle-row {
        flex-direction: row;
        align-items: center;
    }

    /* HUD 移动端 */
    .hud-topbar {
        padding: 8px 10px;
    }
    .hud-match-info {
        padding: 4px 12px;
        gap: 8px;
    }
    .hud-wind {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }
    .hud-round {
        font-size: 0.7rem;
    }
    .hud-deck-info {
        padding: 4px 10px;
    }

    /* 动作按钮移动端 */
    .action-bar {
        gap: 6px;
        padding: 4px;
        bottom: 176px;
    }
    .action-btn {
        min-width: 48px;
        height: 42px;
        padding: 0 12px;
        font-size: 0.9rem;
    }

    /* 玩家信息移动端 */
    .player-info {
        padding: 4px 10px;
        font-size: 0.75rem;
        gap: 6px;
    }
    .player-avatar {
        font-size: 1rem;
    }
    .player-score {
        min-width: 32px;
        font-size: 0.8rem;
    }

    /* 弃牌堆移动端 */
    .discard-pile {
        width: min(55vw, 220px);
        height: min(24vh, 130px);
        padding: 6px;
        gap: 3px;
    }

    #game-screen .game-table {
        grid-template-areas:
            "top top top"
            "left center right"
            "bottom bottom bottom";
        grid-template-columns: 70px minmax(0, 1fr) 70px;
        grid-template-rows: 112px minmax(0, 1fr) 170px;
        gap: 4px;
        padding-left: 8px;
        padding-right: 8px;
    }
    #game-screen .game-table.three-player {
        grid-template-areas:
            ". . ."
            "left center right"
            "bottom bottom bottom";
        grid-template-columns: 66px minmax(0, 1fr) 66px;
        grid-template-rows: 40px minmax(0, 1fr) 170px;
    }
    #game-screen .player-area.top .hand-area .mahjong-tile + .mahjong-tile {
        margin-left: -10px;
    }
    #game-screen .player-area.bottom .hand-area {
        justify-content: flex-start;
    }
    #game-screen .player-area.left .mahjong-tile,
    #game-screen .player-area.right .mahjong-tile,
    #game-screen .player-area.left .mahjong-tile.back,
    #game-screen .player-area.right .mahjong-tile.back {
        width: 30px;
        height: clamp(26px, 4vh, 34px);
    }
    #game-screen .player-area.left .hand-area .mahjong-tile + .mahjong-tile,
    #game-screen .player-area.right .hand-area .mahjong-tile + .mahjong-tile {
        margin-top: -8px;
    }

    /* 结算页移动端 */
    .result-icon {
        font-size: 3rem;
    }
    .result-title {
        font-size: 1.4rem;
    }
    .result-player-row {
        padding: 10px 12px;
    }
    .result-actions {
        flex-direction: column;
    }
}

@media (max-height: 640px) {
    .menu-hero {
        padding: 12px 16px 8px;
    }
    .menu-logo {
        font-size: 2.2rem;
        margin-bottom: 4px;
    }
    .menu-title {
        font-size: 1.3rem;
    }
    .menu-player-badge {
        display: none;
    }
    .menu-body {
        gap: 8px;
        justify-content: flex-start;
        padding-top: 4px;
        padding-bottom: 4px;
    }
    .menu-btn.primary {
        padding: 12px 16px;
    }
}

/* 横屏手机和低高度窗口：压缩牌桌纵向占用，并用叠放牌背保留完整手牌数量。 */
@media (max-height: 560px) and (orientation: landscape) {
    #game-screen .game-table,
    #game-screen .game-table.three-player {
        grid-template-columns: 76px minmax(0, 1fr) 76px;
        grid-template-rows: 72px minmax(0, 1fr) 108px;
        gap: 4px;
        padding: 52px 8px 8px;
    }

    #game-screen .game-table.three-player {
        grid-template-rows: 16px minmax(0, 1fr) 108px;
    }

    #game-screen .player-area.top .player-info {
        padding: 3px 8px;
    }

    #game-screen .player-area.top .player-avatar {
        display: none;
    }

    #game-screen .player-area.top .hand-area {
        padding: 2px;
        gap: 1px;
    }

    #game-screen .player-area.top .mahjong-tile,
    #game-screen .player-area.top .mahjong-tile.back {
        min-width: 0;
        min-height: 0;
        width: 28px;
        height: 38px;
        border-radius: 5px;
    }

    #game-screen .player-area.left .player-info,
    #game-screen .player-area.right .player-info {
        flex-direction: column;
        min-height: 34px;
        padding: 2px 4px;
        gap: 0;
        line-height: 1.05;
    }

    #game-screen .player-area.left .player-name,
    #game-screen .player-area.right .player-name {
        max-width: 66px;
        font-size: 0.65rem;
    }

    #game-screen .player-area.left .player-score,
    #game-screen .player-area.right .player-score {
        min-width: 0;
        text-align: center;
        font-size: 0.7rem;
    }

    #game-screen .player-area.left .hand-area,
    #game-screen .player-area.right .hand-area {
        max-height: calc(100% - 34px);
        padding: 2px;
        gap: 0;
        overflow: hidden;
    }

    #game-screen .player-area.left .hand-area .mahjong-tile,
    #game-screen .player-area.right .hand-area .mahjong-tile {
        min-width: 0;
        min-height: 0;
        width: 24px;
        height: 26px;
        border-radius: 4px;
    }

    #game-screen .player-area.left .hand-area .mahjong-tile + .mahjong-tile,
    #game-screen .player-area.right .hand-area .mahjong-tile + .mahjong-tile {
        margin-top: -21px;
    }

    #game-screen .player-area.bottom .player-info {
        padding: 3px 8px;
    }

    #game-screen .player-area.bottom .hand-area {
        padding: 2px 2px 4px;
        gap: 2px;
    }

    #game-screen .player-area.bottom .mahjong-tile {
        width: 42px;
        height: 58px;
        border-radius: 6px;
    }

    #game-screen .player-area.bottom .mahjong-tile .tile-face {
        font-size: 1.7rem;
    }

    .action-bar {
        bottom: 110px;
        gap: 4px;
        padding: 4px;
    }

    .action-btn {
        min-width: 44px;
        height: 38px;
        padding: 0 10px;
        font-size: 0.85rem;
    }

    .discard-pile {
        height: min(24vh, 96px);
    }
}

/* 回放牌张必须覆盖 game.css 中后声明的通用桌面尺寸。 */
#replay-player .replay-hand .mahjong-tile,
#replay-player .replay-hand .mahjong-tile.tile-small {
    min-width: 0;
    min-height: 0;
    width: 28px;
    height: 40px;
}

#replay-player .replay-melds .mahjong-tile,
#replay-player .replay-melds .mahjong-tile.tile-small,
#replay-player .replay-discard-pile .mahjong-tile,
#replay-player .replay-discard-pile .mahjong-tile.tile-small {
    min-width: 0;
    min-height: 0;
    width: 24px;
    height: 34px;
}

#replay-player .replay-hand .mahjong-tile .tile-face,
#replay-player .replay-melds .mahjong-tile .tile-face,
#replay-player .replay-discard-pile .mahjong-tile .tile-face {
    font-size: 1.05rem;
}

@media (max-width: 768px) and (min-height: 601px) {
    #replay-player .replay-hand {
        max-width: none;
        flex-wrap: nowrap;
        gap: 1px;
    }

    #replay-player .replay-hand .mahjong-tile,
    #replay-player .replay-hand .mahjong-tile.tile-small {
        width: 17px;
        height: 24px;
        border-radius: 3px;
    }

    #replay-player .replay-hand .mahjong-tile .tile-face {
        font-size: 0.68rem;
    }
}

@media (max-height: 600px) {
    #replay-player .replay-hand .mahjong-tile,
    #replay-player .replay-hand .mahjong-tile.tile-small {
        width: 14px;
        height: 20px;
        border-radius: 3px;
    }

    #replay-player .replay-melds .mahjong-tile,
    #replay-player .replay-melds .mahjong-tile.tile-small,
    #replay-player .replay-discard-pile .mahjong-tile,
    #replay-player .replay-discard-pile .mahjong-tile.tile-small {
        width: 13px;
        height: 19px;
        border-radius: 3px;
    }

    #replay-player .replay-hand .mahjong-tile .tile-face,
    #replay-player .replay-melds .mahjong-tile .tile-face,
    #replay-player .replay-discard-pile .mahjong-tile .tile-face {
        font-size: 0.65rem;
    }
}
