* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    overflow: hidden;
    background: #070b10;
    color: #e8eef5;
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
#apps { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

#topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 14px;
    background: linear-gradient(180deg, #16202c 0%, #0f1720 100%);
    border-bottom: 1px solid #23303f;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .55);
    z-index: 30;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }

.brand {
    display: flex; align-items: center; gap: 6px;
    font-size: 15px; font-weight: 700; letter-spacing: .5px;
    color: #ffd166;
    margin-right: 14px;
    flex: 0 0 auto;
    text-shadow: 0 1px 6px rgba(255, 209, 102, .35);
}
.brand .glyphicon { font-size: 17px; }

.metrics {
    display: flex; align-items: center; gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.metrics::-webkit-scrollbar { display: none; }

.metric {
    display: inline-flex; align-items: center; gap: 5px;
    flex: 0 0 auto;
    font-size: 12.5px;
    color: #8fa6bd;
    background: rgba(255, 255, 255, .045);
    border: 1px solid rgba(255, 255, 255, .06);
    padding: 5px 11px;
    border-radius: 14px;
    line-height: 1;
    transition: background .2s, border-color .2s;
}
.metric .glyphicon { font-size: 12px; color: #5ea9ff; }
.metric b { color: #ffd166; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric.hot { border-color: rgba(255, 209, 102, .5); background: rgba(255, 209, 102, .1); }
.metric.hot .glyphicon { color: #ff8a3d; }

.actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-left: 12px; }
.actions .btn {
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1);
    color: #cfe0f0;
    border-radius: 8px;
    padding: 5px 11px;
    font-size: 12.5px;
    transition: all .18s;
}
.actions .btn:hover { background: rgba(94, 169, 255, .22); border-color: rgba(94, 169, 255, .55); color: #fff; }
.actions .btn:focus { outline: none; box-shadow: 0 0 0 2px rgba(94, 169, 255, .3); }
.actions .btn .glyphicon { margin-right: 3px; }

#stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 45%, #0e1a16 0%, #060a0d 75%);
}
#gameCanvas {
    position: absolute;
    display: block;
    border-radius: 10px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, .75), 0 0 0 1px rgba(255, 255, 255, .05);
    cursor: pointer;
}

/* =====================================================================
 * 弹出层：水平 + 垂直居中
 * ===================================================================== */
.modal { text-align: center; padding: 0 !important; }
.modal::before {
    content: '';
    display: inline-block;
    height: 100%;
    vertical-align: middle;
    margin-right: -4px;
}
.modal-dialog {
    display: inline-block;
    text-align: left;
    vertical-align: middle;
    margin: 10px auto;
    max-width: 92vw;
}
.modal-backdrop.in { opacity: .72; }

.game-modal {
    background: linear-gradient(180deg, #1b2634 0%, #121b26 100%);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .8);
    color: #dfe9f3;
    overflow: hidden;
}
.game-modal .modal-header {
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    padding: 18px 24px;
    background: linear-gradient(180deg, rgba(94, 169, 255, .12), transparent);
}
.game-modal .modal-title { font-size: 17px; font-weight: 700; color: #ffd166; letter-spacing: .5px; }
.game-modal .modal-title .glyphicon { margin-right: 6px; }
.game-modal .modal-body { padding: 22px 24px; }
.game-modal .modal-footer { border-top: 1px solid rgba(255, 255, 255, .08); padding: 16px 24px; }
.game-modal .modal-footer .btn + .btn { margin-left: 8px; }

.intro-text {
    font-size: 13.5px;
    color: #9fb3c8;
    line-height: 1.8;
    margin-bottom: 18px;
}

.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 9px;
    font-size: 13px;
    color: #b9cbd9;
    transition: background .18s;
}
.setting-row:last-child { margin-bottom: 0; }
.setting-row:hover { background: rgba(255, 255, 255, .07); }
.setting-row .glyphicon { color: #5ea9ff; margin-right: 7px; }

.setting-row .form-control {
    background-color: #1e2a3a;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%235ea9ff' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 10px 6px;
    border: 1px solid rgba(94, 169, 255, 0.3);
    color: #e8eef5;
    height: 30px;
    padding: 2px 28px 2px 10px;
    font-size: 12.5px;
    width: 156px;
    border-radius: 7px;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border-color .18s, box-shadow .18s;
}
.setting-row .form-control:hover { border-color: rgba(94, 169, 255, 0.6); }
.setting-row .form-control:focus {
    border-color: #5ea9ff;
    box-shadow: 0 0 0 2px rgba(94, 169, 255, 0.2);
    outline: none;
}
.setting-row .form-control option {
    background: #1b2634;
    color: #e8eef5;
    padding: 8px 10px;
    font-size: 13px;
}
.setting-row .form-control option:checked { background: #2a6fd4; color: #ffffff; }

.switch {
    position: relative; display: inline-block;
    width: 42px; height: 22px; margin: 0;
    flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0;
    background: rgba(255, 255, 255, .16);
    border-radius: 22px; cursor: pointer;
    transition: background .22s;
}
.switch .slider::before {
    content: ''; position: absolute;
    height: 16px; width: 16px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%;
    transition: transform .22s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.switch input:checked + .slider { background: linear-gradient(90deg, #3d8bfd, #5ea9ff); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.rule-table { width: 100%; font-size: 12.5px; color: #b9cbd9; border-collapse: separate; border-spacing: 0 5px; }
.rule-table td { padding: 7px 12px; background: rgba(255, 255, 255, .04); vertical-align: middle; }
.rule-table td:first-child { border-radius: 7px 0 0 7px; color: #ffd166; font-weight: 600; width: 100px; }
.rule-table td:last-child { border-radius: 0 7px 7px 0; }

.keycap {
    display: inline-block;
    min-width: 24px; padding: 3px 8px;
    margin: 0 2px;
    font-size: 11.5px; font-weight: 700;
    font-family: Consolas, Menlo, monospace;
    color: #ffd166;
    background: linear-gradient(180deg, #253243, #16202c);
    border: 1px solid rgba(255, 255, 255, .16);
    border-bottom-width: 2px;
    border-radius: 5px;
    line-height: 1.5;
    text-align: center;
}

.pause-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    flex-wrap: nowrap;
}
.pause-actions .btn {
    min-width: 140px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
    transition: all .18s;
    white-space: nowrap;
}

.result-title { font-size: 26px; font-weight: 800; letter-spacing: 3px; margin: 8px 0 16px; }
.result-title.win { color: #ffd166; text-shadow: 0 0 22px rgba(255, 209, 102, .75); animation: popIn .6s cubic-bezier(.2, 1.4, .5, 1) both; }
.result-title.lose { color: #ff6b6b; text-shadow: 0 0 22px rgba(255, 107, 107, .6); animation: shakeIt .7s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes popIn {
    0% { transform: scale(.4) rotate(-8deg); opacity: 0; }
    70% { transform: scale(1.12) rotate(2deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes shakeIt {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-12px) rotate(-3deg); }
    30% { transform: translateX(11px) rotate(3deg); }
    45% { transform: translateX(-8px) rotate(-2deg); }
    60% { transform: translateX(6px) rotate(2deg); }
    80% { transform: translateX(-3px); }
}

.stat-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 18px 0 8px; }
.stat-cell {
    flex: 1 1 120px; min-width: 120px;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 11px;
    padding: 14px 8px;
    text-align: center;
}
.stat-cell .glyphicon { font-size: 17px; color: #5ea9ff; display: block; margin-bottom: 7px; }
.stat-cell .v { font-size: 20px; font-weight: 800; color: #ffd166; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-cell .k { font-size: 11.5px; color: #7d94aa; margin-top: 4px; }

.btn-primary {
    background: linear-gradient(180deg, #3d8bfd, #2a6fd4);
    border: none; border-radius: 9px;
    font-weight: 600; letter-spacing: .5px;
    transition: all .18s;
}
.btn-primary:hover, .btn-primary:focus { background: linear-gradient(180deg, #5ea9ff, #3d8bfd); box-shadow: 0 6px 20px rgba(61, 139, 253, .45); }
.btn-default {
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .14);
    color: #cfe0f0; border-radius: 9px;
}
.btn-default:hover, .btn-default:focus { background: rgba(255, 255, 255, .14); color: #fff; border-color: rgba(255, 255, 255, .3); }

#fxCanvas {
    position: fixed;
    inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 20000;
    display: none;
}

#toastBox {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 21000;
    pointer-events: none;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.toast-item {
    background: rgba(20, 30, 42, .96);
    border: 1px solid rgba(94, 169, 255, .5);
    color: #e8eef5;
    padding: 10px 22px;
    border-radius: 11px;
    font-size: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .7), 0 0 24px rgba(94, 169, 255, .25);
    animation: toastIn .28s cubic-bezier(.2, 1.4, .5, 1) both;
    white-space: nowrap;
}
.toast-item.out { animation: toastOut .28s ease both; }
.toast-item .glyphicon { margin-right: 7px; color: #ffd166; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-14px) scale(.94); } }

@media (max-width: 860px) {
    .metric .label-text { display: none; }
    .brand span.brand-text { display: none; }
    .actions .btn .btn-text { display: none; }
    .actions .btn .glyphicon { margin-right: 0; }
}
@media (max-width: 640px) {
    #topbar { height: 50px; padding: 0 8px; }
    .metrics { gap: 5px; }
    .metric { padding: 3px 8px; font-size: 11.5px; }
    .stat-cell { flex: 1 1 100px; min-width: 100px; padding: 10px 6px; }
    .pause-actions .btn { min-width: 100px; font-size: 13px; padding: 8px 12px; }
}
@media (min-width: 768px) {
    .modal-dialog {
        min-width: auto;
        width: auto;
    }
}