:root {
  --primary: #2c3e50;
  --accent: #e67e22;
  --bg: #f4f7f6;
  --card-bg: #ffffff;
  --text: #333;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

body {
  font-family: "Montserrat", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

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

header {
  background: var(--primary);
  color: white;
  padding: 30px 0;
  text-align: center;
  margin-bottom: 30px;
}

header h1 {
  margin: 0;
  font-size: 2.5rem;
}

/* Навигация */
nav {
  margin-top: 20px;
}
.nav-btn {
  background: transparent;
  border: 2px solid white;
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
  margin: 0 10px;
  transition: all 0.3s;
}
.nav-btn:hover,
.nav-btn.active {
  background: white;
  color: var(--primary);
}

/* Controls & Grid */
.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 30px;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

#searchInput {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  box-sizing: border-box;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.filter-btn {
  padding: 8px 16px;
  border: none;
  background: #eee;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
}

.filter-btn:hover,
.filter-btn.active {
  background: var(--accent);
  color: white;
}

.grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(180px, 1fr)
  ); /* Чуть уже карточки */
  gap: 15px;
}

/* Карточка */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 0;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 280px;
  overflow: hidden;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.card-img-wrapper {
  width: 100%;
  height: 170px;
  background: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Картинка просто вписывается в блок */
.card img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* Показываем весь файл целиком */
  display: block;
}

/* Текст и бейджи остаются без изменений */
.card-info {
  padding: 15px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2;
  background: white;
  border-top: 1px solid #f5f5f5;
}

.card h3 {
  font-size: 1rem;
  margin: 0 0 5px 0;
  color: var(--primary);
  line-height: 1.3;
  font-weight: 700;
}

.card small {
  color: #888;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card .id-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 3;
}

.hidden {
  display: none !important;
}

/* Info Section */
.info-card {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  line-height: 1.6;
}
.info-card a {
  color: var(--accent);
  text-decoration: none;
}
.info-card a:hover {
  text-decoration: underline;
}
.credits ul {
  list-style: none;
  padding: 0;
}
.credits li {
  margin-bottom: 10px;
}

/* Modal & Zoom */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* Модальное окно */
.modal-content {
  background: white;
  padding: 0;
  border-radius: 15px;
  width: 95%;
  max-width: 1200px; /* Шире для детального просмотра */
  height: 90vh;
  max-height: 90vh;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.close-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 32px;
  cursor: pointer;
  z-index: 20;
  color: #333;
  background: rgba(255, 255, 255, 0.8);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Контейнер зума - занимает ВСЁ свободное место */
.zoom-container {
  flex-grow: 1;
  width: 100%;
  background: #f9f9f9;
  position: relative;
  overflow: hidden;
  cursor: grab;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Картинка в модалке */
.zoom-container img {
  /* Максимальные размеры ограничены только контейнером */
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  will-change: transform;
  /* Плавность при изменении viewBox скриптом */
  transition: transform 0.1s ease-out;
}

/* Панель управления зумом */
.zoom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 12px;
  background: white;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

/* Информация внизу */
.modal-info {
  text-align: center;
  padding: 15px 20px;
  background: white;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
  max-height: 25vh; /* Ограничиваем высоту текста, чтобы не съел экран */
  overflow-y: auto;
}

.modal-info h2 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: var(--primary);
}
.badges {
  margin-bottom: 8px;
}
.badge {
  display: inline-block;
  padding: 4px 8px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-right: 5px;
}
.nation-badge {
  background: var(--accent);
}
#modalDesc {
  margin: 0;
  color: #666;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Индикатор загрузки */
.loading-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  z-index: 5;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #eee;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Состояние "загружено" - плавное появление */
.card img.loaded,
.zoom-container img.loaded {
  opacity: 1;
  transition: opacity 0.3s ease-in;
}

.card img,
.zoom-container img {
  opacity: 0;
  transition: opacity 0.3s ease-in;
}
.card img.loaded,
.zoom-container img.loaded {
  opacity: 1;
}
.card-img-wrapper,
.zoom-container {
  position: relative;
}
