:root {
  --red: #cc0000;
  --red-dark: #990000;
  --cream: #fff8f0;
  --dark: #2b2b2b;
  --gray: #e6e6e6;
  --gold: #ffcb05;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--cream);
  color: var(--dark);
}

.topbar {
  background: var(--red);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 4px solid var(--gold);
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}

.header-pokeball {
  height: 1.4em;
  width: 1.4em;
  object-fit: contain;
  image-rendering: pixelated;
  vertical-align: middle;
  margin-right: 2px;
}

.stats {
  display: flex;
  gap: 20px;
  font-weight: bold;
}

.game {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  padding: 24px;
  max-width: 1500px;
  margin: 0 auto;
}

.click-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pokeball-btn {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 6px solid var(--dark);
  background: linear-gradient(to bottom, var(--red) 0%, var(--red) 48%, var(--dark) 48%, var(--dark) 52%, white 52%, white 100%);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  transition: transform 0.05s ease;
  padding: 0;
}

.pokeball-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}

.pokeball-btn:focus {
  outline: none;
}

.pokeball-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.pokeball-icon {
  width: 40px;
  height: 40px;
  background: white;
  border: 5px solid var(--dark);
  border-radius: 50%;
}

.hint {
  color: #777;
  font-size: 0.9rem;
  margin: 0;
}

.pokedex {
  width: 100%;
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.pokedex h2, .shop h2 {
  margin-top: 0;
  font-size: 1.1rem;
  border-bottom: 2px solid var(--gray);
  padding-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.pokedex-stats {
  font-size: 0.75rem;
  font-weight: normal;
  color: #777;
}

.pokedex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 4px;
}

.pokemon-card {
  background: var(--gray);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  transition: opacity 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 3px solid transparent;
}

.pokemon-card.uncaught {
  opacity: 0.4;
}

.pokemon-card.tier-common { border-color: #c0c0c0; }
.pokemon-card.tier-uncommon { border-color: #87ceeb; }
.pokemon-card.tier-rare { border-color: #ffd700; }
.pokemon-card.tier-legendary {
  border-color: #cc0000;
  box-shadow: 0 0 8px rgba(204, 0, 0, 0.6);
}

.pokemon-dex {
  font-size: 0.65rem;
  color: #888;
}

.pokemon-emoji {
  font-size: 2rem;
  display: block;
}

.pokemon-sprite {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  margin: 0 auto;
}

.pokemon-name {
  font-weight: bold;
  font-size: 0.85rem;
  display: block;
}

.pokemon-types {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 16px;
}

.type-badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  color: white;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: bold;
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
}

.pokemon-caught {
  font-size: 0.75rem;
  color: #555;
}

.pokemon-shiny-count {
  font-size: 0.7rem;
  color: #b8860b;
  font-weight: bold;
}

.shop {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  max-height: 640px;
  overflow-y: auto;
}

.building-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.building-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--gray);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--cream);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.building-row:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.building-row:not(:disabled):hover {
  border-color: var(--gold);
}

.building-emoji {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.building-info {
  flex: 1;
}

.building-name {
  font-weight: bold;
}

.building-desc {
  font-size: 0.75rem;
  color: #666;
}

.building-meta {
  text-align: right;
  font-size: 0.8rem;
  white-space: nowrap;
}

.building-cost {
  font-weight: bold;
  color: var(--red-dark);
}

.building-owned {
  color: #555;
}

.trainer-group {
  margin-bottom: 16px;
}

.trainer-group:last-child {
  margin-bottom: 0;
}

.trainer-group-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin: 0 0 8px;
}

.trainer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.trainer-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--gray);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--cream);
}

.trainer-row:hover {
  border-color: var(--gold);
}

.trainer-emoji {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.trainer-info {
  flex: 1;
  min-width: 0;
}

.trainer-name {
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.trainer-level-tag {
  font-size: 0.7rem;
  font-weight: normal;
  color: white;
  background: var(--red);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 4px;
}

.trainer-desc {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%) translateY(-6px);
  width: max-content;
  max-width: 260px;
  background: var(--dark);
  color: white;
  font-size: 0.75rem;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 6px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.trainer-row:hover .trainer-desc {
  opacity: 1;
}

.trainer-action-btn {
  background: var(--red);
  color: white;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: bold;
  font-size: 0.75rem;
  line-height: 1.3;
  cursor: pointer;
  text-align: center;
  flex-shrink: 0;
  max-width: 40%;
}

.trainer-action-btn:hover:not(:disabled) {
  background: var(--red-dark);
}

.trainer-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.trainer-badge {
  font-size: 0.8rem;
  color: #888;
  font-weight: bold;
  white-space: nowrap;
  flex-shrink: 0;
}

.reset-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.reset-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.first-catch-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 2000;
}

.first-catch-modal.visible {
  opacity: 1;
}

.first-catch-card {
  background: white;
  border: 4px solid var(--gold);
  border-radius: 16px;
  padding: 28px 48px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: pop-in 0.3s ease;
  cursor: pointer;
}

/* Only the currently-visible modal's card becomes interactive — otherwise
   every modal (even invisible, opacity:0 ones) sits stacked in the same
   centered spot and the topmost one in source order silently intercepts
   clicks meant for whichever modal is actually showing. */
.first-catch-modal.visible .first-catch-card {
  pointer-events: auto;
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.first-catch-card.shiny-card {
  animation: pop-in 0.3s ease, shiny-glow 1.2s ease-in-out infinite alternate;
}

@keyframes shiny-glow {
  from { box-shadow: 0 0 18px 4px rgba(255, 241, 118, 0.6), 0 12px 40px rgba(0, 0, 0, 0.35); }
  to { box-shadow: 0 0 36px 10px rgba(255, 241, 118, 1), 0 12px 40px rgba(0, 0, 0, 0.35); }
}

.first-catch-label {
  color: var(--red);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.popup-dex {
  color: #888;
  font-size: 0.85rem;
}

.popup-emoji {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: contain;
  image-rendering: pixelated;
  margin: 0 auto;
}

.popup-name {
  font-size: 1.5rem;
  font-weight: bold;
  margin-top: 4px;
}

.popup-types {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  justify-content: center;
}

.tutorial-card {
  max-width: 360px;
  cursor: default;
}

.tutorial-sprite {
  display: block;
  width: 80px;
  height: 80px;
  object-fit: contain;
  image-rendering: pixelated;
  margin: 0 auto 4px;
}

.tutorial-text {
  font-size: 0.9rem;
  color: #444;
  line-height: 1.5;
  margin: 12px 0;
}

.tutorial-ok-btn {
  background: var(--red);
  color: white;
  border: none;
  padding: 8px 28px;
  border-radius: 8px;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 4px;
}

.tutorial-ok-btn:hover {
  background: var(--red-dark);
}
