:root{
  --pink:#ff4f9a; --pink-dark:#bd2366; --purple:#7648d7; --ink:#2a1b3d; --muted:#786683;
  --card:rgba(255,255,255,.92); --line:rgba(75,36,91,.12); --shadow:0 18px 60px rgba(82,37,95,.18);
}
*{box-sizing:border-box}
html,body{width:100%;height:100%;margin:0}
body{
  overflow:hidden;color:var(--ink);
  font-family:Inter,ui-rounded,"SF Pro Rounded",system-ui,-apple-system,"Segoe UI",sans-serif;
  background:radial-gradient(circle at 18% 8%,rgba(255,255,255,.96),transparent 28%),
             linear-gradient(135deg,#ffe4f1,#f4e9ff 48%,#dcf5ff);
  touch-action:manipulation;
}
button,input,select{font:inherit;color:inherit}
button{-webkit-tap-highlight-color:transparent}

.app{height:100%;display:grid;grid-template-rows:auto 1fr}

/* ---------- top bar ---------- */
.topbar{display:grid;grid-template-columns:minmax(200px,1fr) auto;align-items:center;gap:14px;
  padding:10px 16px;background:rgba(255,255,255,.84);backdrop-filter:blur(20px);
  border-bottom:1px solid var(--line);z-index:20}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.brand-mark{width:44px;height:44px;border-radius:15px;display:grid;place-items:center;flex:0 0 auto;
  background:linear-gradient(145deg,#ff69aa,#8757de);box-shadow:0 8px 22px rgba(201,39,112,.25)}
.brand-mark svg{width:26px;height:26px}
.brand-title{font-weight:900;font-size:clamp(15px,2vw,22px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.brand-sub{font-size:11px;color:var(--muted);font-weight:700}
.top-actions{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}

.btn{border:0;cursor:pointer;padding:10px 13px;border-radius:14px;background:#fff;color:var(--ink);
  box-shadow:0 7px 20px rgba(72,34,86,.09);font-weight:800;display:inline-flex;align-items:center;
  justify-content:center;gap:7px;text-decoration:none;transition:transform .14s,box-shadow .14s,opacity .14s}
.btn:hover{transform:translateY(-1px)}
.btn:active{transform:translateY(1px) scale(.99)}
.btn.primary{color:#fff;background:linear-gradient(135deg,var(--pink),var(--purple));box-shadow:0 9px 24px rgba(154,67,169,.25)}
.btn.danger{color:#9e2450;background:#ffe7ef}
.btn.wide{width:100%;margin-top:7px}
.btn:disabled{opacity:.45;cursor:not-allowed;transform:none}
.icon-btn{border:0;cursor:pointer;width:38px;height:38px;border-radius:13px;background:#fff;display:grid;
  place-items:center;box-shadow:0 5px 14px rgba(71,31,87,.09);font-weight:900;font-size:19px;line-height:1}

/* ---------- workspace ---------- */
.workspace{min-height:0;display:grid;grid-template-columns:110px minmax(340px,1fr) minmax(360px,440px);gap:13px;padding:13px}
.panel{min-height:0;background:var(--card);border:1px solid rgba(255,255,255,.85);border-radius:24px;
  box-shadow:var(--shadow);backdrop-filter:blur(16px)}

/* On a wide screen the wardrobe is not a drawer: its children join the grid. */
.wardrobe{display:contents}
.drawer-handle,.rail-arrow,.rail-progress{display:none}
.stage-panel{grid-column:2;grid-row:1}
.category-panel{grid-column:1;grid-row:1}
.options-panel{grid-column:3;grid-row:1}
.rail-wrap{display:contents}

.category-panel{padding:8px;overflow-y:auto;scrollbar-width:none}
.category-panel::-webkit-scrollbar,.option-grid::-webkit-scrollbar,.gallery-grid::-webkit-scrollbar{display:none}
.category-btn{width:100%;border:0;cursor:pointer;border-radius:16px;background:transparent;padding:8px 3px;
  margin-bottom:3px;display:flex;flex-direction:column;align-items:center;gap:4px;color:#6f5a79;
  font-size:9.5px;font-weight:900;text-transform:uppercase;letter-spacing:.03em;text-align:center}
.category-btn.active{color:var(--pink-dark);background:linear-gradient(135deg,rgba(255,79,154,.15),rgba(118,72,215,.1))}
.category-btn.blocked{opacity:.42}
.category-icon{width:40px;height:40px;border-radius:13px;background:#fff;display:grid;place-items:center;
  box-shadow:0 5px 14px rgba(69,27,91,.08)}
.category-btn.active .category-icon{background:linear-gradient(135deg,#ff72b1,#8f67e5)}
.category-icon svg{width:27px;height:27px}
.category-label{display:block;line-height:1.15}

/* ---------- stage ---------- */
.stage-panel{position:relative;overflow:hidden;display:grid;grid-template-rows:auto 1fr auto}
.stage-toolbar{padding:10px 11px 4px;display:flex;align-items:center;justify-content:space-between;gap:9px}
.mode-switch{display:flex;background:rgba(255,255,255,.86);padding:4px;border-radius:14px;box-shadow:0 5px 16px rgba(71,31,87,.08)}
.mode-btn{border:0;cursor:pointer;background:transparent;border-radius:10px;padding:8px 11px;font-weight:800;color:#806b89}
.mode-btn.active{background:linear-gradient(135deg,#ff5fa4,#8c61de);color:#fff;box-shadow:0 5px 14px rgba(123,74,217,.2)}
.mini-actions{display:flex;gap:7px}
.stage-wrap{min-height:0;display:grid;place-items:center;padding:0 9px}
.avatar-frame{width:min(100%,600px);height:100%;max-height:100%;aspect-ratio:10/13;border-radius:26px;overflow:hidden;
  box-shadow:0 18px 54px rgba(60,32,80,.2);border:6px solid rgba(255,255,255,.85);background:#fff}
.avatar-frame svg{width:100%;height:100%;display:block}
.stage-footer{display:grid;grid-template-columns:1fr auto;gap:9px;align-items:end;padding:8px 11px 11px}
.identity-fields{display:grid;grid-template-columns:1fr 96px;gap:8px}
.field label{display:block;font-size:9px;font-weight:900;color:#806b89;text-transform:uppercase;letter-spacing:.06em;margin:0 0 4px 4px}
.field input,.field select,.search-box{width:100%;border:1px solid rgba(97,58,111,.16);background:rgba(255,255,255,.96);
  border-radius:13px;padding:10px 11px;outline:none;font-weight:700}
.field input:focus,.field select:focus,.search-box:focus{border-color:var(--pink)}

/* ---------- options ---------- */
.options-panel{display:grid;grid-template-rows:auto auto 1fr auto;min-height:0;overflow:hidden}
.options-head{padding:15px 16px 6px;display:flex;justify-content:space-between;gap:12px;align-items:flex-start}
.options-title{font-size:19px;font-weight:900;margin:0}
.options-subtitle{font-size:11px;color:var(--muted);font-weight:650;margin-top:3px;line-height:1.4}
.count-badge{background:linear-gradient(135deg,#fff0f7,#f1eaff);color:#8c3c77;border-radius:999px;
  padding:6px 9px;font-size:10px;font-weight:900;white-space:nowrap}
.option-tools{padding:0 16px 9px;display:flex;gap:8px}
.option-grid{min-height:0;overflow-y:auto;padding:4px 13px 14px;display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));align-content:start;gap:9px}
.option-grid.traits{display:block}
.option-card{position:relative;min-height:116px;border:3px solid transparent;border-radius:18px;padding:6px;
  background:#fff;box-shadow:0 7px 18px rgba(77,35,92,.08);display:flex;flex-direction:column;align-items:center;
  gap:5px;overflow:hidden;cursor:pointer;transition:transform .14s,box-shadow .14s}
.option-card:hover{transform:translateY(-1px);box-shadow:0 10px 24px rgba(77,35,92,.14)}
.option-card.selected{border-color:var(--pink);background:linear-gradient(145deg,#fff,#fff0f7)}
.option-card.remove-card{background:linear-gradient(145deg,#fff,#f3f7ff)}
.item-preview{width:100%;height:80px;border-radius:13px;background:linear-gradient(145deg,#fffafd,#f2ecff);
  display:grid;place-items:center;overflow:hidden}
.item-preview svg{width:100%;height:100%;display:block}
.option-name{width:100%;font-size:9px;font-weight:900;text-align:center;line-height:1.15;color:#66516f;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.selected-dot{position:absolute;right:6px;top:6px;width:20px;height:20px;border-radius:50%;background:var(--pink);
  color:#fff;font-size:12px;font-weight:900;display:grid;place-items:center;z-index:3}
.special-control{padding:12px;background:linear-gradient(135deg,#fff2f8,#f3ecff);border-radius:17px;display:grid;gap:14px}
.special-control.inline{grid-column:1/-1;padding:10px 12px;gap:8px;margin-bottom:2px}
.special-control strong{display:block;margin-bottom:8px;font-size:13px}
.palette-row{display:flex;gap:8px;flex-wrap:wrap}
.color-dot{width:34px;height:34px;border-radius:50%;border:4px solid #fff;cursor:pointer;
  box-shadow:0 4px 12px rgba(50,26,68,.13);padding:0}
.color-dot.selected{outline:3px solid var(--pink);transform:scale(1.08)}
.options-foot{margin:0 13px 13px;padding:9px 11px;border-radius:14px;background:#eef8ff;color:#365c72;
  font-size:10px;line-height:1.4;font-weight:700}
.empty-state{grid-column:1/-1;min-height:220px;display:grid;place-items:center;text-align:center;color:#806c89}
.loading{grid-column:1/-1;min-height:240px;display:grid;place-items:center;color:#7b6884;font-weight:800}

/* ---------- toast ---------- */
.toast{position:fixed;left:50%;bottom:22px;transform:translate(-50%,14px);background:rgba(38,22,48,.95);color:#fff;
  padding:12px 17px;border-radius:999px;z-index:100;font-weight:800;box-shadow:0 10px 30px rgba(0,0,0,.22);
  max-width:min(90vw,620px);text-align:center;opacity:0;pointer-events:none;transition:opacity .2s,transform .2s}
.toast.show{opacity:1;transform:translate(-50%,0)}

/* ---------- modals ---------- */
.modal-backdrop{position:fixed;inset:0;z-index:80;background:rgba(39,20,49,.56);backdrop-filter:blur(10px);
  display:grid;place-items:center;padding:18px}
.modal{width:min(1100px,96vw);height:min(780px,92vh);background:#fffafc;border-radius:26px;
  box-shadow:0 30px 100px rgba(35,16,47,.38);overflow:hidden;display:grid;grid-template-rows:auto auto 1fr}
.modal-head{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;
  border-bottom:1px solid var(--line);background:rgba(255,255,255,.92)}
.sheet-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:0 0 14px}
.modal-title{font-size:21px;font-weight:900}
.modal-sub{font-size:11.5px;color:#745f80;font-weight:650;margin-top:3px;line-height:1.45}
.gallery-tabs{display:flex;gap:7px;padding:10px 18px 0}
.gallery-tab{border:0;cursor:pointer;border-radius:999px;padding:9px 14px;background:#f4edf7;color:#6c5277;font-weight:800}
.gallery-tab.active{background:linear-gradient(135deg,var(--pink),var(--purple));color:#fff}
.gallery-grid{padding:18px;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:15px;align-content:start}
.gallery-card{background:#fff;border-radius:20px;overflow:hidden;box-shadow:0 10px 28px rgba(70,31,86,.12);border:1px solid rgba(87,42,103,.08)}
.gallery-card img{width:100%;display:block;aspect-ratio:10/13;object-fit:cover;background:#f8eefa}
.gallery-info{padding:11px}
.gallery-name{font-weight:900;font-size:15px}
.gallery-date{color:#816e89;font-size:10px;font-weight:700;margin-top:2px}
.gallery-status{display:inline-flex;margin-top:6px;padding:4px 8px;border-radius:999px;font-size:9px;font-weight:900;text-transform:uppercase}
.gallery-status.public{background:#dcf8e9;color:#126340}
.gallery-status.private{background:#eee7ff;color:#5c3c91}
.gallery-actions{display:grid;grid-template-columns:repeat(auto-fit,minmax(56px,1fr));gap:6px;margin-top:9px}
.sheet{width:min(620px,95vw);max-height:92vh;overflow:auto;background:#fff;border-radius:26px;
  box-shadow:0 30px 100px rgba(35,16,47,.38);padding:20px}
.privacy-choices{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:6px}
.privacy-card{border:2px solid #eee2f1;border-radius:20px;padding:16px;background:#fffafd;text-align:left;cursor:pointer}
.privacy-card:hover{border-color:#d4b7dc;transform:translateY(-1px)}
.privacy-card strong{display:block;font-size:16px;margin-bottom:5px}
.privacy-card span{display:block;color:#75627f;font-size:11.5px;line-height:1.45}
.privacy-card.public{background:linear-gradient(145deg,#fffafd,#f0fbff)}
.toggle-row{display:flex;align-items:flex-start;gap:9px;margin-top:12px;padding:12px;background:#fff4d9;
  border-radius:14px;color:#6f5114;font-size:11.5px;line-height:1.45;cursor:pointer}
.server-note{margin-top:12px;padding:10px 12px;border-radius:13px;background:#eef9ff;color:#315b72;font-size:11px;line-height:1.5}
.server-note a{color:#1f5f86}
.share-preview{width:min(280px,100%);margin:0 auto 14px;border-radius:20px;overflow:hidden;box-shadow:0 12px 35px rgba(70,31,86,.18)}
.share-preview img{width:100%;display:block;aspect-ratio:10/13;object-fit:cover;background:#fff}
.share-buttons{display:grid;grid-template-columns:repeat(2,1fr);gap:9px}
.share-link-box{margin-top:12px;padding:11px 12px;border-radius:14px;background:#f6f1fa;border:1px solid var(--line)}
.share-link-box[hidden]{display:none}
.share-link-box label{display:block;font-size:10px;font-weight:900;color:#7b5f88;text-transform:uppercase;letter-spacing:.05em;margin-bottom:5px}
.share-link-box input{width:100%;border:1px solid #ddcce4;border-radius:11px;padding:10px;font-size:12.5px;background:#fff;color:var(--ink)}
.share-buttons .wide{grid-column:1/-1;margin-top:0}

/* ---------- responsive ---------- */
@media(max-width:1120px){
  .workspace{grid-template-columns:96px 1fr 340px;gap:9px;padding:9px}
  .option-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
  .brand-sub{display:none}
}

/* =====================  PHONES AND SMALL TABLETS  =====================
   The character gets the whole screen. The wardrobe is a drawer that slides
   down to a handle, so a child can always see the whole outfit. Nothing
   scrolls sideways except the category strip, and that strip shows exactly
   how much more there is. */
@media(max-width:820px){
  html,body{overscroll-behavior:none}
  .topbar{padding:8px 10px}
  .brand-mark{width:38px;height:38px}
  .hide-mobile{display:none}

  .workspace{display:grid;grid-template-columns:1fr;grid-template-rows:minmax(0,1fr) auto;
    padding:6px;gap:6px}

  .stage-panel{grid-column:1;grid-row:1;border-radius:20px}
  .stage-toolbar{padding:5px 6px 2px}
  .mode-btn{padding:7px 10px;font-size:12px}
  /* Fill the stage and let the drawing letterbox inside it. Locking the frame
     to 10/13 made it wider than the screen, which quietly cut the sides off
     capes, trains and wings. */
  .avatar-frame{border-width:4px;border-radius:18px;width:100%;height:100%;max-width:100%;aspect-ratio:auto}
  .stage-wrap{padding:0 6px}
  .stage-footer{padding:4px 6px 6px}
  .field label{display:none}
  .field input,.field select{padding:9px;font-size:13px}
  .btn{padding:9px 11px;font-size:12.5px}

  /* ---- the drawer ----
     The height is animated on the panel inside the drawer, never on the drawer
     itself: a transition on a grid item's own height never advances, which
     left the drawer permanently shut. */
  .wardrobe{grid-column:1;grid-row:2;display:flex;flex-direction:column;min-height:0;height:auto;
    background:var(--card);border:1px solid rgba(255,255,255,.85);
    border-radius:22px 22px 16px 16px;box-shadow:var(--shadow);overflow:hidden}

  .drawer-handle{display:flex;align-items:center;justify-content:center;gap:9px;position:relative;
    border:0;background:transparent;width:100%;padding:9px 12px 4px;cursor:pointer;flex:0 0 auto}
  .grip{width:44px;height:5px;border-radius:3px;background:#d9c6de;flex:0 0 auto}
  .drawer-label{font-weight:900;font-size:12px;color:#7b5f88;text-transform:uppercase;letter-spacing:.05em}
  .drawer-hint{font-size:10.5px;font-weight:800;color:#a693ae}
  .wardrobe.collapsed .grip{background:var(--pink)}

  /* ---- category strip with a real scroll indicator ---- */
  .rail-wrap{display:block;position:relative;flex:0 0 auto;padding:0 2px 6px}
  .category-panel{grid-column:auto;grid-row:auto;display:flex;overflow-x:auto;overflow-y:hidden;
    padding:2px 34px;border-radius:0;background:transparent;border:0;box-shadow:none;backdrop-filter:none;
    scroll-snap-type:x proximity;overscroll-behavior-x:contain;
    -webkit-mask-image:linear-gradient(90deg,transparent 0,#000 26px,#000 calc(100% - 26px),transparent 100%);
    mask-image:linear-gradient(90deg,transparent 0,#000 26px,#000 calc(100% - 26px),transparent 100%)}
  .category-btn{min-width:66px;margin:0 2px;padding:4px 3px;scroll-snap-align:center}
  .category-icon{width:34px;height:34px}
  .category-icon svg{width:23px;height:23px}
  .category-btn .category-label{font-size:8px}

  .rail-arrow{display:grid;place-items:center;position:absolute;top:2px;width:30px;height:52px;z-index:3;
    border:0;border-radius:12px;background:rgba(255,255,255,.92);color:var(--pink-dark);
    font-size:22px;font-weight:900;line-height:1;box-shadow:0 3px 10px rgba(72,34,86,.16);cursor:pointer}
  .rail-arrow.left{left:0}
  .rail-arrow.right{right:0}
  .rail-arrow[hidden]{display:none}
  .rail-progress{display:block;height:4px;margin:2px 34px 0;border-radius:2px;background:rgba(120,90,135,.16)}
  .rail-progress span{display:block;height:100%;border-radius:2px;background:var(--pink);
    width:30%;transform:translateX(0);transition:transform .12s linear}

  /* ---- items scroll DOWN, never sideways ---- */
  .options-panel{grid-column:auto;grid-row:auto;flex:0 0 auto;min-height:0;background:transparent;
    border:0;box-shadow:none;backdrop-filter:none;border-radius:0;overflow:hidden;
    height:min(34vh,272px);grid-template-rows:auto auto 1fr;
    transition:height .26s cubic-bezier(.4,0,.2,1),opacity .2s}
  .wardrobe.collapsed .options-panel{height:0;opacity:0;pointer-events:none}
  .options-head{padding:0 12px 4px}
  .options-title{font-size:15px}
  .options-subtitle{display:none}
  .option-tools{padding:0 12px 6px}
  .search-box{padding:8px 10px;font-size:13px}
  .option-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:7px;
    padding:2px 12px 14px;overflow-y:auto;overflow-x:hidden;overscroll-behavior-y:contain;-webkit-overflow-scrolling:touch}
  .option-card{min-height:96px;padding:5px;border-width:2px}
  .item-preview{height:60px}
  .option-name{font-size:8.5px}
  .options-foot{display:none}

  .gallery-grid{grid-template-columns:repeat(2,minmax(0,1fr));padding:11px;gap:10px}
  .privacy-choices{grid-template-columns:1fr}
  .modal{height:94vh;border-radius:20px}
  .toast{bottom:auto;top:64px}
}

@media(max-width:420px){
  .option-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
  .item-preview{height:66px}
}
