* { box-sizing: border-box; }
html, body {
    width: 100%; height: 100%;
    margin: 0; padding: 0;
    overflow: hidden;
    background: #06122a;
    color: #1b2b45;
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    -webkit-user-select: none;
}
kbd {
    background: #23304a; color: #fff; border-radius: 5px;
    padding: 1px 6px; font-size: 11px; box-shadow: none;
    font-family: inherit;
}
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ============================================================
 * 1. Canvas 层
 * ============================================================ */
#bgCanvas {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    display: block;
}
#gameStage {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 2;
    pointer-events: none;
}
#gameCanvas {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    display: block;
}

/* ============================================================
 * 2. 顶部 HUD
 * ============================================================ */
#hud {
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 14px 8px 10px;
    color: #eaf4ff;
    font-size: 13px;
    background: linear-gradient(180deg, rgba(6,18,44,.72) 0%, rgba(6,18,44,.38) 70%, rgba(6,18,44,0) 100%);
    border-bottom: 1px solid rgba(255,255,255,.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.hud-back {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 9px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.1);
    color: #eaf4ff;
    font-size: 14px;
    text-decoration: none;
    transition: all .18s ease;
    flex: 0 0 auto;
    margin-right: 2px;
}
.hud-back:hover, .hud-back:focus {
    background: rgba(255,255,255,.26);
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
}
.hud-brand {
    display: inline-flex; align-items: center; gap: 7px;
    font-weight: 700; letter-spacing: .6px; white-space: nowrap;
    text-shadow: 0 1px 6px rgba(0,0,0,.5);
}
.hud-brand i { color: #ffe08a; font-size: 15px; }
.hud-stats {
    display: flex; align-items: center; flex-wrap: wrap;
    gap: 6px; flex: 1 1 320px;
    justify-content: center;
}
.stat {
    display: inline-flex; align-items: baseline; gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.14);
    line-height: 1.25;
    white-space: nowrap;
    transition: background .2s, transform .2s;
}
.stat i { font-size: 11px; opacity: .85; align-self: center; }
.stat b { font-size: 14px; font-weight: 800; letter-spacing: .3px; }
.stat small { font-size: 10px; opacity: .72; }
.stat.pulse { animation: statPulse .38s ease; }
@keyframes statPulse {
    0%   { transform: scale(1);    background: rgba(255,255,255,.12); }
    45%  { transform: scale(1.14); background: rgba(255,224,138,.45); }
    100% { transform: scale(1);    background: rgba(255,255,255,.12); }
}
.hud-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.hud-btn {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.2);
    background: rgba(255,255,255,.1);
    color: #eaf4ff;
    font-size: 13px;
    cursor: pointer;
    transition: all .18s ease;
    padding: 0;
    outline: none;
}
.hud-btn:hover, .hud-btn:focus {
    background: rgba(255,255,255,.26);
    transform: translateY(-1px);
    color: #fff;
    outline: none;
}
.hud-btn:active { transform: scale(.94); }

/* ============================================================
 * 3. 底部目标字符
 * ============================================================ */
#targetBar {
    position: fixed; left: 50%; bottom: 20px;
    transform: translateX(-50%);
    z-index: 25;
    display: flex; align-items: center; gap: 10px;
    padding: 7px 18px 7px 14px;
    border-radius: 999px;
    background: rgba(8,20,44,.55);
    border: 1px solid rgba(255,255,255,.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #eaf4ff; font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .3s ease;
}
#targetBar.show { opacity: 1; }
#targetBar .tb-char {
    display: inline-block;
    min-width: 44px; padding: 1px 10px;
    border-radius: 11px;
    background: linear-gradient(180deg, #ffffff 0%, #dbe9f8 100%);
    color: #16304f;
    font-weight: 800; font-size: 20px; text-align: center;
    box-shadow: 0 4px 14px rgba(0,0,0,.4);
    letter-spacing: 1px;
}

/* ============================================================
 * 4. 暗黑主题弹层（居中 · 统一按钮 · 高对比度）
 * ============================================================ */
.modal-layer {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(3,10,24,.85);   /* 【优化】透明度提高，更沉稳 */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity .22s ease;
}
.modal-layer.open { display: flex; opacity: 1; }

.modal-layer .modal-card {
    position: relative;
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 28px 28px 24px;
    border-radius: 20px;
    background: linear-gradient(180deg, #1b2740 0%, #121a2c 100%);
    color: #d8e4f4;
    box-shadow: 0 28px 80px rgba(0,0,0,.8), 0 0 0 1px rgba(120,160,220,.18) inset;
    transform: translateY(16px) scale(.94);
    opacity: 0;
    transition: transform .34s cubic-bezier(.2,.9,.3,1.28), opacity .24s ease;
}
.modal-layer.open .modal-card { transform: none; opacity: 1; }
.modal-card::-webkit-scrollbar { width: 6px; }
.modal-card::-webkit-scrollbar-thumb { background: #2f3e5c; border-radius: 3px; }

.modal-title {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 800;
    color: #eaf1fb;
    letter-spacing: .5px;
}
.modal-title i { color: #5b9df0; }
.modal-sub {
    margin: 0 0 20px;
    font-size: 13.5px;
    color: #8fa4c4;
    line-height: 1.7;
}
.modal-emoji { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.modal-tip {
    margin: 16px 0 0;
    font-size: 12px;
    color: #6a7f9e;
}

/* 按钮容器通用 */
.modal-btn-row {
    display: flex; flex-wrap: wrap;
    gap: 12px;
    margin-top: 22px;
}
.modal-btn-row > .btn,
.modal-btn-row > a.btn { flex: 1 1 0; min-width: 110px; }

/* ---- 统一按钮：字号加大、字重加粗、抗锯齿 ---- */
.modal-card .btn {
    border-radius: 11px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .4px;
    padding: 11px 20px;
    line-height: 1.4;
    transition: all .2s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    outline: none;
}
.modal-card .btn:active { transform: translateY(1px); }
.modal-card .btn i { margin-right: 6px; }

.modal-card .btn-primary {
    background: linear-gradient(180deg, #4f92e6 0%, #3570c0 100%);
    border-color: #2c5fa8;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.modal-card .btn-primary:hover,
.modal-card .btn-primary:focus {
    background: linear-gradient(180deg, #5fa0f0 0%, #3d7cce 100%);
    border-color: #3d7cce;
    color: #ffffff;
    box-shadow: 0 8px 22px rgba(79,146,230,.4);
    transform: translateY(-1px);
}

.modal-card .btn-default {
    background: #223050;
    border-color: #34456a;
    color: #dce8f7;
}
.modal-card .btn-default:hover,
.modal-card .btn-default:focus {
    background: #2d3d5c;
    border-color: #4a5f85;
    color: #ffffff;
    transform: translateY(-1px);
}

/* 主按钮（开始游戏等），加大一号 */
.btn-hero {
    border-radius: 14px;
    padding: 14px 22px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .8px;
    box-shadow: 0 10px 26px rgba(51,122,216,.35);
}
.btn-hero:hover { box-shadow: 0 14px 32px rgba(51,122,216,.5); }

/* ---- 开始弹层专用：左"查看排行" + 右"开始游戏" ---- */
.start-btn-row {
    display: flex;
    gap: 12px;
    margin-top: 22px;
}
.start-btn-row > .btn {
    flex: 1 1 0;
    min-width: 0;
}
.start-btn-row > #btnStart { flex: 1.5 1 0; }

/* ---- 键位模式选择 ---- */
.mode-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.mode-item {
    display: block;
    padding: 12px 14px;
    border-radius: 13px;
    border: 2px solid #2a3958;
    background: #17223a;
    cursor: pointer;
    transition: all .18s ease;
    text-align: left;
    margin: 0;
}
.mode-item:hover { border-color: #3d5590; background: #1c2947; transform: translateY(-1px); }
.mode-item.active {
    border-color: #5b9df0;
    background: linear-gradient(180deg, #1e3459 0%, #16294a 100%);
    box-shadow: 0 6px 18px rgba(91,157,240,.28);
}
.mode-item .mi-name { display: block; font-weight: 800; font-size: 14px; color: #eaf1fb; letter-spacing: .2px; }
.mode-item .mi-desc { display: block; font-size: 11.5px; color: #8fa4c4; margin-top: 3px; line-height: 1.4; }
.mode-item input { display: none; }

.setting-group { margin-bottom: 22px; }
.setting-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #b4c8e3;
    margin-bottom: 10px;
    letter-spacing: .4px;
}
.setting-label i { color: #5b9df0; margin-right: 5px; }
.switch-row { display: flex; gap: 24px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: #b4c8e3; cursor: pointer; margin: 0; font-size: 14px; }
.switch input { width: 17px; height: 17px; accent-color: #5b9df0; cursor: pointer; margin: 0; }

/* ============================================================
 * 5. 结算
 * ============================================================ */
.result-badge {
    font-size: 56px; line-height: 1;
    margin-bottom: 8px;
    animation: badgePop .55s cubic-bezier(.2,.9,.3,1.5);
}
@keyframes badgePop {
    0%   { transform: scale(.3) rotate(-22deg); opacity: 0; }
    60%  { transform: scale(1.22) rotate(6deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
.result-score {
    font-size: 54px;
    font-weight: 900;
    line-height: 1.05;
    letter-spacing: -1px;
    background: linear-gradient(180deg, #7ab8ff 0%, #3d7cd4 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin: 8px 0 4px;
    text-align: center;
}
.result-score-label { font-size: 12px; color: #6a7f9e; letter-spacing: 3px; text-align: center; margin-bottom: 18px; }
.result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 6px;
}
.rs-item {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #17223a;
    border: 1px solid #263556;
    text-align: left;
}
.rs-item i { color: #5b9df0; font-size: 14px; width: 16px; text-align: center; }
.rs-item span { font-size: 12px; color: #8fa4c4; }
.rs-item b { margin-left: auto; font-size: 16px; font-weight: 800; color: #eaf1fb; }
.rs-item small { font-size: 10px; color: #6a7f9e; margin-left: 2px; }

.modal-card.lose { animation: loseShake .6s cubic-bezier(.36,.07,.19,.97); }
@keyframes loseShake {
    0%,100% { transform: translateX(0); }
    12% { transform: translateX(-12px) rotate(-1deg); }
    28% { transform: translateX(11px) rotate(1deg); }
    44% { transform: translateX(-8px); }
    62% { transform: translateX(7px); }
    80% { transform: translateX(-3px); }
}

/* ============================================================
 * 6. 排行榜
 * ============================================================ */
.rank-list { margin-top: 6px; }
.rank-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #17223a;
    border: 1px solid #263556;
    margin-bottom: 8px;
    font-size: 13px;
}
.rank-row.top1 { background: linear-gradient(90deg,#3a2f10,#1d2336); border-color: #6e5a1a; }
.rank-row.top2 { background: linear-gradient(90deg,#2a3145,#1d2336); border-color: #445270; }
.rank-row.top3 { background: linear-gradient(90deg,#332a22,#1d2336); border-color: #5c4630; }
.rank-no {
    width: 26px; height: 26px; flex: 0 0 26px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: #2a3a58; color: #a5bbd8;
    font-weight: 800; font-size: 12px;
}
.rank-row.top1 .rank-no { background: linear-gradient(180deg,#ffd75a,#f5b400); color: #4a3000; }
.rank-row.top2 .rank-no { background: linear-gradient(180deg,#dfe8f2,#a9bdd6); color: #2a3a58; }
.rank-row.top3 .rank-no { background: linear-gradient(180deg,#f6c99a,#cc9455); color: #3d2a10; }
.rank-main { flex: 1 1 auto; min-width: 0; }
.rank-main .rk-score { font-weight: 800; font-size: 15px; color: #eaf1fb; }
.rank-main .rk-meta { font-size: 11px; color: #6a7f9e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-side { text-align: right; font-size: 11px; color: #7d92b2; line-height: 1.4; white-space: nowrap; }
.rank-side b { display: block; font-size: 13px; color: #5b9df0; }
.rank-empty { text-align: center; padding: 26px 10px; color: #6a7f9e; font-size: 13px; }

/* ============================================================
 * 7. Toast（屏幕正中）
 * ============================================================ */
#toastWrap {
    position: fixed; left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2200;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    pointer-events: none;
}
.toast-msg {
    padding: 12px 28px;
    border-radius: 999px;
    background: rgba(16,30,58,.96);
    color: #eaf1fb;
    font-size: 15px; font-weight: 700;
    letter-spacing: .5px;
    box-shadow: 0 16px 40px rgba(0,0,0,.6);
    border: 1px solid rgba(120,160,220,.3);
    animation: toastIn .32s cubic-bezier(.2,.9,.3,1.4);
    white-space: nowrap;
}
.toast-msg.gold { background: linear-gradient(180deg,#ffd75a,#e0a800); color: #3d2800; border-color: #ffe9a8; }
@keyframes toastIn {
    from { transform: scale(.7); opacity: 0; }
    to   { transform: scale(1);  opacity: 1; }
}

/* ============================================================
 * 8. 特效层
 * ============================================================ */
#flash {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    z-index: 1400;
    pointer-events: none;
    opacity: 0;
    background: transparent;
}
#confetti {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    z-index: 2000;
    pointer-events: none;
    display: none;
}

/* ============================================================
 * 9. 响应式
 * ============================================================ */
@media (max-width: 900px) {
    #hud { padding: 6px 10px; gap: 6px 8px; font-size: 12px; }
    .hud-brand .brand-text { display: none; }
    .stat { padding: 2px 8px; }
    .stat b { font-size: 13px; }
    .hud-btn { width: 30px; height: 30px; font-size: 12px; }
    .modal-card { padding: 22px 18px 18px; border-radius: 16px; }
    .modal-title { font-size: 19px; }
    .result-score { font-size: 46px; }
    .mode-list { grid-template-columns: 1fr; }
    .start-btn-row { flex-direction: column; }
    .start-btn-row > #btnStart { order: -1; }
}
@media (max-width: 560px) {
    .hud-stats { justify-content: flex-start; }
    .stat small { display: none; }
    .modal-btn-row > .btn, .modal-btn-row > a.btn { min-width: 100%; }
    #targetBar { bottom: 12px; padding: 6px 14px 6px 10px; }
    #targetBar .tb-char { min-width: 36px; font-size: 17px; }
}
@media (max-height: 520px) {
    .modal-card { padding: 16px 18px; }
    .modal-emoji { display: none; }
    .modal-sub { margin-bottom: 12px; }
    .result-grid { grid-template-columns: repeat(4, 1fr); }
    .rs-item { flex-direction: column; align-items: flex-start; gap: 2px; padding: 7px 9px; }
    .rs-item b { margin-left: 0; font-size: 14px; }
}