*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; width: 100%; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #0d0916; color: #e8eaf0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; outline: none; border: none; background: none; cursor: pointer; padding: 0; }
button:focus { outline: 2px solid rgba(255,211,90,.5); outline-offset: 2px; }

/* ========== 舞台 ========== */
#game-wrap {
    position: relative;
    width: 100vw; min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at 50% 30%, #2c2050 0%, #171029 55%, #0a0714 100%);
    padding: 12px;
}
#stage {
    position: relative;
    width: min(100%, calc((100vh - 24px) * 1000 / 580));
    aspect-ratio: 1000 / 580;
    box-shadow: 0 20px 60px rgba(0,0,0,.75), 0 0 0 1px rgba(255,255,255,.05);
    overflow: hidden;
    background: #0d0916;
    border-radius: 4px;
}
@supports not (aspect-ratio: 1000 / 580) {
    #stage { height: 0; padding-bottom: calc(100% * 580 / 1000); }
}
#gameCanvas { display: block; width: 100%; height: 100%; }

/* ========== HUD —— 靠右对齐，左侧留给 canvas 卡槽 ========== */
#hud {
    position: absolute; top: 0; left: 0; right: 0;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    pointer-events: none;
    z-index: 20;
    background: linear-gradient(180deg, rgba(8,6,16,.82) 0%, rgba(8,6,16,0) 100%);
}
.hud-right {
    display: flex; align-items: center; gap: 6px;
    pointer-events: auto; flex-wrap: nowrap;
}
.hud-chip {
    display: inline-flex; align-items: center; gap: 5px;
    height: 34px; padding: 0 12px;
    border-radius: 17px;
    background: rgba(18,14,32,.88);
    border: 1px solid rgba(255,255,255,.10);
    font-size: 13px; font-weight: 700;
    letter-spacing: .3px; white-space: nowrap;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.hud-chip .gi { font-size: 12px; }
.hud-chip .v { color: #ffe27a; font-variant-numeric: tabular-nums; min-width: 20px; }
.hud-chip.tight { height: 30px; padding: 0 9px; font-size: 11.5px; }
.hud-lives { display: inline-flex; gap: 2px; }
.hud-lives .gi {
    font-size: 13px; color: #ff5a6e;
    transition: color .25s, transform .25s;
    text-shadow: 0 0 6px rgba(255,90,110,.55);
}
.hud-lives .gi.lost { color: #3a3248; text-shadow: none; transform: scale(.8); }

.hud-progress {
    flex: 0 0 auto;
    width: 140px; height: 7px;
    border-radius: 4px;
    background: rgba(18,14,32,.88);
    border: 1px solid rgba(255,255,255,.10);
    overflow: hidden; pointer-events: none;
}
#hudProgressBar {
    height: 100%; width: 0;
    border-radius: 4px;
    background: linear-gradient(90deg, #5fd05f, #b6f07a);
    transition: width .4s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 8px rgba(140,240,120,.55);
}

.btn-icon {
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(18,14,32,.88);
    border: 1px solid rgba(255,255,255,.10);
    color: #dfe4f2; font-size: 13px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background .18s, transform .18s, border-color .18s;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.btn-icon:hover { background: rgba(50,40,80,.95); border-color: rgba(255,226,122,.45); transform: translateY(-1px); }
.btn-icon:active { transform: scale(.93); }
.btn-icon.off { color: #666; }
.btn-icon.on { color: #ffd77a; border-color: rgba(255,211,90,.55); }

/* ========== 提示 ========== */
#hintBar {
    position: absolute; bottom: 10px; left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    padding: 7px 18px; border-radius: 16px;
    background: rgba(10,8,20,.86);
    border: 1px solid rgba(255,255,255,.08);
    backdrop-filter: blur(8px);
    font-size: 12.5px; color: #cfd4e6;
    white-space: nowrap;
    opacity: 0; transition: opacity .35s;
    pointer-events: none;
    max-width: calc(100% - 24px);
    overflow: hidden; text-overflow: ellipsis;
}
#hintBar.show { opacity: 1; }
#hintBar .gi { margin-right: 5px; color: #ffd77a; }
#hintBar kbd {
    display: inline-block; padding: 0 5px; margin: 0 1px;
    border-radius: 4px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.18);
    border-bottom-width: 2px;
    font-size: 10.5px; font-family: ui-monospace, Menlo, Consolas, monospace;
    color: #fff;
}

#flashTip {
    position: absolute; left: 50%; top: 38%;
    transform: translate(-50%, -50%) scale(.85);
    z-index: 16;
    padding: 11px 22px; border-radius: 12px;
    background: rgba(255,211,90,.95);
    color: #2b1c00;
    font-size: 15px; font-weight: 800; letter-spacing: 1px;
    box-shadow: 0 10px 28px rgba(255,180,60,.5);
    opacity: 0; pointer-events: none;
    transition: opacity .22s, transform .22s;
    max-width: 90%;
    text-align: center;
}
#flashTip.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#flashTip .gi { margin-right: 6px; }

/* ========== 弹窗（紧凑布局，防止纵向滚动） ========== */
.mask {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 50;
    display: flex;
    padding: 14px;
    overflow-y: auto;
    background: rgba(6,4,12,.82);
    backdrop-filter: blur(10px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s, visibility .28s;
}
.mask.show { opacity: 1; visibility: visible; }

.panel {
    margin: auto;
    width: 100%; max-width: 480px;
    max-height: calc(100dvh - 28px);
    max-height: calc(100vh - 28px);
    overflow-y: auto;
    padding: 20px 22px 16px;
    border-radius: 18px;
    background: linear-gradient(165deg, #251d3e 0%, #171128 100%);
    border: 1px solid rgba(255,255,255,.10);
    box-shadow: 0 24px 64px rgba(0,0,0,.75), inset 0 1px 0 rgba(255,255,255,.08);
    transform: translateY(14px) scale(.97);
    transition: transform .32s cubic-bezier(.2,.9,.3,1.15);
}
.panel::-webkit-scrollbar { width: 5px; }
.panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }
.mask.show .panel { transform: translateY(0) scale(1); }

.panel-head { text-align: center; margin-bottom: 14px; }
.emblem {
    width: 56px; height: 56px;
    margin: 0 auto 8px;
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    background: linear-gradient(150deg, #54437f, #2a2048);
    border: 1px solid rgba(255,226,122,.30);
    box-shadow: 0 10px 26px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.14);
    animation: floatY 3.2s ease-in-out infinite;
}
@keyframes floatY {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}
.panel-title {
    margin: 0 0 3px; font-size: 21px; font-weight: 800; letter-spacing: 1px;
    background: linear-gradient(180deg, #fff 20%, #ffd77a 100%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.panel-sub { margin: 0; font-size: 12px; color: #9aa2bb; letter-spacing: .4px; }

.opt-block { margin-bottom: 11px; }
.opt-label {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 7px;
    font-size: 12px; font-weight: 700; color: #b9c0d6; letter-spacing: .5px;
}
.opt-label .gi { font-size: 12px; color: #ffd77a; }
.opt-row { display: flex; gap: 7px; flex-wrap: wrap; }
.opt-btn {
    flex: 1 1 0; min-width: 72px;
    padding: 8px 6px 7px; border-radius: 10px;
    border: 1.5px solid rgba(255,255,255,.10);
    background: rgba(255,255,255,.04);
    color: #cfd4e6; text-align: center;
    transition: all .18s ease;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.opt-btn .nm { font-size: 13px; font-weight: 700; }
.opt-btn .nt { font-size: 10px; color: #7d849c; line-height: 1.3; }
.opt-btn:hover { background: rgba(255,255,255,.08); border-color: rgba(255,226,122,.28); }
.opt-btn.active {
    background: linear-gradient(160deg, rgba(255,206,84,.20), rgba(255,160,60,.10));
    border-color: #ffce54; color: #ffe9a8;
    box-shadow: 0 0 0 1px rgba(255,206,84,.25), 0 6px 16px rgba(255,180,60,.15);
}
.opt-btn.active .nt { color: #d8b97e; }

/* 折叠 */
.collapse-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; border-radius: 10px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.07);
    cursor: pointer; transition: background .18s;
    user-select: none;
}
.collapse-head:hover { background: rgba(255,255,255,.07); }
.collapse-head .t {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 700; color: #b9c0d6;
}
.collapse-head .t .gi { color: #ffd77a; font-size: 12px; }
.collapse-head .arrow { transition: transform .25s; color: #8a91a8; font-size: 11px; }
.collapse-head.open .arrow { transform: rotate(180deg); }
.collapse-body {
    max-height: 0; overflow: hidden;
    transition: max-height .35s ease;
}
.collapse-body.open { max-height: 760px; }
.collapse-body .inner {
    padding: 10px 4px 0;
    font-size: 12px; line-height: 1.8; color: #98a0b8;
}
.collapse-body .inner b { color: #ffd77a; font-weight: 700; }
.collapse-body .inner p { margin: 0 0 8px; }
.collapse-body .inner kbd {
    display: inline-block; padding: 1px 5px; margin: 0 1px;
    border-radius: 4px;
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.16);
    border-bottom-width: 2px;
    color: #e8eaf0; font-size: 10px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* 按钮 */
.btn-primary-lg {
    width: 100%; margin-top: 12px;
    padding: 11px 18px; border-radius: 11px;
    font-size: 14.5px; font-weight: 800; letter-spacing: 3px;
    color: #2b1c00;
    background: linear-gradient(180deg, #ffe08a 0%, #ffc23c 55%, #f0a81e 100%);
    box-shadow: 0 10px 24px rgba(240,168,30,.32), inset 0 1px 0 rgba(255,255,255,.6);
    transition: transform .16s, box-shadow .16s, filter .16s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary-lg:hover { filter: brightness(1.07); transform: translateY(-2px); }
.btn-primary-lg:active { transform: translateY(0) scale(.985); }

.btn-ghost-lg {
    width: 100%;
    padding: 10px 14px; border-radius: 11px;
    border: 1.5px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.04);
    color: #c4cadd;
    font-size: 13px; font-weight: 700; letter-spacing: 1px;
    transition: all .16s;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-ghost-lg:hover { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.26); color: #fff; }

/* 多按钮行 */
.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.btn-row .btn-primary-lg,
.btn-row .btn-ghost-lg {
    flex: 1 1 0;
    min-width: 0;
    margin-top: 0;
    padding: 10px 10px;
    font-size: 13px;
    letter-spacing: 1px;
}
.btn-row .btn-primary-lg { letter-spacing: 2px; }

/* 结算 */
.result-badge {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    margin-bottom: 11px; padding: 8px 14px;
    border-radius: 10px;
    font-size: 13.5px; font-weight: 800; letter-spacing: 1px;
}
.result-badge.win { background: rgba(110,224,110,.13); color: #8ff08f; border: 1px solid rgba(110,224,110,.30); }
.result-badge.lose { background: rgba(255,90,110,.12); color: #ff8a9a; border: 1px solid rgba(255,90,110,.28); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px; margin-bottom: 8px;
}
.stat-cell {
    padding: 9px 5px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,.045);
    border: 1px solid rgba(255,255,255,.07);
    text-align: center;
    transition: background .18s;
}
.stat-cell:hover { background: rgba(255,255,255,.07); }
.stat-cell .ico {
    font-size: 14px; color: #ffd77a;
    margin-bottom: 3px; display: block;
}
.stat-cell .v {
    font-size: 16px; font-weight: 800; color: #ffe27a;
    font-variant-numeric: tabular-nums; line-height: 1.2;
    margin-bottom: 2px;
}
.stat-cell .k { font-size: 10px; color: #828aa4; letter-spacing: .3px; }

.weak-keys {
    display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
    margin: 6px 0 2px;
}
.weak-keys:empty { display: none; }
.weak-keys .wk {
    min-width: 28px; padding: 4px 8px;
    border-radius: 7px;
    background: rgba(255,120,120,.13);
    border: 1px solid rgba(255,120,120,.32);
    color: #ff9a9a;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 700; font-size: 12px;
    text-align: center;
}

.kbd-hint {
    display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
    margin-top: 8px; padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,.06);
    font-size: 10.5px; color: #7d849c;
}
.kbd-hint span { display: inline-flex; align-items: center; gap: 3px; }
.kbd-hint kbd {
    padding: 1px 5px; border-radius: 4px;
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.16);
    border-bottom-width: 2px;
    font-size: 10px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    color: #e8eaf0;
}

/* ========== 操作提示面板 ========== */
#helpPanel {
    position: absolute; top: 48px; right: 12px;
    width: 230px; max-width: calc(100% - 24px);
    z-index: 22;
    padding: 10px 11px;
    border-radius: 10px;
    background: rgba(18,14,32,.96);
    border: 1px solid rgba(255,255,255,.10);
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 32px rgba(0,0,0,.5);
    opacity: 0; visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .22s, visibility .22s, transform .22s;
    font-size: 11px; line-height: 1.65;
}
#helpPanel.show { opacity: 1; visibility: visible; transform: translateY(0); }
#helpPanel .hp-item {
    padding: 4px 0;
    display: flex; gap: 6px; align-items: flex-start;
    color: #b3bad0;
    border-bottom: 1px solid rgba(255,255,255,.05);
}
#helpPanel .hp-item:last-child { border-bottom: none; }
#helpPanel .hp-item .gi {
    color: #6ee06e; font-size: 10.5px;
    margin-top: 3px; flex-shrink: 0;
}
#helpPanel kbd {
    padding: 0 4px; border-radius: 3px;
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.14);
    font-size: 9.5px;
    font-family: ui-monospace, Menlo, monospace;
    color: #fff;
}

/* ========== 响应式 ========== */
@media (max-width: 720px) {
    #hud { padding: 6px 8px; }
    .hud-chip { height: 28px; padding: 0 8px; font-size: 11px; }
    .hud-chip.tight { height: 26px; padding: 0 7px; font-size: 10.5px; }
    .hud-chip .gi { font-size: 11px; }
    .hud-lives .gi { font-size: 11px; }
    .btn-icon { width: 28px; height: 28px; font-size: 11px; }
    .hud-progress { width: 70px; }
    #helpPanel { width: calc(100% - 24px); right: 12px; }
    .panel { padding: 16px 14px 12px; border-radius: 14px; }
    .panel-title { font-size: 18px; }
    .emblem { width: 48px; height: 48px; font-size: 24px; margin-bottom: 6px; }
    .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 5px; }
    .stat-cell { padding: 8px 3px 6px; }
    .stat-cell .v { font-size: 13px; }
    .stat-cell .k { font-size: 9px; }
    .btn-row .btn-primary-lg, .btn-row .btn-ghost-lg { font-size: 12px; padding: 9px 6px; }
    #game-wrap { padding: 6px; }
    #hintBar { font-size: 10.5px; padding: 5px 12px; }
}
@media (max-width: 420px) {
    .hud-progress { display: none; }
}