html {
  min-height: 100%;
  background: #070a10;
}

:root {
  --bg: #070a10;
  --panel: rgba(12, 17, 28, 0.86);
  --panel-strong: rgba(18, 25, 39, 0.94);
  --line: rgba(126, 220, 255, 0.18);
  --line-strong: rgba(126, 220, 255, 0.34);
  --text: #ecf8ff;
  --muted: #8fa8b7;
  --cyan: #59d8ff;
  --teal: #30f0c7;
  --amber: #f6c75a;
  --magenta: #da6bff;
  --green: #7dffa0;
  --danger: #ff657d;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    "Segoe UI",
    system-ui,
    sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(74, 213, 255, 0.18), transparent 34rem),
    linear-gradient(140deg, #05070d 0%, #09111c 52%, #0b0b15 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: 100%;
  max-width: 1720px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.topbar,
.control-dock,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 28, 42, 0.9), rgba(9, 13, 22, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  min-height: 82px;
  border-radius: 8px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(126, 220, 255, 0.4);
  background: url("./assets/avatar.png") center / cover no-repeat;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.16), 0 0 28px rgba(89, 216, 255, 0.35);
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), transparent 38%, rgba(0, 0, 0, 0.28));
  pointer-events: none;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.58rem);
  line-height: 1.05;
  font-weight: 780;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
}

.resource-strip {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.resource-card,
.gold-editor {
  min-height: 48px;
  border: 1px solid rgba(126, 220, 255, 0.16);
  border-radius: 8px;
  background: rgba(6, 10, 17, 0.5);
  display: grid;
  align-content: center;
}

.resource-card {
  min-width: 94px;
  padding: 7px 12px;
}

.resource-card span,
.gold-editor span {
  color: var(--muted);
  font-size: 0.72rem;
}

.resource-card strong {
  margin-top: 2px;
  font-size: 1.2rem;
  color: #ffffff;
  line-height: 1;
}

.gold-editor {
  grid-template-columns: auto 124px;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-color: rgba(246, 199, 90, 0.34);
  box-shadow: inset 0 0 18px rgba(246, 199, 90, 0.08);
}

.gold-editor strong {
  min-width: 86px;
  color: var(--amber);
  text-align: right;
  font-size: 0.98rem;
  font-weight: 760;
  line-height: 1;
}

.game-layout {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(182px, 240px) minmax(0, 1fr) minmax(190px, 260px);
  gap: 14px;
}

.panel {
  border-radius: 8px;
  min-height: 0;
  padding: 14px;
}

.panel-title {
  min-height: 42px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-title span {
  font-size: 1rem;
  font-weight: 780;
}

.panel-title small {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
  line-height: 1.35;
}

.tower-shop {
  display: grid;
  gap: 10px;
}

.tower-card {
  width: 100%;
  min-height: 78px;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid rgba(126, 220, 255, 0.15);
  background: rgba(5, 9, 16, 0.52);
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tower-card:hover,
.tower-card.active {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(10, 22, 34, 0.72);
}

.tower-card.active {
  box-shadow: inset 0 0 0 1px rgba(89, 216, 255, 0.2), 0 0 18px rgba(48, 240, 199, 0.08);
}

.tower-icon,
.selected-icon {
  background-image: url("./assets/atlas.png");
  background-size: 400% 300%;
  background-repeat: no-repeat;
}

.tower-icon {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.tower-copy {
  min-width: 0;
}

.tower-copy strong {
  display: block;
  font-size: 0.88rem;
  line-height: 1.15;
}

.tower-copy span {
  margin-top: 5px;
  display: inline-flex;
  color: var(--amber);
  font-size: 0.8rem;
  font-weight: 750;
}

.tower-copy small {
  margin-top: 4px;
  display: block;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.25;
}

.arena-stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  align-self: start;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(126, 220, 255, 0.22);
  background: #05070d;
  box-shadow: var(--shadow);
}

#gameCanvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 5 / 3;
  display: block;
  min-height: 0;
  background: #07101a;
}

.arena-vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.42);
}

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 210px;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 15px;
  border: 1px solid rgba(89, 216, 255, 0.24);
  border-radius: 8px;
  color: #eafaff;
  background: rgba(5, 10, 17, 0.68);
  text-align: center;
  font-size: 0.86rem;
  font-weight: 680;
  backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.selected-artwork {
  min-height: 138px;
  border-radius: 8px;
  border: 1px solid rgba(126, 220, 255, 0.16);
  background:
    linear-gradient(160deg, rgba(89, 216, 255, 0.08), rgba(218, 107, 255, 0.06)),
    rgba(5, 9, 16, 0.56);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.selected-artwork span {
  color: var(--muted);
  font-size: 0.84rem;
}

.selected-icon {
  width: 124px;
  height: 124px;
}

.stat-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-grid div {
  min-height: 56px;
  border-radius: 8px;
  border: 1px solid rgba(126, 220, 255, 0.14);
  background: rgba(5, 9, 16, 0.46);
  padding: 9px 10px;
  display: grid;
  align-content: center;
}

.stat-grid span {
  color: var(--muted);
  font-size: 0.68rem;
}

.stat-grid strong {
  margin-top: 3px;
  font-size: 1rem;
}

.target-modes {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.target-button,
.dock-button,
.ability-button,
.secondary-action,
.primary-action,
.wave-button {
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(126, 220, 255, 0.17);
  background: rgba(5, 9, 16, 0.62);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 720;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.target-button:hover,
.dock-button:hover,
.ability-button:hover,
.secondary-action:hover,
.primary-action:hover,
.wave-button:hover {
  transform: translateY(-1px);
  border-color: rgba(126, 220, 255, 0.36);
}

.target-button.active {
  color: #071016;
  background: linear-gradient(135deg, var(--cyan), var(--teal));
}

.action-stack {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.primary-action,
.wave-button {
  color: #071016;
  border-color: rgba(89, 216, 255, 0.5);
  background: linear-gradient(135deg, #59d8ff, #30f0c7);
  box-shadow: 0 10px 28px rgba(48, 240, 199, 0.14);
}

.secondary-action {
  color: #ffe6eb;
  border-color: rgba(255, 101, 125, 0.26);
}

.control-dock {
  min-height: 70px;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(116px, 150px) 86px 64px 86px 86px minmax(180px, 1fr) 104px 104px;
  gap: 10px;
  align-items: center;
}

.wave-meter {
  min-width: 0;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.meter-track {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(126, 220, 255, 0.12);
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta), var(--amber));
  transition: width 180ms ease;
}

.ability-button {
  position: relative;
  overflow: hidden;
}

.audio-button.active {
  color: #071016;
  background: linear-gradient(135deg, rgba(246, 199, 90, 0.95), rgba(48, 240, 199, 0.9));
}

.ability-button.cooling::after {
  content: "";
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(var(--cooldown, 0));
  background: rgba(255, 255, 255, 0.11);
}

@media (max-width: 1180px) {
  .app-shell {
    padding: 12px;
  }

  .game-layout {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr) 240px;
    gap: 12px;
    align-items: start;
  }

  .inspector-panel .panel-title {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  .stat-grid,
  .target-modes,
  .action-stack {
    margin-top: 0;
  }

  .control-dock {
    grid-template-columns: 1fr 1fr 0.8fr;
  }

  .wave-meter {
    grid-column: 1 / -1;
    order: -1;
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    min-width: 0;
  }

  .resource-strip {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .gold-editor {
    grid-template-columns: minmax(0, 1fr) minmax(96px, 132px);
  }

  .gold-editor strong {
    min-width: 0;
  }

  .game-layout,
  .control-dock,
  .inspector-panel {
    grid-template-columns: 1fr;
  }

  .resource-card,
  .gold-editor {
    min-width: 0;
  }

  .tower-shop {
    grid-template-columns: 1fr;
  }

  .selected-artwork {
    min-height: 114px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
