html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    overflow: hidden;
    background: #06101e;
    color: #dcecff;
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   顶部状态栏 —— 所有实时指标 & 操作按钮单行排列
   ============================================================ */
.tg-app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    height: 100vh;
    height: 100dvh;
}

.tg-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 56px;
    padding: 0 12px;
    box-sizing: border-box;
    background: linear-gradient(180deg, rgba(13, 26, 48, .98) 0%, rgba(7, 16, 32, .98) 100%);
    border-bottom: 1px solid rgba(80, 160, 255, .16);
    box-shadow: 0 2px 20px rgba(0, 0, 0, .5);
    position: relative;
    z-index: 30;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: none;
}
.tg-header::-webkit-scrollbar { display: none; height: 0; }

/* 品牌区 */
.tg-brand {
    display: flex; align-items: center; gap: 6px;
    flex: 0 0 auto;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .5px;
    color: #6fd3ff;
    text-shadow: 0 0 14px rgba(80, 190, 255, .55);
    padding-right: 12px;
    border-right: 1px solid rgba(80, 160, 255, .16);
}
.tg-brand .glyphicon { font-size: 17px; }
.tg-brand-text { font-size: 15px;font-weight:800;letter-spacing:1.2px;margin:0; }

/* 指标组 */
.tg-metrics {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
}

.tg-metric {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    flex: 0 0 auto;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(50, 110, 190, .12);
    border: 1px solid rgba(80, 160, 255, .14);
    font-size: 12px;
    line-height: 1;
    color: #9fc3e8;
    transition: background .2s, border-color .2s;
}
.tg-metric .glyphicon { font-size: 12px; position: relative; top: 1px; color: #57b7ff; }
.tg-metric-label { font-size: 11px; opacity: .78; }
.tg-metric-value {
    font-size: 15px;
    font-weight: 700;
    color: #eaf6ff;
    font-variant-numeric: tabular-nums;
    min-width: 12px;
    text-align: right;
}
.tg-metric-unit { font-size: 10px; opacity: .6; }
.tg-metric.hot { background: rgba(255, 140, 60, .16); border-color: rgba(255, 150, 60, .34); }
.tg-metric.hot .glyphicon { color: #ffa14a; }
.tg-metric.good { background: rgba(60, 200, 120, .14); border-color: rgba(70, 210, 130, .3); }
.tg-metric.good .glyphicon { color: #4ade80; }
.tg-metric.bad { background: rgba(240, 80, 80, .14); border-color: rgba(240, 90, 90, .32); }
.tg-metric.bad .glyphicon { color: #ff7676; }

/* 操作按钮组 */
.tg-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    margin-left: auto;
    padding-left: 10px;
    border-left: 1px solid rgba(80, 160, 255, .16);
}

.tg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    min-width: 32px;
    padding: 0 9px;
    border: 1px solid rgba(90, 170, 255, .28);
    border-radius: 8px;
    background: rgba(30, 70, 130, .3);
    color: #b8d8f8;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transition: all .16s ease;
    outline: none;
    white-space: nowrap;
}
.tg-btn:hover { background: rgba(50, 120, 210, .48); border-color: rgba(120, 200, 255, .6); color: #fff; transform: translateY(-1px); }
.tg-btn:active { transform: translateY(0) scale(.97); }
.tg-btn .glyphicon { font-size: 13px; }
.tg-btn.tg-btn-primary {
    background: linear-gradient(180deg, #2f8dff, #1867d6);
    border-color: #4aa3ff;
    color: #fff;
    box-shadow: 0 2px 12px rgba(40, 130, 255, .35);
}
.tg-btn.tg-btn-primary:hover { background: linear-gradient(180deg, #47a0ff, #2179ee); }
.tg-btn[disabled] { opacity: .38; cursor: not-allowed; transform: none; }

/* ============================================================
   游戏舞台
   ============================================================ */
.tg-stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background: #0a1830;
}

#tg_canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

/* 隐藏输入框：覆盖在文字面板上方，用于接收键盘 / 输入法 */
#tg_input {
    position: absolute;
    z-index: 5;
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    resize: none;
    overflow: hidden;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    opacity: .01;
    font-size: 16px;
    line-height: 1;
    -webkit-user-select: text;
    user-select: text;
    pointer-events: auto;
}
#tg_input::selection { background: transparent; }

/* 失焦提示 */
.tg-focus-hint {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    z-index: 8;
    padding: 12px 22px;
    border-radius: 12px;
    background: rgba(10, 26, 50, .9);
    border: 1px solid rgba(90, 180, 255, .5);
    color: #bfe4ff;
    font-size: 14px;
    pointer-events: none;
    animation: tgPulse 1.8s ease-in-out infinite;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
}
.tg-focus-hint .glyphicon { margin-right: 6px; color: #57b7ff; }
@keyframes tgPulse {
    0%, 100% { opacity: .75; transform: translate(-50%, -50%) scale(1); }
    50%      { opacity: 1;   transform: translate(-50%, -50%) scale(1.035); }
}

/* ============================================================
   Toast 提示 —— 水平垂直居中
   ============================================================ */
.tg-toast {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(.85);
    z-index: 2000;
    padding: 12px 26px;
    border-radius: 40px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .5px;
    color: #fff;
    background: rgba(20, 44, 78, .94);
    border: 1px solid rgba(90, 180, 255, .5);
    box-shadow: 0 12px 48px rgba(0, 0, 0, .7), 0 0 0 6px rgba(60, 150, 255, .08);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s cubic-bezier(.2, 1.5, .4, 1);
    white-space: nowrap;
}
.tg-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}
.tg-toast.ahead   { border-color: rgba(70, 220, 130, .7); box-shadow: 0 12px 48px rgba(0,0,0,.7), 0 0 40px rgba(60, 220, 130, .4); color: #b6ffd4; }
.tg-toast.behind  { border-color: rgba(255, 110, 110, .7); box-shadow: 0 12px 48px rgba(0,0,0,.7), 0 0 40px rgba(255, 90, 90, .4); color: #ffc2c2; }
.tg-toast.finish  { border-color: rgba(255, 214, 70, .8);  box-shadow: 0 12px 48px rgba(0,0,0,.7), 0 0 46px rgba(255, 210, 60, .55); color: #ffe9a0; }
.tg-toast.hint    { border-color: rgba(120, 190, 255, .6); color: #cfe8ff; font-size: 14px; font-weight: 500; }

/* ============================================================
   模态框：水平 + 垂直居中
   ============================================================ */
.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: 12px auto !important;
    max-width: 560px;
    width: calc(100% - 32px);
}
.modal-backdrop.in { opacity: .72; }

.tg-modal .modal-content {
    background: linear-gradient(180deg, rgba(18, 36, 64, .99), rgba(9, 20, 38, .99));
    border: 1px solid rgba(90, 175, 255, .3);
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .85), 0 0 0 1px rgba(120, 200, 255, .08) inset;
    color: #d8ecff;
    overflow: hidden;
}
.tg-modal .modal-header {
    border-bottom: 1px solid rgba(90, 175, 255, .16);
    padding: 16px 20px;
    text-align: center;
    position: relative;
}
.tg-modal .modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #eaf6ff;
    letter-spacing: 1px;
}
.tg-modal .modal-title .glyphicon { color: #57b7ff; margin-right: 8px; }
.tg-modal .modal-body { padding: 20px; }
.tg-modal .modal-footer {
    border-top: 1px solid rgba(90, 175, 255, .16);
    padding: 14px 20px;
    text-align: center;
}
.tg-modal .close {
    position: absolute;
    right: 14px; top: 12px;
    color: #9fc3e8;
    opacity: .6;
    text-shadow: none;
    font-size: 22px;
}
.tg-modal .close:hover { opacity: 1; color: #fff; }

/* 设置项 */
.tg-field { margin-bottom: 16px; }
.tg-field:last-child { margin-bottom: 0; }
.tg-field-label {
    display: block;
    font-size: 12px;
    color: #8fb8dd;
    margin-bottom: 7px;
    letter-spacing: .5px;
}
.tg-field-label .glyphicon { margin-right: 5px; color: #57b7ff; }

.tg-seg { display: flex; gap: 8px; flex-wrap: wrap; }
.tg-seg label {
    flex: 1 1 0;
    min-width: 74px;
    margin: 0;
    padding: 9px 6px;
    text-align: center;
    border-radius: 10px;
    border: 1px solid rgba(90, 170, 255, .24);
    background: rgba(30, 66, 120, .3);
    font-size: 13px;
    font-weight: 500;
    color: #b6d4f0;
    cursor: pointer;
    transition: all .16s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tg-seg label:hover { background: rgba(48, 104, 180, .46); border-color: rgba(120, 200, 255, .5); }
.tg-seg input { position: absolute; opacity: 0; pointer-events: none; }
.tg-seg input:checked + label,
.tg-seg label.active {
    background: linear-gradient(180deg, #2f8dff, #1867d6);
    border-color: #6bb6ff;
    color: #fff;
    box-shadow: 0 3px 16px rgba(40, 130, 255, .42);
}
.tg-seg label .glyphicon { display: block; font-size: 15px; margin-bottom: 3px; }

/* 下拉选择 */
.tg-select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(90, 170, 255, .24);
    background: rgba(20, 46, 84, .9);
    color: #d8ecff;
    font-size: 13px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%237ab8f0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 11px;
}
.tg-select option { background: #12294a; color: #d8ecff; }

/* 规则列表 */
.tg-rules { margin: 0; padding: 0; list-style: none; }
.tg-rules li {
    position: relative;
    padding: 9px 0 9px 30px;
    font-size: 13px;
    line-height: 1.65;
    color: #b8d4ee;
    border-bottom: 1px dashed rgba(90, 170, 255, .12);
}
.tg-rules li:last-child { border-bottom: 0; }
.tg-rules li .glyphicon {
    position: absolute;
    left: 4px; top: 11px;
    font-size: 13px;
    color: #57b7ff;
}
.tg-rules li b { color: #eaf6ff; }
.tg-rules li .kbd {
    display: inline-block;
    padding: 1px 7px;
    margin: 0 2px;
    border-radius: 5px;
    background: rgba(80, 150, 240, .22);
    border: 1px solid rgba(110, 190, 255, .35);
    font-size: 11px;
    color: #bfe4ff;
    font-family: Consolas, Monaco, monospace;
}

/* ============================================================
   结算面板
   ============================================================ */
.tg-result-card { text-align: center; }
.tg-result-icon {
    font-size: 54px;
    line-height: 1;
    margin-bottom: 6px;
    display: block;
    animation: tgPop .6s cubic-bezier(.2, 1.6, .4, 1) both;
}
.tg-result-icon.win  { color: #ffd54a; text-shadow: 0 0 40px rgba(255, 210, 60, .8); }
.tg-result-icon.lose { color: #ff7d7d; text-shadow: 0 0 40px rgba(255, 100, 100, .7); }
@keyframes tgPop {
    0%   { transform: scale(.2) rotate(-25deg); opacity: 0; }
    60%  { transform: scale(1.22) rotate(6deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
.tg-result-title {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 2px;
    margin: 0 0 4px;
    animation: tgPop .6s .08s cubic-bezier(.2, 1.6, .4, 1) both;
}
.tg-result-title.win  { color: #ffe27a; text-shadow: 0 0 30px rgba(255, 210, 60, .6); }
.tg-result-title.lose { color: #ff9c9c; text-shadow: 0 0 30px rgba(255, 100, 100, .5); }
.tg-result-sub { font-size: 12px; color: #8fb8dd; margin-bottom: 16px; letter-spacing: 1px; }

.tg-result-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}
.tg-result-item {
    padding: 10px 4px;
    border-radius: 10px;
    background: rgba(40, 84, 150, .26);
    border: 1px solid rgba(90, 170, 255, .16);
}
.tg-result-item .glyphicon { font-size: 15px; color: #57b7ff; display: block; margin-bottom: 5px; }
.tg-result-item .val {
    font-size: 17px;
    font-weight: 700;
    color: #eaf6ff;
    display: block;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.tg-result-item .lbl { font-size: 11px; color: #8fb8dd; display: block; margin-top: 2px; }

.tg-result-banner {
    display: inline-block;
    padding: 6px 18px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 14px;
}
.tg-result-banner.win  { background: rgba(255, 200, 40, .16); border: 1px solid rgba(255, 210, 60, .5); color: #ffe27a; }
.tg-result-banner.lose { background: rgba(255, 90, 90, .14);  border: 1px solid rgba(255, 110, 110, .45); color: #ff9c9c; }

.tg-newbest {
    display: inline-block;
    padding: 4px 14px;
    margin-bottom: 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    color: #10233e;
    background: linear-gradient(90deg, #ffe066, #ffb300);
    box-shadow: 0 0 26px rgba(255, 200, 60, .7);
    animation: tgBlink 1.1s ease-in-out infinite;
}
@keyframes tgBlink { 0%,100% { opacity: 1; } 50% { opacity: .62; } }

.tg-modal.tg-shake .modal-content { animation: tgShake .5s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes tgShake {
    10%, 90% { transform: translateX(-3px); }
    20%, 80% { transform: translateX(5px); }
    30%, 50%, 70% { transform: translateX(-8px); }
    40%, 60% { transform: translateX(8px); }
}

/* ============================================================
   撒花 / 特效画布
   ============================================================ */
#fx_canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1090;
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 900px) {
    .tg-brand-text { display: none; }
    .tg-metric-label { display: none; }
    .tg-metric { padding: 4px 8px; }
}
@media (max-width: 640px) {
    .tg-header { height: 50px; padding: 0 8px; gap: 6px; }
    .tg-metric { padding: 3px 7px; font-size: 11px; }
    .tg-metric-value { font-size: 13px; }
    .tg-btn { height: 30px; min-width: 30px; padding: 0 7px; }
    .tg-btn .tg-btn-text { display: none; }
    .tg-result-grid { grid-template-columns: repeat(2, 1fr); }
    .tg-result-title { font-size: 20px; }
}
@media (max-height: 520px) {
    .tg-header { height: 46px; }
}