
    * { box-sizing: border-box; user-select: none; font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif; }
    body { margin: 0; background: #0b0e14; color: #eaeaea; display: flex; flex-direction: column; align-items: center; padding: 8px; }
    #game-wrapper { position: relative; width: 1024px; height: 640px; border: 2px solid #354358; border-radius: 10px; overflow: hidden; box-shadow: 0 14px 40px rgba(0,0,0,0.85); background: #1e2621; }
    canvas { display: block; cursor: crosshair; }

    /* 頂部資訊列 */
    #hud-top { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 10; }
    .top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
    .stat-box { background: rgba(13, 18, 26, 0.92); border: 1px solid #41516b; padding: 6px 11px; border-radius: 6px; display: flex; gap: 12px; font-weight: bold; font-size: 13px; pointer-events: auto; align-items: center; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
    .stat-item span { color: #ffd166; }
    .lives-text span { color: #ff6b6b; }
    .hud-btn { background: #26354a; color: #f1f5f9; border: 1px solid #4d6485; padding: 5px 10px; border-radius: 4px; font-weight: bold; cursor: pointer; transition: 0.15s; font-size: 12px; }
    .hud-btn:hover:not(:disabled) { background: #364c6b; border-color: #ffd166; }
    .hud-btn.active-toggle { background: #1d4ed8; border-color: #60a5fa; color: #fff; }
    #btn-next-wave { background: #e63946; border-color: #ff758f; color: #fff; }
    #btn-next-wave:hover:not(:disabled) { background: #ff4d5a; transform: scale(1.02); }
    #btn-next-wave:disabled { background: #333942; border-color: #4b5563; color: #777; cursor: not-allowed; }

    /* 波次預覽與 Boss 血條 */
    #wave-preview-bar { background: rgba(15, 22, 32, 0.88); border: 1px solid #384860; padding: 4px 10px; border-radius: 5px; font-size: 12px; color: #cbd5e1; pointer-events: auto; display: flex; align-items: center; gap: 10px; }
    .preview-tag { background: #1e293b; border: 1px solid #475569; padding: 1px 7px; border-radius: 4px; font-size: 11px; color: #f8fafc; }
    .preview-warn { color: #fbbf24; font-weight: bold; }

    #boss-hud { display: none; background: rgba(20, 12, 16, 0.94); border: 1px solid #ef4444; border-radius: 6px; padding: 6px 14px; width: 620px; align-self: center; pointer-events: auto; box-shadow: 0 0 18px rgba(239, 68, 68, 0.45); }
    .boss-header { display: flex; justify-content: space-between; font-size: 13px; font-weight: bold; color: #fca5a5; margin-bottom: 4px; }
    .boss-bar-bg { width: 100%; height: 11px; background: #2a1215; border-radius: 5px; overflow: hidden; position: relative; border: 1px solid #7f1d1d; }
    .boss-bar-fill { height: 100%; background: linear-gradient(90deg, #dc2626, #f97316); width: 100%; transition: width 0.1s; }
    .boss-phase-tick { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: 0.7; }
    .boss-cast-bar { height: 5px; background: #38bdf8; width: 0%; margin-top: 3px; border-radius: 3px; transition: width 0.08s; }

    /* 底部英雄面板、指揮官技能與提示列 */
    #hud-bottom { position: absolute; bottom: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; z-index: 10; gap: 10px; }
    .bottom-left-group { display: flex; gap: 8px; align-items: flex-end; pointer-events: auto; }

    /* 英雄控制卡 */
    #hero-card { background: rgba(16, 23, 34, 0.95); border: 2px solid #38bdf8; border-radius: 8px; padding: 7px 11px; min-width: 255px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.6); }
    #hero-card.selected { border-color: #ffd166; box-shadow: 0 0 14px rgba(255, 209, 102, 0.65); }
    .hero-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: bold; }
    .hero-lv { background: #0284c7; color: #fff; padding: 1px 6px; border-radius: 4px; font-size: 11px; }
    .hero-bars { display: flex; flex-direction: column; gap: 3px; }
    .bar-wrap { width: 100%; height: 6px; background: #1e293b; border-radius: 3px; overflow: hidden; }
    .hp-fill { height: 100%; background: #22c55e; width: 100%; }
    .xp-fill { height: 100%; background: #eab308; width: 0%; }
    .hero-actions { display: flex; gap: 6px; margin-top: 3px; }
    .hero-btn { flex: 1; background: #1e293b; border: 1px solid #475569; color: #f8fafc; padding: 4px 7px; border-radius: 4px; font-size: 11px; font-weight: bold; cursor: pointer; transition: 0.15s; }
    .hero-btn:hover:not(:disabled) { border-color: #ffd166; background: #334155; }
    .hero-btn.active { background: #b45309; border-color: #fde047; }
    .hero-btn:disabled { opacity: 0.5; cursor: not-allowed; }

    .spell-bar { display: flex; gap: 8px; pointer-events: auto; }
    .spell-btn { background: rgba(16, 22, 32, 0.94); border: 2px solid #52637a; color: #fff; padding: 7px 11px; border-radius: 6px; cursor: pointer; min-width: 165px; text-align: left; transition: 0.15s; }
    .spell-btn.active { border-color: #ffd166; box-shadow: 0 0 12px rgba(255, 209, 102, 0.6); }
    .spell-btn:disabled { opacity: 0.5; cursor: not-allowed; }
    .spell-title { font-weight: bold; font-size: 13px; display: flex; justify-content: space-between; }
    .spell-desc { font-size: 11px; color: #94a3b8; margin-top: 2px; }

    #btn-cancel-action { display: none; background: #dc2626; color: #fff; border: 1px solid #fca5a5; padding: 7px 12px; border-radius: 6px; font-weight: bold; cursor: pointer; pointer-events: auto; font-size: 12px; }

    /* 建造與升級選單 */
    #tower-menu { position: absolute; display: none; background: rgba(14, 19, 28, 0.97); border: 1px solid #64748b; border-radius: 8px; padding: 10px; width: 295px; pointer-events: auto; z-index: 25; box-shadow: 0 8px 25px rgba(0,0,0,0.85); }
    #tower-menu h4 { margin: 0 0 6px 0; font-size: 14px; color: #ffd166; border-bottom: 1px solid #334155; padding-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
    .priority-row { display: flex; align-items: center; justify-content: space-between; background: #1e293b; padding: 4px 8px; border-radius: 4px; margin-bottom: 7px; font-size: 11px; color: #cbd5e1; }
    .priority-btn { background: #334155; color: #38bdf8; border: 1px solid #475569; padding: 2px 7px; border-radius: 3px; cursor: pointer; font-weight: bold; font-size: 11px; }
    .menu-btn { width: 100%; text-align: left; background: #1e293b; border: 1px solid #3b4d66; color: #eee; padding: 6px 9px; margin-bottom: 5px; border-radius: 5px; cursor: pointer; font-size: 12px; transition: 0.12s; }
    .menu-btn:hover:not(:disabled) { background: #2d3e57; border-color: #ffd166; }
    .menu-btn:disabled { opacity: 0.42; cursor: not-allowed; }
    .menu-btn small { display: block; color: #94a3b8; font-size: 11px; margin-top: 2px; }
    .stat-diff { color: #4ade80 !important; font-weight: bold; }
    .btn-rally { background: #1f3d33; border-color: #3b7a62; }
    .btn-sell { background: #451a20; border-color: #7f2d37; margin-bottom: 0; }

    /* 主選單（關卡、英雄專精、天賦樹） */
    #main-hub-overlay { position: absolute; inset: 0; background: linear-gradient(135deg, rgba(11, 15, 23, 0.98), rgba(20, 28, 42, 0.98)); z-index: 40; display: flex; flex-direction: column; padding: 16px 22px; }
    .hub-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; padding-bottom: 10px; margin-bottom: 12px; }
    .hub-title { font-size: 20px; font-weight: bold; color: #ffd166; display: flex; align-items: center; gap: 10px; }
    .star-wallet { background: #1e293b; border: 1px solid #fbbf24; padding: 5px 12px; border-radius: 18px; font-weight: bold; color: #fbbf24; font-size: 14px; }
    .hub-actions { display: flex; gap: 7px; align-items: center; }
    .small-action-btn { background: #283548; color: #e2e8f0; border: 1px solid #475569; padding: 5px 10px; border-radius: 5px; cursor: pointer; font-size: 12px; font-weight: bold; transition: 0.15s; }
    .small-action-btn:hover { background: #3b4f6b; border-color: #ffd166; color: #fff; }
    #btn-return-battle { display: none; background: #059669; border-color: #34d399; color: #fff; }

    .hub-body { display: grid; grid-template-columns: 1.05fr 1fr 1fr; gap: 14px; flex: 1; overflow: hidden; }
    .panel-box { background: rgba(15, 22, 34, 0.85); border: 1px solid #334155; border-radius: 8px; padding: 11px 13px; display: flex; flex-direction: column; overflow: hidden; }
    .panel-box h3 { margin: 0 0 9px 0; font-size: 14px; color: #38bdf8; border-bottom: 1px solid #263345; padding-bottom: 5px; }
    .scroll-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-right: 3px; flex: 1; }

    .level-card, .hero-select-card, .talent-card { background: #1e293b; border: 1px solid #3b4d66; border-radius: 6px; padding: 9px 11px; transition: 0.15s; }
    .hero-select-card.active-hero { border-color: #ffd166; background: #263449; box-shadow: 0 0 10px rgba(255, 209, 102, 0.25); }
    .card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
    .card-top h4 { margin: 0; font-size: 13.5px; color: #f8fafc; }
    .card-desc { margin: 0; font-size: 11.5px; color: #94a3b8; line-height: 1.35; }
    .spec-group { display: flex; gap: 6px; margin-top: 6px; }
    .spec-btn { flex: 1; background: #0f172a; border: 1px solid #475569; color: #cbd5e1; padding: 4px 6px; border-radius: 4px; font-size: 11px; cursor: pointer; text-align: left; }
    .spec-btn.active-spec { border-color: #38bdf8; background: #172554; color: #fff; }
    .btn-play-level { background: #10b981; color: #fff; border: none; padding: 6px 12px; border-radius: 5px; font-weight: bold; cursor: pointer; font-size: 12px; }
    .btn-play-level:hover { background: #059669; }

    .talent-pips { display: inline-flex; gap: 3px; margin-left: 6px; }
    .pip { width: 9px; height: 9px; border-radius: 2px; background: #334155; border: 1px solid #64748b; display: inline-block; }
    .pip.filled { background: #fbbf24; border-color: #fde047; }
    .btn-upgrade-talent { background: #3b82f6; color: #fff; border: none; padding: 5px 10px; border-radius: 5px; font-weight: bold; cursor: pointer; font-size: 11.5px; white-space: nowrap; }
    .btn-upgrade-talent:disabled { background: #334155; color: #64748b; cursor: not-allowed; }

    /* 戰地圖鑑彈窗 (Codex Modal) */
    #codex-modal { position: absolute; inset: 0; background: rgba(10, 14, 22, 0.97); z-index: 50; display: none; flex-direction: column; padding: 18px 24px; }
    .codex-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
    .tab-btn { background: #1e293b; color: #94a3b8; border: 1px solid #334155; padding: 7px 16px; border-radius: 6px; font-weight: bold; cursor: pointer; font-size: 13px; }
    .tab-btn.active { background: #0284c7; color: #fff; border-color: #38bdf8; }
    .codex-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; overflow-y: auto; flex: 1; padding-right: 6px; }
    .codex-item { background: #162030; border: 1px solid #334155; border-radius: 7px; padding: 10px 13px; font-size: 12px; }
    .codex-item h4 { margin: 0 0 4px 0; color: #ffd166; font-size: 14px; display: flex; justify-content: space-between; }
    .codex-tag { background: #334155; color: #38bdf8; padding: 1px 6px; border-radius: 4px; font-size: 11px; }
    .counter-tip { color: #4ade80; margin-top: 5px; font-weight: bold; }

    /* 戰後統計結算彈窗 */
    #result-modal { position: absolute; inset: 0; background: rgba(9, 13, 20, 0.9); z-index: 45; display: none; flex-direction: column; justify-content: center; align-items: center; }
    .result-box { background: #162032; border: 2px solid #475569; border-radius: 10px; padding: 20px 28px; width: 580px; box-shadow: 0 15px 45px rgba(0,0,0,0.9); }
    .result-top { text-align: center; border-bottom: 1px solid #334155; padding-bottom: 10px; margin-bottom: 12px; }
    .result-top h2 { margin: 0; font-size: 24px; }
    .result-stars { font-size: 28px; color: #fbbf24; margin: 4px 0; letter-spacing: 5px; }
    .stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 12px; margin-bottom: 12px; }
    .stat-panel { background: #0f172a; border: 1px solid #263345; border-radius: 6px; padding: 8px 10px; max-height: 150px; overflow-y: auto; }
    .stat-panel h5 { margin: 0 0 6px 0; color: #38bdf8; font-size: 12px; }
    .dmg-row { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 11.5px; }
    .advice-banner { background: rgba(251, 191, 36, 0.12); border: 1px solid #f59e0b; color: #fde68a; padding: 8px 11px; border-radius: 6px; font-size: 12px; margin-bottom: 14px; }
  