/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme Variables ── */
:root, [data-theme="dark"] {
  --bg: #14141a;
  --surface: #1f1f24;
  --elevated: #29292e;
  --gold: #d9bf73;
  --text: #e8e8ed;
  --text-secondary: #8e8e93;
  --red: #ff453a;
  --green: #30d158;
  --orange: #ff9f0a;
  --purple: #bf5af2;
  --blue: #0a84ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-hover: 0 12px 32px rgba(0,0,0,0.5);
  --modal-bg: rgba(0,0,0,0.75);
}

[data-theme="light"] {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --elevated: #e5e5ea;
  --gold: #9a7d2e;
  --text: #1c1c1e;
  --text-secondary: #6c6c70;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --purple: #af52de;
  --blue: #007aff;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-hover: 0 12px 32px rgba(0,0,0,0.15);
  --modal-bg: rgba(0,0,0,0.5);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--elevated);
  padding: 14px 20px 12px;
  transition: background 0.3s;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: -0.03em;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--elevated);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.icon-btn:hover { background: var(--elevated); transform: scale(1.05); }

/* ── Stats Banner ── */
.stats-banner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat-box {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  border: 1px solid var(--elevated);
}

.stat-num {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

/* ── Filter Chips ── */
.filter-chips {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--elevated);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.chip:hover { border-color: var(--gold); color: var(--text); }
.chip.active { background: var(--gold); color: #14141a; border-color: var(--gold); }

/* ── Controls ── */
.controls {
  display: flex;
  gap: 8px;
}

#search {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--elevated);
  background: var(--surface);
  color: var(--text);
  font-size: 0.87rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, background 0.3s;
}

#search::placeholder { color: var(--text-secondary); }
#search:focus { border-color: var(--gold); }

#sort {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--elevated);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: background 0.3s;
}

/* ── Gallery ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

.gallery {
  column-count: 4;
  column-gap: 12px;
}

/* ── Card ── */
.card {
  break-inside: avoid;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(20px);
}

.card.visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-3px) scale(1.015);
  box-shadow: var(--shadow-hover);
}

.card:hover .card-image img {
  transform: scale(1.04);
}

.card-image {
  position: relative;
  width: 100%;
  background: var(--elevated);
  overflow: hidden;
}

.card-image img {
  width: 100%;
  display: block;
  transition: transform 0.3s ease;
}

.card-image .placeholder {
  width: 100%;
  aspect-ratio: 3/4;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 2rem;
  opacity: 0.3;
}

/* ── Flip Card (for back photos) ── */
.card-flip {
  position: relative;
  width: 100%;
  perspective: 800px;
}

.card-flip-inner {
  position: relative;
  width: 100%;
  transition: transform 0.6s ease;
  transform-style: preserve-3d;
}

.card-flip:hover .card-flip-inner,
.card-flip.flipped .card-flip-inner {
  transform: rotateY(180deg);
}

.card-flip-front,
.card-flip-back {
  width: 100%;
  backface-visibility: hidden;
}

.card-flip-back {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotateY(180deg);
}

.card-flip-front img,
.card-flip-back img {
  width: 100%;
  display: block;
}

.flip-hint {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px 6px;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.card-flip:hover .flip-hint { opacity: 1; }

/* ── Card Body ── */
.card-body {
  padding: 10px 12px 12px;
}

.card-player {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-set {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  line-height: 1.4;
}

.badge-grade { background: rgba(255, 69, 58, 0.15); color: var(--red); }
.badge-parallel { background: rgba(191, 90, 242, 0.15); color: var(--purple); }
.badge-number { background: rgba(142, 142, 147, 0.12); color: var(--text-secondary); font-weight: 500; }
.badge-auto { background: rgba(255, 159, 10, 0.15); color: var(--orange); }

/* ── Loading Skeletons ── */
.loading { padding: 0; }

.skeleton-grid {
  column-count: 4;
  column-gap: 12px;
}

.skeleton-card {
  break-inside: avoid;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skel-img {
  width: 100%;
  aspect-ratio: 3/4;
  background: var(--elevated);
}

.skel-body { padding: 12px; }

.skel-line {
  height: 12px;
  background: var(--elevated);
  border-radius: 6px;
  margin-bottom: 8px;
}
.skel-line.w70 { width: 70%; }
.skel-line.w50 { width: 50%; }

.skel-badges { display: flex; gap: 4px; }
.skel-badge {
  width: 50px;
  height: 16px;
  background: var(--elevated);
  border-radius: 8px;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.35; }
}

/* ── Empty ── */
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--modal-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.modal-overlay.open { opacity: 1; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  transform: scale(0.95) translateY(10px);
  transition: transform 0.25s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  line-height: 1;
  background: var(--elevated);
  border: none;
}

.modal-body {
  display: flex;
  flex-direction: column;
}

.modal-images {
  display: flex;
  gap: 2px;
  background: var(--elevated);
}

.modal-images img {
  flex: 1;
  min-width: 0;
  max-height: 55vh;
  object-fit: contain;
  display: block;
  background: var(--bg);
}

.modal-info {
  padding: 20px;
}

.modal-player {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-set {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.modal-badges .badge {
  font-size: 0.8rem;
  padding: 4px 10px;
}

.modal-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-detail {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.modal-detail-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  margin-bottom: 2px;
}

.modal-detail-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.modal-share {
  margin-top: 16px;
  text-align: right;
}

.share-btn {
  background: var(--elevated);
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.share-btn:hover { background: var(--gold); color: #14141a; }
.share-btn.copied { background: var(--green); color: #fff; }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  transition: color 0.3s;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .gallery, .skeleton-grid { column-count: 3; }
}

@media (max-width: 800px) {
  .gallery, .skeleton-grid { column-count: 2; }
  .stats-banner { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .gallery, .skeleton-grid { column-count: 2; column-gap: 8px; }
  .card { margin-bottom: 8px; }
  .card-body { padding: 8px 10px 10px; }
  .card-player { font-size: 0.82rem; }
  .card-set { font-size: 0.68rem; }
  .badge { font-size: 0.6rem; padding: 1px 5px; }
  header { padding: 10px 12px; }
  main { padding: 8px; }
  .stats-banner { gap: 6px; }
  .stat-num { font-size: 0.95rem; }
  .stat-box { padding: 8px 4px; }
  #search { font-size: 16px; }
  .modal { border-radius: 12px; }
  .modal-images { flex-direction: column; }
  .modal-images img { max-height: 40vh; }
  .modal-detail { padding: 8px 10px; }
}

@media (min-width: 1400px) {
  .gallery, .skeleton-grid { column-count: 5; }
}
