:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffd23f;
  --blue: #3fa9ff;
  --red: #ff5a6e;
  --lime: #8cf04a;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
  background:
    radial-gradient(110% 70% at 50% 0%, #1d2346 0%, rgba(15, 16, 32, 0) 60%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 1px 5px;
  border-radius: 6px;
  background: #2f3048;
  box-shadow: 0 2px 0 #0a0b16;
  font: inherit;
  font-size: 0.8em;
  text-align: center;
  color: #e6e7f5;
}
[hidden] {
  display: none !important;
}

.shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.brand-icon {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 3px 6px rgba(63, 169, 255, 0.45));
}
.brand h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff4c9, #ffd23f 50%, #ff9b2f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #7a3b00);
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26283b, #1c1d2c);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.chip strong {
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.chip-gold strong {
  color: var(--gold);
  min-width: 3ch;
}
.chip-age strong {
  font-size: 14px;
  color: #cbbcff;
}
.coin {
  display: inline-block;
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6b8, #ffd23f 50%, #e59400);
  box-shadow:
    inset 0 0 0 2px rgba(201, 122, 0, 0.7),
    0 1px 2px rgba(0, 0, 0, 0.4);
}
.xp-bar {
  display: block;
  width: 56px;
  height: 8px;
  border-radius: 99px;
  background: #0e0f1c;
  overflow: hidden;
}
.xp-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #7e5bff, #c49bff);
  transition: width 0.25s;
}
.hud-buttons {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

/* ---------- buttons ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.pill:active {
  transform: translateY(2px) scale(0.97);
}
.pill:disabled {
  opacity: 0.45;
  cursor: default;
}
.pill-primary {
  background: linear-gradient(180deg, #8a6bff, #6842ff 55%, #5230e0);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #3a1fb0,
    0 8px 18px rgba(104, 66, 255, 0.45);
}
.pill-secondary {
  background: linear-gradient(180deg, #34364c, #2a2b3d);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 3px 0 #111220;
}
.pill-icon {
  width: 42px;
  padding: 0;
  font-size: 15px;
}
.pill-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
#mute .ico-muted,
#mute[aria-pressed="true"] .ico-sound {
  display: none;
}
#mute[aria-pressed="true"] .ico-muted {
  display: block;
}
#speed[aria-pressed="true"] {
  background: linear-gradient(180deg, #ffb13d, #ff8a1f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 #a04b00;
  color: #2a1400;
}
.pill-big {
  min-height: 56px;
  min-width: 190px;
  font-size: 22px;
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  background: #7fd0ff;
  box-shadow:
    0 0 0 3px #26283b,
    0 12px 30px rgba(0, 0, 0, 0.45);
}
.stage.shake {
  animation: shake 0.3s;
}
@keyframes shake {
  20% {
    transform: translate(-4px, 2px);
  }
  40% {
    transform: translate(4px, -2px);
  }
  60% {
    transform: translate(-3px, 1px);
  }
  80% {
    transform: translate(2px, 0);
  }
}
#canvas {
  display: block;
  width: 100%;
  height: 360px;
  touch-action: pan-y;
  cursor: grab;
}
#canvas:focus-visible {
  outline-offset: -4px;
}
.base-bars {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.base-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(42%, 300px);
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 12px;
}
.base-bar-foe {
  justify-content: flex-end;
}
.bb-label {
  font-weight: 900;
  color: var(--blue);
  white-space: nowrap;
}
.base-bar-foe .bb-label {
  color: var(--red);
}
.bb-track {
  flex: 1 1 auto;
  height: 12px;
  border-radius: 99px;
  background: #0b0c18;
  overflow: hidden;
  display: flex;
}
.base-bar-foe .bb-track {
  justify-content: flex-end;
}
.bb-track i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(180deg, #8fe0ff, #3fa9ff 60%, #1f77d8);
  transition: width 0.2s;
}
.base-bar-foe .bb-track i {
  background: linear-gradient(180deg, #ffb0ba, #ff5a6e 60%, #d8304a);
}
.bb-num {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  min-width: 3.2ch;
  text-align: center;
}
.banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  padding: 10px 26px;
  border-radius: 999px;
  background: linear-gradient(180deg, #8a6bff, #6842ff);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 6px 0 #3a1fb0,
    0 12px 30px rgba(0, 0, 0, 0.4);
  font-size: clamp(18px, 4vw, 30px);
  font-weight: 900;
  white-space: nowrap;
  transition:
    transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1),
    opacity 0.2s;
}
.banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.banner.warn {
  background: linear-gradient(180deg, #ff8a96, #ff5a6e);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 6px 0 #a3203a;
}

/* ---------- overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(26, 27, 40, 0.55),
    rgba(15, 16, 32, 0.88)
  );
  backdrop-filter: blur(3px);
  overflow: auto;
}
.panel {
  width: min(440px, 100%);
  padding: 18px 20px 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, #26283b, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 18px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: pop-in 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes pop-in {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
}
.panel-kicker {
  margin: 0;
  color: var(--accent-2);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.panel-title {
  margin: 2px 0 6px;
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 900;
  line-height: 1.05;
  background: linear-gradient(180deg, #fff4c9, #ffd23f 50%, #ff9b2f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #7a3b00);
}
.panel.win .panel-title {
  background-image: linear-gradient(180deg, #f4ffe0, #b6f57a 55%, #52c41a);
  filter: drop-shadow(0 3px 0 #1f5a0c);
}
.panel.lose .panel-title {
  background-image: linear-gradient(180deg, #ffe0e4, #ff8a96 55%, #ff5a6e);
  filter: drop-shadow(0 3px 0 #6b1020);
}
.panel-copy {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}
.final {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}
.final-stat {
  display: flex;
  flex-direction: column;
  min-width: 82px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #13141f;
  color: var(--muted);
  font-size: 12px;
}
.final-stat strong {
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}
.badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe46b, #ffb800);
  color: #3a2400;
  font-weight: 900;
  animation: pop-in 0.4s 0.2s both cubic-bezier(0.2, 1.8, 0.4, 1);
}
.difficulty {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: #13141f;
}
.difficulty button {
  min-height: 40px;
  min-width: 80px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}
.difficulty button[aria-checked="true"] {
  background: linear-gradient(180deg, #8a6bff, #6842ff);
  color: #fff;
  box-shadow: 0 3px 0 #3a1fb0;
}
.panel-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}
.panel-keys {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}
.panel-best {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.panel-best:empty {
  display: none;
}

/* ---------- dock ---------- */
.dock {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #212233, #1a1b28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.units,
.actions {
  display: grid;
  gap: 6px;
}
.units {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 3 1 0;
}
.actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 3.4 1 0;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  min-width: 0;
  min-height: 84px;
  padding: 4px 4px 6px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #3a3c57, #2a2b3d);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #101120;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 0.1s,
    filter 0.15s,
    opacity 0.15s;
}
.card:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 1px 0 #101120;
}
.card.pop {
  animation: card-pop 0.25s;
}
@keyframes card-pop {
  50% {
    transform: scale(1.08);
  }
}
.card.nope {
  animation: nope 0.3s;
}
@keyframes nope {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}
.card.poor {
  filter: saturate(0.35) brightness(0.8);
}
.card:disabled {
  cursor: default;
  opacity: 0.55;
}
.card-art {
  width: 52px;
  height: 52px;
  flex: 1 1 auto;
  max-height: 52px;
  object-fit: contain;
}
.card-name {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.card-name small {
  color: var(--muted);
  font-size: 11px;
}
.card-cost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.card-cost .coin {
  width: 13px;
  height: 13px;
}
.card-key {
  position: absolute;
  top: 5px;
  left: 5px;
  font-size: 10px;
  opacity: 0.8;
}
.unit-card[data-role="melee"] {
  background: linear-gradient(180deg, #3b6fd8, #2a4fa8);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    0 4px 0 #173170;
}
.unit-card[data-role="ranged"] {
  background: linear-gradient(180deg, #2fb57a, #1f8a5a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    0 4px 0 #0f5335;
}
.unit-card[data-role="heavy"] {
  background: linear-gradient(180deg, #e0752f, #b5521c);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    0 4px 0 #6e2e0a;
}
.act-ico {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 2px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}
.act-ico svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}
.act-turret .act-ico {
  color: #9fd8ff;
}
.act-sell .act-ico {
  color: var(--gold);
}
.act-special {
  background: linear-gradient(180deg, #ff8a3d, #e0541f);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #7a2a08;
}
.act-special .card-cost,
.act-evolve .card-cost {
  color: #fff;
}
.act-special .act-ico {
  color: #fff39a;
}
.act-evolve {
  background: linear-gradient(180deg, #8a6bff, #6842ff 60%, #5230e0);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #3a1fb0;
}
.act-evolve .act-ico {
  color: #e7dcff;
}
.act-evolve.ready {
  animation: glow 1.2s infinite alternate;
}
@keyframes glow {
  to {
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.25),
      0 4px 0 #3a1fb0,
      0 0 22px 4px rgba(170, 140, 255, 0.85);
  }
}
.cooldown {
  position: absolute;
  inset: 0;
  top: auto;
  height: 0%;
  background: rgba(10, 11, 22, 0.55);
  pointer-events: none;
}
.cooldown-xp {
  top: 0;
  bottom: auto;
}
.act > :not(.cooldown) {
  position: relative;
  z-index: 1;
}
.card-key {
  z-index: 2;
}
.act .card-key {
  position: absolute;
}
.queue-wrap {
  flex: 1.6 1 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 16px;
  background: #13141f;
}
.queue-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}
.queue {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.qslot {
  position: relative;
  aspect-ratio: 1;
  max-height: 44px;
  border-radius: 10px;
  background: #1e1f30;
  box-shadow: inset 0 0 0 2px #2a2b3d;
  overflow: hidden;
}
.qslot canvas {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
}
.qslot .qfill {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0;
  background: linear-gradient(
    0deg,
    rgba(104, 66, 255, 0.85),
    rgba(138, 107, 255, 0.5)
  );
}

@media (max-width: 860px) {
  .dock {
    flex-wrap: wrap;
  }
  .units {
    flex: 1 1 100%;
  }
  .queue-wrap {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
  }
  .queue {
    flex: 1 1 auto;
  }
  .qslot {
    max-height: 40px;
    aspect-ratio: auto;
    height: 40px;
  }
  .actions {
    flex: 1 1 100%;
  }
}
@media (max-width: 600px) {
  body {
    padding: 6px;
  }
  .hud {
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .brand h1 {
    font-size: 20px;
  }
  .chips {
    order: 3;
    flex: 1 1 100%;
  }
  .chip {
    padding: 0 10px;
  }
  .xp-bar {
    width: 40px;
  }
  .card {
    min-height: 76px;
  }
  .card-art {
    width: 44px;
    height: 44px;
  }
  .card-name {
    font-size: 12px;
  }
  .act-ico {
    width: 32px;
    height: 32px;
  }
  .base-bar {
    font-size: 11px;
    padding: 3px 6px;
  }
  .bb-num {
    display: none;
  }
  .final-stat {
    min-width: 0;
    flex: 1 1 0;
  }
  .difficulty button {
    min-width: 0;
    padding: 0 12px;
  }
}
@media (max-width: 380px) {
  .brand h1 {
    font-size: 17px;
  }
  .brand-icon {
    width: 28px;
    height: 28px;
  }
  .hud-buttons {
    gap: 4px;
  }
  .pill-icon {
    width: 40px;
    min-height: 40px;
  }
  .card-name small {
    display: none;
  }
  .card-cost {
    font-size: 12px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
