/* Character Gallery (Netflix style) */

.cg-section{ margin-top: 14px; }

.cg{
  --cg-bg: var(--surface);
  --cg-title: var(--text);
  --cg-gap: 12px;
  /* Frontend cards should feel like the edit-page thumbnails (not oversized) */
  --cg-item-w: clamp(150px, 18vw, 190px);
  background: var(--cg-bg);
  border: 1px solid var(--border-2);
  border-radius: 22px;
  padding: 12px;
  box-shadow: var(--shadow);
  width: 100%;
}

/* Responsive sizing per layout (items-per-view is computed in JS) */
.cg[data-layout="A"]{ --cg-item-w: clamp(170px, 24vw, 250px); }
.cg[data-layout="B"]{ --cg-item-w: clamp(140px, 18vw, 185px); }
.cg[data-layout="C"]{ --cg-item-w: clamp(44px, 7vw, 64px); }

@media (max-width: 520px){
  /* Make circles slightly larger on mobile (without over-sizing) */
  .cg[data-layout="C"]{ --cg-item-w: clamp(52px, 10vw, 72px); }
}

.cg-track{
  display:flex;
  gap: var(--cg-gap);
  overflow-x:auto;
  overflow-y:hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 6px;
  padding-bottom: 6px;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  align-items: flex-start;
}
.cg-track::-webkit-scrollbar{ display:none; }

.cg-item{
  flex: 0 0 auto;
  width: var(--cg-item-w);
  scroll-snap-align: start;
}

.cg-card{
  width:100%;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  border-radius: 18px;
  overflow:hidden;
  padding: 0;
  cursor:pointer;
  position:relative;
  display:block;
  transform: translateZ(0);
}
.cg-card:focus{ outline: none; }
.cg-card:focus-visible{ box-shadow: 0 0 0 3px rgba(92,124,255,0.35); }

.cg[data-layout="A"] .cg-card{ aspect-ratio: 16 / 9; }
/* Posters like Netflix cards (closer to edit-page thumbnails) */
.cg[data-layout="B"] .cg-card{ aspect-ratio: 4 / 5; }
.cg[data-layout="C"] .cg-card{ aspect-ratio: 1 / 1; border-radius: 999px; }

/* Smaller typography for circles */
.cg[data-layout="C"] .cg-name{ font-size: 11px; margin-top: 6px; }

.cg-img{
  width:100%;
  height:100%;
  object-fit: cover;
  display:block;
  background: rgba(0,0,0,0.08);
}

/* Subtle Netflix-like shine */
.cg-card::after{
  content:"";
  position:absolute;
  inset:0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(0,0,0,0));
  opacity: 0.55;
  pointer-events:none;
}

@media (hover:hover){
  .cg-card:hover{ transform: scale(1.02); border-color: var(--border-strong); }
}

.cg-name{
  margin-top: 8px;
  font-weight: 900;
  color: var(--cg-title);
  font-size: 13px;
  text-align:center;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cg-dots{
  margin-top: 10px;
  display:flex;
  justify-content:center;
  gap: 6px;
  min-height: 10px;
}

.cg-dot{
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 0;
  background: var(--border-strong);
  opacity: 0.55;
  cursor:pointer;
  padding:0;
}
.cg-dot.is-active{
  width: 18px;
  opacity: 1;
  background: var(--text);
}

/* Modal */
.cg-modal[hidden]{ display:none; }
.cg-modal{
  position:fixed;
  inset:0;
  z-index: 500;
}

.cg-modal__backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(10px);
}

.cg-modal__panel{
  position:absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, 92vw);
  max-height: min(86vh, 760px);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow:hidden;
}

.cg-modal__main{
  position:relative;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  padding: 14px;
  touch-action: pan-y;
}

.cg-modal__img{
  max-width: 100%;
  max-height: calc(min(86vh, 760px) - 92px);
  object-fit: contain;
  border-radius: 18px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
}

.cg-modal__caption{
  margin-top: 10px;
  font-weight: 900;
  color: var(--cg-title);
  text-align:center;
}

.cg-modal__close{
  position:absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border-radius: 16px;
  border: 1px solid var(--border-3);
  background: var(--btn-bg-2);
  color: var(--text);
  cursor:pointer;
  font-size: 24px;
  font-weight: 1000;
  z-index: 2;
}

.cg-modal__nav{
  position:absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 16px;
  border: 1px solid var(--border-3);
  background: var(--btn-bg-2);
  /* Follow site mode (dark/light) and remain visible */
  color: var(--text, currentColor);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 0;
  /* Back-compat: old cached HTML used chevrons (‹ ›). Keep them visible. */
  font-size: 26px;
  line-height: 1;
  font-weight: 1000;
  z-index: 2;
}

.cg-modal__nav .cg-ico{
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}

.cg-modal__prev{ left: 10px; }
.cg-modal__next{ right: 10px; }

@media (max-width: 520px){
  .cg-modal__nav{ width: 40px; height: 40px; border-radius: 14px; }
  .cg-modal__close{ width: 40px; height: 40px; border-radius: 14px; }
}

body.cg-no-scroll{
  overflow: hidden !important;
}
