:root {
  --color-primary: #ef5350;
  --color-background-light: #f8f9fa;
  --color-background-dark: #101622;
  --color-text-primary: #212529;
  --color-text-secondary: #6c757d;
  --color-card-light: #ffffff;
}

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

html,
body {
  width: 100%;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background-color: var(--color-background-light);
  color: var(--color-text-primary);
  display: grid;
  grid-template-rows: auto 1fr auto;
  text-align: center;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: var(--color-primary);
}

button:focus,
a:focus {
  outline: none;
}

header {
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
}

header > div {
  display: flex;
  align-items: center;
  gap: 1rem;
}

header img {
  height: 40px;
}

header nav ul {
  list-style: none;
  display: flex;
  gap: 1rem;
}

header nav a {
  color: white;
  font-weight: bold;
  transition: opacity 0.2s ease;
}

header nav a:hover {
  opacity: 0.8;
  text-decoration: underline;
}

main {
  width: 100%;
  padding: 0.5rem;
}

footer {
  background-color: var(--color-background-dark);
  color: white;
  padding: 1rem;
}

/* Dialog */
#pokemonDialog {
  border: none;
  border-radius: 1rem;
  padding: 0;
  max-width: 800px;
  width: 95%;
  background-color: var(--color-card-light);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#pokemonDialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#pokemonDialog.opening {
  animation: scaleIn 0.3s ease-out;
}

#pokemonDialog.closing {
  animation: scaleOut 0.3s ease-in;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8) translate(-50%, -50%);
  }
  to {
    opacity: 1;
    transform: scale(1) translate(-50%, -50%);
  }
}

@keyframes scaleOut {
  from {
    opacity: 1;
    transform: scale(1) translate(-50%, -50%);
  }
  to {
    opacity: 0;
    transform: scale(0.8) translate(-50%, -50%);
  }
}

.close-dialog {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 0;
}

.close-dialog:hover {
  background: #d32f2f;
  transform: scale(1.1);
  transition: all 0.2s ease;
}

/* Pokemon Detail */
.pokemon-detail {
  padding: 2rem;
  text-align: center;
  max-height: 80vh;
  overflow-y: auto;
}

.pokemon-detail img:not(.evolution-image) {
  width: 200px;
  height: 200px;
  object-fit: contain;
}

.pokemon-detail h2 {
  text-transform: capitalize;
  margin: 1rem 0;
  color: var(--color-primary);
}

.pokemon-detail .description {
  margin: 1rem 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Info boxes */
.info-box,
.type-box,
.stats-box,
.evolution-box {
  background: var(--color-background-light);
  border-radius: 0.75rem;
  padding: 1rem;
  margin: 1rem 0;
  text-align: left;
}

.info-box h3,
.type-box h3,
.stats-box h3,
.evolution-box h3 {
  color: var(--color-primary);
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

.info-box p {
  margin: 0.5rem 0;
  color: var(--color-text-primary);
  font-weight: bold;
}

.info-box span {
  font-weight: normal;
  display: inline-flex;
  gap: 0.8rem;
}

/* Type icons */
.type-icon-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 1rem;
  height: 32px;
  padding: 0.25rem 1rem;
}

.type-emoji {
  font-size: 24px;
  line-height: 1;
}

.type-name {
  font-weight: bold;
  text-transform: capitalize;
  font-size: 1rem;
  line-height: 1;
}

/* Badges */
.weakness-badges,
.ability-badges {
  margin: 0.5rem 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.weakness-badges span,
.ability-badges span {
  display: flex;
  gap: 0.25rem;
}

.type-badge,
.ability-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  color: white;
  font-weight: bold;
  text-transform: capitalize;
  font-size: 0.85rem;
}

/* Type colors */
.type-normal { background: #a8a878; }
.type-fire { background: #f08030; }
.type-water { background: #6890f0; }
.type-electric { background: #f8d030; }
.type-grass { background: #78c850; }
.type-ice { background: #98d8d8; }
.type-fighting { background: #c03028; }
.type-poison { background: #a040a0; }
.type-ground { background: #e0c068; }
.type-flying { background: #a890f0; }
.type-psychic { background: #f85888; }
.type-bug { background: #a8b820; }
.type-rock { background: #b8a038; }
.type-ghost { background: #705898; }
.type-dragon { background: #7038f8; }
.type-dark { background: #705848; }
.type-steel { background: #b8b8d0; }
.type-fairy { background: #ee99ac; }

/* Stats */
.stat {
  display: grid;
  grid-template-columns: 80px 1fr 80px;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

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

.stat-bar {
  height: 1.5rem;
  background: #e0e0e0;
  border-radius: 0.75rem;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  border-radius: 0.75rem;
  transition: width 0.5s ease;
}

.hp-fill { background: linear-gradient(90deg, #ff5959 0%, #ff0000 100%); }
.attack-fill { background: linear-gradient(90deg, #f5ac78 0%, #f08030 100%); }
.defense-fill { background: linear-gradient(90deg, #fae078 0%, #f8d030 100%); }
.speed-fill { background: linear-gradient(90deg, #fa92b2 0%, #f85888 100%); }

.stat-value {
  font-weight: bold;
  text-align: right;
}

/* Evolution */
.evolution-chain {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 0.25rem;
  max-width: 100%;
}

.evolution-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
  max-width: 200px;
  overflow: hidden;
}

.evolution-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: white;
  border-radius: 0.5rem;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 2px solid transparent;
  width: 100%;
}

.evolution-link:hover {
  border-color: var(--color-primary);
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.evolution-image {
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 100%;
  background: var(--color-background-light);
  padding: 0.25rem;
}

.evolution-name {
  text-transform: capitalize;
  font-weight: bold;
  font-size: 0.7rem;
}

.evolution-arrow {
  font-size: 1.5rem;
  color: var(--color-text-secondary);
  font-weight: bold;
  margin: 0 0.5rem;
  flex-shrink: 0;
}

/* Pokemon cards */
.pokemon-card {
  cursor: pointer;
  transition: transform 0.2s ease;
}

.pokemon-card:hover {
  transform: scale(1.05);
}

/* Form */
form {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1rem 2rem;
}

input,
textarea,
select {
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 1rem;
}

button {
  font-size: 1rem;
  padding: 0.5rem 2rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: 1rem;
  cursor: pointer;
}

button:hover {
  background-color: #d32f2f;
}

/* Pokemon list */
#pokemonListSection {
  width: 100%;
  padding: 0;
}

#pokemonList {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  list-style: none;
}

#pokemonList > li {
  background-color: var(--color-card-light);
  border: 1px solid #ccc;
  border-radius: 1rem;
  padding: 1rem;
  width: 160px;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#pokemonList article {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#pokemonList img {
  width: 100px;
  height: 100px;
}

#pokemonList h3 {
  margin: 0.5rem 0;
}

#pokemonList p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

/* Pagination */
.pagination {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin: 3rem 0 2rem;
}

.page-input-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.pagination-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.pagination-buttons button {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

#pageInput {
  width: 3rem;
  padding: 0.3rem;
  text-align: center;
  border: 2px solid #ccc;
  border-radius: 8px;
  font-size: 0.9rem;
}

#pageInput:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Responsive */
@media (max-width: 768px) {
  main {
    padding: 0.25rem;
  }

  header {
    padding: 0.25rem 0.75rem;
  }
}

@media (max-width: 400px) {
  .pagination-buttons {
    transform: scale(0.9);
  }
  
  main {
    padding: 0;
  }
}
