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

:root {
  --red: #dc2626;
  --red-dark: #b91c1c;
  --bg: #f5f5f5;
  --card-bg: #fff;
  --text: #1f2937;
  --text-light: #6b7280;
  --shadow: 0 2px 8px rgba(0,0,0,.1);
  --radius: 12px;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.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;
}

.skip-nav {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--red);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 8px 0;
}

.skip-nav:focus {
  top: 0;
}

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* 헤더 */
.header {
  background: var(--red);
  color: #fff;
  padding: 14px 16px 10px;
  position: sticky;
  top: 40px;
  z-index: 90;
  box-shadow: 0 2px 12px rgba(220,38,38,.3);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.logo {
  font-size: 24px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.pokeball {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: #fff;
  border-radius: 50%;
  border: 3px solid #333;
  position: relative;
}

.pokeball::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -3px;
  right: -3px;
  height: 3px;
  background: #333;
  transform: translateY(-50%);
}

.pokeball::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 3px solid #333;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* 언어 전환 */
.lang-switcher {
  display: flex;
  gap: 4px;
}

.lang-btn {
  padding: 4px 10px;
  border: 2px solid rgba(255,255,255,.4);
  background: transparent;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .2s;
  white-space: nowrap;
}

.lang-btn:hover,
.lang-btn.active {
  background: #fff;
  color: var(--red);
  border-color: #fff;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: #9ca3af;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.search-clear:hover {
  background: #6b7280;
}

#search {
  width: 100%;
  padding: 10px 36px 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  background: rgba(255,255,255,.9);
  color: var(--text);
}

#search::placeholder {
  color: var(--text-light);
}

#search:focus-visible {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,.3);
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* 타입 필터 */
.type-filter {
  max-width: 1200px;
  margin: 8px auto 0;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex-wrap: nowrap;
}

.type-filter::-webkit-scrollbar {
  display: none;
}

.type-btn {
  padding: 3px 10px;
  border: 1.5px solid rgba(255,255,255,.4);
  background: transparent;
  color: #fff;
  border-radius: 14px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  transition: all .2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.type-btn:hover,
.type-btn.active {
  background: #fff;
  color: var(--red);
  border-color: #fff;
}

/* 필터 바 */
.filter-bar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: calc(40px + var(--header-h, 100px));
  z-index: 89;
}

.filter-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 16px;
  background: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  transition: color .2s;
}

.filter-toggle:hover {
  color: var(--red);
}

.filter-toggle .arrow {
  transition: transform .2s;
  font-size: 10px;
}

.filter-bar.collapsed .filter-toggle .arrow {
  transform: rotate(180deg);
}

.filter-bar.collapsed .filter-bar-inner {
  display: none;
}

.filter-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 16px 10px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-light);
  white-space: nowrap;
}

.gen-filter {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.gen-btn {
  padding: 3px 10px;
  border: 1.5px solid #d1d5db;
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .2s;
}

.gen-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.gen-btn.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.filter-select {
  padding: 5px 10px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.filter-select:focus-visible {
  border-color: var(--red);
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.range-input {
  width: 60px;
  padding: 5px 8px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.range-input:focus-visible {
  border-color: var(--red);
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.range-sep {
  color: var(--text-light);
  font-size: 14px;
}

.filter-reset {
  padding: 5px 12px;
  border: 1.5px solid #d1d5db;
  background: #fff;
  color: var(--text-light);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .2s;
  margin-left: auto;
}

.filter-reset:hover {
  border-color: var(--red);
  color: var(--red);
}

/* 포켓몬 그리드 */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.pokemon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  contain: layout style;
}

/* 포켓몬 카드 */
.poke-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  contain: content;
}

.poke-card:hover,
.poke-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}

.poke-card:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.poke-card .poke-id {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-light);
}

.poke-card img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  aspect-ratio: 1/1;
}

.poke-card .poke-name {
  font-size: 14px;
  font-weight: 700;
  margin-top: 4px;
  text-transform: capitalize;
}

.poke-card .poke-types {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 6px;
}

.type-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
}

/* 타입 컬러 */
.type-normal { background: #a8a878; }
.type-fire { background: #f08030; }
.type-water { background: #6890f0; }
.type-electric { background: #f8d030; color: #333; }
.type-grass { background: #78c850; }
.type-ice { background: #98d8d8; color: #333; }
.type-fighting { background: #c03028; }
.type-poison { background: #a040a0; }
.type-ground { background: #e0c068; color: #333; }
.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; color: #333; }
.type-fairy { background: #ee99ac; }

/* 로딩 */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
  font-size: 16px;
}

/* 에러 화면 */
.error-screen {
  text-align: center;
  padding: 80px 20px;
}

.error-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.error-screen h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.error-screen p {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.6;
  margin-bottom: 24px;
}

.error-retry {
  padding: 10px 28px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.error-retry:hover {
  background: var(--red-dark);
}

/* 모달 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: #fff;
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: modalIn .25s ease-out;
}

@keyframes modalIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #fff;
  z-index: 10;
  line-height: 1;
}

.modal-header {
  padding: 30px 24px 20px;
  text-align: center;
  border-radius: 16px 16px 0 0;
}

.modal-header img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.2));
}

.modal-header .modal-name {
  font-size: 24px;
  font-weight: 800;
  text-transform: capitalize;
  color: #fff;
  margin-top: 4px;
}

.modal-header .modal-id {
  font-size: 14px;
  color: rgba(255,255,255,.8);
  font-weight: 600;
}

.modal-header .modal-genus {
  font-size: 13px;
  color: rgba(255,255,255,.7);
  margin-top: 2px;
}

.modal-body {
  padding: 20px 24px 24px;
}

.modal-types {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.modal-types .type-badge {
  padding: 4px 14px;
  font-size: 13px;
}

.modal-description {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: center;
}

.modal-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.info-item {
  text-align: center;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
}

.info-item .info-label {
  font-size: 11px;
  color: var(--text-light);
  text-transform: uppercase;
  font-weight: 600;
}

.info-item .info-value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

/* 능력치 바 */
.stat-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}

.stat-name {
  width: 36px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  font-size: 11px;
}

.stat-value {
  width: 32px;
  text-align: right;
  font-weight: 700;
  margin-right: 8px;
}

.stat-bar-bg {
  flex: 1;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.stat-bar {
  height: 100%;
  border-radius: 4px;
  transition: width .6s ease-out;
}

.abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.ability-tag {
  padding: 4px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  text-transform: capitalize;
}

@media (max-width: 360px) {
  .pokemon-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .poke-card {
    padding: 10px;
  }

  .poke-card img {
    width: 68px;
    height: 68px;
  }

  .poke-card .poke-name {
    font-size: 12px;
  }

  .poke-card .poke-id {
    font-size: 10px;
  }

  .type-badge {
    font-size: 9px;
    padding: 2px 6px;
  }

  .header {
    padding: 14px 10px 10px;
  }

  .logo {
    font-size: 18px;
  }

  main {
    padding: 12px 10px 48px;
  }

  .modal-header img {
    width: 120px;
    height: 120px;
  }

  .modal-header .modal-name {
    font-size: 20px;
  }

  .modal-body {
    padding: 16px 16px 20px;
  }
}

@media (max-width: 480px) {
  .pokemon-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .poke-card img {
    width: 80px;
    height: 80px;
  }

  .header-inner {
    gap: 8px;
  }

  .logo {
    font-size: 20px;
  }

  .search-wrap {
    order: 3;
    min-width: 100%;
  }

  .lang-switcher {
    margin-left: auto;
  }

  .filter-bar-inner {
    gap: 10px;
  }

  .filter-group {
    flex-wrap: wrap;
    width: 100%;
  }

  .filter-reset {
    margin-left: 0;
    width: 100%;
    padding: 8px;
  }
}

@media (min-width: 768px) {
  .pokemon-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
  }

  .poke-card img {
    width: 110px;
    height: 110px;
  }

  .poke-card .poke-name {
    font-size: 15px;
  }

  .header {
    padding: 24px 24px 14px;
  }

  .logo {
    font-size: 28px;
  }

  main {
    padding: 24px 24px 60px;
  }

  .modal {
    max-width: 520px;
  }

  .modal-header img {
    width: 180px;
    height: 180px;
  }

  .filter-bar-inner {
    padding: 0 24px 12px;
  }
}

@media (min-width: 1024px) {
  .pokemon-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
  }

  .poke-card img {
    width: 120px;
    height: 120px;
  }

  .poke-card {
    padding: 20px;
  }

  .poke-card .poke-name {
    font-size: 16px;
    margin-top: 8px;
  }

  .header {
    padding: 28px 32px 16px;
  }

  main {
    padding: 32px 32px 80px;
  }

  .modal {
    max-width: 560px;
  }

  .modal-header img {
    width: 200px;
    height: 200px;
  }

  .modal-header .modal-name {
    font-size: 28px;
  }

  .modal-body {
    padding: 24px 32px 32px;
  }

  .filter-bar-inner {
    padding: 0 32px 14px;
  }
}

@media (min-width: 1440px) {
  main {
    max-width: 1400px;
  }

  .header-inner {
    max-width: 1400px;
  }

  .type-filter {
    max-width: 1400px;
  }

  .filter-bar-inner {
    max-width: 1400px;
  }

  .pokemon-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .poke-card img {
    width: 130px;
    height: 130px;
  }

  .poke-card {
    padding: 24px;
  }
}
