        :root {
            --bg-color: #1a1a1a;
            --surface-color: #2c2c2c;
            --primary-color: #f0a048;
            --text-color: #e0e0e0;
            --border-color: #444;
            --shadow-color: rgba(0, 0, 0, 0.5);
            --locked-game-scale: 1;
            --game-stage-scale: 1;
            --battlefield-height: 720px;
            --game-stage-height: 720px;
            --game-stage-origin: center center;
            --game-stage-margin-top: 0px;
            --game-stage-align: auto;
        }
        html {
            touch-action: manipulation;
            overscroll-behavior: none;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        body {
            font-family: 'Noto Sans SC', sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100vh;
            height: 100dvh;
            box-sizing: border-box;
            overflow: hidden;
        }
        .screen {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
            background-color: var(--surface-color);
            padding: 30px;
            border-radius: 0;
            width: 100%;
            max-width: 900px;
            box-shadow: 0 0 30px var(--shadow-color);
            box-sizing: border-box;
        }

        #selection-screen { gap: 16px; overflow: hidden; }
        #selection-screen h1 {
            color: var(--primary-color);
            margin: 0;
        }
        #selection-slots {
            display: flex;
            gap: 10px;
            border: 2px solid var(--border-color);
            padding: 15px;
            border-radius: 0;
            background-color: #1f1f1f;
            min-height: 100px;
            overflow-x: auto;
            overflow-y: hidden;
        }
        .slot {
            width: 80px;
            height: 80px;
            border: 2px dashed var(--border-color);
            border-radius: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .slot .tower-card {
            width: 100%;
            height: 100%;
            cursor: pointer;
        }
        #selection-main {
            display: flex;
            gap: 20px;
            width: 100%;
            min-height: 0;
        }
        #tower-pool {
            flex-grow: 1;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
            gap: 10px;
            max-height: 400px;
            overflow-y: auto;
            padding: 10px;
            background-color: #1f1f1f;
            border-radius: 0;
        }
        .tower-card {
            background-color: #383838;
            border: 2px solid var(--border-color);
            border-radius: 0;
            padding: 5px;
            display: flex;
            flex-direction: column;
            align-items: center;
            cursor: pointer;
            transition: all 0.2s ease;
            position: relative;
        }
        .tower-card:hover {
            transform: scale(1.05);
            border-color: var(--primary-color);
        }
        .tower-card.selected {
            border-color: var(--primary-color);
            box-shadow: 0 0 10px var(--primary-color);
        }
        .tower-card.disabled {
            opacity: 0.4;
            cursor: not-allowed;
            transform: none;
            border-color: var(--border-color);
        }
        .tower-card canvas {
            width: 50px;
            height: 50px;
        }
        .tower-card .name {
            font-size: 0.9em;
            font-weight: bold;
            margin-top: 5px;
        }
        .tower-card .cost {
            font-size: 0.8em;
            color: #ffd700;
        }
        #selection-info {
            width: 250px;
            flex-shrink: 0;
            background-color: #1f1f1f;
            padding: 20px;
            border-radius: 0;
            border: 2px solid var(--border-color);
        }
        #selection-info h4 {
            margin: 0 0 10px 0;
            color: var(--primary-color);
        }
        #selection-info p {
            margin: 0;
            font-size: 0.9em;
            color: var(--text-color);
        }
        #selection-buttons-container {
            display: flex;
            gap: 20px;
            margin-top: 20px;
            width: 100%;
            justify-content: center;
            flex-wrap: wrap;
        }
        .selection-btn {
            color: var(--bg-color);
            font-weight: bold; padding: 12px 25px; font-size: 1.1em;
            border: none; border-radius: 0; cursor: pointer;
            transition: all 0.2s ease;
        }
        #select-map-btn {
             background-color: var(--primary-color);
        }
        #start-game-test-btn {
            background-color: #4dd0e1;
        }
        .selection-btn:disabled {
            background-color: #555;
            color: #888;
            cursor: not-allowed;
        }
        .selection-btn:not(:disabled):hover {
            transform: scale(1.05);
        }

        #map-selection-screen {
            display: none;
            width: min(900px, calc(100vw - 28px));
            height: min(720px, calc(100vh - 28px));
            max-width: none;
            max-height: none;
            box-sizing: border-box;
            overflow: hidden;
        }
        #map-selection-screen h1 {
            color: var(--primary-color);
            margin: 0 0 12px 0;
            flex-shrink: 0;
        }
        #map-list {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 14px;
            width: 100%;
            margin: 0;
            flex: 1 1 auto;
            min-height: 0;
            overflow: hidden;
            align-content: center;
        }
        .map-card {
            border: 3px solid var(--border-color);
            border-radius: 0;
            padding: 8px;
            cursor: pointer;
            transition: all 0.2s ease-in-out;
            background-color: #1f1f1f;
            display: flex;
            flex-direction: column;
            align-items: center;
            overflow: hidden;
        }
        .map-card:hover {
            transform: translateY(-3px);
            border-color: var(--primary-color);
        }
        .map-card.selected {
            border-color: var(--primary-color);
            box-shadow: 0 0 15px var(--primary-color);
            transform: translateY(-3px);
        }
        .map-card canvas {
            width: 100%;
            height: auto;
            aspect-ratio: 250 / 180;
            display: block;
            background-color: var(--surface-color);
            border-radius: 0;
        }
        .map-card .map-name {
            text-align: center;
            font-weight: bold;
            font-size: 1.05em;
            margin-top: 6px;
            color: var(--text-color);
        }
        .map-card .map-modifier {
            text-align: center;
            font-size: 0.8em;
            margin-top: 3px;
            color: var(--primary-color);
            min-height: 1.1em;
        }
        #map-selection-buttons-container {
             display: flex;
             gap: 20px;
             justify-content: center;
             width: 100%;
             flex: 0 0 auto;
             flex-shrink: 0;
        }

        #game-wrapper {
            display: none;
            width: 1560px;
            height: var(--game-stage-height);
            max-width: none;
            transform: scale(var(--game-stage-scale));
            transform-origin: var(--game-stage-origin, center center);
            align-self: var(--game-stage-align, auto);
            margin-top: var(--game-stage-margin-top, 0px);
            will-change: transform;
        }
        #game-container {
            position: relative;
            display: flex;
            gap: 20px;
            flex-wrap: nowrap;
            justify-content: center;
            align-items: flex-start;
            width: 1400px;
            margin-left: 160px;
            height: 100%;
        }
        #canvas-container {
             position: relative;
             flex-shrink: 0;
             width: 1000px;
             min-width: 1000px;
             max-width: 1000px;
             height: var(--battlefield-height);
             box-sizing: border-box;
             box-shadow: 0 0 20px var(--shadow-color);
             border-radius: 0;
             overflow: hidden;
             border: 2px solid var(--border-color);
        }

        #backgroundCanvas, #gameCanvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: block;
            border-radius: 0;
        }
        #backgroundCanvas {
            background-color: var(--surface-color);
            z-index: 1;
        }
        #gameCanvas {
            background-color: transparent;
            z-index: 2;
            cursor: pointer;
        }
        #wave-countdown {
            position: absolute;
            z-index: 3;
            top: 22px;
            left: 50%;
            transform: translateX(-50%) translateY(-10px);
            padding: 10px 18px;
            color: var(--text-color);
            font-size: 18px;
            font-weight: 700;
            letter-spacing: 1px;
            white-space: nowrap;
            background: linear-gradient(160deg, #3b3b3b, #282828);
            border: 2px solid var(--primary-color);
            border-radius: 0;
            box-shadow: 0 6px 18px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.05);
            opacity: 0;
            pointer-events: none;
            transition: opacity .2s ease, transform .2s ease;
        }
        #wave-countdown.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
        #skill-rail {
            position: absolute;
            z-index: 8;
            top: 0;
            left: -160px;
            width: 140px;
            display: flex;
            flex-direction: column;
            gap: 10px;
            pointer-events: auto;
        }
        .skill-rail-slot {
            position: relative;
            min-height: 92px;
            padding: 10px 8px 8px;
            background: linear-gradient(160deg, #313131, #242424);
            border: 2px solid #5a4632;
            color: var(--text-color);
            cursor: pointer;
            overflow: hidden;
            text-align: center;
            transition: border-color .16s ease, background-color .16s ease, filter .16s ease;
        }
        .skill-rail-slot:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
        .skill-rail-slot.ready { border-color: var(--primary-color); box-shadow: inset 0 0 12px rgba(240,160,72,.16), 0 0 12px rgba(240,160,72,.28); }
        .skill-rail-slot.ready:hover { background: linear-gradient(160deg, #414141, #2b2b2b); }
        .skill-rail-slot.active { border-color: var(--primary-color); box-shadow: inset 0 0 16px rgba(240,160,72,.18); }
        .skill-rail-slot.cooldown { filter: grayscale(1); color: #8a8a8a; cursor: not-allowed; }
        .skill-rail-icon { display: block; width: 42px; height: 42px; margin: 0 auto 5px; color: var(--skill-color); filter: drop-shadow(0 0 5px color-mix(in srgb, var(--skill-color) 65%, transparent)); }
        .skill-rail-slot.cooldown .skill-rail-icon { color: #777; filter: none; }
        .skill-rail-name { display: block; font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .skill-cooldown { position: absolute; top: 5px; right: 6px; min-width: 22px; padding: 2px 4px; background: #171717; border: 1px solid #666; color: #ddd; font-size: 13px; font-weight: 700; line-height: 1; }
        #floating-info-panel { animation: none; }
        #floating-info-panel .action-btn:hover { transform: none; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
        .target-selector { display: grid; grid-template-columns: 34px minmax(0, 1fr) 34px; align-items: center; min-height: 34px; background: #252525; border: 1px solid #5b5b5b; }
        .target-selector-label { text-align: center; color: #ddd; font-size: .86em; font-weight: 700; white-space: nowrap; }
        .target-selector-readonly { grid-template-columns: minmax(0, 1fr); background: #202020; border-color: #4a4a4a; }
        .target-cycle { width: 34px; height: 32px; padding: 0; border: 0; border-radius: 0; background: #404040; color: var(--primary-color); font-size: 20px; line-height: 1; cursor: pointer; }
        .target-cycle:hover { background: #505050; transform: none; }
        #settings-dock { position: absolute; z-index: 9; left: -160px; bottom: 0; width: 140px; display: flex; flex-direction: column; gap: 10px; }
        #pause-row, #settings-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; width: 100%; }
        #pause-row.single-control, #settings-row.single-control { grid-template-columns: minmax(0, 1fr); }
        #pause-button, #settings-button, #quick-restart-btn, #abandon-button { min-height: 86px; display: grid; place-items: center; gap: 5px; padding: 10px; color: var(--text-color); background: linear-gradient(160deg, #313131, #242424); border: 2px solid var(--primary-color); border-radius: 0; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
        #quick-restart-btn[hidden], #abandon-button[hidden] { display: none !important; }
        #pause-button:hover, #settings-button:hover, #quick-restart-btn:hover, #abandon-button:hover { background: linear-gradient(160deg, #414141, #2b2b2b); }
        #pause-button.is-paused { color: #ffd48b; border-color: #ffd48b; }
        #pause-button:focus-visible, #settings-button:focus-visible, #quick-restart-btn:focus-visible, #abandon-button:focus-visible, .settings-slider:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
        #pause-button svg, #settings-button svg, #quick-restart-btn svg, #abandon-button svg { width: 34px; height: 34px; color: var(--primary-color); }
        #pause-button span, #settings-button span, #quick-restart-btn span, #abandon-button span { font-size: 13px; font-weight: 700; }
        .settings-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
        .settings-row output { color: #ffd700; font-weight: 700; }
        .settings-slider { grid-column: 1 / -1; width: 100%; accent-color: var(--primary-color); cursor: pointer; }
        @media (prefers-reduced-motion: reduce) { .skill-rail-slot, #floating-info-panel .action-btn { transition: none; } .replay-command-loader span, .replay-tower-cue, .replay-tower-cue::before { animation: none; } }

        #ui-panel {
            background-color: var(--surface-color);
            padding: 20px;
            border-radius: 0;
            border: 2px solid var(--border-color);
            width: 300px;
            display: flex;
            flex-direction: column;
            gap: 15px;
            box-shadow: 0 0 20px var(--shadow-color);
            flex-shrink: 0;
            height: var(--battlefield-height);
            box-sizing: border-box;
        }
        .stats-display {
            background-color: #383838;
            padding: 15px;
            border-radius: 0;
            display: flex;
            flex-direction: column;
            gap: 12px;
            border-left: 4px solid var(--primary-color);
        }
        .stats-display div {
            font-size: 1.1em;
            font-weight: bold;
        }
        #tower-selection {
            display: flex;
            flex-direction: column;
            flex-grow: 1;
            min-height: 0;
        }
        #tower-buttons-list {
            flex-grow: 1;
            display: flex;
            flex-direction: column;
            gap: 5px;
        }

        #replay-command-panel {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 11px;
            padding: 20px 14px;
            text-align: center;
        }
        .replay-command-loader { position: relative; width: 62px; height: 62px; filter: drop-shadow(0 0 8px rgba(255,255,255,.2)); }
        .replay-command-loader span { position: absolute; inset: 0; border: 3px solid transparent; border-top-color: #fff; border-right-color: rgba(255,255,255,.52); border-radius: 50%; animation: replayCommandSpin 1.35s linear infinite; }
        .replay-command-loader span:nth-child(2) { inset: 10px; border-top-color: #f5f1e8; border-left-color: rgba(255,255,255,.48); animation-duration: .95s; animation-direction: reverse; }
        .replay-command-loader span:nth-child(3) { inset: 22px; border-width: 3px; border-top-color: #fff; border-right-color: rgba(255,255,255,.6); animation-duration: .7s; }
        .replay-command-copy h4 { margin: 0; color: #f7f3ea; font-size: 1.08em; letter-spacing: .8px; }
        .replay-command-copy p { margin: 7px 0 0; color: #b8b4ae; font-size: .82em; line-height: 1.5; }
        .replay-command-stale { margin: 0; color: #ff7777; font-size: .76em; font-weight: 800; letter-spacing: .35px; }
        #replay-return-btn { width: min(100%, 216px); margin-top: 5px; padding: 9px 13px; border-color: #a87838; background: linear-gradient(180deg, #4e4030, #38312a); color: #ffe1af; font-weight: 700; }
        #replay-return-btn:hover { background: linear-gradient(180deg, #6a5237, #453729); }
        @keyframes replayCommandSpin { to { transform: rotate(360deg); } }
        .replay-tower-cue { position: absolute; z-index: 5; display: grid; place-items: center; width: 30px; height: 30px; margin: -15px 0 0 -15px; pointer-events: none; animation: replayTowerCueRise .78s cubic-bezier(.18,.78,.3,1) forwards; }
        .replay-tower-cue::before { content: ''; position: absolute; inset: 1px; border: 1px solid currentColor; border-radius: 50%; opacity: .64; transform: scale(.7); animation: replayTowerCueRing .78s ease-out forwards; }
        .replay-tower-cue span { position: relative; color: currentColor; font: 900 24px/1 Arial, sans-serif; text-shadow: 0 0 8px currentColor, 0 1px 2px #000; }
        .replay-tower-cue.upgrade { color: #9bf172; }
        .replay-tower-cue.skill { color: #ffe082; }
        .replay-tower-cue.deploy { color: #ffb968; }
        .replay-tower-cue.target { color: #e8e4dc; }
        @keyframes replayTowerCueRise { 0% { transform: translateY(6px) scale(.7); opacity: 0; } 22% { opacity: 1; } 100% { transform: translateY(-28px) scale(1.08); opacity: 0; } }
        @keyframes replayTowerCueRing { 0% { transform: scale(.55); opacity: .82; } 100% { transform: scale(1.45); opacity: 0; } }
        h3 {
            margin: 0 0 10px 0;
            color: var(--primary-color);
            border-bottom: 2px solid var(--border-color);
            padding-bottom: 8px;
            font-size: 1.3em;
        }
        .tower-btn, .action-btn {
            background-color: #4a4a4a;
            color: var(--text-color);
            border: 1px solid #666;
            border-radius: 0;
            cursor: pointer;
            transition: all 0.2s ease;
            font-size: 1em;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .action-btn {
            padding: 12px 15px;
            text-align: center;
        }
        .tower-btn {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 4px 15px;
            flex: 1;
            min-height: 0;
        }
        .tower-btn .btn-canvas {
            width: 40px;
            height: 40px;
            background-color: #333;
            border-radius: 0;
            flex-shrink: 0;
        }
        .tower-btn .btn-info {
            flex-grow: 1;
        }
        .tower-btn .btn-info .cost {
            float: right;
            font-weight: bold;
            color: #ffd700;
        }
        .tower-btn:hover, .action-btn:hover {
            background-color: #5a5a5a;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.3);
        }
        .tower-btn.selected {
            background-color: var(--primary-color);
            color: var(--bg-color);
            font-weight: bold;
            border-color: var(--primary-color);
        }
        .tower-btn:disabled, .action-btn:disabled {
            background-color: #333;
            color: #777;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        #floating-info-panel {
            display: none;
            position: absolute;
            background-color: rgba(44, 44, 44, 0.9);
            border: 1px solid var(--primary-color);
            border-radius: 0;
            padding: 15px;
            width: 220px;
            z-index: 10;
            backdrop-filter: blur(5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            color: var(--text-color);
            font-size: 0.9em;
        }
        #floating-info-panel h4 { margin: 0 0 10px 0; padding-bottom: 5px; border-bottom: 1px solid var(--border-color); color: var(--primary-color); }
        #floating-info-panel ul { list-style: none; padding: 0; margin: 0 0 10px 0; }
        #floating-info-panel li { margin-bottom: 5px; }
        #floating-info-panel .actions { display: flex; flex-direction: column; gap: 8px; }
        #floating-info-panel .action-btn { width: 100%; padding: 8px; font-size: 0.9em; }
        #floating-info-panel .cost { font-weight: bold; color: #ffd700; }
        .tower-total-damage { margin: 0 0 8px; color: #d5c2a4; font-size: .9em; }
        .tower-total-damage span { color: #ffd700; font-size: 1.14em; font-weight: 800; font-variant-numeric: tabular-nums; }
        #floating-info-panel.modern-detail {
            position: fixed !important;
            display: grid !important;
            grid-template-columns: 164px minmax(0, 1fr) 238px;
            gap: 0;
            align-items: stretch;
            left: var(--modern-panel-left, 0px) !important;
            top: var(--modern-panel-top, 0px) !important;
            width: var(--modern-panel-width, 1000px);
            height: 180px;
            min-height: 0;
            padding: 0;
            box-sizing: border-box;
            overflow: hidden;
            background: linear-gradient(135deg, #262626, #1c1c1c 62%, #252525);
            border: 2px solid var(--primary-color);
            box-shadow: 0 10px 24px rgba(0,0,0,.55);
        }
        .modern-tower-visual { display: grid; place-items: center; padding: 14px; border-right: 1px solid rgba(240,160,72,.45); background: radial-gradient(circle at 50% 42%, rgba(255,255,255,.08), transparent 60%); }
        .modern-tower-visual canvas { width: 126px; height: 126px; }
        .modern-detail-content { min-width: 0; min-height: 0; height: 100%; padding: 14px 24px 12px; box-sizing: border-box; display: flex; flex-direction: column; overflow: hidden; }
        #floating-info-panel.modern-detail h4 { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; margin: 0 0 10px; padding-bottom: 7px; border-bottom: 1px solid rgba(240,160,72,.28); font-size: 1.2em; flex-shrink: 0; }
        #floating-info-panel.modern-detail h4 .tower-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        #floating-info-panel.modern-detail .tower-total-damage { margin: 0; flex-shrink: 0; font-size: .82em; line-height: 1.2; }
        #floating-info-panel.modern-detail ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; row-gap: 5px; margin: 0; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; scrollbar-width: thin; scrollbar-color: var(--primary-color) #1b1b1b; }
        #floating-info-panel.modern-detail ul::-webkit-scrollbar { width: 8px; }
        #floating-info-panel.modern-detail ul::-webkit-scrollbar-track { background: #1b1b1b; }
        #floating-info-panel.modern-detail ul::-webkit-scrollbar-thumb { background: var(--primary-color); border-radius: 0; }
        #floating-info-panel.modern-detail ul::-webkit-scrollbar-thumb:hover { background: #ffd684; }
        #floating-info-panel.modern-detail li { margin: 0; }
        #floating-info-panel.modern-detail .actions { padding: 14px; border-left: 1px solid rgba(240,160,72,.45); background: rgba(255,255,255,.025); justify-content: center; overflow: hidden; }
        #floating-info-panel.modern-detail .action-btn, #floating-info-panel.modern-detail .target-selector { min-height: 38px; }
        .stat-buffed { color: #4dd0e1; font-weight: bold; }
        #tooltip { display: none; position: fixed; background-color: rgba(26, 26, 26, 0.9); border: 1px solid var(--primary-color); border-radius: 0; padding: 10px; z-index: 1000; max-width: 220px; pointer-events: none; font-size: 0.9em; }
        #modal, #confirm-modal, #abandon-confirm-modal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.8); justify-content: center; align-items: center; animation: fadeIn 0.3s; }
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
        #modal-content, #confirm-modal-content, #abandon-confirm-content { background-color: var(--surface-color); padding: 30px 40px; border: 2px solid var(--primary-color); border-radius: 0; text-align: center; width: 80%; max-width: 450px; box-shadow: 0 0 30px var(--shadow-color); }
        #modal-content h2 { margin-top: 0; color: var(--primary-color); font-size: 2em; }
        #confirm-modal-content h2, #abandon-confirm-content h2 { margin-top: 0; color: var(--primary-color); font-size: 1.8em; }
        #restart-btn { background-color: var(--primary-color); color: var(--bg-color); font-weight: bold; padding: 12px 25px; font-size: 1.1em; border: none; border-radius: 0; cursor: pointer; transition: all 0.2s ease; }
        #restart-btn:hover { transform: scale(1.05); }

        .modal-actions, .confirm-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }
        #replay-btn { background-image: linear-gradient(180deg, #7ed47e, #43a047); color: #0e2410; font-weight: bold; padding: 12px 25px; font-size: 1.1em; border: none; border-radius: 0; cursor: pointer; transition: all 0.2s ease; }
        #replay-btn:hover { transform: scale(1.05); }
        .confirm-actions .action-btn { padding: 10px 24px; font-size: 1.05em; font-weight: bold; }
        #confirm-restart-yes { background-image: linear-gradient(180deg, #ff8a65, #f4511e); color: #fff; border-color: #f4511e; }
        #confirm-restart-no { background-color: #555; }
        #confirm-abandon-yes { background-image: linear-gradient(180deg, #ef6c62, #b83d35); border-color: #ef6c62; color: #fff; }
        #confirm-abandon-no { background: #555; }

        #announcement-modal { display: none; position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,0.82); justify-content: center; align-items: center; animation: fadeIn 0.3s; }
        #announcement-content {
            position: relative; background: linear-gradient(160deg, #2f2f2f, #232323);
            border: 2px solid var(--primary-color); box-shadow: 0 0 36px var(--shadow-color);
            width: 92%; max-width: 720px; max-height: 86vh; display: flex; flex-direction: column;
            animation: popIn .4s cubic-bezier(.2,.8,.3,1.1) both; box-sizing: border-box;
        }
        #announcement-content > h2 {
            margin: 0; padding: 18px 24px 12px; color: var(--primary-color); font-size: 1.5em;
            text-align: center; border-bottom: 1px solid var(--border-color);
            background: linear-gradient(180deg, rgba(240,160,72,.12), transparent);
        }
        .announce-sub { margin: 12px 24px 0; text-align: center; opacity: .85; font-size: .95em; }
        .announce-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 24px; }
        .announce-body {
            overflow-y: auto; padding: 4px 24px 8px; flex: 1;
            scrollbar-width: thin;
            scrollbar-color: var(--primary-color) #1b1b1b;
        }
        .announce-body::-webkit-scrollbar { width: 10px; }
        .announce-body::-webkit-scrollbar-track { background: #1b1b1b; border-left: 1px solid #4b4238; }
        .announce-body::-webkit-scrollbar-thumb { background: linear-gradient(180deg, #ffc478, var(--primary-color)); border: 2px solid #1b1b1b; border-radius: 6px; }
        .announce-body::-webkit-scrollbar-thumb:hover { background: #ffd394; }
        .announce-tower { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px dashed var(--border-color); }
        .announce-tower:last-child { border-bottom: none; }
        .announce-tower h3 { margin: 0 0 8px; font-size: 1.15em; letter-spacing: .5px; border-left: 4px solid currentColor; padding-left: 10px; }
        .announce-tower ul { margin: 0; padding: 0 0 0 4px; list-style: none; }
        .announce-tower li { margin: 6px 0; line-height: 1.55; font-size: .92em; }
        .announce-tower li b { color: #fff; }
        .announce-value-before, .announce-value-after { display: inline-block; padding: 0 5px; border: 1px solid currentColor; font-weight: 800; line-height: 1.45; }
        .announce-value-before { color: #ff9d9d; background: rgba(154,42,42,.22); text-decoration: line-through; }
        .announce-value-after { color: #9df1a1; background: rgba(44,118,51,.24); }
        .announce-value-arrow { display: inline-block; margin: 0 5px; color: #ffe082; font-weight: 900; }
        .announce-compare-note { margin: 0 24px 3px; color: #c8bcae; text-align: center; font-size: .78em; }
        .tag { display: inline-block; padding: 1px 8px; margin-right: 7px; font-size: .78em; font-weight: 700; vertical-align: middle; white-space: nowrap; }
        .tag-buff { background: #1f4d22; color: #8cff92; border: 1px solid #3a7d3f; }
        .tag-nerf { background: #5a3411; color: #ffc680; border: 1px solid #8a5a2a; }
        .tag-new  { background: #5a5114; color: #ffe17a; border: 1px solid #8a7c2a; }
        .tag-rework { background: #3a2359; color: #d6a6f0; border: 1px solid #5e3a8f; }
        .announce-footer { padding: 12px 24px 18px; border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
        .announce-dismiss { font-size: .85em; opacity: .82; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
        #announce-ok { background-image: linear-gradient(180deg, #ffb968, var(--primary-color)); color: var(--bg-color); font-weight: bold; padding: 10px 28px; border: none; cursor: pointer; transition: all .2s ease; }
        #announce-ok:hover { transform: scale(1.05); }
        #announce-close-x { position: absolute; top: 6px; right: 10px; background: none; border: none; color: var(--text-color); font-size: 1.25em; cursor: pointer; opacity: .6; line-height: 1; }
        #announce-close-x:hover { opacity: 1; color: var(--primary-color); }
        #selection-top-actions { --selection-action-width: 136px; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; flex-wrap: wrap; }
        #open-announcement-btn, #open-leaderboard-btn, #open-wiki-btn, #open-settings-btn { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 6px; inline-size: var(--selection-action-width); min-block-size: 34px; background: none; border: 1px solid var(--primary-color); color: var(--primary-color); padding: 5px 14px; font-size: .85em; cursor: pointer; transition: all .2s ease; }
        #open-announcement-btn:hover, #open-leaderboard-btn:hover, #open-wiki-btn:hover, #open-settings-btn:hover { background: var(--primary-color); color: var(--bg-color); }
        #open-leaderboard-btn { border-color: #ffe082; color: #ffe082; }
        #open-leaderboard-btn:hover { background: #ffe082; color: #241707; }
        #preferences-modal { display: none; position: fixed; inset: 0; z-index: 145; justify-content: center; align-items: center; background: rgba(0,0,0,.84); animation: fadeIn .25s; }
        #preferences-content { position: relative; display: flex; flex-direction: column; width: min(760px, 94vw); max-height: 88vh; overflow: hidden; box-sizing: border-box; background: linear-gradient(155deg, #34302a, #242321 62%, #1d1d1d); border: 2px solid var(--primary-color); box-shadow: 0 0 42px rgba(240,160,72,.38); animation: popIn .32s cubic-bezier(.2,.8,.3,1.1) both; }
        #preferences-close-x { position: absolute; top: 10px; right: 13px; z-index: 2; background: none; border: none; color: #fff5de; font-size: 1.4em; line-height: 1; cursor: pointer; opacity: .72; }
        #preferences-close-x:hover { color: var(--primary-color); opacity: 1; }
        .preferences-header { padding: 20px 48px 14px 22px; border-bottom: 1px solid rgba(255,224,130,.3); background: linear-gradient(180deg, rgba(255,224,130,.10), transparent); }
        .preferences-header h2 { margin: 0; color: #ffe082; font-size: 1.5em; }
        .preferences-header p { margin: 5px 0 0; color: #c9bda9; font-size: .88em; }
        #preferences-body { min-height: 0; overflow-y: auto; padding: 4px 22px 20px; scrollbar-width: thin; scrollbar-color: var(--primary-color) #1b1b1b; }
        .preference-section { padding: 16px 0; border-bottom: 1px solid rgba(255,255,255,.09); }
        .preference-section:last-child { border-bottom: 0; }
        .preference-section h3 { margin: 0 0 8px; color: #ffc478; font-size: 1.03em; }
        .preference-section > p { margin: 0 0 10px; color: #bfb4a5; font-size: .82em; line-height: 1.5; }
        .preference-audio-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; }
        .preference-audio-grid .settings-row { margin: 0; }
        .detail-mode-options { display: flex; gap: 10px; flex-wrap: wrap; }
        .detail-mode-option { flex: 1 1 180px; display: flex; align-items: flex-start; gap: 9px; min-height: 56px; padding: 11px 12px; border: 1px solid #5f513e; background: rgba(255,255,255,.03); cursor: pointer; }
        .detail-mode-option:has(input:checked) { border-color: var(--primary-color); background: rgba(240,160,72,.11); }
        .detail-mode-option input { accent-color: var(--primary-color); margin-top: 3px; }
        .detail-mode-option b { display: block; color: #f2e7d6; font-size: .92em; }
        .detail-mode-option small { display: block; margin-top: 3px; color: #b8aa98; font-size: .76em; line-height: 1.35; }
        .shortcut-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
        .shortcut-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 35px; padding: 7px 9px; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.09); color: #d8cec0; font-size: .86em; }
        .keybinding-capture { min-width: 52px; padding: 5px 9px; border: 1px solid #80633d; background: #211b14; color: #ffe082; font: inherit; font-weight: 800; cursor: pointer; }
        .keybinding-capture.is-capturing { border-color: #fff; color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.2); }
        .preferences-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 22px; border-top: 1px solid rgba(255,255,255,.09); }
        #restore-shortcuts-btn { padding: 8px 12px; border: 1px solid #76624b; background: #34302a; color: #f5dfbd; font: inherit; cursor: pointer; }
        @media (max-width: 620px) { .preference-audio-grid, .shortcut-grid { grid-template-columns: 1fr; } }
        .ui-svg-icon { display: block; width: 1.05em; height: 1.05em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

        #score-summary { display: none; margin: 16px 0 0; padding: 13px 15px; background: linear-gradient(135deg, rgba(240,160,72,.17), rgba(255,224,130,.06)); border: 1px solid rgba(255,224,130,.6); text-align: left; color: #f7e7d4; }
        #score-summary .score-total { display: block; margin-bottom: 8px; color: #ffe082; font-size: 1.5em; font-weight: 800; text-align: center; }
        #score-summary .score-breakdown { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; font-size: .8em; }
        #score-summary .score-breakdown span { color: #cdbda8; }
        #score-summary .score-breakdown b { display: block; color: #fff5de; font-size: 1.08em; }
        #upload-score-btn { display: none; background-image: linear-gradient(180deg, #ffe082, #f0a048); color: #281a09; border: none; padding: 12px 20px; font-weight: 800; font-size: 1.05em; cursor: pointer; }
        #upload-score-btn:hover { filter: brightness(1.07); transform: scale(1.04); }

        #leaderboard-modal { display: none; position: fixed; inset: 0; z-index: 130; background: rgba(0,0,0,.84); justify-content: center; align-items: center; animation: fadeIn .25s; }
        #leaderboard-content { position: relative; display: flex; flex-direction: column; width: min(920px, 94vw); max-height: 86vh; min-height: min(480px, 86vh); overflow: hidden; background: linear-gradient(155deg, #34302a, #242321 62%, #1d1d1d); border: 2px solid #ffe082; box-shadow: 0 0 42px rgba(240,160,72,.38); box-sizing: border-box; animation: popIn .32s cubic-bezier(.2,.8,.3,1.1) both; }
        #leaderboard-close-x { position: absolute; top: 10px; right: 13px; z-index: 2; background: none; border: none; color: #fff5de; font-size: 1.4em; line-height: 1; cursor: pointer; opacity: .72; }
        #leaderboard-close-x:hover { color: #ffe082; opacity: 1; }
        .leaderboard-header { flex: 0 0 auto; padding: 20px 48px 14px 22px; border-bottom: 1px solid rgba(255,224,130,.3); background: linear-gradient(180deg, rgba(255,224,130,.10), transparent); }
        .leaderboard-header h2 { margin: 0; color: #ffe082; font-size: 1.5em; }
        .leaderboard-header p { margin: 5px 0 0; color: #c9bda9; font-size: .88em; }
        #leaderboard-account { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; min-height: 38px; padding: 9px 22px; border-bottom: 1px solid rgba(255,255,255,.08); color: #d7cebf; font-size: .88em; }
        .leaderboard-login, .leaderboard-logout, .watch-replay-btn { border: 1px solid #d79e4d; background: #45311b; color: #ffe7b6; padding: 6px 10px; font: inherit; font-weight: 700; cursor: pointer; }
        .leaderboard-login:hover, .watch-replay-btn:hover { background: #68431e; }
        .leaderboard-logout { margin-left: auto; background: #343434; border-color: #676767; color: #d8d8d8; }
        #leaderboard-map-tabs { display: flex; flex: 0 0 auto; gap: 7px; padding: 12px 22px; overflow-x: auto; overscroll-behavior-x: contain; border-bottom: 1px solid rgba(255,255,255,.08); }
        .leaderboard-map-tab { flex: 0 0 auto; white-space: nowrap; border: 1px solid #64543d; background: #2b2824; color: #d9cfbf; padding: 7px 11px; cursor: pointer; font: inherit; font-size: .85em; }
        .leaderboard-map-tab.active { background: linear-gradient(180deg, #ffcf82, #d88c31); border-color: #ffe082; color: #291806; font-weight: 800; }
        #leaderboard-status { flex: 0 0 auto; min-height: 22px; padding: 10px 22px 4px; color: #d8c7ab; font-size: .88em; }
        #leaderboard-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0; padding: 0 22px 18px; list-style: none; scrollbar-width: thin; scrollbar-color: #e2a554 #1b1b1b; }
        #leaderboard-list::-webkit-scrollbar { width: 9px; }
        #leaderboard-list::-webkit-scrollbar-track { background: #1b1b1b; }
        #leaderboard-list::-webkit-scrollbar-thumb { background: #d6923d; border: 2px solid #1b1b1b; }
        .leaderboard-entry { display: grid; grid-template-columns: 46px minmax(92px, .9fr) minmax(284px, 1.5fr) auto auto; align-items: center; gap: 12px; padding: 11px 8px; border-bottom: 1px solid rgba(255,255,255,.08); }
        .leaderboard-rank { color: #ffe082; font-weight: 800; font-size: 1.2em; text-align: center; }
        .leaderboard-rank.top-three { color: #fff4b4; text-shadow: 0 0 10px rgba(255,224,130,.45); }
        .leaderboard-player { min-width: 0; }
        .leaderboard-player b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #f0e8dc; }
        .leaderboard-player span { color: #a8a098; font-size: .78em; }
        .leaderboard-score { color: #ffe082; font-weight: 800; text-align: right; white-space: nowrap; }
        .leaderboard-score small { display: block; color: #b7aa99; font-weight: 400; font-size: .72em; }
        .leaderboard-loadout { min-width: 284px; min-height: 46px; display: flex; align-items: center; gap: 4px; padding: 4px; overflow: hidden; }
        .leaderboard-loadout-tower { flex: 0 0 36px; width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.13); background: rgba(12,12,12,.28); }
        .leaderboard-loadout-tower canvas { display: block; width: 36px; height: 36px; image-rendering: auto; }
        .leaderboard-loadout-empty { color: #968b7b; font-size: .76em; padding: 0 4px; }
        .leaderboard-replay-stale { display: block; margin-top: 3px; color: #ff7777 !important; font-size: .75em !important; font-weight: 800; letter-spacing: .2px; }
        .leaderboard-empty { padding: 36px 8px; color: #a9a099; text-align: center; }

        #wiki-modal { display: none; position: fixed; inset: 0; z-index: 135; background: rgba(0,0,0,.82); justify-content: center; align-items: center; animation: fadeIn .3s; }
        #wiki-content { position: relative; display: flex; flex-direction: column; width: min(1080px, 96vw); max-height: 86vh; min-height: min(420px, 86vh); overflow: hidden; background: linear-gradient(160deg, #2f2f2f, #232323); border: 2px solid var(--primary-color); box-shadow: 0 0 36px var(--shadow-color); box-sizing: border-box; animation: popIn .4s cubic-bezier(.2,.8,.3,1.1) both; }
        #wiki-close-x { position: absolute; top: 8px; right: 12px; z-index: 3; background: none; border: none; color: var(--text-color); font-size: 1.4em; line-height: 1; cursor: pointer; opacity: .7; }
        #wiki-close-x:hover { color: var(--primary-color); opacity: 1; }
        .wiki-header { flex: 0 0 auto; padding: 18px 48px 12px 22px; border-bottom: 1px solid var(--border-color); background: linear-gradient(180deg, rgba(240,160,72,.12), transparent); }
        .wiki-header h2 { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--primary-color); font-size: 1.5em; }
        .wiki-header .ui-svg-icon { width: 1.2em; height: 1.2em; }
        .wiki-header p { margin: 5px 0 0; color: #d0c7ba; font-size: .86em; }
        #wiki-tabs { display: flex; flex: 0 0 auto; gap: 7px; padding: 12px 22px; overflow-x: auto; border-bottom: 1px solid var(--border-color); }
        .wiki-tab { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; white-space: nowrap; border: 1px solid #66513a; background: #292521; color: #ded1bf; padding: 7px 13px; cursor: pointer; font: inherit; font-size: .85em; }
        .wiki-tab .ui-svg-icon { width: 1em; height: 1em; }
        .wiki-tab.active { background: linear-gradient(180deg, #ffbd70, var(--primary-color)); border-color: var(--primary-color); color: var(--bg-color); font-weight: 800; }
        #wiki-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 22px 22px; scrollbar-width: thin; scrollbar-color: var(--primary-color) #1b1b1b; }
        #wiki-body::-webkit-scrollbar { width: 9px; }
        #wiki-body::-webkit-scrollbar-track { background: #1b1b1b; border-left: 1px solid #4b4238; }
        #wiki-body::-webkit-scrollbar-thumb { background: linear-gradient(180deg, #ffc478, var(--primary-color)); border: 2px solid #1b1b1b; }
        .wiki-section-title { color: var(--primary-color); font-size: 1.1em; margin: 18px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--border-color); letter-spacing: .5px; }
        .wiki-section-title:first-child { margin-top: 0; }
        .wiki-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
        .wiki-card { background: linear-gradient(160deg, rgba(255,255,255,.05), rgba(255,255,255,.012)); border: 1px solid rgba(255,255,255,.14); border-left: 4px solid var(--card-accent, #888); padding: 13px; border-radius: 0; overflow: hidden; }
        .wiki-card-heading { display: flex; align-items: center; gap: 11px; min-height: 62px; margin-bottom: 8px; }
        .wiki-card h3 { margin: 0; font-size: 1.06em; color: var(--card-accent, #e0e0e0); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
        .wiki-model { flex: 0 0 auto; display: block; width: 62px; height: 62px; background: radial-gradient(circle, rgba(255,255,255,.06), rgba(0,0,0,.08)); border: 1px solid rgba(255,255,255,.13); }
        .wiki-card .wiki-limit { font-size: .72em; color: #bcae9a; font-weight: 400; }
        .wiki-card .wiki-desc { font-size: .82em; line-height: 1.5; color: #d0c7ba; margin: 0 0 8px; }
        .wiki-card .wiki-ex { font-size: .8em; line-height: 1.5; color: #ffe082; margin: 0 0 8px; }
        .wiki-feature-title { display: block; margin: 8px 0 3px; color: #ffc478; font-size: .75em; font-weight: 800; letter-spacing: .45px; }
        .wiki-table { width: 100%; border-collapse: collapse; font-size: .78em; }
        .wiki-table th, .wiki-table td { padding: 4px 6px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.08); white-space: nowrap; }
        .wiki-table th { color: #ffc478; font-weight: 700; background: rgba(240,160,72,.08); }
        .wiki-table td.lvl { color: #ffd700; font-weight: 700; }
        .wiki-table tr.ex-row td { color: #ffe082; }
        .wiki-stat-key { display: inline-block; min-width: 5.5em; color: #b8ac9e; }
        .wiki-enemy-card .wiki-stat-list { font-size: .82em; line-height: 1.7; }
        .wiki-note { font-size: .78em; color: #b8ac9e; margin: 6px 0 0; line-height: 1.5; }
        .wiki-pill { display: inline-block; padding: 1px 7px; margin: 0 3px 3px 0; font-size: .72em; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; color: #dfd4c5; }
        .wiki-skill { font-size: .8em; color: #ffb0a8; margin: 4px 0 0; line-height: 1.5; }
        @media (max-width: 600px) { #wiki-content { width: 96vw; } .wiki-grid { grid-template-columns: 1fr; } #wiki-body { padding: 12px; } }

        #speed-controls { display: flex; gap: 4px; }
        .speed-opt { flex: 1; padding: 10px 0; text-align: center; cursor: pointer; background-color: #4a4a4a; color: var(--text-color); border: 1px solid #666; border-radius: 0; font-size: 0.95em; font-weight: 600; transition: all 0.15s ease; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
        .speed-opt:hover { background-color: #5a5a5a; }
        .speed-opt.active { background-image: linear-gradient(180deg, #ffb968, var(--primary-color)); color: var(--bg-color); border-color: var(--primary-color); box-shadow: 0 0 10px var(--shadow-color); }

        #tower-pool::-webkit-scrollbar {
            width: 8px;
        }
        #tower-pool::-webkit-scrollbar-track {
            background: var(--surface-color);
            border-radius: 0;
        }
        #tower-pool::-webkit-scrollbar-thumb {
            background: #555;
            border-radius: 0;
            border: 2px solid var(--surface-color);
        }
        #tower-pool::-webkit-scrollbar-thumb:hover {
            background: var(--primary-color);
        }

        * { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

        @keyframes screenIn { from { opacity: 0; transform: translateY(22px) scale(.985); } to { opacity: 1; transform: none; } }
        @keyframes gameScreenIn { from { opacity: 0; } to { opacity: 1; } }
        @keyframes popIn { 0% { opacity: 0; transform: translateY(18px) scale(.85); } 60% { transform: translateY(0) scale(1.03); } 100% { opacity: 1; transform: none; } }
        @keyframes cardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
        @keyframes titleGlow { 0%,100% { filter: drop-shadow(0 0 6px rgba(240,160,72,.35)); } 50% { filter: drop-shadow(0 0 16px rgba(240,160,72,.75)); } }
        @keyframes ctaPulse { 0%,100% { box-shadow: 0 4px 14px rgba(0,0,0,.4), 0 0 0 0 rgba(240,160,72,.55); } 50% { box-shadow: 0 4px 18px rgba(0,0,0,.4), 0 0 22px 4px rgba(240,160,72,.45); } }
        @keyframes fieldGlow { 0%,100% { box-shadow: 0 0 24px var(--shadow-color), inset 0 0 60px rgba(0,0,0,.35), 0 0 0 1px rgba(240,160,72,.18); } 50% { box-shadow: 0 0 32px var(--shadow-color), inset 0 0 60px rgba(0,0,0,.35), 0 0 0 1px rgba(240,160,72,.42); } }
        @keyframes borderFlow { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }
        @keyframes ambientDrift { 0%,100% { opacity: .5; transform: translate(-2%, -1%) scale(1); } 50% { opacity: .85; transform: translate(2%, 1%) scale(1.06); } }
        @keyframes statGain { 0% { transform: scale(1); } 32% { transform: scale(1.14); color: #ffe082; } 100% { transform: scale(1); } }
        @keyframes statLoss { 0% { transform: scale(1); } 32% { transform: scale(.9); color: #ff6e6e; } 100% { transform: scale(1); } }

        body { background: radial-gradient(circle at 50% -10%, #2a2a2a, var(--bg-color) 65%); }
        body::before {
            content: ''; position: fixed; inset: -10%; z-index: 0; pointer-events: none;
            background: radial-gradient(ellipse 45% 40% at 50% 38%, rgba(240,160,72,.10), transparent 70%);
            animation: ambientDrift 11s ease-in-out infinite;
        }
        body.in-battle::before { animation: none; }
        body.in-battle #canvas-container { animation: none; }
        .screen, #game-wrapper { position: relative; z-index: 1; }

        #modal { position: fixed; z-index: 100; }
        #confirm-modal { position: fixed; z-index: 110; }

        .screen {
            background: linear-gradient(160deg, #333, #262626 60%, #222);
            border-top: 3px solid var(--primary-color);
            box-shadow: 0 14px 48px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.05);
            animation: screenIn .45s cubic-bezier(.2,.75,.3,1) both;
        }
        #map-selection-screen { animation: screenIn .4s cubic-bezier(.2,.75,.3,1) both; }

        #selection-screen h1, #map-selection-screen h1 {
            background: linear-gradient(90deg, #ffce8f, var(--primary-color) 55%, #ffb968);
            -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
            letter-spacing: 3px; animation: titleGlow 3.2s ease-in-out infinite;
        }
        h3 { letter-spacing: .5px; }

        .selection-btn, .action-btn, #restart-btn { position: relative; overflow: hidden; letter-spacing: .5px; }
        .selection-btn::after, .action-btn::after, #restart-btn::after {
            content: ''; position: absolute; top: 0; left: -120%; width: 60%; height: 100%;
            background: linear-gradient(100deg, transparent, rgba(255,255,255,.28), transparent);
            transform: skewX(-18deg); transition: left .55s ease; pointer-events: none;
        }
        .selection-btn:not(:disabled):hover::after, .action-btn:not(:disabled):hover::after, #restart-btn:hover::after { left: 130%; }
        .selection-btn:not(:disabled):active, .action-btn:not(:disabled):active, #restart-btn:active { transform: scale(.97); }
        #select-map-btn, #start-game-from-map-btn:not(:disabled), #restart-btn { background-image: linear-gradient(180deg, #ffb968, var(--primary-color)); }
        #start-game-test-btn:not(:disabled) { background-image: linear-gradient(180deg, #6ee0ef, #4dd0e1); }

        #start-wave-btn:not(:disabled) {
            background-image: linear-gradient(180deg, #ffb968, var(--primary-color));
            color: var(--bg-color); border-color: var(--primary-color); font-weight: 700;
            animation: ctaPulse 2.1s ease-in-out infinite;
        }
        #start-wave-btn:not(:disabled):hover { filter: brightness(1.08); }

        .tower-card { animation: cardIn .35s ease both; background: linear-gradient(160deg, #404040, #343434); }
        .tower-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.45), 0 0 12px rgba(240,160,72,.35); }
        .tower-card.selected {
            border-color: transparent;
            background:
                linear-gradient(#383838, #383838) padding-box,
                linear-gradient(90deg, var(--primary-color), #ffe082, var(--primary-color)) border-box;
            background-size: auto, 200% 100%;
            animation: borderFlow 2.5s linear infinite;
            box-shadow: 0 0 16px rgba(240,160,72,.5);
        }
        .tower-card canvas, .tower-btn .btn-canvas { transition: transform .2s ease, filter .2s ease; }
        .tower-card:hover canvas, .tower-btn:hover .btn-canvas { transform: scale(1.08); filter: drop-shadow(0 0 4px rgba(240,160,72,.6)); }
        .tower-btn { position: relative; overflow: hidden; background: linear-gradient(180deg, #505050, #444); }
        .tower-btn::before {
            content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
            background: var(--primary-color); transform: scaleY(0); transform-origin: center; transition: transform .2s ease;
        }
        .tower-btn:hover::before { transform: scaleY(1); }
        .tower-btn.selected { box-shadow: 0 0 14px rgba(240,160,72,.5); }
        .tower-btn.selected::before { transform: scaleY(1); background: var(--bg-color); }

        .slot { transition: border-color .2s ease, box-shadow .2s ease; }
        .slot:hover { border-color: var(--primary-color); box-shadow: inset 0 0 12px rgba(240,160,72,.25); }

        .map-card { background: linear-gradient(160deg, #262626, #1d1d1d); }
        .map-card canvas { transition: transform .25s ease; }
        .map-card:hover { box-shadow: 0 10px 26px rgba(0,0,0,.5), 0 0 14px rgba(240,160,72,.3); }
        .map-card:hover canvas { transform: scale(1.04); }
        .map-card.selected { animation: cardIn .3s ease; }

        #canvas-container { border-color: #5a4632; animation: fieldGlow 4.5s ease-in-out infinite; }
        #game-wrapper { animation: gameScreenIn .5s cubic-bezier(.2,.75,.3,1) both; }

        #ui-panel { background: linear-gradient(165deg, #313131, #272727); border-top: 3px solid var(--primary-color); }
        #ui-panel::before, #ui-panel::after {
            content: ''; position: absolute; width: 16px; height: 16px; pointer-events: none;
        }
        #ui-panel { position: relative; }
        #ui-panel::before { top: 8px; right: 8px; border-top: 2px solid var(--primary-color); border-right: 2px solid var(--primary-color); }
        #ui-panel::after { bottom: 8px; left: 8px; border-bottom: 2px solid var(--primary-color); border-left: 2px solid var(--primary-color); }

        .stats-display { background: linear-gradient(160deg, #3d3d3d, #343434); box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
        .stats-display div { transform-origin: left center; transition: color .25s ease; }
        .stat-gain { animation: statGain .42s ease; }
        .stat-loss { animation: statLoss .42s ease; }

        #floating-info-panel { animation: none; box-shadow: 0 8px 24px rgba(0,0,0,.45), 0 0 14px rgba(240,160,72,.25); }
        #floating-info-panel .action-btn { background: linear-gradient(180deg, #555, #4a4a4a); }
        #tooltip { animation: popIn .18s ease both; box-shadow: 0 6px 18px rgba(0,0,0,.5), 0 0 10px rgba(240,160,72,.2); }

        #modal-content { animation: popIn .4s cubic-bezier(.2,.8,.3,1.1) both; background: linear-gradient(160deg, #333, #262626); }
        #modal-content h2 { animation: titleGlow 3s ease-in-out infinite; }

        #rotate-hint { display: none; }
        #wechat-browser-tip[hidden] { display: none !important; }
        #wechat-browser-tip {
            position: fixed;
            left: 50%;
            bottom: calc(max(10px, env(safe-area-inset-bottom)) + 2px);
            transform: translateX(-50%);
            z-index: 90;
            display: flex;
            align-items: center;
            gap: 10px;
            width: min(92vw, 560px);
            padding: 10px 12px;
            box-sizing: border-box;
            border: 1px solid rgba(240, 160, 72, 0.65);
            background: rgba(18, 18, 18, 0.94);
            color: var(--text-color);
            box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
            backdrop-filter: blur(10px);
            pointer-events: none;
        }
        .wechat-tip-content {
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
            pointer-events: none;
        }
        .wechat-tip-content strong {
            color: var(--primary-color);
            font-size: 0.88em;
            letter-spacing: 0.04em;
        }
        .wechat-tip-content p {
            margin: 0;
            color: #f7e3c7;
            font-size: 0.78em;
            line-height: 1.35;
        }
        #wechat-browser-tip-close {
            flex: 0 0 auto;
            width: 28px;
            height: 28px;
            border: 1px solid rgba(240, 160, 72, 0.55);
            background: rgba(255,255,255,0.04);
            color: #fff1d8;
            font-size: 18px;
            line-height: 1;
            cursor: pointer;
            pointer-events: auto;
        }
        @keyframes rotateHintSpin { 0%,55% { transform: rotate(0deg); } 80%,100% { transform: rotate(-90deg); } }
        @media (pointer: coarse) and (orientation: portrait) and (max-width: 820px) {
            #rotate-hint {
                display: flex; position: fixed; inset: 0; z-index: 9999;
                flex-direction: column; align-items: center; justify-content: center; gap: 18px;
                background: radial-gradient(circle at 50% 40%, #2a2a2a, #121212 70%);
                color: var(--text-color); text-align: center; padding: 30px; box-sizing: border-box;
            }
            #rotate-hint .rot-icon { width: 88px; height: 88px; color: var(--primary-color); animation: rotateHintSpin 2.4s ease-in-out infinite; transform-origin: 50% 50%; }
            #rotate-hint h2 { color: var(--primary-color); margin: 0; font-size: 1.4em; }
            #rotate-hint p { margin: 0; opacity: .85; }
        }

        @media (pointer: coarse) and (max-width: 1024px) {
            html, body {
                height: 100dvh;
                min-height: 100dvh;
            }

            body {
                padding:
                    max(8px, env(safe-area-inset-top))
                    max(8px, env(safe-area-inset-right))
                    max(8px, env(safe-area-inset-bottom))
                    max(8px, env(safe-area-inset-left));
                align-items: center;
            }

            #game-wrapper { animation: none; transform: scale(var(--game-stage-scale)); transform-origin: var(--game-stage-origin, center center); align-self: var(--game-stage-align, auto); margin-top: var(--game-stage-margin-top, 0px); }

            #game-container { gap: 14px; }

            #skill-rail, #settings-dock { left: -102px; width: 96px; }
            #skill-rail { top: 0; }
            #settings-dock { bottom: 0; gap: 6px; }
            .skill-rail-slot { min-height: 78px; padding: 8px 6px 6px; }
            .skill-rail-icon { width: 34px; height: 34px; margin-bottom: 4px; }
            .skill-rail-name { font-size: 11px; }
            .skill-cooldown { top: 4px; right: 4px; min-width: 18px; padding: 1px 3px; font-size: 11px; }
            #pause-row, #settings-row { gap: 4px; }
            #pause-button, #settings-button, #quick-restart-btn, #abandon-button { min-height: 62px; padding: 6px; }
            #pause-button svg, #settings-button svg, #quick-restart-btn svg, #abandon-button svg { width: 26px; height: 26px; }
            #pause-button span, #settings-button span, #quick-restart-btn span, #abandon-button span { font-size: 11px; }
            #ui-panel { width: 264px; padding: 14px; gap: 10px; }
            .stats-display { padding: 12px; gap: 8px; }
            .stats-display div { font-size: 1em; }
            #tower-buttons-list { gap: 4px; }

            .screen {
                width: 100%;
                max-width: none;
                height: 100%;
                max-height: none;
                padding: 12px;
                gap: 10px;
                box-sizing: border-box;
                overflow: hidden;
            }

            #selection-screen, #map-selection-screen {
                zoom: 1;
                width: 100%;
                height: 100%;
                max-width: none;
                max-height: none;
                overflow: hidden;
            }
            #selection-screen { align-items: stretch; }
            #selection-screen h1 { font-size: 1.3em; }
            #selection-top-actions { justify-content: flex-start; gap: 8px; }
            #open-announcement-btn, #open-leaderboard-btn, #open-wiki-btn, #open-settings-btn {
                inline-size: auto;
                min-inline-size: calc(50% - 4px);
                flex: 1 1 calc(50% - 4px);
                padding: 6px 10px;
                font-size: .8em;
            }
            #selection-slots { min-height: 82px; padding: 10px; gap: 8px; }
            #selection-main {
                display: grid;
                grid-template-columns: minmax(0, 1fr) minmax(200px, 28%);
                gap: 10px;
                flex: 1 1 auto;
                min-height: 0;
            }
            #tower-pool {
                max-height: none;
                min-height: 0;
                overflow: auto;
                grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
                gap: 8px;
                padding: 8px;
            }
            #selection-info {
                width: auto;
                min-width: 0;
                min-height: 0;
                padding: 14px;
                overflow: auto;
            }
            #selection-buttons-container {
                margin-top: 0;
                gap: 10px;
                padding-bottom: env(safe-area-inset-bottom);
            }
            .selection-btn {
                flex: 1 1 220px;
                min-height: 46px;
                padding: 10px 14px;
                font-size: 1em;
            }

            #map-selection-screen {
                width: 100%;
                height: 100%;
                padding: 12px;
                gap: 10px;
                overflow: hidden;
            }
            #map-selection-screen h1 { margin-bottom: 0; font-size: 1.35em; }
            #map-list { grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 10px; margin: 0; padding: 0 2px 4px; overflow: auto; align-content: start; }
            .map-card { padding: 8px; }
            .map-card .map-name { font-size: 1em; margin-top: 6px; }
            .map-card .map-modifier { font-size: .75em; margin-top: 3px; }
            #map-selection-buttons-container { gap: 12px; padding-bottom: env(safe-area-inset-bottom); }

            #announcement-content { zoom: 1; width: 55vw; max-width: 460px; height: 100vh; max-height: 100vh; }
            #announcement-content > h2 { padding: 12px 16px 8px; font-size: 1.25em; }
            .announce-sub { margin: 8px 16px 0; font-size: .88em; }
            .announce-legend { gap: 6px; padding: 8px 16px; }
            .announce-body { padding: 4px 16px 8px; }
            .announce-footer { padding: 10px 16px; }
            #leaderboard-content { width: 94vw; min-height: 0; height: 92vh; max-height: 92vh; }
            .leaderboard-header { padding: 15px 42px 10px 16px; }
            #leaderboard-account, #leaderboard-map-tabs, #leaderboard-status { padding-left: 16px; padding-right: 16px; }
            #leaderboard-list { padding-left: 14px; padding-right: 14px; }
            .leaderboard-entry { grid-template-columns: 32px minmax(0, 1fr) auto; gap: 7px; }
            .leaderboard-loadout { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; box-sizing: border-box; min-height: 42px; }
            .leaderboard-loadout-tower { flex-basis: 34px; width: 34px; height: 34px; }
            .leaderboard-loadout-tower canvas { width: 34px; height: 34px; }
            .leaderboard-score { grid-column: 2 / -1; grid-row: 3; justify-self: start; text-align: left; font-size: .86em; }
            .leaderboard-entry .watch-replay-btn { grid-column: 2 / -1; grid-row: 4; justify-self: start; }
            #score-summary .score-breakdown { grid-template-columns: 1fr; gap: 4px; }

            html, body, button, canvas, .tower-card, .map-card, .slot, .skill-rail-slot {
                -webkit-tap-highlight-color: transparent;
                -webkit-user-select: none;
                user-select: none;
            }

            #wechat-browser-tip {
                width: min(94vw, 520px);
                padding: 8px 10px;
                gap: 8px;
            }
            .wechat-tip-content strong { font-size: 0.82em; }
            .wechat-tip-content p { font-size: 0.74em; }
            #wechat-browser-tip-close { width: 26px; height: 26px; }

            .stats-display div { transition: none; transform: none !important; }
            .stat-gain, .stat-loss { animation: none !important; }

            body::before, #selection-screen h1, #map-selection-screen h1,
            #start-wave-btn:not(:disabled), #canvas-container, .tower-card.selected { animation: none; }
            #canvas-container { box-shadow: 0 0 14px var(--shadow-color); }
            .tower-card.selected { background-size: auto, auto; }
        }

        @media (pointer: coarse) and (orientation: landscape) and (max-width: 1024px) and (max-height: 520px) {
            #selection-screen { gap: 8px; }
            #selection-screen h1, #map-selection-screen h1 { font-size: 1.16em; }
            #selection-top-actions {
                flex-wrap: nowrap;
                gap: 6px;
                overflow-x: auto;
                overflow-y: hidden;
                padding-bottom: 2px;
            }
            #open-announcement-btn, #open-leaderboard-btn, #open-wiki-btn, #open-settings-btn {
                min-block-size: 32px;
                min-inline-size: max-content;
                flex: 0 0 auto;
                padding: 5px 8px;
                font-size: .76em;
            }
            #selection-slots { min-height: 68px; padding: 8px; gap: 6px; }
            .slot { width: 64px; height: 64px; }
            #selection-main { grid-template-columns: minmax(0, 1fr); }
            #tower-pool {
                grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
                padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
                align-content: start;
            }
            #selection-info { display: none; }
            #selection-buttons-container { gap: 8px; }
            .selection-btn { min-height: 42px; padding: 8px 12px; font-size: .92em; }
            #ui-panel { width: 236px; padding: 12px; gap: 8px; }
            #pause-button span, #settings-button span, #quick-restart-btn span, #abandon-button span { display: none; }
            #pause-button, #settings-button, #quick-restart-btn, #abandon-button { min-height: 54px; padding: 5px; }
            #pause-button svg, #settings-button svg, #quick-restart-btn svg, #abandon-button svg { width: 24px; height: 24px; }
            .skill-rail-slot { min-height: 68px; }
            .skill-rail-name { display: none; }
        }

        body.wechat-compact .screen {
            padding: 8px;
            gap: 8px;
        }
        body.wechat-compact #selection-screen,
        body.wechat-compact #map-selection-screen {
            gap: 6px;
        }
        body.wechat-compact #selection-screen h1,
        body.wechat-compact #map-selection-screen h1 {
            font-size: 1.02em;
            letter-spacing: 1px;
        }
        body.wechat-compact #selection-top-actions {
            gap: 4px;
            padding-bottom: 0;
        }
        body.wechat-compact #open-announcement-btn,
        body.wechat-compact #open-leaderboard-btn,
        body.wechat-compact #open-wiki-btn,
        body.wechat-compact #open-settings-btn {
            min-block-size: 28px;
            padding: 4px 7px;
            font-size: 0.72em;
        }
        body.wechat-compact #selection-slots {
            min-height: 58px;
            padding: 6px;
            gap: 4px;
        }
        body.wechat-compact .slot {
            width: 54px;
            height: 54px;
        }
        body.wechat-compact #tower-pool {
            grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
            gap: 6px;
            padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
        }
        body.wechat-compact .tower-card {
            padding: 4px;
        }
        body.wechat-compact .tower-card .name {
            font-size: 0.7em;
        }
        body.wechat-compact .tower-card .cost {
            font-size: 0.72em;
        }
        body.wechat-compact #selection-buttons-container {
            gap: 6px;
        }
        body.wechat-compact .selection-btn {
            min-height: 38px;
            padding: 7px 10px;
            font-size: 0.86em;
        }
        body.wechat-compact #map-list {
            grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
            gap: 8px;
        }
        body.wechat-compact .map-card {
            padding: 6px;
        }
        body.wechat-compact .map-card .map-name {
            font-size: 0.9em;
            margin-top: 5px;
        }
        body.wechat-compact .map-card .map-modifier {
            font-size: 0.68em;
            margin-top: 2px;
        }
        body.wechat-compact #map-selection-buttons-container {
            gap: 8px;
        }
        body.wechat-compact #game-container {
            gap: 10px;
        }
        body.wechat-compact #skill-rail,
        body.wechat-compact #settings-dock {
            left: -86px;
            width: 80px;
        }
        body.wechat-compact .skill-rail-slot {
            min-height: 58px;
            padding: 6px 4px;
        }
        body.wechat-compact .skill-rail-icon {
            width: 28px;
            height: 28px;
            margin-bottom: 2px;
        }
        body.wechat-compact .skill-cooldown {
            min-width: 16px;
            font-size: 10px;
        }
        body.wechat-compact #pause-button,
        body.wechat-compact #settings-button,
        body.wechat-compact #quick-restart-btn,
        body.wechat-compact #abandon-button {
            min-height: 48px;
            padding: 4px;
        }
        body.wechat-compact #pause-button svg,
        body.wechat-compact #settings-button svg,
        body.wechat-compact #quick-restart-btn svg,
        body.wechat-compact #abandon-button svg {
            width: 20px;
            height: 20px;
        }
        body.wechat-compact #ui-panel {
            width: 214px;
            padding: 10px;
            gap: 6px;
        }
        body.wechat-compact .stats-display {
            padding: 8px;
            gap: 5px;
        }
        body.wechat-compact .stats-display div {
            font-size: 0.88em;
        }
        body.wechat-compact #wechat-browser-tip {
            left: auto;
            right: 8px;
            transform: none;
            width: min(46vw, 320px);
            bottom: calc(max(8px, env(safe-area-inset-bottom)) + 2px);
            padding: 6px 8px;
            gap: 6px;
            align-items: flex-start;
        }
        body.wechat-compact .wechat-tip-content strong {
            display: none;
        }
        body.wechat-compact .wechat-tip-content p {
            font-size: 0.68em;
            line-height: 1.25;
        }
        body.wechat-compact #wechat-browser-tip-close {
            width: 22px;
            height: 22px;
            font-size: 15px;
        }

        @media (max-width: 700px) {
            .leaderboard-entry { grid-template-columns: 32px minmax(0, 1fr) auto; gap: 7px; }
            .leaderboard-loadout { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; min-height: 42px; box-sizing: border-box; }
            .leaderboard-loadout-tower { flex-basis: 34px; width: 34px; height: 34px; }
            .leaderboard-loadout-tower canvas { width: 34px; height: 34px; }
            .leaderboard-score { grid-column: 2 / -1; grid-row: 3; justify-self: start; text-align: left; font-size: .86em; }
            .leaderboard-entry .watch-replay-btn { grid-column: 2 / -1; grid-row: 4; justify-self: start; }
        }
