/* ═══════════════════════════════════════════════════════════════════════════
   PAPER DOLL MODULE — Industry-grade visual upgrade
   Layered PNG rendering · item tinting · specials override · chip status dots
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS custom properties ──────────────────────────────────────────────── */
:root {
  --pdc-accent:      #6366f1;
  --pdc-accent-glow: rgba(99,102,241,.28);
  --pdc-glass:       rgba(255,255,255,.76);
  --pdc-glass-dk:    rgba(15,23,42,.78);
  --pdc-tint-op:     0.52;
  --pdc-equip-dur:   360ms;
}

/* ── Category chip status dots ──────────────────────────────────────────── */
/* The chip needs position:relative for the ::after dot to anchor */
.wde-cat-chips { gap: 4px !important; }
.wde-cat-chip  { position: relative !important; overflow: visible !important; }

/* Dot that appears when a category has an item equipped */
.wde-cat-chip.pdc-has-item::after {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--pdc-chip-tint, var(--pdc-accent));
  border: 1.5px solid rgba(255,255,255,.9);
  box-shadow: 0 0 5px var(--pdc-chip-tint, var(--pdc-accent-glow));
  animation: pdcDotPop .35s cubic-bezier(.34,1.56,.64,1) both;
  pointer-events: none;
}
@keyframes pdcDotPop {
  0%   { transform: scale(0) rotate(-45deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Active chip with item → accent ring */
.wde-cat-chip.active.pdc-has-item {
  box-shadow: 0 0 0 2px var(--pdc-accent), 0 2px 8px var(--pdc-accent-glow) !important;
}

/* ── Tint overlay on clothing layer ─────────────────────────────────────── */
.wde-clothing-layer { position: absolute !important; inset: 0 !important; }

.pdc-tint-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: var(--pdc-tint-op);
  border-radius: inherit;
  transition: background .22s ease, opacity .22s ease;
}

/* In dark mode, 'screen' blends lighter tints better */
body.dark .pdc-tint-overlay {
  mix-blend-mode: screen;
  opacity: calc(var(--pdc-tint-op) * 0.75);
}

/* ── Tint picker row (injected into item detail) ─────────────────────────── */
.pdc-tint-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 9px 11px;
  background: rgba(99,102,241,.07);
  border-radius: 11px;
  border: 1px solid rgba(99,102,241,.18);
  flex-wrap: wrap;
  animation: pdcFadeSlide .25s ease both;
}
@keyframes pdcFadeSlide {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pdc-tint-label {
  font-size: .6rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--pdc-accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.pdc-tint-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.pdc-tint-preset {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 3px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), border-color .12s, box-shadow .12s;
  flex-shrink: 0;
}
.pdc-tint-preset:hover {
  transform: scale(1.3);
  box-shadow: 0 2px 8px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.4);
  z-index: 1;
}
.pdc-tint-preset.active {
  border-color: var(--pdc-accent);
  transform: scale(1.22);
  box-shadow: 0 0 0 3px var(--pdc-accent-glow), 0 2px 6px rgba(0,0,0,.2);
}

.pdc-tint-input {
  width: 26px;
  height: 26px;
  border: 1.5px solid rgba(0,0,0,.12);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  background: none;
  outline: none;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  transition: transform .12s, box-shadow .12s;
}
.pdc-tint-input:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

.pdc-tint-clear {
  font-size: .62rem;
  color: var(--wdb-muted, #9ca3af);
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 5px;
  font-family: inherit;
  line-height: 1;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.pdc-tint-clear:hover {
  background: rgba(0,0,0,.07);
  color: var(--wdb-ink, #1f2937);
}

body.dark .pdc-tint-row {
  background: rgba(99,102,241,.11);
  border-color: rgba(99,102,241,.24);
}
body.dark .pdc-tint-preset {
  border-color: rgba(255,255,255,.12);
}
body.dark .pdc-tint-input {
  border-color: rgba(255,255,255,.15);
}
body.dark .pdc-tint-clear:hover {
  background: rgba(255,255,255,.08);
  color: #f1f5f9;
}

/* ── Clothing rail tile: enhanced selected state ────────────────────────── */
.wde-rail-tile {
  transition: transform .2s cubic-bezier(.34,1.56,.64,1),
              border-color .15s, box-shadow .15s, background .15s !important;
}
.wde-rail-tile.selected {
  border-color: var(--pdc-accent) !important;
  background: rgba(99,102,241,.09) !important;
  box-shadow: 0 0 0 3px rgba(99,102,241,.18),
              0 4px 14px rgba(99,102,241,.18) !important;
}
.wde-rail-tile.selected .wde-rail-tile-icon {
  animation: pdcTileEquip var(--pdc-equip-dur) cubic-bezier(.34,1.56,.64,1);
}
@keyframes pdcTileEquip {
  0%   { transform: scale(1); filter: brightness(1); }
  35%  { transform: scale(1.1); filter: brightness(1.15); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* PNG thumbnails in rail tiles: clean rounded display */
.wde-rail-tile-icon img {
  border-radius: 8px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.12));
}
.wde-rail-tile:hover .wde-rail-tile-icon img {
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.2));
}
.wde-rail-tile.selected .wde-rail-tile-icon img {
  filter: drop-shadow(0 2px 8px rgba(99,102,241,.3));
}

/* ── Clothing layer equip animation ─────────────────────────────────────── */
.wde-clothing-layer.pdc-equip {
  animation: pdcLayerEquip var(--pdc-equip-dur) cubic-bezier(.34,1.56,.64,1);
}
@keyframes pdcLayerEquip {
  0%   { filter: brightness(1.5) saturate(1.2); }
  55%  { filter: brightness(1.08) saturate(1.05); }
  100% { filter: brightness(1) saturate(1); }
}

/* Smooth clothing layer transitions */
.wde-clothing-layer {
  transition: opacity .28s ease !important;
}
.wde-clothing-layer img {
  transition: opacity .25s ease !important;
}

/* Specials override: fade out hidden layers smoothly */
.wde-clothing-layer.pdc-specials-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ── Figure / Croquis stage upgrade ─────────────────────────────────────── */
.wde-croquis-stage {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99,102,241,.08), transparent),
    linear-gradient(rgba(200,185,160,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,185,160,.07) 1px, transparent 1px) !important;
  background-size: auto, 20px 20px, 20px 20px !important;
  border-radius: 10px;
}
body.dark .wde-croquis-stage {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99,102,241,.14), transparent),
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) !important;
  background-size: auto, 20px 20px, 20px 20px !important;
}

/* Subtle floor shadow beneath the figure */
.wde-croquis-inner::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 65%;
  height: 10px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.14) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

/* ── Completeness bar at figure bottom ──────────────────────────────────── */
.pdc-completeness-bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(0,0,0,.07);
  margin: 4px 8px 0;
  overflow: hidden;
  flex-shrink: 0;
}
.pdc-completeness-fill {
  height: 100%;
  border-radius: 2px;
  /* Width and solid-color background are set via inline style in JS for precise
     control. Only animate the width; background transitions on gradients are
     not reliably interpolated across browsers so we skip that. */
  transition: width .4s cubic-bezier(.34,1.56,.64,1);
  background: var(--pdc-accent);
}

/* ── Item detail panel wrapper enhancement ──────────────────────────────── */
#wde-item-detail {
  transition: background .2s ease;
}
#wde-item-detail:not(:empty) {
  border-radius: 10px;
}

/* ── Glint sweep on layer equip ─────────────────────────────────────────── */
.wde-clothing-overlays::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 35%,
    rgba(255,255,255,.32) 50%,
    transparent 65%);
  opacity: 0;
  pointer-events: none;
  border-radius: inherit;
  z-index: 50;
}
.wde-clothing-overlays.pdc-glint::before {
  animation: pdcGlintSweep .55s ease forwards;
}
@keyframes pdcGlintSweep {
  0%   { opacity: 1; transform: translateX(-120%); }
  100% { opacity: 1; transform: translateX(140%); }
}

/* ── Board card mini doll outfit overlay ────────────────────────────────── */
.wdb-card-portrait { overflow: hidden; }

.pdc-card-outfit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.pdc-card-layer {
  position: absolute;
  inset: 0;
}
.pdc-card-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 18%; /* crop to show head/torso */
  opacity: 0;
  transition: opacity .4s ease;
}
.pdc-card-layer img.loaded { opacity: 1; }

/* ── Missing-asset placeholder tile ────────────────────────────────────── */
.wde-rail-tile.pdc-missing .wde-rail-tile-icon {
  opacity: .38;
  filter: grayscale(1);
}
.wde-rail-tile.pdc-missing::after {
  content: 'soon';
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: .48rem;
  font-weight: 900;
  letter-spacing: .03em;
  color: #9ca3af;
  pointer-events: none;
}

/* ── Dark mode chip adjustments ─────────────────────────────────────────── */
body.dark .wde-cat-chip.pdc-has-item::after {
  border-color: rgba(15,23,42,.8);
  box-shadow: 0 0 7px var(--pdc-chip-tint, rgba(99,102,241,.5));
}

/* ── Smooth rail scroll ─────────────────────────────────────────────────── */
.wde-rail-wrap {
  scroll-behavior: smooth !important;
}

/* ── Responsive: phone adjustments ─────────────────────────────────────── */
@media (max-width: 600px) {
  .pdc-tint-row { gap: 4px; padding: 7px 9px; }
  .pdc-tint-preset { width: 16px; height: 16px; }
  .pdc-tint-input { width: 24px; height: 24px; }
  .wde-cat-chip.pdc-has-item::after { width: 6px; height: 6px; top: 2px; right: 2px; }
}

/* ── Scene Continuity — custom toggle checkboxes ─────────────────────── */
.wde-scene-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  transition: background .15s;
  cursor: pointer;
}
.wde-scene-row:hover { background: rgba(99,102,241,.06); }
.wde-scene-row.assigned { background: rgba(99,102,241,.09); }

/* Hide native checkbox */
.wde-scene-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #d1d5db;
  border: none;
  outline: none;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background .2s;
}
.wde-scene-cb::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s;
}
.wde-scene-cb:checked {
  background: #6366f1;
}
.wde-scene-cb:checked::after {
  transform: translateX(16px);
}
.wde-scene-name {
  flex: 1;
  font-size: .78rem;
  color: var(--wdb-ink, #1e293b);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wde-scene-row.assigned .wde-scene-name {
  color: #4f46e5;
  font-weight: 600;
}

/* ── Wardrobe Rail — uniform tile proportions ────────────────────────── */
.wde-rail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px 8px;
  padding: 8px 4px;
}
.wde-rail-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border-radius: 10px;
  border: 2px solid transparent;
  padding: 0 4px 8px;
  cursor: pointer;
  background: #f8fafc;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  min-height: 120px;
  position: relative;
  overflow: hidden;
}
.wde-rail-tile:hover {
  border-color: #c7d2fe;
  box-shadow: 0 2px 8px rgba(99,102,241,.15);
  transform: translateY(-2px);
}
.wde-rail-tile.selected {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
  background: #eef2ff;
}
/* PNG clothing image inside tile */
.wde-rail-tile-img {
  width: 100%;
  height: 80px;
  object-fit: contain;
  object-position: center bottom;
  display: block;
  border-radius: 6px 6px 0 0;
  background: transparent;
}
.wde-rail-tile-icon {
  font-size: 2rem;
  line-height: 1;
  width: 100%;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wde-rail-tile-name {
  font-size: .65rem;
  font-weight: 600;
  text-align: center;
  color: #374151;
  margin-top: 4px;
  line-height: 1.2;
  word-break: break-word;
  width: 100%;
  padding: 0 2px;
}
.wde-rail-tile.selected .wde-rail-tile-name { color: #4338ca; }

/* Deselect indicator: show ✕ badge on selected tile hover */
.wde-rail-tile.selected::after {
  content: '✕';
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: .6rem;
  color: #6366f1;
  opacity: 0;
  transition: opacity .15s;
  font-weight: 900;
}
.wde-rail-tile.selected:hover::after { opacity: 1; }

/* ── Base paper-doll body mannequin layer ──────────────────────────────── */
.wde-base-body-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2%;
}
.wde-base-body-layer svg {
  height: 88%;
  width: auto;
  opacity: 0.13;
}

/* Ensure all clothing layers sit above base body */
.wde-clothing-overlays { z-index: 2; }
