:root {
  color-scheme: light;
  --bg: #f4f4f6;
  --card: #ffffff;
  --surface: #f8f8fb;
  --text: #1c1c1c;
  --muted: #60606b;
  --accent: #da1f26;
  --accent-dark: #a2141a;
  --border: rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, sans-serif;
  background: radial-gradient(circle at top left, #ffffff 0%, #eef0f4 35%, #d8d9de 100%);
  color: var(--text);
}

body {
  padding: 24px;
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  min-width: 160px;
}

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-size: 1.2rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 2000;
}

.back-to-top:hover {
  transform: translateY(-2px);
}

.back-to-top.show {
  display: inline-flex;
  opacity: 1;
}

.header h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 2.4vw, 2.8rem);
}

.header p {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
  max-width: 720px;
}

.actions button,
button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  padding: 12px 16px;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: #f0f0f4;
}

button:focus-visible {
  outline: 3px solid rgba(218, 31, 38, 0.25);
  outline-offset: 3px;
}

#printButton {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

#printButton:hover {
  background: var(--accent-dark);
}

#listButton,
#clearButton,
.list-controls button {
  min-width: 140px;
}

.controls {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 18px;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group label {
  font-weight: 600;
}

input,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

details.generation-dropdown {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  padding: 0;
}

details.generation-dropdown summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

details.generation-dropdown summary::-webkit-details-marker {
  display: none;
}

details.generation-dropdown summary::after {
  content: '▾';
  font-size: 0.85rem;
  color: var(--muted);
}

details.generation-dropdown[open] summary {
  background: var(--surface);
}

.generation-options {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.08);
  max-height: 280px;
  overflow-y: auto;
  z-index: 10;
}

.generation-options label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  transition: background 0.2s ease;
}

.generation-options label:hover {
  background: #f4f4f6;
}

.generation-options input {
  width: 18px;
  height: 18px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(1em + 2px), calc(100% - 12px) calc(1em + 2px);
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

select::-ms-expand {
  display: none;
}

input::placeholder {
  color: rgba(96, 96, 107, 0.7);
}

.button-group {
  align-self: end;
}

.summary {
  margin-bottom: 18px;
  color: var(--muted);
}

.list-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.pokemon-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.cards-grid {
  display: none;
}

.pokemon-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.pokemon-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.pokemon-item img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.pokemon-item__info {
  flex: 1;
}

.pokemon-item__number {
  font-size: 0.9rem;
  color: var(--muted);
}

.pokemon-item__name {
  font-weight: 600;
}

.list-print {
  font-family: Arial, sans-serif;
  padding: 20px;
}

.list-print h1 {
  text-align: center;
  margin-bottom: 20px;
}

.list-print ul {
  list-style: none;
  padding: 0;
}

.list-print li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #ddd;
}

.list-print .print-list-checkbox {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

@page {
  size: A4 portrait;
  margin: 8mm;
}

@media print {
  html, body {
    width: 100%;
    background: #fff;
    padding: 0;
  }

  .header,
  .controls,
  .summary,
  .list-controls,
  .pokemon-list,
  button,
  input,
  select {
    display: none !important;
  }

  .page-container {
    margin: 0;
    padding: 0;
  }

  .cards-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 63mm);
    grid-auto-rows: 88mm;
    gap: 6mm;
    justify-content: center;
    width: auto;
    margin: 0 auto;
  }

  .card {
    width: 63mm;
    min-height: 88mm;
    padding: 10mm;
    display: flex;
    flex-direction: column;
    page-break-inside: avoid;
    break-inside: avoid;
    break-inside: avoid-column;
    page-break-after: auto;
    justify-content: space-between;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-radius: 10px;
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
    page-break-after: avoid;
    margin: 0;
  }

  .card__header {
    margin-bottom: 6mm;
  }

  .card__meta {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    font-size: 0.75rem;
    color: #555;
    margin-bottom: 4px;
  }

  .card__name {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.1;
  }

  .card__art {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
  }

  .card__art-frame {
    width: 100%;
    height: 100%;
    min-height: 52mm;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    padding: 0;
    overflow: hidden;
  }

  .card__image {
    width: 100%;
    height: 100%;
    object-fit: fill;
  }

  .card__footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.72rem;
    color: #444;
    margin-top: 6mm;
  }

  .list-print {
    display: block !important;
    font-family: Arial, sans-serif;
    padding: 20px;
  }

  .list-print h1 {
    text-align: center;
    margin-bottom: 20px;
  }

  .list-print ul {
    list-style: none;
    padding: 0;
  }

  .list-print li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #ddd;
  }

  .list-print input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card);
  padding: 24px;
  border-radius: 16px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-content h3 {
  margin: 0 0 16px;
}

.modal-content p {
  margin: 0 0 16px;
  color: var(--muted);
}

.modal-content button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease;
}

.modal-content button:hover {
  background: #f0f0f4;
}

.modal-content button#closeModal {
  background: transparent;
  color: var(--muted);
}
