:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #0b1211;
  color: #ecf6df;
  font-synthesis: none;
  --bg: #0b1211;
  --panel: #13201d;
  --panel-light: #192b25;
  --line: #294238;
  --muted: #93a99b;
  --text: #ecf6df;
  --accent: #b9ed88;
  --accent-dark: #1c3326;
  --gold: #ffd166;
  --danger: #ff8585;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 50% -20%, #1c352a 0, var(--bg) 48%); }
button { font: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

#app { width: min(1380px, calc(100% - 40px)); margin: 0 auto; }
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 28px 0 20px; border-bottom: 1px solid var(--line); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 38px); letter-spacing: .12em; }
h2 { margin-bottom: 8px; font-size: 21px; }
.eyebrow { margin-bottom: 7px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .18em; }
.wallet { padding: 12px 18px; border: 1px solid #71623c; border-radius: 12px; background: #29271b; color: var(--gold); font-size: 21px; font-weight: 800; }
.scene { padding: 22px 0; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--panel) 96%, transparent); box-shadow: 0 14px 40px #0002; }
.workshop-intro { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 22px 24px; margin-bottom: 18px; background: linear-gradient(110deg, #1a3428, var(--panel)); }
.workshop-intro p:last-child { margin-bottom: 0; color: var(--muted); }
.loadout-summary { color: var(--muted); white-space: nowrap; }
.loadout-summary strong { display: block; margin-top: 6px; color: var(--text); font-size: 20px; text-align: right; }
section.panel { padding: 22px 24px; margin-bottom: 18px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-heading h2 { margin-bottom: 0; }
.section-heading > span { color: var(--muted); font-size: 13px; }

.tower-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.tower-card { position: relative; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-light); }
.tower-card.locked { opacity: .82; }
.tower-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tower-card-header { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.tower-card h3 { margin: 0 0 5px; font-size: 18px; }
.tower-role { color: var(--muted); font-size: 13px; }
.level-badge { padding: 4px 8px; border-radius: 6px; background: #294335; color: var(--accent); font-size: 12px; font-weight: 700; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 17px 0; color: #c9d8cd; font-size: 13px; }
.next-stats { min-height: 34px; margin-bottom: 14px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.card-actions { display: flex; gap: 8px; }
.button { min-height: 40px; padding: 9px 16px; border: 1px solid #3b5b4c; border-radius: 9px; background: #20382d; color: var(--text); font-weight: 650; cursor: pointer; transition: background .15s, transform .15s; }
.button:hover:not(:disabled) { background: #2b4a3b; transform: translateY(-1px); }
.button.primary { border-color: #b9ed88; background: var(--accent); color: #172218; }
.button.primary:hover:not(:disabled) { background: #d0f8aa; }
.button.ghost { background: transparent; color: var(--muted); }
.button.compact { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button.full { width: 100%; }
.button:disabled { opacity: .42; cursor: not-allowed; }
.card-actions .button { flex: 1; font-size: 13px; }

.level-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-button { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #17271f; color: var(--text); text-align: left; cursor: pointer; }
.level-button.selected { border-color: var(--accent); background: #263e2d; }
.level-button:disabled { opacity: .45; cursor: not-allowed; }
.level-button strong, .level-button span { display: block; }
.level-button span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.level-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 20px; }
.level-footer p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.battle-hud { display: flex; align-items: center; gap: 28px; padding: 12px 18px; margin-bottom: 14px; }
.hud-item span, .hud-item strong { display: block; }
.hud-item span { margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.hud-item strong { font-size: 17px; }
#battle-gold, #battle-earned { color: var(--gold); }
#battle-lives { color: #ff9b9b; }
.hud-actions { display: flex; gap: 8px; margin-left: auto; }
.boss-health { padding: 12px 18px; margin-bottom: 14px; border-color: #745269; }
.boss-label { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 8px; color: #f1c4e2; font-size: 13px; }
.boss-track { height: 9px; overflow: hidden; border-radius: 8px; background: #2b1c29; }
#boss-fill { width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #bb5c9b, #ffe69a); transition: width .12s linear; }
.battle-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr) 160px; gap: 14px; align-items: stretch; }
.battle-sidebar, .wave-panel { padding: 16px; }
.battle-loadout { display: grid; gap: 10px; }
.battle-tower-button { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #1a2d25; color: var(--text); text-align: left; cursor: pointer; }
.battle-tower-button.selected { border-color: var(--accent); background: #2a4433; }
.battle-tower-button:disabled { opacity: .5; cursor: not-allowed; }
.battle-tower-button strong, .battle-tower-button span { display: block; }
.battle-tower-button span { margin-top: 5px; color: var(--gold); font-size: 12px; }
.help-text, #wave-detail { margin: 16px 0 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.board-wrap { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 10px; overflow: hidden; }
#battle-canvas { display: block; width: 100%; height: auto; aspect-ratio: 11 / 5; cursor: crosshair; }
.battle-message { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); padding: 6px 12px; border: 1px solid #53745b; border-radius: 20px; background: #102019df; color: var(--accent); font-size: 12px; pointer-events: none; }
.wave-status { display: block; margin-top: 14px; font-size: 20px; }
.wave-panel .button { margin-top: 20px; }
.selection-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 58px; padding: 10px 16px; margin-top: 14px; color: var(--muted); font-size: 13px; }

.result-card { max-width: 560px; margin: 35px auto; padding: 34px; text-align: center; }
.result-icon { margin: 15px 0; color: var(--accent); font-size: 48px; }
#result-subtitle { color: var(--muted); }
.reward-list { margin: 24px 0 10px; border-top: 1px solid var(--line); }
.reward-row, .result-total { display: flex; justify-content: space-between; gap: 20px; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.reward-row span:last-child { color: var(--gold); }
.result-total { margin-bottom: 25px; color: var(--gold); font-size: 19px; }
.result-actions { display: flex; justify-content: center; gap: 10px; }
footer { padding: 10px 0 25px; color: #61776a; font-size: 12px; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 5; transform: translate(-50%, 20px); padding: 10px 18px; border: 1px solid #53745b; border-radius: 10px; background: #1c3228; color: var(--text); opacity: 0; pointer-events: none; transition: .2s; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1050px) {
  .battle-layout { grid-template-columns: 150px minmax(0, 1fr); }
  .wave-panel { grid-column: 1 / -1; display: flex; align-items: center; gap: 20px; }
  .wave-panel .eyebrow, .wave-panel .wave-status, .wave-panel p { margin: 0; }
  .wave-panel .button { margin: 0 0 0 auto; width: auto; }
}
@media (max-width: 720px) {
  #app { width: min(100% - 24px, 1380px); }
  .app-header { padding-top: 18px; }
  .wallet { padding: 9px 12px; font-size: 17px; }
  .workshop-intro, .section-heading, .level-footer { align-items: start; flex-direction: column; }
  .loadout-summary strong { text-align: left; }
  .level-list { grid-template-columns: repeat(2, 1fr); }
  .level-footer .button { width: 100%; }
  .battle-hud { flex-wrap: wrap; gap: 12px 20px; }
  .hud-actions { width: 100%; margin-left: 0; }
  .battle-layout { grid-template-columns: 1fr; }
  .battle-loadout { grid-template-columns: repeat(3, 1fr); }
  .help-text { display: none; }
  .wave-panel { grid-column: auto; flex-wrap: wrap; }
  .selection-bar { align-items: start; }
}
