.games-page {
  max-width: 1140px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* ---- game-select tabs ---- */
.games-tabbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 0.75rem;
}

/* ---- global chat widget (shared under both games) ---- */
.games-chat-card {
  margin-bottom: 1.5rem;
}
.games-chat-card .gc-window {
  max-height: 220px;
}
@media (min-width: 900px) {
  .games-chat-card .gc-window {
    max-height: 260px;
  }
}
.games-tab-btn {
  background: var(--card-bg2);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  font-weight: 700;
  font-family: 'Rajdhani', sans-serif;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.15s ease;
}
.games-tab-btn:hover { color: var(--text); border-color: var(--gold); }
.games-tab-btn.active-tab {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #1a1108;
  border-color: transparent;
}
.games-tab-btn .soon-flag { font-size: 0.65rem; opacity: 0.7; margin-left: 0.35rem; }

.game-panel { display: none; }
.game-panel.active-panel { display: block; }

/* ---- Tower Defense layout ----
   Build Towers sits left of the maze, Selected Tower / Wave Intel sits
   right of it — both always in view beside the board instead of below
   it, so placing/upgrading a tower never needs a page scroll. Reference
   material (how-to, points, matchups, leaderboard) lives in its own grid
   further down since it's not needed mid-build. */
.td-layout {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  grid-template-areas: "left board right";
  gap: 1.25rem;
  align-items: start;
}
.td-side-left { grid-area: left; }
.td-board-card { grid-area: board; }
.td-side-right { grid-area: right; }
.td-side { min-width: 0; }
.td-side .td-sidebar-card { position: sticky; top: 76px; }

/* Medium screens: drop the left column above the board (still zero
   scroll to reach it — it's the very next thing after the board),
   keep the right column (Selected Tower/Wave Intel) beside the board
   since that's the panel you're glancing at constantly while playing. */
@media (max-width: 1180px) {
  .td-layout {
    grid-template-columns: 1fr 280px;
    grid-template-areas:
      "left  right"
      "board right";
  }
}

/* Mobile: single column, stacked in the order you actually use them —
   Build Towers first (pick a tower), then the maze (place it), then
   Selected Tower/Wave Intel right after (manage it) — before any of the
   reference cards further down. */
@media (max-width: 920px) {
  .td-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "left" "board" "right";
  }
  .td-side .td-sidebar-card { position: static; }
}

.td-reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.td-board-card { display: flex; flex-direction: column; align-items: center; position: relative; }

.td-hud {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.td-hud-block { text-align: center; min-width: 70px; }
.td-buy-life-btn { display: block; margin: 4px auto 0; padding: 2px 8px; font-size: 0.7rem; line-height: 1.4; white-space: nowrap; }
.td-hud-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.65; }
.td-hud-value { font-family: "Orbitron", sans-serif; font-size: 1.3rem; font-weight: 700; color: var(--gold-bright); }
.td-hud-value.lives-val { color: #ff6b6b; }
.td-hud-value.energy-val { color: #f4e04d; }

.td-watchers-badge {
  align-self: center;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 80, 80, 0.12);
  border: 1px solid rgba(255, 80, 80, 0.35);
  color: #ff8080;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: default;
}

.td-build-mode-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.75rem;
  background: rgba(80,220,120,0.12);
  border: 1px solid rgba(80,220,120,0.4);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
}
.td-build-mode-bar b { color: #7dffa0; }
.td-build-mode-bar button {
  background: var(--card-bg2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.td-build-mode-bar button:hover { border-color: #ff6b6b; color: #ff6b6b; }

#td-canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: var(--card-bg2);
}
#td-canvas { display: block; touch-action: none; cursor: crosshair; max-width: 100%; }

.td-status-bar {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--card-bg2);
  border: 1px dashed var(--border-soft);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  min-height: 1.4em;
}

.td-session-row {
  width: 100%;
  display: flex;
  gap: 0.75rem;
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.td-session-row b { color: var(--gold-bright); font-family: "Share Tech Mono", monospace; }
.td-live-total { color: var(--text-dim); opacity: 0.75; font-size: 0.72rem; }
.td-live-total b { color: var(--text-dim); font-weight: 600; }

.td-lb-row {
  display: grid;
  grid-template-columns: 32px 28px 1fr auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.9rem;
}
.td-lb-row-me {
  background: rgba(241, 196, 15, 0.08);
  border-radius: 6px;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  border-bottom-color: rgba(241, 196, 15, 0.25);
}
.td-lb-rank { opacity: 0.6; font-family: "Share Tech Mono", monospace; }
.td-lb-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255,255,255,0.08) center/cover no-repeat;
}
.td-lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-lb-wave { font-weight: 700; color: var(--gold-bright); }
.td-lb-played { font-size: 0.72rem; color: var(--text-dim); text-align: right; white-space: nowrap; }

/* Currently-playing row — a subtle green pulse so it reads as "live"
   at a glance without fighting with the gold "it's you" highlight
   (both can be active at once if you're on the board yourself). */
.td-lb-row-live {
  background: rgba(124, 252, 124, 0.06);
  border-radius: 6px;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  border-bottom-color: rgba(124, 252, 124, 0.2);
}
.td-lb-live-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 800;
  color: #7CFC7C;
  background: rgba(124, 252, 124, 0.12);
  border: 1px solid rgba(124, 252, 124, 0.4);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  margin-left: 0.35rem;
  vertical-align: middle;
  animation: td-lb-live-pulse 1.6s ease-in-out infinite;
}
.td-lb-best {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.72rem;
}
@keyframes td-lb-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.td-controls-row {
  width: 100%;
  display: flex;
  gap: 0.6rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}
.td-controls-row button {
  flex: 1;
  min-width: 100px;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--card-bg2);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
}
.td-controls-row button:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-bright); }
.td-controls-row button:disabled { opacity: 0.45; cursor: not-allowed; }
.td-controls-row button.primary-btn { background: linear-gradient(135deg, var(--gold-bright), var(--gold)); color: #1a1108; border: none; }
.td-controls-row button.active-speed { border-color: var(--gold); color: var(--gold-bright); }
#td-sound-btn { flex: none; min-width: 44px; width: 44px; padding: 0.6rem 0; font-size: 1rem; }

/* ---- Sidebar ---- */

.td-action-split { display: flex; flex-direction: column; gap: 1rem; }
.td-action-half h2 { margin-bottom: 0.4rem; }
.td-action-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0.15rem 0;
}
#td-wave-intel { max-height: 220px; overflow-y: auto; }

.td-shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 0.75rem; }
/* The left rail is narrower than the old full-width sidebar was, so its
   shop grid goes single-column to keep each tower's name/cost/stats
   readable instead of squeezed into ~100px tiles. */
.td-side-left .td-shop-grid { grid-template-columns: 1fr; }
.td-shop-item {
  background: var(--card-bg2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.6rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.td-shop-item:hover { border-color: var(--gold); }
.td-shop-item.selected-shop-item {
  border-color: var(--gold);
  background: rgba(255,90,31,0.12);
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.td-shop-icon { font-size: 1.4rem; }
.td-shop-name { font-size: 0.72rem; font-weight: 700; margin-top: 0.2rem; }
.td-shop-cost { font-size: 0.7rem; color: #f4e04d; font-family: "Share Tech Mono", monospace; margin-top: 0.1rem; }
.td-shop-stats { font-size: 0.62rem; color: var(--text-dim); margin-top: 0.2rem; line-height: 1.35; }

.td-selection-empty { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.6rem; }
.td-selection-box { margin-top: 0.6rem; }
.td-selection-row { display: flex; justify-content: space-between; font-size: 0.8rem; margin: 0.2rem 0; color: var(--text-dim); }
.td-selection-row b { color: var(--text); }

/* Group ("select all of type" via double-click) panel — same base look
   as the single-tower box, plus a gold accent border/glow so it's
   obviously a distinct multi-select state at a glance. */
#td-group-box {
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: rgba(255, 184, 0, 0.06);
  box-shadow: 0 0 0 1px rgba(255, 184, 0, 0.15) inset;
}
#td-group-box .td-upgrade-row button,
#td-group-special-upgrade-btn {
  color: var(--gold-bright);
}

.td-hpbar-wrap, .td-mpbar-wrap { margin-top: 0.5rem; }
.td-bar-label { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--text-dim); margin-bottom: 2px; }
.td-bar-track { height: 6px; border-radius: 3px; background: rgba(0,0,0,0.4); overflow: hidden; }
.td-bar-fill { height: 100%; }
.td-bar-fill.hp-fill { background: #7CFC7C; }
.td-bar-fill.mp-fill { background: #7fe8ff; }

.td-upgrade-tracks { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
.td-upgrade-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card-bg2); border: 1px solid var(--border-soft);
  border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 0.75rem;
}
.td-upgrade-row .tu-label { font-weight: 700; }
.td-upgrade-row .tu-level { color: var(--text-dim); margin-left: 0.35rem; }
.td-upgrade-row button {
  padding: 0.3rem 0.6rem; border-radius: 6px; border: 1px solid var(--border-soft);
  background: var(--card-bg); color: var(--gold-bright); font-weight: 700; cursor: pointer;
  font-size: 0.7rem;
}
.td-upgrade-row button:hover:not(:disabled) { border-color: var(--gold); }
.td-upgrade-row button:disabled { opacity: 0.4; cursor: not-allowed; }

.td-selection-actions { display: flex; gap: 0.5rem; margin-top: 0.65rem; }
.td-selection-actions button {
  flex: 1; padding: 0.5rem; border-radius: 8px; border: 1px solid var(--border-soft);
  background: var(--card-bg2); color: var(--text); font-weight: 700; cursor: pointer; font-size: 0.75rem;
}
.td-selection-actions button.repair-btn:hover:not(:disabled) { border-color: #7CFC7C; color: #7CFC7C; }
.td-selection-actions button.sell-btn:hover { border-color: #ff6b6b; color: #ff6b6b; }
.td-selection-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

.td-howto { font-size: 0.75rem; color: var(--text-dim); line-height: 1.6; margin-top: 0.6rem; }
.td-howto li { margin-bottom: 0.3rem; }

.td-matchup-table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-size: 0.72rem; }
.td-matchup-table th, .td-matchup-table td { padding: 0.3rem 0.4rem; text-align: center; border-bottom: 1px solid var(--border-soft); }
.td-matchup-table th { color: var(--text-dim); font-weight: 700; }
.td-matchup-strong { color: #7CFC7C; font-weight: 700; }
.td-matchup-weak { color: #ff6b6b; font-weight: 700; }

/* ---- Dynamic per-tier speed buttons (1x..6x depending on VIP tier) ---- */
.td-speed-buttons { display: inline-flex; gap: 0.4rem; }
.td-speed-buttons button {
  padding: 0.5rem 0.7rem; border-radius: 8px; border: 1px solid var(--border-soft);
  background: var(--card-bg2); color: var(--text); cursor: pointer; font-weight: 700; font-size: 0.78rem;
}
.td-speed-buttons button:hover { border-color: var(--gold); color: var(--gold-bright); }
.td-speed-buttons button.active-speed { border-color: var(--gold); color: var(--gold-bright); background: rgba(255,90,31,0.12); }

/* ---- Sidebar card header row (title + action button) ---- */
.td-sidebar-head-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.td-sidebar-head-row h2 { margin: 0; }
.td-shop-info-btn { font-size: 0.72rem; padding: 0.4rem 0.7rem; white-space: nowrap; }

/* ---- Wave Intel: creep / boss max-HP readout ---- */
#td-wave-intel { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
.td-intel-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card-bg2); border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 0.45rem 0.65rem; font-size: 0.75rem;
}
.td-intel-row.td-intel-boss { border-color: #ffd700; background: rgba(255,215,0,0.08); }
.td-intel-glyph { font-size: 1rem; margin-right: 0.4rem; }
.td-intel-hp { font-family: "Share Tech Mono", monospace; color: #7CFC7C; font-weight: 700; }
.td-intel-boss .td-intel-hp { color: #ffd700; }

/* ================================================================
   Tower Shop Guide — modal + clickable, expandable tower/level cards
   ================================================================ */
.td-info-modal-overlay {
  position: fixed; inset: 0; background: rgba(10,8,7,0.82);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 1rem;
}
.td-info-modal-overlay.show-td-modal { display: flex; }
.td-info-modal-box {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
  max-width: 640px; width: 100%; max-height: 85vh; display: flex; flex-direction: column;
}
.td-info-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-soft);
}
.td-info-modal-header h2 { margin: 0; color: var(--gold-bright); }
.td-info-modal-close {
  background: none; border: 1px solid var(--border-soft); border-radius: 8px;
  color: var(--text); width: 32px; height: 32px; cursor: pointer; font-size: 0.9rem;
}
.td-info-modal-close:hover { border-color: #ff6b6b; color: #ff6b6b; }
.td-info-modal-body { padding: 1.25rem; overflow-y: auto; }

.td-info-section { margin-bottom: 1.5rem; }
.td-info-section:last-child { margin-bottom: 0; }
.td-info-section h3 { margin: 0 0 0.6rem; color: var(--gold-bright); font-size: 1rem; }

.td-info-tower {
  background: var(--card-bg2); border: 1px solid var(--border-soft);
  border-radius: 10px; margin-bottom: 0.6rem; overflow: hidden;
}
.td-info-tower-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; padding: 0.7rem 0.9rem; cursor: pointer; text-align: left;
}
.td-info-tower-title { font-weight: 700; color: var(--text); }
.td-info-tower-element { color: var(--text-dim); font-weight: 400; font-size: 0.8rem; }
.td-info-caret { transition: transform 0.15s ease; color: var(--text-dim); }
.td-info-tower-open .td-info-caret { transform: rotate(180deg); }
.td-info-tower-note { padding: 0 0.9rem 0.6rem; font-size: 0.72rem; color: var(--text-dim); font-style: italic; }
.td-info-tower-body { display: none; padding: 0 0.7rem 0.7rem; }
.td-info-tower-open .td-info-tower-body { display: block; }

.td-info-level {
  background: var(--card-bg); border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 0.6rem 0.75rem; margin-top: 0.5rem; font-size: 0.75rem;
}
.td-info-level:first-child { margin-top: 0; }
.td-info-level-max { border-color: var(--gold); }
.td-info-level-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.td-info-level-tag { font-weight: 700; color: var(--gold-bright); }
.td-info-level-stats { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--text-dim); margin-bottom: 0.35rem; }
.td-info-level-stats b { color: var(--text); }
.td-info-level-special { color: #7fe8ff; margin-bottom: 0.3rem; }
.td-info-level-extra { color: var(--text-dim); margin-bottom: 0.3rem; }
.td-info-level-cost { color: #f4e04d; font-family: "Share Tech Mono", monospace; }

.td-lock-badge { font-size: 0.65rem; padding: 0.15rem 0.5rem; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.td-lock-open { background: rgba(124,252,124,0.15); color: #7CFC7C; }
.td-lock-vip { background: rgba(79,184,232,0.15); color: #4fb8e8; }
.td-lock-svip { background: rgba(255,215,0,0.15); color: #ffd700; }

/* Overlays */
.td-overlay {
  position: absolute; inset: 0; background: rgba(10,7,4,0.9);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 0.75rem; z-index: 5; border-radius: 8px; padding: 1rem;
}
.td-overlay.show-overlay { display: flex; }
.td-overlay h2 { font-family: "Cinzel", serif; color: var(--gold-bright); }
.td-overlay button {
  padding: 0.65rem 1.4rem; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold)); color: #1a1108;
  font-weight: 800; cursor: pointer;
}

.td-tier-grid {
  display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; margin-top: 0.5rem;
}
.td-tier-btn {
  background: var(--card-bg); border: 1px solid var(--border-soft); border-radius: 12px;
  padding: 0.85rem 1.1rem; cursor: pointer; text-align: left; min-width: 150px;
  transition: all 0.15s ease;
}
.td-tier-btn:hover { border-color: var(--gold); transform: translateY(-2px); }
.td-tier-btn .tt-name { font-weight: 800; font-family: 'Cinzel', serif; color: var(--gold-bright); font-size: 0.95rem; }
.td-tier-btn .tt-stats { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.35rem; line-height: 1.5; }

.games-coming-soon { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }
.games-coming-soon .soon-icon { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }

/* ---- Shared account bar (TOPC/GEM/VIP — synced across both games) ---- */
.games-account-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.1rem;
  margin-bottom: 1.25rem;
  background: var(--card-bg2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  font-size: 0.85rem;
}
.games-account-bar .ga-item { display: flex; align-items: center; gap: 0.35rem; }
.games-account-bar b { font-family: "Share Tech Mono", monospace; color: var(--gold-bright); }
.games-account-bar .ga-vip { font-weight: 700; color: var(--gold-bright); margin-left: auto; }

/* ---- Locked tier styling (tier picker gated by real VIP status) ---- */
.td-tier-btn.td-tier-locked {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.6);
}
.td-tier-btn.td-tier-locked:hover { border-color: var(--border-soft); transform: none; }
