:root {
    --bg-deep:     #0a0e17;   /* 最深背景 */
    --bg-base:     #0f1420;   /* 基础背景 */
    --bg-panel:    #141b2d;   /* 面板背景 */
    --bg-elevated: #1c2438;   /* 抬升层 */
    --bg-card:     #202840;   /* 卡片背景 */

    --accent:      #7c5cff;   /* 主紫 */
    --accent-lt:   #a78bfa;
    --accent-dk:   #5b3fd9;

    --gold:        #fbbf24;   /* 阳光金 */
    --gold-lt:     #fde047;
    --gold-dk:     #d97706;

    --cyan:        #22d3ee;   /* 霓虹青 */
    --cyan-dk:     #0891b2;

    --pink:        #f472b6;   /* 霓虹粉 */
    --green:       #4ade80;
    --red:         #f87171;
    --orange:      #fb923c;

    --text:        #e2e8f0;   /* 主文字 */
    --text-dim:    #94a3b8;   /* 次级文字 */
    --text-mute:   #64748b;   /* 弱化文字 */

    --border:      #2d3a54;   /* 边框 */
    --border-lt:   #3d4a64;
    --border-glow: rgba(124, 92, 255, 0.5);

    --shadow:      rgba(0, 0, 0, 0.5);
}

/* ================================================================
   全局重置
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    height: 100%; margin: 0; padding: 0;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text);
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
body { display: flex; flex-direction: column; }

/* ================================================================
   顶部信息栏 —— 深色底 + 紫色霓虹边
   ================================================================ */
.game-bar {
    position: relative;
    flex: 0 0 auto;
    display: flex; align-items: center;
    gap: 10px;
    height: 56px;
    padding: 0 10px;
    background: linear-gradient(180deg, #141b2d 0%, #0f1420 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 0 rgba(124,92,255,.15), 0 4px 18px rgba(0,0,0,.6), inset 0 1px 0 rgba(124,92,255,.08);
    z-index: 20;
    white-space: nowrap;
}
.gb-back {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    width: 34px; height: 34px; border-radius: 10px;
    color: var(--accent-lt); background: rgba(124,92,255,.1);
    border: 1px solid rgba(124,92,255,.3);
    text-decoration: none; font-size: 14px;
    transition: all .18s;
}
.gb-back:hover, .gb-back:focus {
    background: rgba(124,92,255,.22);
    color: #fff;
    text-decoration: none;
    box-shadow: 0 0 16px rgba(124,92,255,.5);
    transform: translateY(-1px);
}
.gb-title { flex: 0 0 auto; display: flex; align-items: baseline; gap: 6px; }
.gb-title strong {
    font-size: 15px; font-weight: 900; letter-spacing: .5px;
    color: var(--accent-lt);
    text-shadow: 0 0 12px rgba(167,139,250,.6);
}
.gb-title span { font-size: 10px; color: var(--text-mute); letter-spacing: 1px; }

/* 打字指标区 */
.gb-stats {
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: center; justify-content: center;
    gap: 5px;
    overflow: hidden;
}
.stat {
    display: inline-flex; align-items: center; gap: 4px;
    flex: 0 0 auto;
    height: 32px; padding: 0 9px;
    background: rgba(32, 40, 64, .8);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 11px; color: var(--text-dim);
    transition: background .2s, border-color .2s, transform .2s;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.stat .glyphicon { font-size: 12px; color: var(--accent-lt); }
.stat b {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px; font-weight: 900; color: var(--text);
    font-variant-numeric: tabular-nums;
}
.stat small { font-size: 9px; color: var(--text-mute); margin-left: 1px; }
.stat.hot {
    background: linear-gradient(180deg, rgba(244,114,182,.2), rgba(244,114,182,.08));
    border-color: rgba(244,114,182,.6);
    transform: scale(1.05);
    box-shadow: 0 0 16px rgba(244,114,182,.4);
}
.stat.hot b { color: var(--pink); }
.stat.hot .glyphicon { color: var(--pink); }
.stat.bump { animation: statBump .32s cubic-bezier(.34,1.56,.64,1); }
@keyframes statBump { 0%{transform:scale(1)} 45%{transform:scale(1.16)} 100%{transform:scale(1)} }

/* 裂隙血量条 */
.stat.rift { gap: 6px; }
.rift-bar {
    position: relative; width: 76px; height: 10px; border-radius: 5px;
    background: rgba(0,0,0,.5);
    box-shadow: inset 0 1px 3px rgba(0,0,0,.8);
    overflow: hidden;
}
.rift-bar i {
    display: block; height: 100%; width: 100%;
    border-radius: 5px;
    background: linear-gradient(90deg, #4ade80 0%, #86efac 100%);
    box-shadow: 0 0 10px rgba(74,222,128,.7);
    transition: width .35s cubic-bezier(.4,0,.2,1), background .35s;
}
.rift-bar i.mid { background: linear-gradient(90deg, #fbbf24 0%, #fde047 100%); box-shadow: 0 0 10px rgba(251,191,36,.75); }
.rift-bar i.low {
    background: linear-gradient(90deg, #dc2626 0%, #f87171 100%);
    box-shadow: 0 0 12px rgba(248,113,113,.9);
    animation: riftPulse .6s infinite alternate;
}
@keyframes riftPulse { from { opacity: .55; } to { opacity: 1; } }

/* 工具栏按钮 */
.gb-tools { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; }
.tbtn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(32, 40, 64, .8);
    color: var(--accent-lt); font-size: 13px;
    cursor: pointer; outline: none;
    transition: all .18s;
}
.tbtn:hover {
    background: rgba(124,92,255,.18);
    color: #fff;
    border-color: var(--border-glow);
    box-shadow: 0 0 16px rgba(124,92,255,.4);
    transform: translateY(-1px);
}
.tbtn:active { transform: translateY(0); }
.tbtn.off { opacity: .4; }

.gb-progress {
    position: absolute; left: 0; bottom: -1px;
    width: 100%; height: 2px; background: rgba(124,92,255,.1);
    overflow: hidden;
}
.gb-progress i {
    display: block; height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--cyan));
    box-shadow: 0 0 10px rgba(124,92,255,.9);
    transition: width .4s cubic-bezier(.4,0,.2,1);
}

/* ================================================================
   主舞台 —— 暗色深空背景
   ================================================================ */
.game-main {
    position: relative;
    flex: 1 1 auto; min-height: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 8px;
    background:
            radial-gradient(ellipse at 50% 25%, rgba(124,92,255,.12) 0%, transparent 60%),
            radial-gradient(ellipse at 50% 80%, rgba(34,211,238,.06) 0%, transparent 60%),
            var(--bg-deep);
}
.stage {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    box-shadow:
            0 16px 60px rgba(0,0,0,.9),
            0 0 0 1px var(--border),
            0 0 0 2px rgba(124,92,255,.3),
            0 0 100px rgba(124,92,255,.15);
    background: #08090f;
}
#gameCanvas { display: block; width: 100%; height: 100%; }

/* ================================================================
   覆盖层 —— 保证严格水平垂直居中
   遮罩背景改半透明，去掉 backdrop-filter 以便看到底层持续粒子效果
   ================================================================ */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: rgba(6, 8, 16, .72);
    z-index: 1000;
    opacity: 0; pointer-events: none;
    transition: opacity .28s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* 结算面板专用的全屏粒子画布（在遮罩上、面板下） */
.fx-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1001;
    display: none;
}
.fx-canvas.show { display: block; }

.overlay-panel {
    position: relative;
    width: 100%; max-width: 580px;
    flex-shrink: 0;
    margin: auto;
    background: linear-gradient(180deg, #141b2d 0%, #0f1420 100%);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow:
            inset 0 1px 0 rgba(124,92,255,.12),
            0 0 0 1px rgba(124,92,255,.25),
            0 24px 70px rgba(0,0,0,.85),
            0 0 80px rgba(124,92,255,.15);
    padding: 26px 28px;
    transform: translateY(14px) scale(.97);
    transition: transform .32s cubic-bezier(.34,1.56,.64,1);
    z-index: 1002;
}
.overlay.show .overlay-panel { transform: translateY(0) scale(1); }
.overlay-panel.wide { max-width: 760px; }

.op-title {
    margin: 0 0 8px; text-align: center;
    font-size: 26px; font-weight: 900; letter-spacing: 1px;
    color: var(--accent-lt);
    text-shadow: 0 0 24px rgba(124,92,255,.6), 0 2px 0 rgba(0,0,0,.4);
}
.op-sub {
    margin: 0 0 18px; text-align: center;
    font-size: 13px; color: var(--text-dim); line-height: 1.75;
}
.op-sub b { color: var(--gold); font-weight: 800; }

/* 结束面板 */
.op-result { text-align: center; margin-bottom: 14px; }
.op-result .big-icon {
    display: inline-block;
    font-size: 56px; line-height: 1;
    margin-bottom: 8px;
}
.op-result .big-icon.win {
    color: var(--gold);
    text-shadow: 0 0 30px rgba(251,191,36,.95), 0 0 60px rgba(251,191,36,.5), 0 4px 0 var(--gold-dk);
    animation: popIn .55s cubic-bezier(.34,1.56,.64,1) both, floatWin 2.6s ease-in-out .6s infinite;
}
.op-result .big-icon.lose {
    color: var(--red);
    text-shadow: 0 0 26px rgba(248,113,113,.7), 0 4px 0 #7f1d1d;
    animation: popIn .55s cubic-bezier(.34,1.56,.64,1) both, shakeLose .45s ease-in-out .6s 2;
}
@keyframes popIn { from { opacity:0; transform: scale(.25) rotate(-16deg); } to { opacity:1; transform: scale(1) rotate(0); } }
@keyframes floatWin { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-9px)} }
@keyframes shakeLose { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-9px)} 75%{transform:translateX(9px)} }

.op-result h2 { margin: 0 0 2px; font-size: 24px; font-weight: 900; color: var(--text); }
.op-result h2.win { color: var(--gold); text-shadow: 0 0 18px rgba(251,191,36,.5); }
.op-result h2.lose { color: var(--red); text-shadow: 0 0 18px rgba(248,113,113,.5); }

.op-score {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 44px; font-weight: 900; color: var(--text);
    text-shadow: 0 0 24px rgba(124,92,255,.5);
    line-height: 1.08;
}
.op-score small {
    display: block; font-family: inherit; font-size: 10px;
    color: var(--text-mute); font-weight: 700; letter-spacing: 4px; margin-top: 2px;
}

/* 结束面板指标网格 */
.op-stats {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px; margin: 18px 0;
}
.op-stat {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 11px 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 11px;
    text-align: center;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.op-stat .glyphicon { font-size: 15px; color: var(--accent-lt); }
.op-stat b {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 15px; color: var(--text); font-weight: 900;
    font-variant-numeric: tabular-nums;
}
.op-stat span { font-size: 10px; color: var(--text-mute); letter-spacing: .5px; }

/* 按钮 */
.btn-game {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-width: 132px; height: 46px; padding: 0 22px;
    border: none; border-radius: 12px;
    font-size: 14px; font-weight: 900; letter-spacing: .5px;
    cursor: pointer; outline: none; text-decoration: none;
    transition: transform .1s, filter .15s, box-shadow .15s;
    font-family: inherit;
    position: relative;
}
.btn-game:active { transform: translateY(2px); }
.btn-game .glyphicon { font-size: 13px; }

.btn-gold {
    background: linear-gradient(180deg, var(--gold-lt) 0%, var(--gold) 45%, var(--gold-dk) 100%);
    color: #1c1917;
    box-shadow: 0 4px 0 #92400e, 0 6px 14px rgba(146,64,14,.4), inset 0 1px 0 rgba(255,255,255,.5);
    text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.btn-gold:hover {
    filter: brightness(1.08);
    color: #1c1917;
    text-decoration: none;
    box-shadow: 0 4px 0 #92400e, 0 8px 22px rgba(251,191,36,.6), inset 0 1px 0 rgba(255,255,255,.5);
}
.btn-gold:active { box-shadow: 0 2px 0 #92400e, 0 2px 6px rgba(146,64,14,.3), inset 0 1px 0 rgba(255,255,255,.5); }

.btn-accent {
    background: linear-gradient(180deg, var(--accent-lt) 0%, var(--accent) 45%, var(--accent-dk) 100%);
    color: #ffffff;
    box-shadow: 0 4px 0 #3b1f8a, 0 6px 14px rgba(59,31,138,.5), inset 0 1px 0 rgba(255,255,255,.25);
    text-shadow: 0 1px 0 rgba(0,0,0,.4);
}
.btn-accent:hover {
    filter: brightness(1.08);
    color: #ffffff;
    text-decoration: none;
    box-shadow: 0 4px 0 #3b1f8a, 0 8px 22px rgba(124,92,255,.7), inset 0 1px 0 rgba(255,255,255,.25);
}

.btn-ghost {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border-lt);
    box-shadow: 0 3px 0 #0a0e17, 0 4px 10px rgba(0,0,0,.4);
}
.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text);
    text-decoration: none;
    border-color: var(--accent);
    box-shadow: 0 3px 0 #0a0e17, 0 0 16px rgba(124,92,255,.4);
}

.btn-quiet {
    background: transparent;
    color: var(--text-mute);
    border: 1px solid var(--border);
    min-width: 104px;
}
.btn-quiet:hover {
    color: var(--text-dim);
    border-color: var(--border-lt);
    background: rgba(255,255,255,.03);
    text-decoration: none;
}

.op-actions {
    display: flex; flex-wrap: wrap; gap: 10px;
    justify-content: center; margin-top: 18px;
}
.op-hint {
    margin: 16px 0 0; text-align: center;
    font-size: 11px; color: var(--text-mute); line-height: 1.9;
}
.op-hint kbd {
    display: inline-block; padding: 2px 7px; margin: 0 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-lt);
    border-radius: 4px;
    box-shadow: 0 1px 0 rgba(0,0,0,.6);
    font-family: ui-monospace, monospace; font-size: 10px; color: var(--text-dim);
}

/* 关卡网格 */
.level-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 8px; margin: 12px 0 4px;
}
.level-cell {
    padding: 9px 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 11px;
    text-align: center; cursor: pointer;
    transition: all .15s;
    color: var(--text-dim);
    box-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.level-cell:hover {
    background: var(--bg-elevated);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 16px rgba(124,92,255,.35);
}
.level-cell.active {
    background: linear-gradient(180deg, rgba(124,92,255,.32), rgba(91,63,217,.18));
    border-color: var(--accent-lt);
    color: #fff;
    box-shadow: 0 3px 0 var(--accent-dk), 0 0 20px rgba(124,92,255,.5);
}
.level-cell.active small,
.level-cell.active .stars { color: var(--gold-lt); }
.level-cell b { display: block; font-size: 15px; font-weight: 900; }
.level-cell small { display: block; font-size: 9px; margin-top: 1px; color: var(--text-mute); }
.level-cell .stars { display: block; font-size: 10px; color: var(--gold); letter-spacing: 1px; margin-top: 1px; }

/* 选项卡 */
.mode-tabs {
    display: flex; gap: 6px; padding: 4px;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 12px; margin-bottom: 12px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
}
.mode-tab {
    flex: 1; padding: 8px 0;
    border: none; border-radius: 8px;
    background: transparent; color: var(--text-dim);
    font-size: 13px; font-weight: 800;
    cursor: pointer; font-family: inherit;
    transition: all .15s;
}
.mode-tab.active {
    background: linear-gradient(180deg, rgba(124,92,255,.4), rgba(91,63,217,.25));
    color: #fff;
    box-shadow: 0 2px 0 var(--accent-dk), inset 0 1px 0 rgba(255,255,255,.15);
}
.mode-tab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.05); }

/* 规则条目 */
.rule-list { display: flex; flex-direction: column; gap: 11px; }
.rule-item {
    display: flex; gap: 12px;
    padding: 11px 13px;
    background: var(--bg-card);
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.rule-item .glyphicon { color: var(--accent-lt); font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.rule-item h4 { margin: 0 0 3px; font-size: 13px; color: var(--accent-lt); font-weight: 900; }
.rule-item p { margin: 0; font-size: 12px; color: var(--text-dim); line-height: 1.75; }
.rule-item p b { color: var(--gold); font-weight: 800; }

/* 设置项 */
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 11px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px; color: var(--text);
    font-weight: 700;
}
.setting-row:last-of-type { border-bottom: none; }
.setting-row .glyphicon { margin-right: 6px; color: var(--accent-lt); }
.setting-row .mode-tabs { margin: 0; width: 220px; flex: 0 0 auto; }
.setting-row .mode-tab { font-size: 12px; padding: 6px 0; }

/* 顶部轻提示 */
.toast-tip {
    position: fixed; top: 72px; left: 50%;
    transform: translateX(-50%) translateY(-14px);
    padding: 10px 20px;
    background: linear-gradient(180deg, var(--bg-elevated), var(--bg-panel));
    border: 1px solid var(--accent);
    border-radius: 12px;
    color: var(--text); font-size: 13px; font-weight: 700;
    pointer-events: none; opacity: 0;
    transition: all .3s; z-index: 1500;
    box-shadow: 0 6px 24px rgba(0,0,0,.7), 0 0 20px rgba(124,92,255,.4);
}
.toast-tip.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================================================================
   响应式
   ================================================================ */
@media (max-width: 1080px) {
    .gb-title span { display: none; }
    .stat { padding: 0 6px; }
    .rift-bar { width: 58px; }
}
@media (max-width: 880px) {
    .gb-title { display: none; }
    .stat small { display: none; }
    .stat b { font-size: 12px; }
    .stat { height: 28px; padding: 0 5px; }
    .tbtn { width: 30px; height: 30px; font-size: 12px; }
    .gb-stats { gap: 3px; }
}
@media (max-width: 700px) {
    .stat.wpm, .stat.acc { display: none; }
    .rift-bar { width: 42px; }
    .op-stats { grid-template-columns: repeat(2, 1fr); }
    .overlay-panel { padding: 20px 18px; }
    .op-title { font-size: 21px; }
    .overlay { padding: 12px; }
}
@media (max-width: 520px) {
    .stat.combo { display: none; }
    .gb-tools .tbtn:nth-child(4) { display: none; }
}
@media (max-height: 500px) {
    .game-bar { height: 46px; }
    .op-result .big-icon { font-size: 38px; }
    .op-score { font-size: 32px; }
    .overlay { padding: 10px; }
}