/* ── Panel overlay backdrop ──────────────────────────────────────────────── */
#panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-panel);
  z-index: var(--z-overlay);
}

#panel-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Detail panel ────────────────────────────────────────────────────────── */
#detail-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-height: 78vh;
  background: var(--panel-bg);
  border-top: 2px solid var(--panel-border);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -30px 60px -20px rgba(15, 30, 60, 0.35);
  transform: translateY(100%);
  transition: transform 420ms cubic-bezier(.2, .8, .2, 1);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
}

#detail-panel.open {
  transform: translateY(0);
}

/* Drag grip */
#detail-panel::before {
  content: "";
  display: block;
  width: 60px;
  height: 5px;
  border-radius: 4px;
  background: var(--panel-border);
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* Custom scrollbar */
#detail-panel::-webkit-scrollbar { width: 5px; }
#detail-panel::-webkit-scrollbar-track { background: transparent; }
#detail-panel::-webkit-scrollbar-thumb {
  background: var(--sand);
  border-radius: 3px;
}

/* ── Panel header ────────────────────────────────────────────────────────── */
.panel-header {
  padding: 20px 20px 16px;
  border-bottom: 3px solid var(--panel-border);
  position: relative;
  flex-shrink: 0;
}

.panel-header-accent {
  height: 4px;
  width: 100%;
  margin-bottom: 14px;
  border-radius: 2px 2px 0 0;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  line-height: 1.1;
}

.panel-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}

/* ── Close button ────────────────────────────────────────────────────────── */
.panel-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: border-color var(--t-hover), color var(--t-hover), background var(--t-hover);
  cursor: pointer;
  background: transparent;
  font-family: var(--font-body);
}

.panel-close:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: rgba(0,0,0,0.05);
}

/* ── Stats row ─── now a row of bold LEGO-style cards ───────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 14px 16px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.03);
  border-bottom: 1px solid rgba(0,0,0,0.07);
}

.stat-item {
  background: #fff;
  border-radius: 10px;
  padding: 13px 12px 11px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.06);
  position: relative;
  overflow: hidden;
  /* pop-in animation */
  animation: stat-pop 360ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.stat-item:nth-child(1) { animation-delay:  40ms; }
.stat-item:nth-child(2) { animation-delay:  90ms; }
.stat-item:nth-child(3) { animation-delay: 140ms; }
.stat-item:nth-child(4) { animation-delay: 190ms; }

/* coloured top-bar accent using --stat-color set inline */
.stat-item::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  border-radius: 10px 10px 0 0;
  background: var(--stat-color, var(--sand));
}

/* stud dots decorating top-right corner */
.stat-item::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--stat-color, var(--sand));
  opacity: 0.25;
}

.stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.06);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.stat-icon {
  font-size: 18px;
  line-height: 1;
  margin-bottom: 2px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--stat-color, var(--text-primary));
  line-height: 1;
  letter-spacing: -0.01em;
}

.stat-label {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: 600;
  margin-top: 1px;
}

@keyframes stat-pop {
  from { opacity: 0; transform: scale(0.82) translateY(6px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}


/* ── Panel body (charts section) ─────────────────────────────────────────── */
.panel-body {
  padding: 0 16px 24px;
  flex: 1;
}

/* ── IP Folder UI ────────────────────────────────────────────────────────── */
.ip-folder-header {
  padding: 14px 16px 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-family: var(--font-body);
  flex-shrink: 0;
}

.ip-folder {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
  flex-shrink: 0;
}

.ip-card {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 14px 12px;
  cursor: pointer;
  text-align: center;
  transition:
    background var(--t-hover),
    transform var(--t-hover),
    border-color var(--t-hover),
    box-shadow var(--t-hover);
  background: rgba(0,0,0,0.04);
  outline: none;
}

.ip-card:hover,
.ip-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.ip-card.selected {
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(0,0,0,0.2);
}

.ip-card-label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.2;
}

.ip-card-count {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
  letter-spacing: 0.04em;
}

/* Logo image inside IP franchise card */
.ip-card-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  margin: 0 auto 2px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.25));
  transition: filter var(--t-hover);
}

/* Keep logos readable on the colored selected background */
.ip-card.selected .ip-card-logo {
  filter: brightness(0) invert(1) drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}

/* ── IP sub-panel (charts below the card grid) ──────────────────────────── */
#ip-sub-panel {
  border-top: 1px solid rgba(0,0,0,0.08);
  flex: 1;
  overflow: visible;
}

#ip-sub-panel .panel-body {
  padding-top: 4px;
}

/* ── Back button (IP sub → IP folder) ───────────────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  padding: 14px 16px 4px;
  font-family: var(--font-body);
  transition: color var(--t-hover);
}

.back-btn:hover {
  color: var(--text-primary);
}

.back-btn::before {
  content: '\2190';
  font-size: 14px;
}

/* ── Set card grid ───────────────────────────────────────────────────────── */

.set-grid-section {
  border-bottom: none;
}

.set-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: 2px;
}

/* Scrollbar inside the grid */
.set-grid::-webkit-scrollbar { width: 4px; }
.set-grid::-webkit-scrollbar-track { background: transparent; }
.set-grid::-webkit-scrollbar-thumb {
  background: var(--sand);
  border-radius: 2px;
}

.set-card {
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  cursor: default;
  transition: transform var(--t-hover), box-shadow var(--t-hover);
  outline: none;
}

.set-card:hover,
.set-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

/* Image area — fixed 3:2 aspect ratio */
.set-card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #f0f0ec;
  overflow: hidden;
}

.set-card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
  box-sizing: border-box;
}

/* Shown when image fails to load */
.set-card-img-wrap.img-error .set-card-img {
  display: none;
}

.set-card-img-fallback {
  position: absolute;
  inset: 0;
  display: none;
  background:
    repeating-linear-gradient(
      45deg,
      #e8e8e2 0px,
      #e8e8e2 6px,
      #f0f0ec 6px,
      #f0f0ec 12px
    );
}

.set-card-img-wrap.img-error .set-card-img-fallback {
  display: block;
}

/* Text below image */
.set-card-body {
  padding: 7px 9px 8px;
}

.set-card-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--font-body);
}

.set-card-meta {
  font-size: 10px;
  margin-top: 4px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  #detail-panel { max-height: 88vh; }
}
