:root {
  --bg1: #ffe3f1;
  --bg2: #e0f0ff;
  --panel: #ffffff;
  --ink: #3a2b45;
  --accent: #ff5fa2;
  --accent2: #7c5cff;
  --ring: #ffd23f;
  --shadow: 0 10px 30px rgba(90, 40, 90, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI Rounded", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 0 #fff;
}
.topbar h1 span {
  font-size: 20px;
  color: var(--accent2);
  display: inline-block;
}

.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.pill {
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 11px 16px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.pill:hover { transform: translateY(-2px); }
.pill:active { transform: translateY(1px); }
.pill.primary { background: var(--accent); color: #fff; }

/* signed-in chip — only rendered on a host that enforces login */
.whoami {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 999px;
  padding: 6px 14px 6px 6px;
  box-shadow: var(--shadow);
  font-size: 14px; font-weight: 700;
}
.whoami img { width: 30px; height: 30px; border-radius: 50%; display: block; }
.whoami span { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami a { color: var(--accent2); text-decoration: none; border-left: 2px solid #eee6fa; padding-left: 10px; }
.whoami a:hover { text-decoration: underline; }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 460px) 1fr;
  gap: 22px;
  padding: 0 22px 32px;
  align-items: start;
}

.stage {
  position: sticky;
  top: 16px;
  background: radial-gradient(circle at 50% 30%, #fff 0%, #ffeef7 70%);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.stage-inner {
  background: repeating-linear-gradient(45deg, #fff6fb, #fff6fb 22px, #ffeaf5 22px, #ffeaf5 44px);
  border-radius: 20px;
  padding: 10px;
}
.doll-wrap { position: relative; }
#doll {
  width: 100%; height: auto; display: block;
  cursor: grab;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}
#dropzone {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
#dropzone rect {
  fill: rgba(255, 95, 162, 0.16);
  stroke: var(--accent);
  stroke-width: 4;
  stroke-dasharray: 14 9;
  animation: march 0.6s linear infinite;
}
@keyframes march { to { stroke-dashoffset: -23; } }

.hint {
  margin: 12px 4px 2px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: #a37fae;
}

.wardrobe {
  position: relative;
  background: var(--panel);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab {
  border: 3px solid transparent;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  background: #f2effa;
  color: var(--ink);
}
.tab.active { background: var(--accent2); color: #fff; border-color: var(--ring); }

/* an author `display` rule beats the UA rule for [hidden], so say it explicitly
   or the swatch row leaks onto tabs that have no colours (Skin, Boy/Girl) */
[hidden] { display: none !important; }

.colors { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #d9d2ec;
  cursor: pointer;
  padding: 0;
}
.swatch.active { box-shadow: 0 0 0 4px var(--ring); transform: scale(1.08); }

.items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.item {
  border: 3px solid #eee6fa;
  background: #fbf9ff;
  border-radius: 18px;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.item:hover { border-color: #d7c8ff; }
.item.active { border-color: var(--accent); background: #fff0f7; }
.item svg { width: 100%; height: 92px; pointer-events: none; }
.item .label { font-size: 13px; font-weight: 700; }

/* the boy/girl choice gets a big preview — it's the "who am I" pick */
.item.body-pick { grid-column: span 2; }
.item.body-pick svg { height: 210px; }
.item.body-pick .label { font-size: 17px; }

/* whole-look tiles show the entire character, so they need room */
.item.preset svg { height: 190px; }
.item.preset .label { font-size: 14px; }
.item.preset.active { border-color: var(--accent2); background: #f4f0ff; }

/* ---- drag & drop ---- */
.item {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}
.item.arming { transform: scale(0.96); }
.item.armed {
  transform: scale(1.08);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

body.dragging { cursor: grabbing; user-select: none; }
body.dragging #doll { cursor: grabbing; }
#doll.armed { filter: drop-shadow(0 0 7px var(--accent)); }

.stage, .wardrobe { transition: box-shadow 0.12s ease; }
.stage.drop-active { box-shadow: var(--shadow), 0 0 0 3px #ffd9ea; }
.stage.drop-hot { box-shadow: var(--shadow), 0 0 0 5px var(--accent); }
.wardrobe.drop-active { box-shadow: var(--shadow), 0 0 0 3px #e2dbf8; }
.wardrobe.drop-hot { box-shadow: var(--shadow), 0 0 0 5px var(--accent2); }
/* absolutely positioned so it can't reflow the panel out from under the pointer
   in the middle of a drag */
.wardrobe.drop-hot::before {
  content: "🧺 Drop it here to take it off";
  position: absolute;
  left: 14px; right: 14px; top: 14px;
  z-index: 5;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f2effa;
  box-shadow: 0 4px 12px rgba(90, 40, 90, 0.12);
  color: var(--accent2);
  font-weight: 700;
  font-size: 14px;
  text-align: center;
}

.drag-ghost {
  position: fixed;
  left: 0; top: 0;
  width: 124px; height: 124px;
  margin: -62px 0 0 -62px;
  pointer-events: none;
  z-index: 100;
  filter: drop-shadow(0 10px 16px rgba(90, 40, 90, 0.35));
}
.drag-ghost svg { width: 100%; height: 100%; display: block; overflow: visible; }
.drag-ghost.snap { transition: transform 0.22s ease, opacity 0.22s ease; opacity: 0; }
.drag-ghost.poof { transition: opacity 0.18s ease; opacity: 0; }

/* ---- the crew ---- */
.cheer-wrap { margin-top: 10px; border-top: 2px dashed #ffd9ea; padding-top: 10px; }
.cheer-title { margin: 0 0 8px; text-align: center; font-size: 13px; font-weight: 700; color: #a37fae; }
.cheer { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.cheerer {
  border: 3px solid #ffe3f1; background: #fff; border-radius: 50%;
  width: 46px; height: 46px; padding: 0; cursor: pointer; overflow: hidden;
  flex: 0 0 auto;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.cheerer svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.cheerer:hover { transform: translateY(-4px) scale(1.1); border-color: var(--accent); }

.forwho { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.forwho-label { font-size: 13px; font-weight: 700; color: #a37fae; }
.pickme {
  border: 2px solid #eee6fa; background: #fbf9ff; color: var(--ink);
  border-radius: 999px; padding: 5px 11px; font: inherit; font-weight: 700;
  font-size: 12px; cursor: pointer;
}
.pickme.active { background: var(--accent); border-color: var(--ring); color: #fff; }

.saved-card .credit {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--accent2);
}
.saved-card .credit svg {
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 2px solid #eee6fa;
}

.saved { margin-top: 22px; border-top: 2px dashed #e7dff5; padding-top: 14px; }
.saved h2 { margin: 0 0 10px; font-size: 20px; }
.saved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.saved-card {
  background: #fbf9ff;
  border: 3px solid #eee6fa;
  border-radius: 18px;
  padding: 8px;
  text-align: center;
}
.saved-card svg { width: 100%; height: 120px; }
.saved-card .name { font-weight: 700; font-size: 14px; margin: 4px 0; word-break: break-word; }
.saved-card .row { display: flex; gap: 6px; justify-content: center; }
.mini {
  border: none; cursor: pointer; font: inherit; font-weight: 700;
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
}
.mini.load { background: var(--accent2); color: #fff; }
.mini.del { background: #ffe0e6; color: #c02a52; }
.muted { color: #9a90ad; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stage { position: static; }
}
