*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #120c08;
  --panel: #1c1410;
  --cream: #f3e9d8;
  --muted: rgba(243, 233, 216, 0.55);
  --gold: #fbbf24;
  --purple: #a78bfa;
  --cyan: #3df0ff;
  --danger: #f87171;
  --ok: #4ade80;
  --stone: #6b5b4f;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(180, 120, 50, 0.12), transparent 55%),
    radial-gradient(ellipse 40% 30% at 80% 90%, rgba(124, 58, 237, 0.08), transparent 50%),
    var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.9rem 0.35rem;
  flex-shrink: 0;
}

.home-link {
  color: #fbbf24;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.logo {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Duo with squared 2 at top-right → Duo² */
.duo-title {
  position: relative;
  display: inline-block;
  color: #c4b5fd;
  letter-spacing: 0.08em;
}

.duo-title .duo-sq {
  position: absolute;
  top: -0.45em;
  right: -0.55em;
  font-size: 0.62em;
  font-weight: 800;
  color: #fde68a;
  line-height: 1;
  letter-spacing: 0;
}

.version {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  opacity: 0.45;
  color: #86efac;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  justify-content: center;
  padding: 0.25rem 0.75rem 0.45rem;
  flex-shrink: 0;
}

.stat {
  min-width: 4.5rem;
  padding: 0.35rem 0.7rem;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-bottom: 0.1rem;
}

.stat strong {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.stat.lives strong {
  color: var(--danger);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0.6rem;
  gap: 0.4rem;
}

#game {
  width: min(960px, 100%);
  height: auto;
  max-height: 100%;
  aspect-ratio: 960 / 540;
  border-radius: 0.85rem;
  border: 2px solid rgba(180, 140, 80, 0.35);
  background: #2a2218;
  box-shadow:
    0 0 0 4px rgba(40, 28, 18, 0.8),
    0 12px 40px rgba(0, 0, 0, 0.5);
  cursor: crosshair;
  touch-action: none;
  display: block;
}

/* JS sizes buffer to the stage — CSS just fills it */
#game.fill-stage {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: auto;
}

.tower-panel {
  position: absolute;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding: 0.35rem;
  border-radius: 0.55rem;
  background: rgba(28, 20, 16, 0.96);
  border: 1px solid rgba(251, 191, 36, 0.55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  transform: translateY(-50%);
  touch-action: manipulation;
}

.tower-panel[hidden] {
  display: none !important;
}

.tp-btn {
  min-width: 6.4rem;
  padding: 0.4rem 0.55rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tp-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tp-btn.upgrade {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(34, 197, 94, 0.15);
}

.tp-btn.sell {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(239, 68, 68, 0.12);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.1rem;
}

.dock {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.4));
}

.tower-picks {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: center;
}

.pick {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  min-width: 6.4rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.pick:hover {
  border-color: rgba(251, 191, 36, 0.45);
}

.pick[aria-pressed="true"] {
  border-color: rgba(167, 139, 250, 0.75);
  background: rgba(124, 58, 237, 0.16);
}

.pick[data-type="tri"][aria-pressed="true"] {
  border-color: rgba(61, 240, 255, 0.7);
  background: rgba(61, 240, 255, 0.1);
}

.pick[data-type="circ"][aria-pressed="true"] {
  border-color: rgba(251, 113, 133, 0.75);
  background: rgba(244, 63, 94, 0.14);
}

.pick-icon {
  width: 1.35rem;
  height: 1.35rem;
  margin-bottom: 0.15rem;
}

.squipy-ico {
  border-radius: 0.28rem;
  background: linear-gradient(160deg, #c4b5fd, #7c3aed 55%, #5b21b6);
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.45);
}

.tri-ico {
  width: 0;
  height: 0;
  border-left: 0.65rem solid transparent;
  border-right: 0.65rem solid transparent;
  border-bottom: 1.15rem solid #3df0ff;
  background: none;
  filter: drop-shadow(0 0 6px rgba(61, 240, 255, 0.5));
}

.circ-ico {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fda4af, #fb7185 50%, #e11d48);
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 10px rgba(251, 113, 133, 0.5);
}

.pick-name {
  font-weight: 800;
  font-size: 0.92rem;
}

.pick-meta {
  font-size: 0.72rem;
  opacity: 0.6;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.btn {
  min-width: 5.4rem;
  padding: 0.55rem 0.85rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, #b45309, #78350f);
  border-color: rgba(253, 230, 138, 0.4);
  color: #fffbeb;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.ghost:hover:not(:disabled) {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.1);
}

.btn[aria-pressed="true"]#btn-auto {
  border-color: rgba(74, 222, 128, 0.55);
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

.modal {
  position: fixed;
  inset: var(--rg-bar) 0 0 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(12, 8, 6, 0.8);
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.modal[hidden] {
  display: none !important;
}

.modal-card {
  width: min(22rem, 100%);
  padding: 1.35rem 1.25rem 1.2rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, #2a1e16, #1c1410);
  border: 1px solid rgba(251, 191, 36, 0.25);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  font-size: 1.45rem;
  color: #fde68a;
  margin-bottom: 0.3rem;
}

.modal-sub {
  font-size: 0.9rem;
  opacity: 0.65;
  margin-bottom: 0.85rem;
  line-height: 1.4;
}

.over-score {
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

.over-score strong {
  color: var(--gold);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

@media (max-width: 700px) {
  .top-bar {
    padding: max(0.25rem, env(safe-area-inset-top)) 0.4rem 0.1rem;
    gap: 0.3rem;
  }

  .logo {
    font-size: 0.76rem;
  }

  .home-link {
    font-size: 0.68rem;
  }

  .version {
    font-size: 0.55rem;
  }

  .hud {
    gap: 0.22rem 0.28rem;
    padding: 0.1rem 0.3rem 0.2rem;
  }

  .stat {
    min-width: 2.7rem;
    padding: 0.18rem 0.28rem;
  }

  .stat strong {
    font-size: 0.85rem;
  }

  .stat .label {
    font-size: 0.5rem;
    margin-bottom: 0.04rem;
  }

  .stage {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 0.15rem;
    gap: 0;
    justify-content: stretch;
    align-items: stretch;
  }

  #game,
  #game.fill-stage {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: auto;
    border-radius: 0.4rem;
  }

  .hint {
    display: none;
  }

  .pick {
    min-width: 0;
    flex: 1 1 30%;
    padding: 0.32rem 0.28rem;
  }

  .pick-name {
    font-size: 0.76rem;
  }

  .pick-meta {
    font-size: 0.54rem;
  }

  .btn {
    min-width: 3.8rem;
    min-height: 2.25rem;
    padding: 0.38rem 0.4rem;
    font-size: 0.72rem;
  }

  .dock {
    gap: 0.28rem;
    padding: 0.25rem 0.25rem max(0.4rem, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  .tower-picks {
    width: 100%;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0.25rem;
  }

  .actions {
    width: 100%;
    gap: 0.25rem;
    justify-content: center;
  }

  .tower-panel {
    transform: translateY(-50%) scale(1.05);
  }

  .tp-btn {
    min-height: 2.35rem;
    min-width: 6.2rem;
  }
}

@media (max-width: 420px) {
  .pick-meta {
    font-size: 0.5rem;
  }

  .top-bar {
    padding: max(0.22rem, env(safe-area-inset-top)) 0.35rem 0.08rem;
  }

  .logo {
    font-size: 0.7rem;
  }
}
