html {
  --page-bg: #071013;
  --map-bg: #071013;
  --panel-bg: rgba(7, 15, 18, 0.78);
  --panel-strong-bg: rgba(10, 23, 28, 0.94);
  --control-bg: rgba(23, 43, 51, 0.92);
  --card-bg: rgba(16, 34, 41, 0.88);
  --card-muted-bg: rgba(16, 34, 41, 0.58);
  --line: rgba(194, 216, 224, 0.18);
  --text: #edf6f8;
  --text-strong: #f8fbff;
  --text-muted: #91a6ad;
  --text-soft: rgba(226, 239, 243, 0.68);
  --mint: #58d68d;
  --mint-soft: #dff6ea;
  --bad: #ff5f73;
  --gold: #ffd166;
  --gold-soft: rgba(255, 209, 102, 0.18);
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.42);
  --overlay-bg: rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] {
  --page-bg: #dfe9e6;
  --map-bg: #dfe9e6;
  --panel-bg: rgba(247, 250, 246, 0.82);
  --panel-strong-bg: rgba(255, 255, 252, 0.96);
  --control-bg: rgba(255, 255, 252, 0.94);
  --card-bg: rgba(255, 255, 252, 0.9);
  --card-muted-bg: rgba(230, 236, 232, 0.7);
  --line: rgba(52, 73, 78, 0.2);
  --text: #203034;
  --text-strong: #10191c;
  --text-muted: #5c7075;
  --text-soft: rgba(44, 62, 67, 0.7);
  --mint: #18895a;
  --mint-soft: #0f5c42;
  --bad: #c9364b;
  --gold: #9a6400;
  --gold-soft: rgba(255, 196, 77, 0.24);
  --shadow: 0 18px 48px rgba(37, 55, 58, 0.2);
  --overlay-bg: rgba(228, 236, 233, 0.58);
}

body {
  background: var(--page-bg) !important;
  color: var(--text) !important;
}

#map {
  background: var(--map-bg);
  cursor: crosshair;
  touch-action: none;
}

.bg-shell {
  background-color: var(--panel-bg) !important;
}

.bg-shellStrong {
  background-color: var(--panel-strong-bg) !important;
}

.border-line {
  border-color: var(--line) !important;
}

.text-slate-50,
.text-slate-100,
.text-white {
  color: var(--text-strong) !important;
}

.text-slate-300 {
  color: var(--text-muted) !important;
}

.text-amber-100 {
  color: var(--text-strong) !important;
}

.text-gold {
  color: var(--gold) !important;
}

.border-gold\/40 {
  border-color: color-mix(in srgb, var(--gold) 42%, transparent) !important;
}

.bg-gold\/15 {
  background-color: var(--gold-soft) !important;
}

.shadow-hud {
  box-shadow: var(--shadow) !important;
}

#endOverlay {
  background: var(--overlay-bg) !important;
}

#map canvas {
  display: block;
  width: 100%;
  height: 100%;
}

button:disabled {
  cursor: not-allowed;
}

.loading-overlay {
  display: grid;
  z-index: 45;
  pointer-events: auto;
}

.loading-overlay.hidden {
  display: none;
}

.loading-panel {
  display: grid;
  min-width: min(360px, calc(100vw - 32px));
  place-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  background: var(--panel-bg-strong);
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 1000;
  line-height: 1.2;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid color-mix(in srgb, var(--text-strong) 18%, transparent);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.startup-error {
  display: grid;
  place-content: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 96px 18px 150px;
  overflow: hidden;
  color: var(--text);
  text-align: center;
}

.startup-error strong {
  font-size: 24px;
}

.startup-error span {
  width: min(640px, calc(100% - 36px));
  max-width: 100%;
  color: var(--text-muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 760px) {
  .startup-error {
    position: fixed;
    inset: 0;
    width: 100vw;
  }

  .startup-error span {
    width: 300px;
  }

}

@media (max-width: 420px) {
  .status-bar {
    top: 52px !important;
    right: 12px !important;
  }

  .build-bar {
    top: 96px !important;
  }

  #waveStartBar {
    top: 180px !important;
  }

  .status-bar div {
    padding-left: 4px;
    padding-right: 4px;
  }
}

.status-icon {
  display: inline-grid;
  width: 14px;
  min-width: 14px;
  place-items: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

@media (min-width: 640px) {
  .status-icon {
    width: 18px;
    min-width: 18px;
    font-size: 14px;
  }
}

.end-overlay:not(.hidden) {
  display: grid;
}

.help-overlay:not(.hidden) {
  display: grid;
}

.end-panel {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
}

.help-panel {
  align-self: end;
  width: 100%;
  max-height: min(86dvh, 760px);
  overflow: hidden;
  border-radius: 14px 14px 0 0;
  color: var(--text);
}

.help-header {
  display: flex;
  height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
}

.help-header h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 1000;
  line-height: 1;
}

.help-close {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text-strong);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.help-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.help-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 1000;
}

.help-tab.active {
  border-color: color-mix(in srgb, var(--mint) 85%, transparent);
  background: color-mix(in srgb, var(--mint) 16%, transparent);
  color: var(--mint-soft);
}

.help-content {
  max-height: calc(min(86dvh, 760px) - 105px);
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
}

.help-meta {
  margin-bottom: 10px;
  border: 1px solid color-mix(in srgb, var(--gold) 42%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--gold) 12%, var(--panel-bg));
  color: var(--gold);
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 1000;
  line-height: 1;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.help-card {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 10px;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  padding: 9px;
}

.help-preview {
  position: relative;
  display: grid;
  min-width: 0;
  place-items: center;
  border-radius: 7px;
  background: color-mix(in srgb, var(--panel-bg) 62%, transparent);
  overflow: hidden;
}

.help-preview .hud-model-icon {
  width: 88px;
  height: 62px;
}

.help-card-body {
  min-width: 0;
}

.help-card h3 {
  margin: 0 0 4px;
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 1000;
  line-height: 1.1;
}

.help-card p {
  margin: 0 0 8px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.help-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
}

.help-stats div {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 6px;
  padding: 5px 6px;
  background: color-mix(in srgb, var(--panel-bg) 52%, transparent);
}

.help-stats dt {
  overflow: hidden;
  color: var(--text);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-stats dd {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--text-strong);
  font-size: 11px;
  font-weight: 1000;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-stat.stat-cost dd,
.help-stat.stat-reward dd {
  color: var(--mint);
}

.help-stat.stat-hp dd {
  color: #ffb3bd;
}

html[data-theme="light"] .help-stat.stat-hp dd {
  color: #a82135;
}

.help-stat.stat-damage dd {
  color: var(--bad);
}

.help-stat.stat-speed dd {
  color: #8fd3ff;
}

html[data-theme="light"] .help-stat.stat-speed dd {
  color: #176b8c;
}

.help-stat.stat-range dd {
  color: var(--gold);
}

.help-stat.stat-neutral dd {
  color: var(--text-strong);
}

.end-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: color-mix(in srgb, var(--card-bg) 76%, transparent);
}

.end-stats span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
  font-size: 10px;
}

.end-stats strong {
  color: var(--text-strong);
  font-size: 14px;
}

@media (min-width: 640px) {
  .end-panel {
    max-height: calc(100dvh - 48px);
    padding: 20px;
  }

  .help-panel {
    align-self: center;
    width: min(860px, calc(100vw - 48px));
    border-radius: 8px;
  }

  .help-header {
    height: 58px;
    padding: 0 18px;
  }

  .help-content {
    padding: 14px;
  }

  .help-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .end-stats div {
    padding: 10px;
  }

  .end-stats span {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .end-stats strong {
    font-size: 18px;
  }
}

.hud-action,
.tower-card {
  flex: 0 0 auto;
  width: 58px;
  min-width: 58px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
}

@media (min-width: 640px) {
  .hud-action,
  .tower-card {
    width: 64px;
    min-width: 64px;
  }
}

.hud-action {
  position: relative;
  display: block;
  padding: 4px 5px;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.hud-action:disabled {
  color: var(--text-muted);
}

.hud-action.affordable {
  color: var(--mint);
}

.hud-action.unaffordable {
  color: var(--bad);
}

.base-action.active,
.tower-card.active {
  border-color: color-mix(in srgb, var(--mint) 82%, transparent);
  background: color-mix(in srgb, var(--mint) 16%, transparent);
}

.base-action {
  color: var(--mint-soft);
}

.base-action.repair-mode::after {
  content: "+";
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 999px;
  background: var(--mint);
  color: var(--page-bg);
  font-size: 14px;
  font-weight: 1000;
  line-height: 1;
}

.tower-card {
  position: relative;
  display: block;
  padding: 4px 5px;
  text-align: center;
}

.tower-card:disabled {
  opacity: 1;
}

.tower-card.unaffordable {
  border-color: color-mix(in srgb, var(--line) 58%, transparent);
  background: var(--card-muted-bg);
}

.tower-card > span:not(.tower-price) {
  display: none;
}

.tower-card strong,
.hud-action strong {
  position: absolute;
  right: 4px;
  bottom: 5px;
  left: 4px;
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--text-strong);
  font-size: 10px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tower-price {
  position: absolute;
  top: 5px;
  right: 4px;
  left: 4px;
  display: block;
  min-height: 12px;
  color: var(--mint);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
}

.tower-card.unaffordable .tower-price {
  color: var(--bad);
}

.hud-action.unaffordable .tower-price {
  color: var(--bad);
}

.hud-model-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: 44px;
  height: 30px;
  object-fit: contain;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

@media (max-width: 420px) {
  .hud-model-icon {
    width: 42px;
    height: 28px;
  }
}

.hud-symbol {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--text-strong);
  font-size: 19px;
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%);
}

.wave-start-button {
  display: flex;
  width: 100%;
  height: 34px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid color-mix(in srgb, var(--gold) 48%, transparent);
  border-radius: 8px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 12px;
  font-weight: 1000;
  line-height: 1;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.wave-start-button span {
  font-size: 14px;
}

.wave-start-button:disabled {
  border-color: color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--card-bg) 72%, transparent);
  color: var(--text-muted);
}

.wave-start-button.active:not(:disabled) {
  border-color: color-mix(in srgb, var(--mint) 82%, transparent);
  background: color-mix(in srgb, var(--mint) 18%, transparent);
  color: var(--mint-soft);
}

.hud-icon-fallback {
  display: grid;
  width: 42px;
  height: 30px;
  place-items: center;
  color: var(--text-strong);
  font-size: 20px;
  font-weight: 1000;
  line-height: 1;
}

.map-control-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: var(--control-bg);
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.map-control-btn.active {
  background: color-mix(in srgb, var(--gold) 24%, var(--control-bg));
  color: var(--gold);
}

@media (min-width: 640px) {
  .map-control-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }
}

.map-controls {
  align-self: center;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.build-bar {
  scrollbar-width: none;
}

.build-bar::-webkit-scrollbar {
  display: none;
}

.map-choice {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  text-align: left;
  padding: 0 14px;
}

.map-choice.active {
  border-color: color-mix(in srgb, var(--mint) 85%, transparent);
  background: color-mix(in srgb, var(--mint) 16%, transparent);
  color: var(--mint-soft);
}

.difficulty-choice {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.15;
  padding: 7px 8px;
  text-align: left;
}

.difficulty-choice span {
  display: block;
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 9px;
  font-weight: 800;
}

@media (min-width: 640px) {
  .map-choice {
    min-height: 44px;
    font-size: 14px;
  }

  .difficulty-choice {
    min-height: 62px;
    padding: 8px 10px;
  }

  .difficulty-choice span {
    font-size: 10px;
  }
}

.difficulty-choice.active {
  border-color: color-mix(in srgb, var(--mint) 85%, transparent);
  background: color-mix(in srgb, var(--mint) 16%, transparent);
  color: var(--mint-soft);
}
