@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap');

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

:root {
  --bg: #0d0d1a;
  --surface: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.08);
  --text: #ffffff;
  --muted: #888;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
}

#app {
  max-width: 700px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 40px;
}

@media (min-width: 900px) {
  #app { max-width: 1200px; }
  .poke-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .poke-grid .poke-sprite-wrap { width: 120px !important; height: 120px !important; }
  .poke-grid .poke-sprite-wrap img { width: 102px !important; height: 102px !important; }
}

/* ── Header / sticky bar ── */
.phase-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, #0d0d1aee, #1a0a2eee);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  margin: 0 -16px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.phase-header__left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.phase-header__left .round-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.phase-header__left .round-title {
  font-size: 17px;
  font-weight: 900;
  color: #fff;
}
.phase-header__right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.phase-header__count { text-align: center; }
.phase-header__count .count-num {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}
.phase-header__count .count-of {
  font-size: 10px;
  color: var(--muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-family: inherit;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary { background: #A29BFE; color: #1a1a2e; }
.btn-teal  { background: #00CEC9; color: #1a1a2e; box-shadow: 0 4px 20px #00CEC966; }
.btn-ghost {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.2);
  color: #fff;
}
.btn-danger { background: linear-gradient(135deg,#FF6B6B,#A29BFE); color: #fff; }
.btn-small { padding: 6px 12px; font-size: 12px; border-radius: 9px; }

/* ── Search bar ── */
.search-bar {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 10px 16px;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.15s;
}
.search-bar:focus { border-color: rgba(255,255,255,0.4); }
.search-bar::placeholder { color: var(--muted); }
.select-all-bar { display: flex; gap: 8px; margin-bottom: 12px; }

/* ── Filter bar ── */
.filter-bar { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #ccc;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 14px;
  cursor: pointer;
  align-self: flex-start;
  -webkit-tap-highlight-color: transparent;
}
.filter-count {
  background: #A29BFE;
  color: #1a1a2e;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 900;
}
/* Mobile: content hidden until toggled */
.filter-content { display: none; flex-direction: column; gap: 6px; }
.filter-content.open { display: flex; }
/* Desktop: always show content, hide toggle button */
@media (min-width: 640px) {
  .filter-toggle { display: none; }
  .filter-content { display: flex; }
}
.filter-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.filter-label { font-size: 10px; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; min-width: 30px; flex-shrink: 0; }
.filter-chips { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.fchip {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,0.15);
  background: transparent;
  color: #bbb;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.fchip:active { opacity: 0.7; }
.fchip.active { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.5); color: #fff; }
.type-fchip { border-color: var(--tc); color: var(--tc); }
.type-fchip.active { background: var(--tc); color: #1a1a2e; }

/* ── Pokémon grid ── */
.poke-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}

/* ── Pokémon card ── */
.poke-card {
  position: relative;
  cursor: pointer;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  min-width: 0;
  overflow: hidden;
}
.poke-card.selected {
  transform: scale(1.05);
}
.poke-card .check-mark {
  position: absolute;
  top: 4px; right: 5px;
  font-size: 11px;
  line-height: 1;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}
.poke-card__name {
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  text-transform: capitalize;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  padding: 0 2px;
}
.poke-card__types {
  display: flex;
  align-items: center;
  gap: 3px;
}
.type-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.type-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
  letter-spacing: 0.5px;
}
.rank-badge {
  position: absolute;
  top: -7px; left: -7px;
  background: #FFD700;
  color: #1a1a2e;
  border-radius: 50%;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 900;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.team-badge {
  position: absolute;
  top: -7px; right: -7px;
  background: #00CEC9;
  color: #1a1a2e;
  border-radius: 50%;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 900;
  z-index: 2;
}

/* ── Sprite / avatar ── */
.poke-sprite-wrap {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.poke-sprite-wrap .fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
.poke-sprite-wrap .fallback .fb-num {
  font-weight: 900;
  color: rgba(255,255,255,0.4);
  line-height: 1;
}
.poke-sprite-wrap .fallback .fb-init {
  font-weight: 900;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.poke-sprite-wrap img {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Home screen ── */
.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px 0;
  text-align: center;
}
.home__title {
  font-size: 40px;
  font-weight: 900;
  background: linear-gradient(90deg, #FF6B6B, #FF9F43, #FFEAA7, #55EFC4, #74B9FF, #A29BFE);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.home__sub { font-size: 14px; color: var(--muted); max-width: 320px; line-height: 1.5; }
.home-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }
.home__import { width: 100%; max-width: 420px; }
.home__import textarea {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: #fff;
  font-family: monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
  min-height: 80px;
  outline: none;
}
.home__import .import-error { color: #FF6B6B; font-size: 12px; margin-top: 6px; }
.home__import .import-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ── Round 4 rank list ── */
.rank-list { display: flex; flex-direction: column; gap: 6px; }
.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 8px 10px;
  border: 1.5px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.22s cubic-bezier(0.25,0.46,0.45,0.94);
}
.rank-row.in-team {
  background: rgba(0,206,201,0.13);
  border-color: #00CEC966;
}
.rank-row:not(.in-team) { background: rgba(255,255,255,0.04); }
.rank-num {
  font-size: 15px;
  font-weight: 900;
  color: #FFD700;
  min-width: 26px;
  text-align: right;
}
.rank-arrows { display: flex; flex-direction: column; gap: 2px; }
.rank-arrows button {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 5px;
  color: #fff;
  font-size: 10px;
  width: 22px; height: 20px;
  cursor: pointer;
  line-height: 1;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.rank-arrows button:disabled {
  background: rgba(255,255,255,0.05);
  color: #555;
  cursor: default;
}
.rank-info { flex: 1; min-width: 0; }
.rank-info .rank-name {
  font-weight: 800;
  font-size: 14px;
  text-transform: capitalize;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-info .rank-type {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.team-btn {
  background: rgba(255,255,255,0.1);
  color: #aaa;
  border: none;
  border-radius: 9px;
  padding: 6px 10px;
  font-family: inherit;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.team-btn.in-team { background: #00CEC9; color: #1a1a2e; }

/* ── My team preview ── */
.team-preview {
  margin-bottom: 16px;
  background: rgba(0,206,201,0.08);
  border-radius: 16px;
  padding: 14px;
  border: 1.5px solid #00CEC944;
}
.team-preview__title {
  font-size: 12px;
  font-weight: 800;
  color: #00CEC9;
  margin-bottom: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.team-hint { font-size: 10px; color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; margin-left: 6px; }
.team-preview__cards { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.team-card-wrap { cursor: pointer; }
.team-card-wrap:hover .poke-card { filter: brightness(0.75); }
.team-card-wrap:active .poke-card { filter: brightness(0.55); }
.mega-select-wrap { margin-top: 8px; }
.mega-select-wrap label { font-size: 11px; color: #aaa; display: block; margin-bottom: 6px; }
.mega-select-wrap select {
  background: #1a1a2e;
  color: #fff;
  border: 1px solid #00CEC9;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  padding: 6px 10px;
  width: 100%;
  outline: none;
}

/* ── Results ── */
.results-hero { text-align: center; margin-bottom: 32px; }
.results-hero .trophy { font-size: 48px; }
.results-hero .results-title {
  font-size: 32px;
  font-weight: 900;
  background: linear-gradient(90deg, #FF6B6B, #FF9F43, #FFEAA7, #55EFC4, #74B9FF, #A29BFE);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.results-hero .results-sub { font-size: 14px; color: var(--muted); margin-top: 4px; }

.results-section { margin-bottom: 32px; }
.results-section__header {
  font-size: 18px;
  font-weight: 900;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid;
  padding-bottom: 8px;
}
.results-section__header .section-count {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}

.favorites-list { display: flex; flex-direction: column; gap: 6px; }
.fav-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 8px 12px;
  border: 1.5px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.04);
}
.fav-row.in-team {
  background: rgba(0,206,201,0.08);
  border-color: #00CEC944;
}
.fav-rank { font-size: 15px; font-weight: 900; color: #FFD700; min-width: 28px; text-align: right; }
.fav-info { flex: 1; min-width: 0; }
.fav-name {
  font-weight: 800;
  font-size: 14px;
  text-transform: capitalize;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fav-type { font-size: 10px; font-weight: 700; text-transform: uppercase; }
.fav-team-badge {
  font-size: 11px;
  font-weight: 800;
  color: #00CEC9;
  background: rgba(0,206,201,0.15);
  border-radius: 8px;
  padding: 3px 8px;
  flex-shrink: 0;
}
.mega-note {
  font-size: 9px;
  color: #A29BFE;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  margin-top: 2px;
}

.results-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 20px auto 0;
  flex-wrap: wrap;
}

/* ── Copy code btn (corner) ── */
.copy-code-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 200;
  background: rgba(255,255,255,0.1);
  border: 1.5px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 50%;
  width: 42px; height: 42px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.copy-code-btn:hover { background: rgba(255,255,255,0.2); }

/* ── Animations ── */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeIn 0.2s ease forwards; }

/* ── Hint text ── */
.hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

/* ── Round description ── */
.round-desc {
  font-size: 13px;
  color: #aaa;
  line-height: 1.5;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border-left: 3px solid rgba(255,255,255,0.12);
}

/* ── Shiny button ── */
.shiny-btn {
  position: absolute;
  bottom: 5px;
  left: 5px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1;
  padding: 3px 4px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}
.shiny-btn:hover, .shiny-btn.active { opacity: 1; }
.shiny-btn.active { background: rgba(255,220,80,0.25); border-color: rgba(255,220,80,0.6); transform: scale(1.15); }
.fav-row .shiny-btn { position: static; margin-left: auto; opacity: 0.5; flex-shrink: 0; }

/* ── Mobile adaptations (≤ 540px) ── */
@media (max-width: 540px) {

  /* 1 — Results action buttons: stack vertically, full width */
  .results-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .results-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* 2 — Round 4 ▲▼ buttons: larger touch targets */
  .rank-arrows button {
    width: 32px;
    height: 28px;
    font-size: 13px;
    border-radius: 7px;
  }

  /* 3 — Fav-row: wrap so badge + shiny drop to a second line,
          and tighten spacing so sprite + info always fit */
  .fav-row {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
  }
  /* Rank and sprite sit on the left, info expands to fill remaining space */
  .fav-rank { min-width: 22px; font-size: 13px; }
  .fav-info  { min-width: 0; flex-basis: 0; flex-grow: 1; }
  /* Push badge and shiny button together onto their own wrapped row */
  .fav-team-badge { order: 5; }
  .fav-row .shiny-btn { order: 5; margin-left: 0; }
}
