* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    width: 100%; height: 100%; overflow: hidden;
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
    user-select: none; -webkit-user-select: none;
    background-color: #0d1120;
}

body.theme-dark {
    --ui-panel: rgba(20, 26, 42, .65);
    --ui-panel-solid: #171d2e;
    --ui-text: #eef2ff;
    --ui-sub: #9aa6c4;
    --ui-border: rgba(140, 170, 255, .16);
    --ui-shadow: 0 10px 34px rgba(0, 0, 0, .5);
    --ui-accent: #6c8cff;
    --ui-accent-2: #b47cff;
    --ui-glow: rgba(108, 140, 255, .55);
    --ui-highlight: #00ffcc;
}
body.theme-bright {
    --ui-panel: rgba(255, 255, 255, .75);
    --ui-panel-solid: #f4f7fc;
    --ui-text: #1b2030;
    --ui-sub: #5f6b85;
    --ui-border: rgba(30, 50, 100, .12);
    --ui-shadow: 0 10px 34px rgba(30, 60, 120, .16);
    --ui-accent: #5b6ef0;
    --ui-accent-2: #a15ce8;
    --ui-glow: rgba(91, 110, 240, .40);
    --ui-highlight: #00a67c;
}

#game-container {
    position: relative; width: 100%; height: 100%;
    background-color: var(--ui-panel-solid);
    color: var(--ui-text);
    transition: background-color .35s ease, color .35s ease;
}

#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.edge-glow {
    position: absolute; top: 0; bottom: 0; width: 15%; pointer-events: none; z-index: 10;
    opacity: 0; transition: opacity 0.5s, background 0.5s;
}
.edge-glow.left { left: 0; background: linear-gradient(90deg, rgba(0, 255, 200, 0.15) 0%, transparent 100%); }
.edge-glow.right { right: 0; background: linear-gradient(-90deg, rgba(255, 140, 0, 0.15) 0%, transparent 100%); }

.error-flash {
    position: absolute; inset: 0; pointer-events: none; z-index: 11;
    background: rgba(255, 50, 50, 0.15); opacity: 0; transition: opacity 0.1s;
}

/* ==========================================================
   顶部 HUD 数据栏
   ========================================================== */
.hud-layer {
    position: absolute; top: 0; left: 0; right: 0;
    padding: 12px 20px; pointer-events: none; z-index: 20;
    display: flex; justify-content: center; align-items: flex-start;
}
.hud-bar {
    background: var(--ui-panel); border: 1px solid var(--ui-border);
    border-radius: 20px; padding: 8px 24px; box-shadow: var(--ui-shadow);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    display: flex; flex-wrap: nowrap; align-items: center;
    gap: 12px 24px; pointer-events: auto; justify-content: center;
    max-width: 95%; width: auto; overflow-x: auto;
}

.hud-solo { display: flex; gap: 16px; align-items: center; }
.hud-pvp { display: none; gap: 15px; align-items: center; width: 100%; justify-content: space-between; padding: 0 10px; flex-direction: row; }

.player-stat { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.player-stat span { font-size: 13px; font-weight: 700; color: var(--ui-sub); }
.player-stat b { font-size: 20px; font-weight: 900; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.player-stat b.highlight { color: var(--ui-highlight); text-shadow: 0 0 10px rgba(0,255,200,0.3); }

.vs-badge { font-size: 16px; font-weight: 900; color: var(--ui-accent); font-style: italic; }

.stat-item {
    display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 15px;
    font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ui-sub);
}
.stat-item .glyphicon { font-size: 18px; color: var(--ui-accent); }
.stat-item span { font-size: 20px; font-weight: 900; line-height: 1; color: var(--ui-text); }
.stat-item span.highlight { color: var(--ui-highlight); }

.control-group { display: flex; gap: 6px; margin-left: 10px; border-left: 1px solid var(--ui-border); padding-left: 16px; flex-shrink: 0; }
.btn-circle {
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(128,128,128,0.1); border: 1px solid var(--ui-border);
    color: var(--ui-text); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform .2s, background .2s;
}
.btn-circle:hover { transform: scale(1.1); background: var(--ui-accent); color: #fff; }
.btn-circle .glyphicon { font-size: 15px; }

/* ==========================================================
   底部进度条
   ========================================================== */
.bottom-layer {
    position: absolute; bottom: 15px; left: 0; right: 0;
    padding: 0 20px; display: flex; flex-direction: column; gap: 8px;
    pointer-events: none; z-index: 15; opacity: 0; transition: opacity .3s;
}
.bottom-layer.active { opacity: 1; }

.progress-container { width: 100%; max-width: 800px; margin: 0 auto; pointer-events: auto; }
.progress-head {
    display: flex; justify-content: space-between; font-size: 12px; font-weight: 800;
    color: var(--ui-sub); margin-bottom: 4px; align-items: flex-end;
}
.progress-head span.kpm { color: var(--ui-highlight); }

.progress-track {
    position: relative; height: 10px; border-radius: 5px;
    background: var(--ui-panel); border: 1px solid var(--ui-border);
    overflow: visible;
}
.progress-fill {
    position: absolute; inset: 0 auto 0 0; width: 0%;
    border-radius: 5px; background: linear-gradient(90deg, #00e5c4, #6c8cff);
    box-shadow: 0 0 10px var(--ui-glow); transition: width .3s cubic-bezier(.34,1.2,.64,1);
}
.progress-fill.opponent {
    background: linear-gradient(90deg, #ff8c42, #ffb15c);
    box-shadow: 0 0 10px rgba(255, 140, 66, 0.5); transition: opacity .3s;
}
.icon-player, .icon-opponent {
    position: absolute; top: -8px; font-size: 16px; transition: left .3s cubic-bezier(.34,1.2,.64,1);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}
.icon-player { color: #00e5c4; left: 0%; }
.icon-opponent { color: #ff8c42; left: 0%; top: 10px; font-size: 14px; }

/* ==========================================================
   全屏遮罩与弹窗
   ========================================================== */
.screen-mask {
    position: absolute; inset: 0; z-index: 50;
    background: rgba(8, 12, 24, 0.7); backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center;
    padding: 20px; overflow-y: auto;
}
body.theme-bright .screen-mask { background: rgba(220, 230, 250, 0.7); }
.screen-mask.active { display: flex; }

.dialog-card {
    background: var(--ui-panel-solid); border: 1px solid var(--ui-border);
    border-radius: 24px; padding: 30px; width: 100%; max-width: 600px;
    box-shadow: var(--ui-shadow); display: flex; flex-direction: column; gap: 24px;
    animation: slideIn .3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.dialog-header { display: flex; align-items: center; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--ui-border); position: relative; }
.dialog-icon {
    width: 56px; height: 56px; border-radius: 16px;
    background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 26px; box-shadow: 0 8px 20px var(--ui-glow); flex-shrink: 0;
}
.dialog-title h2 { font-size: 24px; font-weight: 900; margin: 0 0 6px 0; letter-spacing: 0.5px; }
.dialog-title p { font-size: 14px; color: var(--ui-sub); font-weight: 600; margin: 0; }

.history-icon-btn {
    position: absolute; right: 0; top: 0; width: 40px; height: 40px; border-radius: 12px;
    background: var(--ui-panel); border: 1px solid var(--ui-border);
    display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all .2s;
}
.history-icon-btn:hover { background: var(--ui-accent); color: #fff; }

.dialog-body { display: flex; flex-direction: column; gap: 20px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stat-box {
    display: flex; gap: 12px; align-items: center; padding: 16px;
    background: var(--ui-panel); border-radius: 16px; border: 1px solid var(--ui-border);
}
.stat-box .glyphicon { font-size: 28px; }
.stat-box .val { font-size: 26px; font-weight: 900; line-height: 1; color: var(--ui-text); }
.stat-box .label { font-size: 13px; color: var(--ui-sub); font-weight: 700; margin-top: 4px; }

.tip-box {
    padding: 16px; background: rgba(108,140,255,0.08); border-radius: 14px;
    font-size: 14px; line-height: 1.7; color: var(--ui-text); border: 1px solid rgba(108,140,255,0.2);
}
.btn-group-custom { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.btn-custom {
    padding: 14px 20px; border-radius: 14px; border: 1px solid var(--ui-border);
    background: var(--ui-panel); color: var(--ui-text); font-weight: 800; font-size: 16px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: all .2s; font-family: inherit;
}
.btn-custom:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--ui-glow); border-color: var(--ui-accent); }
.btn-custom.primary { background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2)); color: #fff; border-color: transparent; }

.float-score {
    position: absolute; font-weight: 900; font-size: 24px;
    pointer-events: none; z-index: 30; text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    animation: floatUp 1.5s ease-out forwards; white-space: nowrap;
}
@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-80px) scale(1.6); }
}

.match-tips { font-size: 18px; font-weight: 800; text-align: center; color: var(--ui-accent); }
.countdown-num { font-size: 80px; font-weight: 900; color: var(--ui-accent); text-align: center; text-shadow: 0 0 20px var(--ui-glow); animation: pop 1s ease-in-out infinite; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }

.toast-msg {
    position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: #fff; padding: 12px 24px;
    border-radius: 30px; font-size: 16px; font-weight: 700; z-index: 60;
    pointer-events: none; opacity: 0; transition: opacity 0.3s, transform 0.3s;
    border: 1px solid var(--ui-border); box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.toast-msg.show { opacity: 1; transform: translateX(-50%) translateY(10px); }

@media (max-width: 768px) {
    .hud-bar { gap: 8px; padding: 6px 12px; flex-wrap: wrap; }
    .hud-pvp { flex-direction: column; gap: 4px; padding: 0; align-items: flex-start; }
    .player-stat { flex-direction: row; gap: 4px; }
    .stat-item { font-size: 13px; }
    .stat-item span { font-size: 16px; }
    .dialog-card { padding: 20px; gap: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
}