:root {
    --bg-deep: #070b14;
    --panel: rgba(17, 23, 39, .74);
    --panel-line: rgba(255, 255, 255, .10);
    --text: #e8edf7;
    --muted: #93a0bb;
    --accent: #ffd166;
    --danger: #ff5d6c;
    --ok: #51cf95;
}
* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; height: 100%; overflow: hidden;
    background: #070b14;
}
body {
    background:
            radial-gradient(1100px 700px at 50% 8%, #1b2745 0%, #0d1322 45%, #070b14 100%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}
#game-canvas {
    position: fixed; inset: 0; width: 100%; height: 100%;
    display: block; touch-action: none; cursor: grab;
}
#game-canvas.grabbing { cursor: grabbing; }

/* ============ 顶部信息栏（单行、紧凑、图标化） ============ */
.hud {
    position: fixed; top: 0; left: 0; right: 0; z-index: 10;
    min-height: 50px;
    display: flex; align-items: center; gap: 16px;
    padding: 6px 16px;
    background: linear-gradient(180deg, rgba(7, 11, 20, .92) 0%, rgba(7, 11, 20, .55) 78%, rgba(7, 11, 20, 0) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    backdrop-filter: blur(8px);
    font-size: 13px;
}
.brand {
    display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
    text-decoration: none; color: inherit; cursor: pointer;
    border-radius: 9px; padding: 2px 4px; margin-left: -4px;
    transition: .18s ease;
}
.brand:hover { background: rgba(255, 209, 102, .12); color: #fff; text-decoration: none; }
.brand:hover .brand-mark { box-shadow: 0 6px 18px rgba(255, 209, 102, .45); }
.brand:focus-visible { outline: 2px solid rgba(255, 209, 102, .7); outline-offset: 2px; }
.brand-mark {
    width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
    background: linear-gradient(135deg, #ff7b9c, #ffd166 55%, #59c2ff);
    color: #10151f; font-size: 13px;
    box-shadow: 0 4px 14px rgba(255, 209, 102, .28);
}
.brand-text { font-weight: 700; letter-spacing: .5px; font-size: 15px; white-space: nowrap; }
.stats { display: flex; align-items: center; gap: 14px; margin: 0; padding: 0; list-style: none; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.stats li { display: flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--muted); }
.stats li .glyphicon { font-size: 12px; color: rgba(255, 209, 102, .85); }
.stats li b {
    color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
    display: inline-block; text-align: right;   /* 数值定宽右对齐：数字跳动时整行不左右晃 */
}
/* 各指标的最小宽度按"最长取值"预留（等宽字体下 1ch = 一个数字宽） */
#hud-level { min-width: 3.4ch; }
#hud-time  { min-width: 4.2ch; }
#hud-wpm   { min-width: 2.6ch; }
#hud-acc   { min-width: 4.2ch; }
#hud-combo { min-width: 2.6ch; }
#hud-score { min-width: 4.2ch; }
#hud-err   { min-width: 4.2ch; }
/* 数值弹跳：加分 / 连击变化 / 失误增加时闪一下，视线余光也能感知 */
.stats li b.bump { animation: hudBump .34s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes hudBump {
    0% { transform: scale(1); }
    35% { transform: scale(1.26); color: #ffd166; }
    100% { transform: scale(1); }
}
.acts { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.hbtn {
    border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .05);
    color: #d8e1f2; border-radius: 9px; padding: 5px 11px; font-size: 12.5px;
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    transition: .18s ease; white-space: nowrap;
}
.hbtn:hover { background: rgba(255, 209, 102, .16); border-color: rgba(255, 209, 102, .5); color: #fff; }
.hbtn:active { transform: translateY(1px); }

/* ============ 颜色锁定图例 ============ */
.legend {
    position: fixed; right: 16px; top: 50%; transform: translateY(-50%); z-index: 9;
    width: 176px; padding: 12px 12px 8px;
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px;
    backdrop-filter: blur(10px); box-shadow: 0 18px 44px rgba(0, 0, 0, .38);
}
.legend-title { font-size: 11.5px; color: var(--muted); letter-spacing: 1px; margin-bottom: 9px; display: flex; align-items: center; gap: 6px; }
.legend-title .glyphicon { color: var(--accent); }
.lg-row {
    position: relative; border-radius: 10px; padding: 6px 7px 8px; margin-bottom: 5px;
    border: 1px solid transparent; transition: .2s ease;
}
.lg-row.active { border-color: rgba(255, 209, 102, .45); background: rgba(255, 209, 102, .1); }
.lg-row.done { opacity: .42; }
.lg-head { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.lg-key {
    width: 17px; height: 17px; border-radius: 5px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .16);
    font-size: 11px; font-weight: 700; color: #dfe8f8; flex: 0 0 auto;
}
.lg-row.active .lg-key { background: var(--accent); color: #14161d; border-color: transparent; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 10px currentColor; }
.lg-name { flex: 1 1 auto; color: #cfd9ea; }
.lg-pct { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lg-bar { margin-top: 6px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.lg-bar i { display: block; height: 100%; width: 100%; border-radius: 3px; transition: width .3s ease; }

/* ============ 底部提示（靠左下角摆放，给居中的炮筒让位） ============ */
.hintbar {
    position: fixed; left: 16px; bottom: 14px; z-index: 9;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-start;
    padding: 7px 14px; border-radius: 12px;
    background: rgba(12, 17, 30, .62); border: 1px solid rgba(255, 255, 255, .08);
    backdrop-filter: blur(8px); font-size: 12px; color: #a8b4c9;
    max-width: min(46vw, 520px);
}
.hintbar span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.hintbar .glyphicon { color: rgba(255, 209, 102, .8); font-size: 11px; }

/* ============ 反馈层：提示统一走顶部/底部空档，绝不遮挡 3D 像素块 ============ */
/* 2D 特效层（炮筒/炮弹/光带），位于 3D 画面之上、UI 之下 */
#cannon-canvas { position: fixed; inset: 0; z-index: 4; pointer-events: none; }

/* 连击数：贴左侧摆放，避开模型主体 */
.combo {
    position: fixed; left: 22px; top: 60px; transform: scale(.6);
    transform-origin: left center;
    z-index: 14; pointer-events: none; opacity: 0;
    font-size: 34px; font-weight: 900; color: var(--accent);
    text-shadow: 0 0 26px rgba(255, 209, 102, .65), 0 6px 18px rgba(0, 0, 0, .6);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.combo.pop { animation: comboPop .5s cubic-bezier(.2, .9, .3, 1.4) forwards; }
@keyframes comboPop {
    0% { opacity: 0; transform: scale(.5); }
    35% { opacity: 1; transform: translateY(-4px) scale(1.14); }
    100% { opacity: 0; transform: translateY(-18px) scale(1); }
}

/* 命中飘分：命中点上方弹出，上浮 + 淡出（命中反馈的关键一环） */
.float-score {
    position: fixed; z-index: 6; pointer-events: none;
    transform: translate(-50%, -50%);
    font: 900 20px/1 "Arial Black", Arial, sans-serif;
    color: #fff; letter-spacing: .5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, .62), 0 0 14px rgba(255, 255, 255, .35);
    animation: floatScoreUp .85s cubic-bezier(.2, .7, .3, 1) forwards;
    will-change: transform, opacity;
}
@keyframes floatScoreUp {
    0% { opacity: 0; transform: translate(-50%, -40%) scale(.65); }
    22% { opacity: 1; transform: translate(-50%, -66%) scale(1.16); }
    100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}

/* 失误提示：HUD 下方空档，位于模型上方，绝不压住像素块 */
.locked-banner {
    position: fixed; left: 50%; top: 92px; transform: translateX(-50%);
    z-index: 15; pointer-events: none; display: none;
    padding: 10px 22px; border-radius: 12px;
    background: rgba(255, 60, 80, .18); border: 2px solid rgba(255, 93, 108, .85);
    color: #ffd7dc; font-size: 16px; font-weight: 800; letter-spacing: 1px;
    box-shadow: 0 0 30px rgba(255, 60, 80, .35), inset 0 0 22px rgba(255, 60, 80, .2);
    max-width: 80vw; text-align: center;
}
.locked-banner.show { display: block; animation: lockShake .3s ease-in-out 2; }
@keyframes lockShake {
    0%, 100% { transform: translateX(-50%) rotate(0); }
    25% { transform: translateX(calc(-50% - 7px)) rotate(-1.2deg); }
    75% { transform: translateX(calc(-50% + 7px)) rotate(1.2deg); }
}
.locked-banner b { color: #fff; font-size: 17px; letter-spacing: 2px; margin-right: 4px; }

/* 轻提示：与失误提示同区（同一槽位轮换显示，互不叠压） */
.toast {
    position: fixed; left: 50%; top: 92px; transform: translateX(-50%) scale(.92);
    z-index: 16; pointer-events: none; padding: 9px 18px; border-radius: 11px;
    background: rgba(12, 18, 32, .92); border: 1px solid rgba(255, 209, 102, .35);
    color: #f2f6ff; font-size: 14px; font-weight: 600; letter-spacing: .5px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .5); opacity: 0; transition: .22s ease;
    display: flex; align-items: center; gap: 8px; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) scale(1); }
.toast .glyphicon { color: var(--accent); }
/* 矮窗口（如笔记本半边屏）：提示条压扁一档，把纵向空间让给模型本体 */
@media (max-height: 700px) {
    .toast { top: 78px; padding: 6px 12px; font-size: 12.5px; }
}

/* 全屏闪光 */
#flash {
    position: fixed; inset: 0; z-index: 13; pointer-events: none; opacity: 0;
    background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .9), rgba(255, 209, 102, .35) 40%, transparent 72%);
}

/* ============ 通用弹出层（水平 + 垂直居中） ============ */
.overlay {
    position: fixed; inset: 0; z-index: 20;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at 50% 40%, rgba(24, 34, 58, .62), rgba(5, 8, 15, .84));
    backdrop-filter: blur(3.5px);
}
.overlay.hidden { display: none; }
.gpanel {
    display: none; width: min(580px, 94vw); max-height: 90vh; overflow-y: auto;
    padding: 24px 24px 20px; border-radius: 20px;
    background: linear-gradient(180deg, rgba(26, 34, 55, .96), rgba(14, 19, 32, .98));
    border: 1px solid rgba(255, 255, 255, .12);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .08);
    animation: panelIn .26s cubic-bezier(.2, .9, .3, 1.1) both;
}
.gpanel.active { display: block; }
@keyframes panelIn { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.gpanel h2 { font-size: 20px; font-weight: 800; margin: 0 0 6px; text-align: center; letter-spacing: .5px; }
.gpanel .sub { text-align: center; color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 16px; }
.panel-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.mbtn {
    border: 1px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .06);
    color: #dbe4f5; border-radius: 11px; padding: 10px 18px; font-size: 14px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none;
    transition: .18s ease; white-space: nowrap;
}
.mbtn:hover { background: rgba(255, 255, 255, .12); color: #fff; text-decoration: none; }
.mbtn.primary { background: linear-gradient(135deg, #ffd166, #ffa94d); color: #17202f; border-color: transparent; box-shadow: 0 8px 24px rgba(255, 169, 77, .3); }
.mbtn.primary:hover { filter: brightness(1.08); color: #17202f; }
.mbtn.danger { background: rgba(255, 93, 108, .16); border-color: rgba(255, 93, 108, .5); color: #ffd2d7; }
.mbtn kbd {
    background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .18); color: #cfe0ff;
    border-radius: 5px; padding: 1px 6px; font-size: 11px; font-family: ui-monospace, monospace;
}
.mbtn.primary kbd { background: rgba(255, 255, 255, .92); border-color: rgba(255, 255, 255, .5); color: #22293a; }

/* 关卡选择（已解锁可点选重开） */
.level-select { margin: 2px 0 16px; }
.ls-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.ls-title .glyphicon { color: rgba(255, 209, 102, .85); margin-right: 5px; }
.ls-title span { font-size: 11.5px; color: #8ea0c0; }
.ls-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ls-item {
    position: relative; border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(255, 255, 255, .05); border-radius: 11px; padding: 9px 6px 8px;
    text-align: center; cursor: pointer; transition: .18s ease; color: #d6e0f2; line-height: 1.35;
}
.ls-item:hover { background: rgba(255, 209, 102, .14); border-color: rgba(255, 209, 102, .45); }
.ls-item .ls-no { display: block; font-weight: 800; font-size: 13px; color: #fff; }
.ls-item .ls-name { display: block; font-size: 11px; color: #93a0bb; margin-top: 2px; }
.ls-item.locked { cursor: not-allowed; opacity: .48; }
.ls-item.locked:hover { background: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .12); }
.ls-item .ls-lock { position: absolute; right: 6px; top: 6px; font-size: 10px; color: #ff8f9d; }
.ls-item.cleared .ls-no { color: var(--ok); }

/* 设置控件 */
.settings { margin: 6px 0 2px; border-top: 1px dashed rgba(255, 255, 255, .12); padding-top: 14px; }
.setting-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.setting-row .label { flex: 0 0 74px; font-size: 13px; color: #c3cee1; display: flex; align-items: center; gap: 6px; }
.setting-row .label .glyphicon { color: rgba(255, 209, 102, .8); font-size: 12px; }
.setting-row .opts { display: flex; gap: 6px; flex: 1 1 auto; flex-wrap: wrap; }
.sbtn {
    border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .05);
    color: #c7d2e5; padding: 5px 14px; border-radius: 8px; font-size: 12.5px; cursor: pointer; transition: .16s;
}
.sbtn:hover { background: rgba(255, 255, 255, .11); }
.sbtn.active { background: rgba(255, 209, 102, .22); border-color: rgba(255, 209, 102, .62); color: #fff3cf; font-weight: 600; }

/* 规则列表 */
.rules { font-size: 13px; line-height: 1.85; color: #c8d3e6; }
.rules li { margin-bottom: 7px; list-style: none; padding-left: 22px; position: relative; }
.rules li .glyphicon { position: absolute; left: 0; top: 3px; color: rgba(255, 209, 102, .85); font-size: 12px; }
.rules li b { color: #fff; }

/* 结算 */
.end-head { text-align: center; margin-bottom: 14px; }
.end-icon { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.end-icon .glyphicon { color: var(--accent); text-shadow: 0 0 26px rgba(255, 209, 102, .6); }
.end-icon.lose .glyphicon { color: var(--danger); text-shadow: 0 0 26px rgba(255, 93, 108, .55); }
.end-score { font-size: 34px; font-weight: 900; color: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; }
.end-score small { font-size: 13px; color: var(--muted); margin-left: 4px; font-weight: 400; }
.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.es-cell { background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08); border-radius: 11px; padding: 9px 8px; text-align: center; }
.es-cell .glyphicon { display: block; font-size: 13px; color: rgba(255, 209, 102, .8); margin-bottom: 4px; }
.es-cell b { display: block; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.es-cell span { font-size: 11px; color: var(--muted); }

/* 撒花 / 失败特效画布：层级高于弹出层 */
#fx-canvas { position: fixed; inset: 0; z-index: 30; pointer-events: none; }

/* 小屏适配：按重要度渐进隐藏指标，永远不出现"挤成一团/文字被裁一半"的状态 */
@media (max-width: 1180px) {
    /* 第一档：先撤掉最次要的「关卡 / WPM」 */
    .stats li[data-pri="3"] { display: none; }
    .hud { gap: 12px; }
    .stats { gap: 12px; }
}
@media (max-width: 980px) {
    .hud { min-height: 46px; gap: 10px; padding: 5px 10px; font-size: 12px; }
    .stats { gap: 10px; }
    .brand-text { font-size: 13px; }
    .legend { width: 152px; padding: 10px 9px 6px; }
    /* 第二档：再撤掉「用时 / 准确」，只留连击 / 得分 / 失误 */
    .stats li[data-pri="2"] { display: none; }
}
@media (max-width: 820px) {
    .hud { flex-wrap: wrap; row-gap: 4px; }
    .stats { flex-wrap: wrap; row-gap: 4px; }
    .legend { display: none; }
    .hintbar { font-size: 11px; gap: 10px; padding: 6px 12px; }
    .gpanel { padding: 18px 16px 16px; }
    .end-stats { grid-template-columns: repeat(2, 1fr); }
    .ls-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    /* 极窄：藏标题文字只留图标，按钮收紧，给三位核心指标腾干净空间 */
    .brand-text { display: none; }
    .hbtn { padding: 5px 8px; font-size: 12px; }
    .stats { gap: 9px; }
    /* 提示条收窄，避免压到居中炮筒 */
    .hintbar { max-width: 38vw; font-size: 10.5px; gap: 8px; padding: 5px 9px; }
}
@media (max-height: 560px) {
    .hintbar { display: none; }
    .gpanel { max-height: 94vh; }
}