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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg: #0b0d14;
  --surface: #13151f;
  --surface2: #1a1d2b;
  --border: #252838;
  --text: #e0e0e0;
  --text-dim: #6b7280;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.3);
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --orange: #fb923c;
}

body {
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
}

.music-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: opacity 0.2s;
}
.music-btn:hover {
  opacity: 0.7;
}

.music-svg {
  display: block;
}

.agent-card.is-self {
  border-color: var(--gold, #fbbf24);
  box-shadow: 0 0 0 1px var(--gold, #fbbf24) inset;
  background: linear-gradient(
    180deg,
    rgba(251, 191, 36, 0.08),
    rgba(251, 191, 36, 0.02)
  );
}
.agent-card.is-self .agent-card-name::after {
  content: "YOU";
  margin-left: 8px;
  font-size: 9px;
  font-weight: 800;
  color: #0b0d14;
  background: var(--gold, #fbbf24);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

/* ─── App layout ──────────────────────────────────────────────────────────── */

.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Map panel (left) ────────────────────────────────────────────────────── */

.map-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px;
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
  overscroll-behavior: contain;
}

.canvas-wrapper.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  padding: 0;
}

.canvas-wrapper.fullscreen #overworld {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
}

.ws-blocked-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.ws-blocked-card {
  max-width: 320px;
  padding: 20px 24px;
  background: rgba(20, 20, 28, 0.95);
  border: 1px solid rgba(248, 113, 113, 0.5);
  border-radius: 10px;
  color: #fff;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.ws-blocked-title {
  font-size: 15px;
  font-weight: 600;
  color: #f87171;
  margin-bottom: 8px;
}
.ws-blocked-text {
  font-size: 13px;
  color: #d4d4d8;
  line-height: 1.5;
}

.maximize-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.maximize-btn:hover {
  background: rgba(56, 189, 248, 0.3);
}

.follow-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  backdrop-filter: blur(4px);
}
.follow-indicator .follow-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 6px #38bdf8;
  animation: follow-pulse 1.5s ease-in-out infinite;
}
@keyframes follow-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.85);
  }
}
.follow-indicator strong {
  color: #38bdf8;
  font-weight: 700;
}
.follow-indicator #follow-unlock,
.follow-indicator #follow-copy {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.follow-indicator #follow-unlock {
  font-size: 16px;
}
.follow-indicator #follow-unlock:hover,
.follow-indicator #follow-copy:hover {
  color: #fff;
}

.follow-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 6px;
  color: #38bdf8;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.follow-btn:hover {
  background: rgba(56, 189, 248, 0.2);
}
.follow-btn.active {
  background: #38bdf8;
  color: #000;
  border-color: #38bdf8;
}
.follow-btn-icon {
  font-size: 13px;
}

#overworld {
  border: 2px solid var(--border);
  border-radius: 10px;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  display: block;
  transition: box-shadow 0.3s;
  touch-action: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#overworld:hover {
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.1);
}

.map-controls {
  flex-shrink: 0;
  position: relative;
  text-align: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}
.map-logo {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.map-logo img {
  height: 18px;
  width: auto;
  display: block;
}
.controls-mobile {
  display: none;
}
@media (hover: none) and (pointer: coarse) {
  .controls-desktop {
    display: none;
  }
  .controls-mobile {
    display: inline;
  }
}

.map-legend {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: 10px;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ─── Tab panel (right) ───────────────────────────────────────────────────── */

.tab-panel {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.tab-bar {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 6px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.tab-content.active {
  display: block;
}

/* ─── Agent directory (tab) ───────────────────────────────────────────────── */

.agent-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  gap: 10px;
  align-items: center;
}

.agent-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.agent-avatar {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom center;
  image-rendering: pixelated;
}
.agent-avatar img {
  height: 110%;
  width: auto;
  image-rendering: pixelated;
  display: block;
}

.agent-card-info {
  flex: 1;
  min-width: 0;
}
.agent-card-name {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-card-meta {
  color: var(--text-dim);
  font-size: 10px;
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.agent-card-score {
  color: var(--green);
  font-weight: 700;
  font-size: 14px;
}
.agent-last-active {
  color: #444;
  font-style: italic;
}

/* ─── Leaderboards tab ────────────────────────────────────────────────────── */

.lb-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.lb-cat {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: all 0.15s;
}

.lb-cat:hover {
  color: var(--text);
  border-color: var(--accent);
}
.lb-cat.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.lb-row:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.lb-rank {
  width: 28px;
  text-align: center;
  font-weight: 800;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.lb-row.top-1 .lb-rank {
  color: #ffd24a;
}
.lb-row.top-2 .lb-rank {
  color: #d8d8d8;
}
.lb-row.top-3 .lb-rank {
  color: #d99860;
}

.lb-avatar {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom center;
  image-rendering: pixelated;
}
.lb-avatar img {
  height: 110%;
  width: auto;
  image-rendering: pixelated;
  display: block;
}

.lb-name {
  flex: 1;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-value {
  font-weight: 800;
  font-size: 14px;
  color: var(--green);
  flex-shrink: 0;
}

.lb-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.status-dot.exploring {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.status-dot.battling {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  animation: blink 0.6s infinite;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 560px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

/* Widened variant for interior views - the 800×640 canvas wants ~1120px. */
.modal.modal-interior-open {
  max-width: 1120px;
}

.modal h3 {
  font-size: 12px;
  color: var(--gold);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s,
    transform 0.15s;
  z-index: 2;
}
.close-btn:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.close-btn:active {
  transform: scale(0.94);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding-right: 44px;
}

.modal-avatar {
  width: 50px;
  height: 75px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
}
.modal-avatar img {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 800;
}

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}
.status-badge.exploring {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
}
.status-badge.battling {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
}

/* Interact buttons (trade / battle from spectator modal) */
.modal-interact {
  margin: 10px 0 6px;
  padding: 10px 12px;
  background: rgba(56, 189, 248, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* Current PvP battle panel inside the agent modal. Visual frame comes from
 * the inner .encounter-viewer (shared with the wild-encounter panel); the
 * outer container is just spacing + the section label. */
.modal-current-battle {
  margin: 10px 0 6px;
}
.modal-current-battle .interact-label {
  font-size: 11px;
  color: var(--red);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}
.modal-current-battle .modal-active-battle {
  cursor: pointer;
  transition: border-color 0.15s;
}
.modal-current-battle .modal-active-battle:hover {
  border-color: var(--accent);
}
.modal-interact .interact-btns {
  display: flex;
  gap: 8px;
}
.modal-interact .interact-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.modal-interact .interact-msg {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}
.modal-interact .interact-msg.error {
  color: var(--red);
}
.modal-interact .interact-msg.success {
  color: var(--green);
}

/* Post-submit waiting card: shows the offer summary, a countdown, and the
 * resolution verdict (accepted / declined / expired / invalid / cancelled)
 * once the receiver responds or the timer runs out. */
.trade-waiting-summary {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.trade-waiting-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.trade-waiting-dir {
  color: var(--text-dim);
  font-size: 11px;
  min-width: 78px;
  flex-shrink: 0;
}
.trade-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
}
.trade-waiting-countdown {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.trade-waiting-result {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.trade-waiting-result.success {
  background: rgba(74, 222, 128, 0.08);
  border-color: var(--green);
  color: var(--green);
}
.trade-waiting-result.declined,
.trade-waiting-result.invalid {
  background: rgba(248, 113, 113, 0.08);
  border-color: var(--red);
  color: var(--red);
}
.trade-waiting-result.expired,
.trade-waiting-result.cancelled {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-dim);
}

/* Trade picker inside spectator modal */
.modal-trade-picker {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.modal-trade-picker .picker-col-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.modal-trade-picker label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.modal-trade-picker label:hover {
  background: rgba(255, 255, 255, 0.04);
}
.modal-trade-picker .creature-emoji {
  font-size: 16px;
}

/* Interior viewer */
.interior-viewer {
  margin: 12px 0;
  text-align: center;
}
.interior-viewer h3 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#interior-canvas {
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #1a1d2b;
  max-width: 100%;
  image-rendering: pixelated;
}
.modal-invite-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  text-align: left;
}
.modal-invite-bar input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-size: 11px;
  font-family: monospace;
  outline: none;
}
.modal-invite-bar .invite-bar-label {
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Compact interior view - shown when opening an agent's profile from inside
 * the standalone interior viewer. Thumbnail scale, clickable to pop the
 * interior view back to full size. */
.modal.modal-interior-compact .interior-viewer {
  float: right;
  margin: 0 0 10px 14px;
  text-align: center;
  cursor: pointer;
  opacity: 0.9;
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.modal.modal-interior-compact .interior-viewer:hover {
  opacity: 1;
  transform: scale(1.02);
}
.modal.modal-interior-compact .interior-viewer h3 {
  font-size: 10px;
  margin-bottom: 4px;
}
.modal.modal-interior-compact #interior-canvas {
  width: 180px;
  height: auto;
  cursor: pointer;
}
.modal.modal-interior-compact .interior-viewer::after {
  content: "↗ click to expand";
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Badges */
.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--gold);
}

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stat-item {
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 8px;
  text-align: center;
}
.stat-item .stat-label {
  color: var(--text-dim);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-item .stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-top: 1px;
}

/* Creature cards */
.creature-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 12px;
  transition: background 0.2s;
}
.creature-card:hover {
  background: var(--surface2);
}
.creature-emoji {
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}
.creature-emoji img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.creature-info {
  flex: 1;
}
.creature-name {
  font-weight: 700;
  font-size: 12px;
}
.creature-stats {
  color: var(--text-dim);
  font-size: 10px;
  font-family: "SF Mono", "Fira Code", monospace;
}

.type-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.type-flame {
  background: #c44b2f;
}
.type-aqua {
  background: #2563eb;
}
.type-leaf {
  background: #16a34a;
}
.type-shock {
  background: #ca8a04;
  color: #000;
}
.type-rock {
  background: #78716c;
}
.type-shadow {
  background: #6b21a8;
}
.type-normal {
  background: #6b7280;
}
.type-mixed {
  background: linear-gradient(135deg, #c44b2f, #2563eb, #16a34a);
}

/* HP bar */
.hp-bar-container {
  width: 100%;
  height: 4px;
  background: #1a1d28;
  border-radius: 2px;
  margin-top: 2px;
}
.hp-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}
.hp-bar.high {
  background: var(--green);
}
.hp-bar.mid {
  background: var(--orange);
}
.hp-bar.low {
  background: var(--red);
}

/* Item display */
.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.item-name {
  flex: 1;
}
.item-qty {
  color: var(--accent);
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

/* ─── Gym grid (tab) ──────────────────────────────────────────────────────── */

.gym-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gym-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  transition: all 0.2s;
}
.gym-card:hover {
  border-color: var(--accent);
}

.gym-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.gym-type-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.gym-name {
  font-weight: 800;
  font-size: 14px;
}
.gym-town {
  color: var(--text-dim);
  font-size: 11px;
}
.gym-leader {
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 4px;
}

.gym-badge-name {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.2);
  color: var(--gold);
}

.gym-team {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.gym-team-member {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

/* ─── Battle list (tab) ───────────────────────────────────────────────────── */

.battles-section {
  margin-bottom: 18px;
}
.battles-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.battles-count {
  background: var(--surface2);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
}

.active-battles-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.active-battles-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 14px;
  font-style: italic;
}

.active-battle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
  animation: livePulse 1.5s ease-in-out infinite;
}
.active-battle:hover {
  border-color: var(--accent);
}
.active-battle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.active-battle-name {
  font-weight: 700;
  color: var(--text);
}
.active-battle-name.ab-left {
  text-align: right;
  flex: 1;
}
.active-battle-name.ab-right {
  flex: 1;
}
.active-battle-vs {
  color: var(--red);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.1em;
}
.active-battle-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 10px;
  margin-top: 4px;
}
.ab-fighter {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-dim);
  font-size: 10px;
}
.ab-sprite {
  width: 18px;
  height: 18px;
  object-fit: contain;
  image-rendering: pixelated;
}
.ab-hp-bar {
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}
.ab-hp-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}
.ab-hp-fill.low {
  background: var(--orange);
}
.ab-hp-fill.crit {
  background: var(--red);
}

.battle-list {
  display: flex;
  flex-direction: column;
}

.battle-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.battle-item .vs {
  color: var(--text-dim);
  font-size: 10px;
}
.battle-winner {
  color: var(--green);
  font-weight: 700;
}
.battle-loser {
  color: var(--red);
}
.battle-score {
  margin-left: auto;
  color: var(--gold);
  font-weight: 700;
  font-size: 11px;
}
.battle-time {
  color: #444;
  font-size: 10px;
  min-width: 50px;
  text-align: right;
}

/* ─── Join tab ────────────────────────────────────────────────────────────── */

.sidebar-join-blurb {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 14px;
  text-align: center;
}
.sidebar-join-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.sidebar-join-form input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.sidebar-join-form input[type="email"]:focus {
  border-color: var(--accent);
}
#sidebar-join-btn {
  width: 100%;
  padding: 10px;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
#sidebar-join-btn:hover {
  background: #f59e0b;
}
#sidebar-join-btn:disabled {
  background: #4b5563;
  color: var(--text-dim);
  cursor: not-allowed;
}
.sidebar-join-msg {
  display: none;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}
.sidebar-join-msg.error {
  display: block;
  background: #450a0a;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
}
.sidebar-join-sent {
  display: none;
  text-align: center;
  padding: 12px 8px;
}
.sidebar-join-sent.visible {
  display: block;
}
.sidebar-join-sent .sent-icon {
  font-size: 32px;
  margin-bottom: 8px;
}
.sidebar-join-sent .sent-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.sidebar-join-sent .sent-body {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 8px;
}
.sidebar-join-sent #sidebar-join-sent-email {
  color: var(--gold);
  font-weight: 600;
  word-break: break-all;
}
.sidebar-join-agent-details {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-join-agent-details > summary {
  font-size: 12px;
}

.join-hero {
  text-align: center;
  margin-bottom: 20px;
}
.join-hero h3 {
  color: var(--gold);
  font-size: 18px;
  margin-bottom: 10px;
}

.join-prompt {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.join-prompt a {
  color: var(--accent);
  font-weight: 600;
  word-break: break-all;
}
.join-copy-btn {
  margin-top: 10px;
  padding: 6px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition:
    border-color 0.2s,
    background 0.2s;
}
.join-copy-btn:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.join-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.join-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.join-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.join-setup-guide {
  margin-top: 16px;
}
.join-setup-guide h4 {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.join-tool {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg);
}
.join-tool summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.join-tool summary::before {
  content: "\25B6";
  margin-right: 8px;
  font-size: 10px;
  display: inline-block;
  transition: transform 0.2s;
}
.join-tool[open] summary::before {
  transform: rotate(90deg);
}
.join-tool summary:hover {
  color: var(--accent);
}
.join-tool p {
  padding: 0 14px 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}
.join-tool pre {
  margin: 4px 14px 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.join-tool code {
  font-size: 12px;
  color: var(--accent);
  font-family: "SF Mono", "Fira Code", monospace;
}
.join-tool em {
  color: var(--text-dim);
  font-size: 12px;
}

/* ─── Compendium (tab) ────────────────────────────────────────────────────── */

.compendium-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-btn {
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}
.filter-btn:hover,
.filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.compendium-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.compendium-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  transition: all 0.2s;
  position: relative;
  cursor: pointer;
}
.compendium-card:hover {
  border-color: var(--accent);
}
.compendium-id {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 9px;
  color: #333;
  font-weight: 700;
}
.compendium-emoji {
  font-size: 24px;
  margin-bottom: 2px;
}
.compendium-name {
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 2px;
}
.compendium-meta {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 2px;
}
.compendium-evo {
  font-size: 9px;
  color: #555;
  margin-top: 2px;
}

.rarity-common {
  color: #9ca3af;
}
.rarity-uncommon {
  color: var(--green);
}
.rarity-rare {
  color: var(--accent);
}
.rarity-epic {
  color: #a78bfa;
}
.rarity-legendary {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* ─── Agent Detail Enhancements ──────────────────────────────────────────── */

.compendium-summary {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.held-item-label {
  font-size: 9px;
  color: var(--gold);
  background: rgba(251, 191, 36, 0.1);
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
}
.creature-status {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
}
.status-poison {
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.15);
}
.status-burn {
  color: var(--orange);
  background: rgba(251, 146, 60, 0.15);
}
.status-paralyze {
  color: var(--gold);
  background: rgba(251, 191, 36, 0.15);
}
.status-sleep {
  color: var(--text-dim);
  background: rgba(107, 114, 128, 0.2);
}
.status-freeze {
  color: #67e8f9;
  background: rgba(103, 232, 249, 0.15);
}

/* ─── Battle Replay ──────────────────────────────────────────────────────── */

.battle-replay {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 4px 0 8px;
  padding: 8px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.6;
}
.replay-entry {
  padding: 2px 4px;
  border-radius: 3px;
}
.replay-entry:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
.replay-faint {
  color: var(--red);
  font-weight: 700;
}
.replay-super {
  color: var(--green);
}
.replay-weak {
  color: var(--text-dim);
}
.replay-status {
  color: var(--orange);
  font-style: italic;
}
.replay-end {
  color: var(--gold);
  font-weight: 700;
  text-align: center;
  margin-top: 4px;
}
.replay-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 12px;
  font-style: italic;
}

/* ─── Event Feed ─────────────────────────────────────────────────────────── */

.event-feed {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}
.event-item {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.event-time {
  color: var(--text-dim);
  font-size: 10px;
  min-width: 48px;
  flex-shrink: 0;
}
.event-msg {
  flex: 1;
}
.event-battle {
  border-left: 2px solid var(--red);
}
.event-catch {
  border-left: 2px solid var(--green);
}
.event-gym_win {
  border-left: 2px solid var(--gold);
}
.event-evolve {
  border-left: 2px solid #a78bfa;
}
.event-trade {
  border-left: 2px solid var(--accent);
}
.event-world_event {
  border-left: 2px solid var(--orange);
}
.event-heal {
  border-left: 2px solid #67e8f9;
}

/* ─── World Events Bar ──────────────────────────────────────────────────── */

.world-events-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  margin-bottom: 4px;
}
.world-event-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  font-size: 11px;
}
.we-emoji {
  font-size: 14px;
}
.we-name {
  font-weight: 700;
  color: var(--gold);
}
.we-loc {
  color: var(--text-dim);
}
.we-timer {
  color: var(--orange);
  font-size: 10px;
}

/* ─── Encounter Viewer (in agent modal) ──────────────────────────────────── */

.encounter-viewer {
  margin: 12px 0;
  background: linear-gradient(135deg, #1a2a1a 0%, #0d1117 50%, #1a1a2a 100%);
  border: 1px solid #2d4a2d;
  border-radius: 8px;
  padding: 16px;
}

.encounter-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.encounter-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.encounter-sprite {
  font-size: 48px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.encounter-sprite img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Wild creature sits on the left facing the agent's lead (right). Sprites
 * ship facing right by default, so mirror the wild side horizontally. */
.encounter-wild .encounter-sprite img {
  transform: scaleX(-1);
}

.encounter-vs {
  font-weight: bold;
  font-size: 18px;
  color: var(--red);
  text-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
  padding: 0 8px;
}

.encounter-info {
  width: 100%;
  text-align: center;
}

.encounter-name {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 4px;
}

.encounter-hp-bar {
  width: 100%;
  height: 8px;
  background: #1a1d2b;
  border-radius: 4px;
  overflow: hidden;
}

.encounter-hp-fill {
  height: 100%;
  border-radius: 4px;
  transition:
    width 0.5s ease,
    background 0.5s ease;
}

.encounter-wild .encounter-hp-fill {
  background: var(--red);
}
.encounter-agent .encounter-hp-fill {
  background: var(--green);
}

.encounter-hp-text {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ─── Battle Modal ───────────────────────────────────────────────────────── */

.battle-modal {
  max-width: 700px;
  width: 95vw;
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  background: var(--surface);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
}
.battle-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 14px 24px;
  background: linear-gradient(135deg, #141627, #1e2035, #1a1d2b);
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.battle-trainer-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.battle-trainer {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.battle-trainer.winner {
  color: var(--gold);
}
.battle-team-roster {
  display: flex;
  gap: 4px;
  align-items: center;
}
.roster-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition:
    background 0.3s,
    opacity 0.3s;
}
.roster-dot.fainted {
  background: var(--red);
  opacity: 0.5;
}
.roster-dot.active {
  box-shadow: 0 0 6px var(--accent);
  border-color: var(--accent);
}
.battle-vs-badge {
  flex-shrink: 0;
}
.battle-vs-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--red);
  background: rgba(248, 113, 113, 0.12);
  padding: 3px 12px;
  border-radius: 12px;
  letter-spacing: 2px;
  border: 1px solid rgba(248, 113, 113, 0.2);
}
.battle-result-bar {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.5px;
  background: linear-gradient(
    90deg,
    rgba(251, 191, 36, 0.1),
    rgba(251, 191, 36, 0.05)
  );
  border-bottom: 1px solid var(--border);
  color: var(--gold);
  flex-shrink: 0;
}
.battle-scene {
  background: #000;
  display: flex;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.battle-scene canvas {
  width: 100%;
  max-height: 320px;
  image-rendering: auto;
}
.battle-hud {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 10px;
  background: var(--bg);
  flex-shrink: 0;
}
.battle-hud-left,
.battle-hud-right {
  flex: 1;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.3s;
}
.battle-hud-left.taking-damage,
.battle-hud-right.taking-damage {
  border-color: var(--red);
}
.bh-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.bh-name {
  font-weight: 700;
  font-size: 13px;
}
.bh-level {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 11px;
}
.bh-type {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: auto;
}
.bh-hp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.bh-hp-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gold);
}
.bh-hp-track {
  flex: 1;
  height: 8px;
  background: #111320;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #2a2d3a;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}
.bh-hp-fill {
  height: 100%;
  border-radius: 4px;
  transition:
    width 0.3s ease,
    background 0.3s ease;
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.3);
}
.bh-hp-fill.mid {
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.3);
}
.bh-hp-fill.low {
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.3);
}
.bh-hp-num {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 55px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.battle-narration {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  background: linear-gradient(180deg, var(--surface), var(--surface2));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  height: 40px;
  min-height: 40px;
  max-height: 40px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  overflow: hidden;
}
.bt-narration-icon {
  color: var(--accent);
  font-size: 10px;
  flex-shrink: 0;
  opacity: 0.7;
}
.bt-narration-text {
  flex: 1;
}
.battle-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
  flex-shrink: 0;
}
.battle-controls button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.battle-controls button:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}
.battle-controls button:active {
  transform: scale(0.92);
}
.bt-speed-btn {
  font-size: 11px !important;
  font-weight: 700;
  min-width: 36px;
  width: auto !important;
  padding: 0 6px;
}
.bt-speed-btn.speed-2x {
  color: var(--gold);
  border-color: rgba(251, 191, 36, 0.3);
}
.bt-speed-btn.speed-3x {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.3);
}
.battle-progress {
  flex: 1;
  height: 6px;
  background: #111320;
  border-radius: 3px;
  overflow: hidden;
  margin: 0 6px;
  cursor: pointer;
  border: 1px solid #1e2030;
}
.battle-progress:hover {
  border-color: var(--accent);
}
.battle-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 3px;
  transition: width 0.2s;
}
.battle-turn-counter {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.battle-log-text {
  height: 120px;
  min-height: 120px;
  max-height: 120px;
  overflow-y: auto;
  padding: 8px 16px;
  font-size: 11px;
  line-height: 1.7;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.battle-log-text::-webkit-scrollbar {
  width: 4px;
}
.battle-log-text::-webkit-scrollbar-track {
  background: transparent;
}
.battle-log-text::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.bl-entry {
  padding: 2px 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  animation: blFadeIn 0.15s ease-out;
}
@keyframes blFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.bl-icon {
  font-size: 10px;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}
.bl-text {
  flex: 1;
}
.bl-faint {
  color: var(--red);
  font-weight: 700;
}
.bl-attack {
  color: var(--text);
}
.bl-end {
  color: var(--gold);
  font-weight: 700;
}
.bl-status {
  color: var(--orange);
  font-style: italic;
}
.bl-heal {
  color: var(--green);
}
.bl-stat {
  color: #a78bfa;
}
.bl-miss {
  color: var(--text-dim);
  font-style: italic;
}

/* ─── Live Battle Indicator ─────────────────────────────────────────────── */

.battle-live {
  border-left: 3px solid var(--red);
  padding-left: 5px;
  animation: livePulse 1.5s ease-in-out infinite;
}
@keyframes livePulse {
  0%,
  100% {
    background: transparent;
  }
  50% {
    background: rgba(248, 113, 113, 0.06);
  }
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  display: inline-block;
  animation: dotPulse 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes dotPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }
  .app-layout {
    flex-direction: column;
    overflow: visible;
  }
  .map-panel {
    height: 50vh;
    min-height: 300px;
    flex: none;
  }
  .tab-panel {
    width: 100%;
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .tab-content {
    max-height: none;
  }
  .compendium-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .battle-modal {
    max-width: 100vw;
  }
  .battle-scene canvas {
    max-height: 200px;
  }
}

@media (max-width: 600px) {
  body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }
  .app-layout {
    flex-direction: column;
    overflow: visible;
  }

  /* Map */
  .map-panel {
    height: 45vh;
    min-height: 260px;
    flex: none;
    padding: 6px;
  }
  .map-controls {
    font-size: 10px;
    margin-top: 4px;
  }
  .map-logo img {
    height: 16px;
  }
  .map-legend {
    font-size: 9px;
    gap: 6px;
  }

  /* Tabs */
  .tab-panel {
    width: 100%;
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .tab-btn {
    padding: 10px 4px;
    font-size: 11px;
    letter-spacing: 0;
  }
  .tab-content {
    padding: 10px;
    max-height: none;
  }

  /* Agent cards */
  .agent-card {
    padding: 10px 8px;
    gap: 8px;
  }
  .agent-avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .agent-card-name {
    font-size: 12px;
  }
  .agent-card-meta {
    font-size: 9px;
    gap: 6px;
  }

  /* Modals */
  .modal {
    width: 96%;
    max-height: 90vh;
    padding: 16px;
    border-radius: 10px;
  }
  .modal-avatar {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  .modal-header h2 {
    font-size: 16px;
  }
  .modal-header {
    gap: 10px;
  }
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }
  .stat-item {
    padding: 6px 8px;
  }
  .stat-item .stat-value {
    font-size: 15px;
  }

  /* Battle modal */
  .battle-modal {
    width: 100vw;
    max-width: 100vw;
    border-radius: 0;
    max-height: 100vh;
  }
  .battle-header {
    padding: 10px 12px;
    gap: 10px;
  }
  .battle-trainer {
    font-size: 13px;
  }
  .battle-scene canvas {
    max-height: 180px;
  }
  .battle-hud {
    padding: 6px 10px;
    gap: 8px;
  }
  .bh-name {
    font-size: 11px;
  }
  .battle-narration {
    padding: 8px 12px;
    font-size: 12px;
  }
  .battle-controls {
    padding: 6px 10px;
    gap: 4px;
  }
  .battle-controls button {
    width: 36px;
    height: 36px;
  }
  .battle-log-text {
    padding: 6px 10px;
    font-size: 10px;
    max-height: 120px;
  }

  /* Encounter viewer */
  .encounter-viewer {
    padding: 10px;
  }
  .encounter-sprite {
    font-size: 36px;
    height: 48px;
  }
  .encounter-sprite img {
    width: 48px;
    height: 48px;
  }

  /* Join tab */
  .join-hero h3 {
    font-size: 15px;
  }
  .join-prompt {
    font-size: 12px;
    padding: 10px;
  }
  .join-step {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* Creature cards */
  .creature-card {
    padding: 6px 8px;
    gap: 8px;
  }
  .creature-emoji {
    font-size: 18px;
    width: 26px;
    height: 26px;
  }
  .creature-emoji img {
    width: 26px;
    height: 26px;
  }
  .creature-name {
    font-size: 11px;
  }

  /* Compendium */
  .compendium-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  /* Welcome modal mobile */
  .welcome-modal {
    padding: 20px;
  }
  .welcome-logo {
    font-size: 40px;
  }
  .welcome-title {
    font-size: 20px;
  }
  .welcome-step {
    padding: 10px 12px;
  }
  .welcome-step p {
    font-size: 12px;
  }
}

/* ─── Welcome Modal ─────────────────────────────────────────────────────── */

.welcome-modal {
  max-width: 520px;
  text-align: center;
}

.welcome-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.welcome-logo {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 4px;
}

.welcome-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
}

.welcome-subtitle {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 0;
}

.welcome-desc {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 420px;
  margin: 8px 0 4px;
}

.welcome-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin: 12px 0;
  text-align: left;
}

.welcome-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.welcome-step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.welcome-step strong {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.welcome-step p {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
}

.welcome-step a {
  color: var(--accent);
  text-decoration: none;
}
.welcome-step a:hover {
  text-decoration: underline;
}

.welcome-copy-btn {
  margin-top: 6px;
  padding: 5px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
}
.welcome-copy-btn:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.welcome-human-section {
  width: 100%;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 4px;
}

.welcome-human-section strong {
  font-size: 14px;
  color: var(--gold);
}

.welcome-human-section p {
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0 0;
}

.welcome-human-section a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.welcome-human-section a:hover {
  text-decoration: underline;
}

.welcome-cta {
  margin-top: 8px;
  padding: 12px 32px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.1s;
}
.welcome-cta:hover {
  background: #5ccbfa;
  transform: translateY(-1px);
}
.welcome-cta:active {
  transform: translateY(0);
}

/* ─── Sidebar dashboard (My Agent tab) ─────────────────────────────────────── */

.sidebar-hero {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.sidebar-hero:hover {
  border-color: var(--accent, #6aa9ff);
  background: var(--bg-hover, var(--bg));
}
.sidebar-hero-sprite {
  flex-shrink: 0;
  width: 40px;
  height: 60px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sidebar-hero-sprite img {
  width: 32px;
  height: 48px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.sidebar-hero-info {
  flex: 1;
  min-width: 0;
}
.sidebar-hero-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-hero-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-dim);
}
.sidebar-hero-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.3px;
}
.sidebar-hero-status.exploring {
  color: var(--green);
}
.sidebar-hero-status.battling {
  color: var(--red);
}
.sidebar-hero-status.offline {
  color: var(--text-dim);
}
.sidebar-hero-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar-hero-status.exploring .sidebar-hero-status-dot {
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
}
.sidebar-hero-status.battling .sidebar-hero-status-dot {
  background: var(--red);
  box-shadow: 0 0 4px var(--red);
  animation: blink 0.6s infinite;
}
.sidebar-hero-status.offline .sidebar-hero-status-dot {
  background: var(--text-dim);
}
.sidebar-hero-stats {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-dim);
}
.sidebar-hero-stats strong {
  color: var(--gold);
  font-weight: 700;
}

.sidebar-section {
  margin-bottom: 12px;
}
.sidebar-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* Compact creature list for sidebar */
.sidebar-creature {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 11px;
  transition: background 0.15s;
}
.sidebar-creature:hover {
  background: var(--surface2);
}
.sidebar-creature-sprite {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.sidebar-creature-info {
  flex: 1;
  min-width: 0;
}
.sidebar-creature-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-creature-meta {
  font-size: 10px;
  color: var(--text-dim);
}
.sidebar-creature-hp {
  width: 50px;
  height: 4px;
  background: #1a1d28;
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-creature-hp-fill {
  height: 100%;
  border-radius: 2px;
}

/* Compact activity for sidebar */
.sidebar-activity {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-activity-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 4px;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 4px;
}
.sidebar-activity-item:hover {
  background: var(--surface2);
}
.sidebar-activity-icon {
  font-size: 10px;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}
.sidebar-activity-text {
  flex: 1;
  color: var(--text-dim);
}
.sidebar-activity-time {
  font-size: 9px;
  color: #444;
  white-space: nowrap;
}

/* Sidebar invite */
.sidebar-invite-buttons {
  display: flex;
  gap: 8px;
}
.sidebar-invite-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  justify-content: center;
}
.sidebar-invite-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sidebar-invite-note {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-dim);
}
.sidebar-invite-note a {
  color: var(--gold);
  text-decoration: underline;
}
.sidebar-invite-active {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
}
.sidebar-invite-active input {
  width: 100%;
  padding: 5px 8px;
  margin: 6px 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-size: 11px;
  font-family: monospace;
  outline: none;
}
.sidebar-invite-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.sidebar-invite-actions button {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  justify-content: center;
}
.sidebar-invite-waiting {
  color: var(--text-dim);
  font-size: 10px;
  margin-top: 4px;
}

.sidebar-dash-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 20px 10px;
  font-style: italic;
}
.sidebar-dash-link {
  display: block;
  text-align: center;
  padding: 8px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition:
    border-color 0.2s,
    background 0.2s;
}
.sidebar-dash-link:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Login page
   ═══════════════════════════════════════════════════════════════════════════ */

body.page-login {
  height: auto;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  min-height: 100vh;
}

.page-grid {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  max-width: 1000px;
  margin: 0 auto;
  min-height: calc(100vh - 40px);
  padding-top: 20px;
}

/* Loading spinner */
.login-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 300px;
  width: 100%;
  max-width: 400px;
}
.login-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.login-loading-text {
  color: var(--text-dim);
  font-size: 14px;
}

/* Login card */
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  flex: 1 1 360px;
}

/* Hero branding */
.login-hero {
  text-align: center;
  margin-bottom: 28px;
}
.login-hero-sprites {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 4px;
  margin-bottom: 16px;
  height: 56px;
}
.login-hero-sprites img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}
.login-hero-sprites img:nth-child(1) {
  width: 40px;
  height: 40px;
}
.login-hero-sprites img:nth-child(2) {
  width: 56px;
  height: 56px;
}
.login-hero-sprites img:nth-child(3) {
  width: 40px;
  height: 40px;
}
.login-logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 1px;
  text-align: center;
}
.login-logo a {
  color: var(--gold);
  text-decoration: none;
  display: inline-block;
}
.login-logo img {
  height: 56px;
  width: auto;
  display: block;
  image-rendering: auto;
}
.login-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

/* Form elements */
.login-card label {
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.login-card input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input[type="email"]:focus {
  border-color: var(--accent);
}

#submit-btn {
  width: 100%;
  padding: 12px;
  margin-top: 20px;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}
#submit-btn:hover {
  background: #f59e0b;
}
#submit-btn:disabled {
  background: #4b5563;
  color: var(--text-dim);
  cursor: not-allowed;
}

.message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  display: none;
}
.message.success {
  display: block;
  background: #064e3b;
  color: #6ee7b7;
  border: 1px solid #065f46;
}
.message.error {
  display: block;
  background: #450a0a;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
}

.back-link {
  display: block;
  text-align: center;
  margin-top: 20px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  padding: 0;
  font-family: inherit;
}
.back-link:hover {
  text-decoration: underline;
  background: none;
}

/* Sent state */
.sent-state {
  display: none;
  text-align: center;
}
.sent-state.visible {
  display: block;
}
.sent-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 16px;
}
.sent-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}
.sent-body {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 8px;
}
.sent-email {
  color: var(--gold);
  font-weight: 500;
  word-break: break-all;
}
.sent-hint {
  color: #6b7280;
  font-size: 12px;
  margin-top: 16px;
}

/* Join card (login page) */
.join-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 440px;
  flex: 1 1 400px;
}
.join-card h2 {
  color: var(--gold);
  font-size: 18px;
  margin-bottom: 14px;
  text-align: center;
}
.join-blurb {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  margin-bottom: 18px;
  line-height: 1.5;
}
.join-card label {
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.join-card input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.join-card input[type="email"]:focus {
  border-color: var(--accent);
}
#join-btn {
  width: 100%;
  padding: 12px;
  margin-top: 20px;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}
#join-btn:hover {
  background: #f59e0b;
}
#join-btn:disabled {
  background: #4b5563;
  color: var(--text-dim);
  cursor: not-allowed;
}

.join-agent-details {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.join-agent-details > summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  list-style: none;
  padding: 4px 0;
  user-select: none;
  transition: color 0.15s;
}
.join-agent-details > summary::-webkit-details-marker {
  display: none;
}
.join-agent-details > summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}
.join-agent-details[open] > summary::before {
  transform: rotate(90deg);
}
.join-agent-details > summary:hover {
  color: var(--accent);
}
.join-agent-details[open] > summary {
  margin-bottom: 14px;
}

/* Login responsive */
@media (max-width: 600px) {
  body.page-login {
    padding: 12px;
  }
  .login-card,
  .join-card {
    padding: 24px;
  }
  .login-hero-sprites img:nth-child(1),
  .login-hero-sprites img:nth-child(3) {
    width: 32px;
    height: 32px;
  }
  .login-hero-sprites img:nth-child(2) {
    width: 44px;
    height: 44px;
  }
  .login-hero-sprites {
    height: 44px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Dashboard page
   ═══════════════════════════════════════════════════════════════════════════ */

body.page-dashboard {
  height: auto;
  overflow: auto;
  display: block;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-logo {
  color: var(--gold);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.topbar-logo img {
  height: 32px;
  width: auto;
  display: block;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-name {
  color: var(--text-dim);
  font-size: 14px;
}

/* Shared button system */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  line-height: 1;
}
.btn-primary {
  background: var(--gold);
  color: var(--bg);
}
.btn-primary:hover {
  background: #f59e0b;
}
.btn-danger {
  background: #dc2626;
  color: #fff;
}
.btn-danger:hover {
  background: #b91c1c;
}
.btn-secondary {
  background: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: #333750;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ─── Hero card ───────────────────────────────────────────────────────────── */

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.hero-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.1);
}
.hero-card::after {
  content: "View on map \2192";
  position: absolute;
  right: 20px;
  bottom: 12px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.2s;
}
.hero-card:hover::after {
  opacity: 1;
}

.hero-sprite {
  flex-shrink: 0;
  width: 80px;
  height: 120px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--surface2);
  border-radius: 10px;
  border: 2px solid var(--border);
  padding: 8px 4px 4px;
}
.hero-sprite img {
  width: 64px;
  height: 96px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hero-info {
  flex: 1;
  min-width: 0;
}
.hero-name {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.2;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.hero-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.hero-status.exploring {
  background: rgba(52, 211, 153, 0.12);
  color: var(--green);
}
.hero-status.battling {
  background: rgba(248, 113, 113, 0.12);
  color: var(--red);
}
.hero-status.offline {
  background: rgba(107, 114, 128, 0.15);
  color: var(--text-dim);
}

.hero-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hero-status.exploring .hero-status-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: heroPulse 1.5s ease-in-out infinite;
}
.hero-status.battling .hero-status-dot {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  animation: heroBlink 0.6s infinite;
}
.hero-status.offline .hero-status-dot {
  background: var(--text-dim);
}

@keyframes heroPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
@keyframes heroBlink {
  50% {
    opacity: 0.3;
  }
}

.hero-location {
  font-size: 13px;
  color: var(--text-dim);
}
.hero-location strong {
  color: var(--text);
}

.hero-stats-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.hero-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.hero-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
}
.hero-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
}

/* ─── Dashboard two-column layout ─────────────────────────────────────────── */

.dash-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
.dash-col {
  min-width: 0;
}

/* ─── Dashboard sections ──────────────────────────────────────────────────── */

body.page-dashboard .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
body.page-dashboard .stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
body.page-dashboard .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--gold);
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}
.section h2 {
  color: var(--accent);
  font-size: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.creature-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.creature-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: 8px;
}
/* Dashboard overrides for shared class names (spectator defines smaller sizes) */
body.page-dashboard .creature-emoji {
  font-size: 24px;
  width: 36px;
  height: auto;
  text-align: center;
}
body.page-dashboard .creature-sprite {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}
body.page-dashboard .creature-name {
  font-weight: 600;
  font-size: 14px;
}
body.page-dashboard .creature-meta {
  font-size: 12px;
  color: var(--text-dim);
}
body.page-dashboard .hp-bar-container {
  width: 100px;
  height: 8px;
  background: var(--border);
}
body.page-dashboard .hp-bar {
  height: 100%;
}
.hp-high {
  background: var(--green);
}
.hp-mid {
  background: var(--gold);
}
.hp-low {
  background: var(--red);
}

/* Storage swap UI - compact tiles in an auto-fill grid so the PC box can
   show many creatures at once. Lives inside a modal. */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.section-header h2 {
  margin: 0 0 16px 0;
}
.storage-modal-box {
  max-width: 880px;
}
.storage-subhead {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 8px 0;
}
.storage-hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 12px 0;
}
.storage-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.storage-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
  text-align: center;
}
.storage-tile:hover {
  border-color: var(--border);
}
.storage-tile.selected {
  border-color: var(--gold);
  background: rgba(234, 179, 8, 0.1);
}
.storage-tile.disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.storage-tile img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}
.storage-tile-name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  word-break: break-word;
}
.storage-tile-meta {
  font-size: 11px;
  color: var(--text-dim);
}
.storage-tile-hp {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.storage-tile-hp-fill {
  height: 100%;
  border-radius: 2px;
}
.storage-empty {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--text-dim);
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: 8px;
  text-align: center;
}
.storage-message-error {
  color: var(--red);
}
.storage-message-success {
  color: var(--green);
}

/* Dashboard trade/battle modal - promotes the private-room flow from the
   Trade/Battle buttons and from deep-link routes (/dashboard/trade,
   /dashboard/battle, /invite). Auto-opens when a room is active. */
.dash-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px 24px;
  z-index: 100;
  overflow-y: auto;
}
.dash-modal-box {
  position: relative;
  background: #13151f;
  border: 1px solid #252838;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  padding: 24px 24px 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}
.dash-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.dash-modal-close:hover {
  background: #1a1d2b;
  color: #e0e0e0;
}
.dash-modal-close:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.dash-modal-title {
  margin: 0 0 4px;
  font-size: 20px;
  color: #fbbf24;
}
.dash-modal-subtitle {
  color: #9ca3af;
  font-size: 13px;
  margin-bottom: 16px;
}

.token-section {
  margin-top: 0;
}
.token-display {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.token-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.warning {
  background: #451a03;
  border: 1px solid #78350f;
  color: var(--gold);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
}

.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-dim);
  font-size: 16px;
}

.badge-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.badge-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--gold);
}

.stats-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: 14px;
}
.stats-row span {
  color: var(--text-dim);
}
.stats-row strong {
  color: var(--text);
}

/* Compendium (dashboard) */
body.page-dashboard .compendium-header {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-dim);
}
body.page-dashboard .compendium-header strong {
  color: var(--gold);
  font-weight: 700;
}
.compendium-progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.compendium-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 0.4s;
}

.compendium-filter {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.compendium-filter.active {
  background: #1e293b;
  border-color: var(--accent);
  color: var(--accent);
}

body.page-dashboard .compendium-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.dex-slot {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  position: relative;
  min-height: 96px;
}
.dex-slot.caught {
  border-color: var(--green);
  background: #102018;
}
.dex-slot.seen {
  border-color: #3b4b6b;
}
.dex-slot.unseen {
  opacity: 0.55;
}

.dex-num {
  font-size: 10px;
  color: #6b7280;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.dex-slot.caught .dex-num {
  color: var(--green);
}

.dex-sprite {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  object-fit: contain;
}
.dex-sprite.silhouette {
  filter: brightness(0) saturate(100%);
}

.dex-placeholder {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  font-size: 22px;
  font-weight: 700;
}

.dex-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.dex-slot.seen .dex-name,
.dex-slot.unseen .dex-name {
  color: #6b7280;
}

.dex-type {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  padding: 1px 5px;
  background: var(--border);
  border-radius: 3px;
}
.dex-caught-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.6);
}
.dex-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px;
  text-align: center;
}

/* Collapsible sections */
.section.collapsible {
  cursor: default;
}
.section.collapsible > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.section.collapsible > summary::-webkit-details-marker {
  display: none;
}
.section.collapsible > summary h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section.collapsible > summary h2::before {
  content: "\25B6";
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.section.collapsible[open] > summary h2::before {
  transform: rotate(90deg);
}
.compendium-summary-stat {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: auto;
}

/* Settings groups inside a collapsible section */
.settings-group {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.settings-group:first-of-type {
  padding-top: 8px;
}
.settings-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}
.settings-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Bot section (dashboard) ───────────────────────────────────────── */
.bot-driver-pill {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 999px;
  background: var(--surface2, #1a1d2b);
  color: var(--text-dim, #9ca3af);
  border: 1px solid var(--border, #252838);
  vertical-align: middle;
}
.bot-driver-pill[data-driver="bot"] {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.4);
}
.bot-driver-pill[data-driver="agent"] {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.4);
}
.bot-driver-pill[data-driver="paused"] {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.4);
}
.bot-driver-pill[data-driver="idle-waiting"] {
  background: rgba(156, 163, 175, 0.12);
  color: #9ca3af;
}

/* Hero panel — big status at the top of the Bot section */
.bot-hero {
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface2, #1a1d2b);
  border: 1px solid var(--border, #252838);
  border-radius: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.bot-hero-left {
  flex: 1 1 220px;
  min-width: 0;
}
.bot-hero-state {
  font-size: 22px;
  font-weight: 700;
  color: var(--text, #e0e0e0);
  margin-bottom: 4px;
  line-height: 1.2;
}
.bot-hero-state[data-driver="bot"] {
  color: #38bdf8;
}
.bot-hero-state[data-driver="agent"] {
  color: #22c55e;
}
.bot-hero-state[data-driver="paused"] {
  color: #fbbf24;
}
.bot-hero-sub {
  font-size: 13px;
  color: var(--text-dim, #9ca3af);
  line-height: 1.4;
}
.bot-hero-right {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}
.bot-hero-stat {
  min-width: 80px;
}
.bot-hero-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim, #9ca3af);
  margin-bottom: 2px;
}
.bot-hero-stat-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #e0e0e0);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Primary action bar */
.bot-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.bot-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}
.bot-action-icon {
  font-size: 11px;
  line-height: 1;
  opacity: 0.9;
}

/* Inline status messages */
.bot-inline-msg {
  margin: 6px 0 14px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #22c55e;
}
.bot-inline-msg.err {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

/* Strategy block */
.bot-strategy {
  padding-top: 14px;
  border-top: 1px solid var(--border, #252838);
}
.bot-strategy-header {
  margin-bottom: 12px;
}
.bot-strategy-blurb {
  font-size: 12px;
  color: var(--text-dim, #9ca3af);
  margin: 0;
}
.bot-config-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
}
.bot-config-field {
  display: grid;
  grid-template-columns: 160px 1fr;
  align-items: center;
  gap: 14px;
}
.bot-config-field-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bot-config-field-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #e0e0e0);
}
.bot-config-field-default {
  font-size: 11px;
  color: var(--text-dim, #9ca3af);
}
.bot-config-field-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.bot-config-field-hint {
  font-size: 11px;
  color: var(--text-dim, #9ca3af);
  line-height: 1.35;
}
.bot-config-field input[type="text"],
.bot-config-field input[type="number"] {
  padding: 7px 10px;
  background: var(--bg, #0b0d14);
  border: 1px solid var(--border, #252838);
  border-radius: 6px;
  color: var(--text, #e0e0e0);
  font-size: 13px;
  outline: none;
  min-width: 0;
}
.bot-config-field input:focus {
  border-color: var(--accent, #38bdf8);
}
.bot-config-field input::placeholder {
  color: #4b5563;
  font-style: italic;
}
.bot-config-towns {
  display: flex;
  gap: 8px;
}
.bot-config-towns input {
  flex: 1;
}
.bot-config-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.bot-config-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent, #38bdf8);
}
.bot-config-slider-row .bot-config-slider-value {
  min-width: 48px;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text, #e0e0e0);
}
.bot-config-slider-row .bot-config-clear {
  background: none;
  border: none;
  color: var(--text-dim, #9ca3af);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.bot-config-slider-row .bot-config-clear:hover {
  color: var(--text, #e0e0e0);
}
.bot-config-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .bot-config-field {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

/* ── Welcome / onboarding page ─────────────────────────────────────── */
.welcome-loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  color: var(--text-dim, #9ca3af);
  font-size: 14px;
}
.welcome-shell {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  background: var(--bg, #0b0d14);
}
.welcome-card {
  width: 100%;
  max-width: 760px;
  background: var(--surface, #11141f);
  border: 1px solid var(--border, #252838);
  border-radius: 14px;
  padding: 36px 36px 30px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45);
}
.welcome-header {
  text-align: center;
  margin-bottom: 26px;
}
.welcome-header .login-logo img {
  width: 220px;
  height: auto;
  max-width: 100%;
  margin: 0 auto;
}
.welcome-title {
  font-size: 26px;
  margin: 14px 0 4px;
  color: var(--text, #e0e0e0);
}
.welcome-subtitle {
  color: var(--text-dim, #9ca3af);
  font-size: 14px;
  margin: 0 0 16px;
}
.welcome-steps {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.welcome-step {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface2, #1a1d2b);
  border: 1px solid var(--border, #252838);
  color: var(--text-dim, #9ca3af);
}
.welcome-step.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: #38bdf8;
}
.welcome-step.done {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: #22c55e;
}
.welcome-step-panel {
  padding: 24px 0 8px;
  border-top: 1px solid var(--border, #252838);
}
.welcome-step-panel h2 {
  margin: 0 0 6px;
  font-size: 19px;
  color: var(--text, #e0e0e0);
}
.welcome-blurb {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-dim, #9ca3af);
  line-height: 1.5;
}
.welcome-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim, #9ca3af);
}
.welcome-name-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.welcome-name-row input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg, #0b0d14);
  border: 1px solid var(--border, #252838);
  border-radius: 8px;
  color: var(--text, #e0e0e0);
  font-size: 15px;
  outline: none;
}
.welcome-name-row input:focus {
  border-color: var(--accent, #38bdf8);
}
.welcome-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}
.welcome-actions .btn-secondary {
  margin-right: auto;
}
.welcome-msg {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #22c55e;
}
.welcome-msg.err {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}
.welcome-sprite-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}
.welcome-sprite-tile {
  background: var(--surface2, #1a1d2b);
  border: 2px solid var(--border, #252838);
  border-radius: 10px;
  padding: 10px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.welcome-sprite-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(56, 189, 248, 0.4);
}
.welcome-sprite-tile.selected {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}
.welcome-sprite-img {
  width: 32px;
  height: 48px;
  image-rendering: pixelated;
}
.welcome-sprite-name {
  font-size: 11px;
  color: var(--text-dim, #9ca3af);
}
.welcome-sprite-tile.selected .welcome-sprite-name {
  color: #38bdf8;
}
.welcome-starter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.welcome-starter-tile {
  background: var(--surface2, #1a1d2b);
  border: 2px solid var(--border, #252838);
  border-radius: 10px;
  padding: 16px 14px;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.1s ease, border-color 0.15s ease;
  color: var(--text, #e0e0e0);
}
.welcome-starter-tile:hover {
  transform: translateY(-2px);
  border-color: rgba(56, 189, 248, 0.4);
}
.welcome-starter-tile.selected {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.08);
}
.welcome-starter-img {
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
}
.welcome-starter-name {
  font-size: 17px;
  font-weight: 700;
}
.welcome-starter-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.welcome-starter-type.type-leaf {
  background: rgba(34, 197, 94, 0.18);
  color: #22c55e;
}
.welcome-starter-type.type-flame {
  background: rgba(239, 68, 68, 0.18);
  color: #fb7185;
}
.welcome-starter-type.type-aqua {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
}
.welcome-starter-desc {
  font-size: 12px;
  color: var(--text-dim, #9ca3af);
  line-height: 1.4;
}

/* ── Bot mini-controls on front-page sidebar ──────────────────────── */
.sidebar-bot {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-bot-buttons {
  display: flex;
  gap: 6px;
}
.sidebar-bot-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  justify-content: center;
}
.sidebar-bot-status {
  font-size: 11px;
  color: var(--text-dim, #9ca3af);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-bot-status .bot-driver-pill {
  margin-left: 0;
  padding: 1px 8px;
  font-size: 10px;
}

/* ─── Activity feed ───────────────────────────────────────────────────────── */

.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 13px;
  animation: activitySlide 0.25s ease-out;
  border-left: 3px solid var(--border);
}
@keyframes activitySlide {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.activity-item.act-catch {
  border-left-color: var(--green);
}
.activity-item.act-battle {
  border-left-color: var(--red);
}
.activity-item.act-level {
  border-left-color: var(--accent);
}
.activity-item.act-evolve {
  border-left-color: #a78bfa;
}
.activity-item.act-gym {
  border-left-color: var(--gold);
}
.activity-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}
.activity-text {
  flex: 1;
  color: var(--text);
}
.activity-time {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}
.activity-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 12px;
  font-style: italic;
}

/* ─── In-room PvP battle UI ───────────────────────────────────────────────── */

.rbattle-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.rbattle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rbattle-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rbattle-side-right {
  align-items: flex-end;
}
.rbattle-trainer {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}
.rbattle-vs {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}
.rbattle-roster {
  display: flex;
  gap: 3px;
}
.rbattle-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  border: 1px solid transparent;
}
.rbattle-dot.active {
  background: var(--accent);
  box-shadow: 0 0 4px var(--accent);
}
.rbattle-dot.fainted {
  background: var(--red);
  opacity: 0.4;
}

.rbattle-canvas {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
  background: #0e1018;
}

.rbattle-hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rbattle-hud-card {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rbattle-hud-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.rbattle-hud-lvl {
  color: var(--text-dim);
  font-size: 11px;
}
.rbattle-hp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rbattle-hp-label {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
}
.rbattle-hp-track {
  flex: 1;
  height: 8px;
  background: #0b0d14;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.rbattle-hp-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.rbattle-hp-num {
  font-size: 10px;
  color: var(--text-dim);
  font-family: monospace;
}

.rbattle-controls {
  min-height: 40px;
}
.rbattle-moves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rbattle-move-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition:
    border-color 0.15s,
    background 0.15s;
  text-align: left;
}
.rbattle-move-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #1a1d2b;
}
.rbattle-move-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.rbattle-move-name {
  font-weight: 700;
  font-size: 13px;
}
.rbattle-move-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.rbattle-move-type {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
}
.rbattle-waiting {
  padding: 10px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.rbattle-narration {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--text);
  min-height: 32px;
}

.rbattle-switch-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.rbattle-switch-btn:hover {
  border-color: var(--accent);
  background: #1a1d2b;
}

.rbattle-switch-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rbattle-switch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
}
.rbattle-switch-back {
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
.rbattle-switch-back:hover {
  border-color: var(--accent);
}
.rbattle-switch-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}
.rbattle-switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rbattle-switch-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.rbattle-switch-card:hover {
  border-color: var(--accent);
  background: #1a1d2b;
}
.rbattle-switch-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
}
.rbattle-switch-lvl {
  color: var(--text-dim);
  font-size: 11px;
}
.rbattle-switch-type {
  align-self: flex-start;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
}

.rbattle-log {
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
  scrollbar-width: thin;
}
.rbattle-log-entry {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  color: var(--text);
}
.rbattle-log-icon {
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.rbattle-conclusion {
  text-align: center;
  padding: 16px;
  border-radius: 8px;
}
.rbattle-conclusion.rbattle-win {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
}
.rbattle-conclusion.rbattle-loss {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.rbattle-concl-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.rbattle-win .rbattle-concl-title {
  color: var(--green);
}
.rbattle-loss .rbattle-concl-title {
  color: var(--red);
}
.rbattle-concl-detail {
  font-size: 13px;
  color: var(--text);
}

/* ─── Dashboard toast ─────────────────────────────────────────────────────── */

.dash-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: #16a34a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-12px);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  pointer-events: none;
  z-index: 200;
}
.dash-toast.show {
  opacity: 1;
  transform: translateY(0);
}
.dash-toast.err {
  background: #dc2626;
}

/* ─── Dashboard responsive ────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .dash-columns {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 600px) {
  .topbar {
    padding: 10px 14px;
  }
  .topbar-right {
    gap: 8px;
  }
  .topbar-name {
    display: none;
  }
  .btn {
    padding: 6px 12px;
    font-size: 12px;
  }
  .container {
    padding: 16px 12px;
  }
  .hero-card {
    flex-direction: column;
    text-align: center;
    gap: 16px;
    padding: 20px;
  }
  .hero-sprite {
    width: 64px;
    height: 96px;
  }
  .hero-sprite img {
    width: 48px;
    height: 72px;
  }
  .hero-meta {
    justify-content: center;
  }
  .hero-stats-row {
    justify-content: center;
  }
  .hero-name {
    font-size: 20px;
  }
  .hero-card::after {
    display: none;
  }
  body.page-dashboard .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
