* {
  box-sizing: border-box;
}

:root {
  --bg-a: #0b0f1f;
  --bg-b: #1c2244;
  --bg-c: #2c1757;
  --panel: rgba(15, 20, 38, 0.86);
  --panel-border: rgba(159, 125, 255, 0.35);
  --text: #edf1ff;
  --muted: #b8c0e5;
  --accent: #8f7cff;
  --accent-2: #53d5ff;
  --danger: #ff6f91;
  --good: #37d67a;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Poppins", sans-serif;
  background:
    radial-gradient(circle at 10% 12%, rgba(143, 124, 255, 0.22), transparent 28%),
    radial-gradient(circle at 88% 20%, rgba(83, 213, 255, 0.2), transparent 32%),
    linear-gradient(140deg, var(--bg-a), var(--bg-b) 48%, var(--bg-c));
}

.teams-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(5, 8, 18, 0.75);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(143, 124, 255, 0.35);
}

.teams-brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.teams-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.teams-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.teams-nav a {
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.teams-nav a:hover {
  border-color: rgba(143, 124, 255, 0.65);
  box-shadow: 0 0 0 1px rgba(143, 124, 255, 0.45) inset;
}

.teams-nav-toggle {
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(83, 213, 255, 0.35);
  background: rgba(83, 213, 255, 0.12);
  cursor: pointer;
}

.teams-nav-toggle:hover {
  border-color: rgba(83, 213, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(83, 213, 255, 0.4) inset;
}

.teams-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 1.1fr;
  gap: 14px;
  padding: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(143, 124, 255, 0.2);
  border: 1px solid rgba(143, 124, 255, 0.45);
  font-size: 0.82rem;
  color: #d8d1ff;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

input,
select,
button {
  font-family: inherit;
}

input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px;
}

option {
  color: #111;
}

.builder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  color: #0f1230;
  background: linear-gradient(135deg, var(--accent), #b49bff);
}

.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn.tiny {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn.tiny.active {
  background: linear-gradient(135deg, var(--accent-2), #aaf1ff);
  color: #07273a;
}

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

.slot-card {
  min-height: 82px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.slot-card img {
  width: 58px;
  height: 58px;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.slot-meta {
  flex: 1;
  min-width: 0;
}

.slot-meta h4 {
  margin: 0;
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-meta p {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.remove-slot {
  border: none;
  border-radius: 8px;
  padding: 4px 7px;
  cursor: pointer;
  background: rgba(255, 111, 145, 0.25);
  color: #ffdbe5;
}

.sub-head {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.sub-head h3 {
  margin: 0;
  font-size: 0.9rem;
}

.pool-list {
  max-height: 380px;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.pool-item {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pool-item img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
}

.pool-item .meta {
  flex: 1;
  min-width: 0;
}

.pool-item .meta h4 {
  margin: 0;
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pool-item .meta p {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.pool-item button {
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 700;
  background: rgba(83, 213, 255, 0.2);
  color: #d4f7ff;
  cursor: pointer;
}

.saved-list {
  display: grid;
  gap: 8px;
  max-height: 700px;
  overflow: auto;
  padding-right: 4px;
}

.team-card {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
}

.team-card h4 {
  margin: 0;
  font-size: 0.9rem;
}

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

.team-sprites {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 6px 0;
}

.team-sprites img {
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
}

.team-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.team-actions button {
  border: none;
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  font-weight: 700;
}

.team-actions .use {
  background: rgba(143, 124, 255, 0.28);
  color: #ece8ff;
}

.team-actions .del {
  background: rgba(255, 111, 145, 0.25);
  color: #ffdbe5;
}

.battle-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.battle-controls.compact {
  gap: 10px;
}

.battle-controls label {
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.battle-controls label .btn {
  width: 100%;
}

.arena-stage {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, rgba(47, 95, 146, 0.4), rgba(31, 48, 76, 0.55));
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.battle-scene {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 2px solid rgba(255, 203, 5, 0.5);
  background: linear-gradient(180deg, #6eb8f3 0%, #3c6fa8 100%);
  box-shadow: inset 0 -40px 80px rgba(9, 19, 46, 0.45);
}

.battle-terrain {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 128px;
  background:
    radial-gradient(circle at 22% 28%, rgba(109, 180, 103, 0.9), rgba(57, 116, 66, 0.95) 60%, transparent 62%),
    radial-gradient(circle at 78% 48%, rgba(109, 180, 103, 0.9), rgba(57, 116, 66, 0.95) 56%, transparent 60%),
    linear-gradient(180deg, rgba(126, 204, 113, 0.88), rgba(64, 128, 72, 0.95));
  z-index: 1;
}

.terrain-platform {
  position: absolute;
  width: 168px;
  height: 42px;
  border-radius: 999px;
  background: radial-gradient(circle at 50% 50%, rgba(227, 235, 248, 0.9), rgba(170, 188, 209, 0.8));
  border: 1px solid rgba(59, 91, 167, 0.55);
  z-index: 2;
}

.opponent-platform {
  top: 32%;
  right: 13%;
}

.player-platform {
  bottom: 19%;
  left: 13%;
}

.fighter {
  text-align: center;
}

.player-fighter,
.opponent-fighter {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-fighter {
  left: 8%;
  bottom: 8%;
}

.opponent-fighter {
  right: 8%;
  top: 10%;
}

.fighter img {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
}

.pokemon-sprite {
  transition: transform 0.2s ease, opacity 0.2s ease, filter 0.25s ease;
}

.pokemon-sprite.intro-hidden {
  opacity: 0;
  transform: scale(0.2);
}

.pokemon-sprite.intro-active {
  opacity: 1;
  transform: scale(1);
}

.player-sprite {
  animation: float-player 2.6s ease-in-out infinite;
}

.opponent-sprite {
  animation: float-opponent 2.6s ease-in-out infinite;
}

.stats-box {
  width: 190px;
  border-radius: 10px;
  border: 2px solid rgba(59, 91, 167, 0.75);
  background: linear-gradient(145deg, rgba(245, 245, 245, 0.92), rgba(213, 223, 240, 0.92));
  color: #1f2a44;
  padding: 8px;
}

.fighter h4 {
  margin: 0 0 4px;
  font-size: 0.86rem;
}

.hp-wrap {
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.hp-wrap.damage {
  animation: hp-decrease 0.35s ease-in-out;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #5af08c, #35c96b);
  transition: width 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.versus {
  font-weight: 800;
  color: #ffd978;
  letter-spacing: 1px;
}

.battle-dialogue {
  position: absolute;
  z-index: 4;
  max-width: 45%;
  min-height: 30px;
  border-radius: 10px;
  color: #fff;
  font-size: 0.76rem;
  line-height: 1.35;
  padding: 8px 10px;
  border: 2px solid rgba(255, 203, 5, 0.8);
  background: rgba(0, 0, 0, 0.58);
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.battle-dialogue.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.left-dialogue {
  left: 6%;
  top: 8%;
}

.right-dialogue {
  right: 6%;
  bottom: 8%;
}

.pokeball {
  width: 40px;
  height: 40px;
  position: absolute;
  z-index: 5;
  opacity: 0;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.4));
}

.opponent-pokeball {
  top: 30%;
  left: 18%;
}

.player-pokeball {
  bottom: 30%;
  right: 18%;
}

.pokeball.throw-opponent {
  opacity: 1;
  animation: throw-ball-opponent 1s forwards;
}

.pokeball.throw-player {
  opacity: 1;
  animation: throw-ball-player 1s forwards;
}

.visual-status {
  margin-top: 8px;
  border-color: rgba(255, 203, 5, 0.55);
  background: linear-gradient(135deg, rgba(16, 27, 53, 0.85), rgba(28, 43, 79, 0.82));
}

.visual-feed {
  display: none;
}

.arena-stage.attack-left .player-sprite,
.battle-modal-stage.attack-left .player-sprite {
  transform: translate(14px, -4px) scale(1.02);
}

.arena-stage.attack-right .opponent-sprite,
.battle-modal-stage.attack-right .opponent-sprite {
  transform: translate(-14px, 4px) scale(1.02);
}

.arena-stage.damage-left .player-sprite,
.battle-modal-stage.damage-left .player-sprite,
.arena-stage.damage-right .opponent-sprite,
.battle-modal-stage.damage-right .opponent-sprite {
  filter: brightness(1.45) saturate(1.5);
}

.battle-status {
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
  font-size: 0.85rem;
}

.battle-log {
  margin: 8px 0 0;
  max-height: 230px;
  overflow: auto;
  padding-left: 20px;
  color: #d9e2ff;
  font-size: 0.78rem;
  line-height: 1.5;
}

.teams-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 22, 44, 0.95);
  border: 1px solid rgba(143, 124, 255, 0.45);
  color: #f2f4ff;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.teams-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 6, 14, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.confirm-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.confirm-modal {
  width: min(430px, 92vw);
  border-radius: 14px;
  border: 1px solid rgba(143, 124, 255, 0.45);
  background: linear-gradient(170deg, rgba(15, 22, 46, 0.98), rgba(20, 28, 58, 0.98));
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  padding: 16px;
  transform: translateY(12px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.confirm-overlay.open .confirm-modal {
  transform: translateY(0) scale(1);
}

.confirm-modal h3 {
  margin: 0 0 8px;
  color: #edf1ff;
  font-size: 1rem;
}

.confirm-modal p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.confirm-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-cancel-btn,
.confirm-ok-btn {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.confirm-cancel-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.confirm-ok-btn {
  color: #fff;
  background: linear-gradient(135deg, #ff6f91, #ff4f7d);
}

.confirm-cancel-btn:hover,
.confirm-ok-btn:hover {
  filter: brightness(1.08);
}

.arena-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 6, 14, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  padding: 12px;
}

.arena-modal.open {
  display: flex;
}

.arena-modal-card {
  width: min(880px, 98vw);
  max-height: 88vh;
  border-radius: 18px;
  border: 2px solid rgba(255, 203, 5, 0.6);
  background: linear-gradient(170deg, rgba(15, 22, 46, 0.97), rgba(20, 28, 58, 0.97));
  padding: 16px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.arena-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 203, 5, 0.35);
}

.arena-modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: #d8d1ff;
}

.arena-modal-close {
  border: none;
  border-radius: 10px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: #f5f7ff;
  background: rgba(255, 255, 255, 0.1);
  font-size: 1rem;
}

.arena-modal-close:hover {
  background: rgba(255, 111, 145, 0.25);
  color: #ffdbe5;
}

.arena-stage {
  flex: 1;
  min-height: 340px;
  max-height: 520px;
}

.arena-modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 203, 5, 0.2);
}

.battle-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 6, 14, 0.75);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 12px;
}

.battle-modal.open {
  display: flex;
}

.battle-modal-card {
  width: min(760px, 96vw);
  border-radius: 16px;
  border: 1px solid rgba(143, 124, 255, 0.45);
  background: linear-gradient(170deg, rgba(15, 22, 46, 0.96), rgba(20, 28, 58, 0.96));
  padding: 14px;
  position: relative;
}

.battle-modal-card h3 {
  margin: 0 0 8px;
}

.battle-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: #f5f7ff;
  background: rgba(255, 255, 255, 0.1);
}

.battle-modal-loading {
  margin: 4px 0 10px;
  color: #d6e0ff;
  font-size: 0.86rem;
}

.battle-modal-stage {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, rgba(53, 102, 156, 0.45), rgba(26, 42, 72, 0.55));
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.modal-fighter {
  text-align: center;
}

.modal-fighter img {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
}

.battle-modal-moves {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.battle-modal-result {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 203, 5, 0.45);
  background: linear-gradient(135deg, rgba(16, 27, 53, 0.9), rgba(33, 52, 94, 0.9));
  color: #f7f3d8;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 12px;
  display: none;
}

.battle-modal-result.show {
  display: block;
}

.move-action-btn {
  border: none;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-weight: 700;
  color: #0b1730;
  background: linear-gradient(135deg, #7de7ff, #b2c3ff);
}

.move-action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media (max-width: 1200px) {
  .teams-layout {
    grid-template-columns: 1fr;
  }

  .saved-list {
    max-height: 420px;
  }
}

@media (max-width: 640px) {
  .teams-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .battle-controls {
    grid-template-columns: 1fr;
  }

  .slot-grid {
    grid-template-columns: 1fr;
  }

  .battle-modal-moves {
    grid-template-columns: 1fr;
  }

  .battle-scene {
    min-height: 350px;
  }

  .player-fighter,
  .opponent-fighter {
    transform: scale(0.94);
  }

  .player-fighter {
    left: 1%;
    bottom: 6%;
  }

  .opponent-fighter {
    right: 1%;
    top: 9%;
  }

  .stats-box {
    width: 155px;
  }

  .battle-dialogue {
    max-width: 60%;
    font-size: 0.72rem;
  }
}

@keyframes float-player {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes float-opponent {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

.battle-result-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  border-radius: 18px;
}

@keyframes throw-ball-opponent {
  0% {
    transform: translate(180px, -90px) rotate(0deg);
  }
  60% {
    transform: translate(0, 0) rotate(720deg);
  }
  100% {
    transform: translate(0, 0) rotate(720deg);
  }
}

@keyframes throw-ball-player {
  0% {
    transform: translate(-180px, 90px) rotate(0deg);
  }
  60% {
    transform: translate(0, 0) rotate(-720deg);
  }
  100% {
    transform: translate(0, 0) rotate(-720deg);
  }
}

@keyframes hp-decrease {
  0% { transform: translateX(0); }
  50% { transform: translateX(-5px); }
  100% { transform: translateX(0); }
}

.battle-result-card {
  text-align: center;
  background: linear-gradient(135deg, rgba(30, 120, 200, 0.9), rgba(50, 80, 160, 0.9));
  border: 2px solid rgba(255, 203, 5, 0.7);
  border-radius: 14px;
  padding: 24px;
  max-width: 320px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.battle-result-card h2 {
  margin: 0 0 12px;
  font-size: 1.6rem;
  color: #ffd700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.battle-result-card p {
  margin: 0 0 16px;
  font-size: 0.95rem;
  color: #f0f8ff;
  line-height: 1.5;
}

.battle-result-card .btn {
  width: 100%;
}
