html, body {
    height: 100%; margin: 0; padding: 0; overflow: hidden;
    background: #070b16;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none; -webkit-user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; width: 100%; }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0,0,0,0);
}

/* =====================================================================
 * § 顶部 HUD
 * ===================================================================== */
#hud {
    flex: 0 0 46px; height: 46px;
    display: flex; align-items: center;
    width: 100%;
    padding: 0 8px;
    background: linear-gradient(180deg, #1e2d55 0%, #131c33 100%);
    border-bottom: 1px solid #2f4374;
    box-shadow: 0 2px 12px rgba(0,0,0,.55);
    position: relative; z-index: 40;
    color: #cfe0ff;
}
#hud .brand {
    flex: 0 0 auto;
    font-size: 15px; font-weight: 700;
    color: #ffd6e8; letter-spacing: .5px;
    margin-right: 10px; white-space: nowrap;
    text-shadow: 0 0 12px rgba(255,130,190,.6);
    display: inline-flex; align-items: center; gap: 4px;
}
#hud .brand .glyphicon { font-size: 15px; }

#hud .metrics {
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: center;
    gap: 11px;
    overflow-x: auto; overflow-y: hidden;
    white-space: nowrap;
    padding: 0 4px;
    scrollbar-width: none;
}
#hud .metrics::-webkit-scrollbar { display: none; }

.metric {
    flex: 0 0 auto;
    display: inline-flex; align-items: baseline; gap: 4px;
    font-size: 11px; color: #8fa8d6; line-height: 1;
}
.metric > .glyphicon {
    font-size: 10.5px; opacity: .8;
    align-self: center; margin-right: 1px;
}
.metric .mv {
    font-size: 13px; font-weight: 700; color: #e9f2ff;
    font-family: Consolas, Menlo, monospace;
    display: inline-block; transition: color .2s;
}
.metric .mv.warm  { color: #ffe9a8; }
.metric .mv.green { color: #7ee08a; }
.metric .mv.pink  { color: #ff9dc4; }

@keyframes pulseHi {
    0%   { transform: scale(1);    color: #fff; text-shadow: 0 0 0 rgba(255,255,255,0); }
    35%  { transform: scale(1.38); color: #fff; text-shadow: 0 0 14px rgba(255,255,255,.95); }
    100% { transform: scale(1);    text-shadow: 0 0 0 rgba(255,255,255,0); }
}
.metric.pulse .mv { animation: pulseHi .45s cubic-bezier(.3,1.6,.5,1); }

#hud .actions { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; margin-left: 8px; }
#hud .actions .btn {
    font-size: 11px; padding: 3px 10px; border-radius: 14px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(140,180,255,.28);
    color: #cfe0ff; box-shadow: none; outline: none;
    transition: all .15s; text-decoration: none;
    display: inline-flex; align-items: center; gap: 3px;
    line-height: 1.5;
}
#hud .actions .btn .glyphicon { font-size: 10.5px; }
#hud .actions .btn:hover,
#hud .actions .btn:focus {
    background: rgba(120,180,255,.22);
    border-color: rgba(160,200,255,.6);
    color: #fff;
}
#hud .actions .btn:active { transform: translateY(1px); }

/* =====================================================================
 * § 舞台 / 画布
 * ===================================================================== */
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #070b16; }
#game  { display: block; width: 100%; height: 100%; outline: none; }

/* =====================================================================
 * § 开始遮罩
 * ===================================================================== */
#startOverlay {
    position: absolute; left: 0; top: 0; right: 0; bottom: 0;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 40%, rgba(20,32,64,.72), rgba(4,8,18,.93));
    z-index: 25;
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
#startOverlay.hide { display: none; }

.start-card {
    width: min(470px, 88vw);
    padding: 26px 28px 24px;
    border-radius: 20px;
    text-align: center;
    background: linear-gradient(160deg, rgba(46,66,116,.94), rgba(20,29,54,.97));
    border: 1px solid rgba(130,170,255,.3);
    box-shadow: 0 22px 60px rgba(0,0,0,.65), inset 0 1px 0 rgba(255,255,255,.12);
    animation: cardIn .45s cubic-bezier(.2,1.3,.4,1);
}
@keyframes cardIn {
    from { opacity: 0; transform: translateY(18px) scale(.94); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.start-card h1 {
    margin: 0 0 10px;
    font-size: 25px; font-weight: 800; color: #fff;
    text-shadow: 0 0 22px rgba(255,140,200,.55); letter-spacing: 1px;
}
.start-card p { margin: 0 0 6px; font-size: 13px; line-height: 1.75; color: #a9c0e8; }
.start-card .keys {
    display: inline-block; margin: 10px 0 16px;
    padding: 7px 14px; border-radius: 10px;
    background: rgba(0,0,0,.28);
    border: 1px dashed rgba(140,180,255,.35);
    font-size: 12px; color: #9fe8ff;
    font-family: Consolas, monospace;
}

.btn-candy {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 11px 32px;
    border: none; outline: none; border-radius: 26px;
    font-size: 16px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #ff8ab8, #e5447f);
    box-shadow: 0 8px 22px rgba(229,68,127,.45), inset 0 1px 0 rgba(255,255,255,.4);
    cursor: pointer;
    transition: transform .14s, box-shadow .14s;
}
.btn-candy:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 12px 28px rgba(229,68,127,.6); }
.btn-candy:active { transform: translateY(0) scale(.98); }

/* =====================================================================
 * § 关卡反馈浮层
 * ===================================================================== */
#flashMsg {
    position: absolute; left: 50%; top: 20%;
    transform: translate(-50%, -50%) scale(.82);
    opacity: 0; pointer-events: none; z-index: 22;
    padding: 10px 26px; border-radius: 16px;
    font-size: 18px; font-weight: 800; color: #fff;
    background: rgba(16,26,48,.86);
    border: 1px solid rgba(150,190,255,.35);
    box-shadow: 0 10px 34px rgba(0,0,0,.55);
    white-space: nowrap;
    transition: opacity .28s ease, transform .28s cubic-bezier(.2,1.5,.4,1);
    text-shadow: 0 0 16px rgba(255,255,255,.35);
}
#flashMsg.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#flashMsg.good { border-color: rgba(126,224,138,.55); box-shadow: 0 10px 34px rgba(126,224,138,.25); }
#flashMsg.bad  { border-color: rgba(255,120,120,.6);  box-shadow: 0 10px 34px rgba(255,80,80,.28); }

/* =====================================================================
 * § 模态框（统一水平 + 垂直居中）
 * ===================================================================== */
.modal-mask {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    display: none;
    align-items: center;      /* 垂直居中 */
    justify-content: center;  /* 水平居中 */
    background: rgba(3,7,16,.78);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    padding: 16px;
    box-sizing: border-box;
}
.modal-mask.show { display: flex !important; }

.modal-box {
    width: min(540px, 94vw);
    max-height: 86vh;
    display: flex; flex-direction: column;
    border-radius: 18px;
    background: linear-gradient(160deg, #26355c, #141d33);
    border: 1px solid rgba(130,170,255,.28);
    box-shadow: 0 26px 70px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.1);
    color: #d7e4ff;
    opacity: 0; transform: scale(.9) translateY(10px);
    transition: opacity .22s ease, transform .22s cubic-bezier(.2,1.3,.4,1);
    overflow: hidden;
}
.modal-mask.show .modal-box { opacity: 1; transform: scale(1) translateY(0); }

.modal-head {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(130,170,255,.16);
}
.modal-head h3 {
    margin: 0; font-size: 17px; font-weight: 800; color: #fff;
    letter-spacing: .5px;
    display: inline-flex; align-items: center; gap: 7px;
}
.modal-head h3 .glyphicon { font-size: 15px; color: #ffd6e8; }

.modal-close {
    border: none; background: transparent; outline: none;
    color: #8fa8d6; font-size: 22px; line-height: 1;
    padding: 0 4px; cursor: pointer;
    transition: color .15s, transform .15s;
}
.modal-close:hover { color: #fff; transform: rotate(90deg); }

.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 20px 18px;
    font-size: 13.5px; line-height: 1.8;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: rgba(140,180,255,.3); border-radius: 3px; }

.modal-body h4 {
    margin: 16px 0 6px;
    font-size: 14px; font-weight: 700; color: #9fe8ff;
    display: flex; align-items: center; gap: 6px;
}
.modal-body h4:first-child { margin-top: 0; }
.modal-body h4 .glyphicon { font-size: 12px; }
.modal-body p  { margin: 0 0 6px; color: #b9cbe8; }
.modal-body ul { margin: 0 0 6px; padding-left: 20px; color: #b9cbe8; }
.modal-body li { margin-bottom: 3px; }
.modal-body kbd {
    display: inline-block; padding: 1px 7px; margin: 0 2px;
    border-radius: 5px;
    background: rgba(0,0,0,.4);
    border: 1px solid rgba(150,190,255,.3); border-bottom-width: 2px;
    font-family: Consolas, monospace; font-size: 12px; color: #ffe9a8;
}

.modal-foot {
    flex: 0 0 auto;
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 0 20px 18px;
}

.btn-ghost {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 18px; border-radius: 20px;
    font-size: 13px; font-weight: 600;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(140,180,255,.3);
    color: #cfe0ff; cursor: pointer; outline: none;
    transition: all .15s; text-decoration: none;
}
.btn-ghost:hover, .btn-ghost:focus {
    background: rgba(120,180,255,.2); color: #fff; text-decoration: none;
}

.btn-primary-candy {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 20px; border-radius: 20px;
    font-size: 13px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #ff8ab8, #e5447f);
    border: none; cursor: pointer; outline: none;
    box-shadow: 0 6px 18px rgba(229,68,127,.4);
    transition: transform .14s, box-shadow .14s;
}
.btn-primary-candy:hover { transform: translateY(-1px); box-shadow: 0 9px 24px rgba(229,68,127,.55); }
.btn-primary-candy:active { transform: translateY(0) scale(.98); }

/* =====================================================================
 * § 设置项（左标签 + 右控件 视觉对齐）
 * ===================================================================== */
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px dashed rgba(130,170,255,.14);
    font-size: 13.5px;
}
.setting-row:last-of-type { border-bottom: none; }
.setting-row .lbl {
    display: inline-flex; align-items: center; gap: 6px;
    color: #cfe0ff; min-width: 0;
}
.setting-row .lbl .glyphicon {
    width: 16px; text-align: center;
    font-size: 12px; color: #9fe8ff; flex-shrink: 0;
}

.switch {
    position: relative; width: 46px; height: 24px; flex: 0 0 auto;
    border-radius: 12px; cursor: pointer;
    background: #33405f; transition: background .2s;
}
.switch::after {
    content: ''; position: absolute; left: 3px; top: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background: #93a7c9; transition: all .2s;
}
.switch.on { background: #e5447f; }
.switch.on::after { left: 25px; background: #fff; }

.seg-group { display: flex; gap: 6px; flex: 0 0 auto; }
.seg {
    padding: 5px 14px; border-radius: 16px; cursor: pointer;
    font-size: 12.5px; font-weight: 600;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(140,180,255,.22);
    color: #a9c0e8; transition: all .15s;
    user-select: none;
}
.seg:hover { background: rgba(120,180,255,.16); }
.seg.on {
    background: linear-gradient(135deg, #ff8ab8, #e5447f);
    border-color: transparent; color: #fff;
    box-shadow: 0 4px 14px rgba(229,68,127,.4);
}

/* =====================================================================
 * § 结算面板（图标 + 数值 视觉对齐）
 * ===================================================================== */
#resultTitle {
    text-align: center; font-size: 22px; font-weight: 900;
    margin: 4px 0 18px; color: #fff;
    text-shadow: 0 0 24px rgba(255,200,120,.5);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
#resultTitle .glyphicon { font-size: 20px; }

.result-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 8px 12px; margin: 0 0 18px;
}
@media (max-width: 480px) { .result-grid { grid-template-columns: 1fr; } }

.result-item {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px;
    padding: 9px 12px; border-radius: 10px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(130,170,255,.14);
    font-size: 12.5px;
    transition: background .15s, border-color .15s;
}
.result-item:hover {
    background: rgba(120,180,255,.10);
    border-color: rgba(140,180,255,.3);
}
.result-item .rk {
    display: inline-flex; align-items: center; gap: 6px;
    color: #8fa8d6; min-width: 0;
}
.result-item .rk .glyphicon {
    width: 14px; text-align: center;
    font-size: 11.5px; color: #9fe8ff; flex-shrink: 0;
}
.result-item .rv {
    font-weight: 800; color: #ffe9a8;
    font-family: Consolas, Menlo, monospace; font-size: 14px;
    white-space: nowrap;
}

.result-actions {
    display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}

/* =====================================================================
 * § 无障碍 / 减少动画偏好
 * ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    .modal-box, #flashMsg, .start-card { transition: none; animation: none; }
}