/* Layout: a top bar, the model filling the stage, a tool panel at the right; at phone width the panel sits under the model. */
:root {
  --bg: #eef0f3;
  --panel: #f8f9fb;
  --card: #ffffff;
  --stage: #dfe3e8;
  --fg: #1b2129;
  --muted: #5d6773;
  --line: #d9dee4;
  --accent: #2f62b3;
  --accent-fg: #ffffff;
  --accent-soft: #e5edf9;
  --chip: #eef1f5;
  --warn: #9c4209;
  --focus: #2f62b3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b; --panel: #161b21; --card: #1d232b; --stage: #222931; --fg: #e6e9ed; --muted: #9ba5b1;
    --line: #2d353f; --accent: #82abe8; --accent-fg: #0c1420; --accent-soft: #23324a; --chip: #262d36; --warn: #f0a46b; --focus: #9cc0f2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161b; --panel: #161b21; --card: #1d232b; --stage: #222931; --fg: #e6e9ed; --muted: #9ba5b1;
  --line: #2d353f; --accent: #82abe8; --accent-fg: #0c1420; --accent-soft: #23324a; --chip: #262d36; --warn: #f0a46b; --focus: #9cc0f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
html { height: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 14px; overflow: hidden; }
#app { display: grid; grid-template-columns: minmax(0, 1fr) 316px; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* top bar */
#bar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand svg { color: var(--accent); width: 20px; height: 20px; }
.figpick { display: flex; gap: 8px; align-items: center; flex: 1 1 280px; min-width: 0; }
.figpick select { flex: 1 1 auto; min-width: 0; max-width: 300px; }
.barright { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.menuwrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16,24,40,.18); padding: 6px; display: flex; flex-direction: column; }
.menu button { background: transparent; border: 0; text-align: left; justify-content: flex-start; padding: 8px 10px; border-radius: 6px; min-height: 34px; }
.menu button:hover:not(:disabled) { background: var(--chip); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; width: auto; }

#stage { position: relative; overflow: hidden; background: var(--stage); touch-action: none; min-width: 0; min-height: 0; }
#view { display: block; width: 100%; height: 100%; outline: none; }
#cloneMark { position: absolute; pointer-events: none; width: 18px; height: 18px; transform: translate(-50%, -50%); }
#cloneMark::before, #cloneMark::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
#cloneMark::before { left: 8px; top: 0; width: 2px; height: 18px; }
#cloneMark::after { top: 8px; left: 0; height: 2px; width: 18px; }
#cursor { position: absolute; pointer-events: none; border: 1.5px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.55); transform: translate(-50%, -50%); }
#lasso { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#lasso polyline { fill: rgba(127,169,230,.18); stroke: #fff; stroke-width: 1.5; stroke-dasharray: 5 4; }
#help { position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px); max-height: calc(100% - 24px); overflow: auto; font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--panel) 88%, transparent); padding: 6px 10px; border-radius: 8px; }
#help .lg-head { all: unset; cursor: pointer; font-weight: 600; color: var(--text, inherit); display: block; }
#help .lg-group { margin-top: 6px; font-weight: 600; color: var(--text, inherit); }
#help { font-size: 11.5px; }
#help .lg-row { display: grid; grid-template-columns: 8.5em 1fr; gap: 6px; line-height: 1.45; }
#help .lg-row kbd { font: inherit; font-weight: 600; white-space: nowrap; }
#help.folded .lg-body { display: none; }
#toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); max-width: calc(100% - 24px); background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; font-size: 13px; line-height: 1.35; box-shadow: var(--shadow); z-index: 5; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 15px; text-align: center; padding: 24px; }
#finding { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5; width: min(420px, calc(100% - 32px)); }
.findcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; font-size: 13px; }
.findtrack { grid-column: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#findBar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#findCancel { grid-row: 1 / span 2; grid-column: 2; }
#findBox { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
#empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.emptycard { max-width: 380px; text-align: center; background: var(--card); border: 2px dashed var(--line); border-radius: 16px; padding: 32px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.emptycard svg { width: 40px; height: 40px; color: var(--accent); }
.emptycard h1 { margin: 0; font-size: 20px; font-weight: 600; }
.emptycard p { margin: 0; color: var(--muted); line-height: 1.45; }
#dropzone { position: absolute; inset: 10px; border: 3px dashed var(--accent); border-radius: 16px; background: color-mix(in srgb, var(--accent) 12%, transparent); display: grid; place-items: center; z-index: 10; pointer-events: none; }
#dropzone div { background: var(--accent); color: var(--accent-fg); padding: 10px 18px; border-radius: 999px; font-weight: 600; }
/* (on a phone the box is taller than the view: it scrolls inside itself, with its close button always in reach; the view
   below takes no touch scrolling, so without this the box could neither scroll nor close) */
#guide { position: absolute; right: 16px; top: 16px; width: min(360px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px rgba(16,24,40,.22); padding: 16px 18px; z-index: 8; box-sizing: border-box; }
#guideX { position: sticky; top: 0; float: right; margin: -6px -8px 0 8px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 18px; line-height: 1; cursor: pointer; z-index: 1; }
#guide h2 { font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--fg); }
#guide ol { margin: 10px 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; line-height: 1.45; }

/* panel */
#panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; min-width: 0;
  padding-block: 12px 24px; padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 10px; }
.sister { font-size: 12px; color: var(--muted); text-decoration: none; padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.sister:hover { color: var(--fg); border-color: var(--accent); }
@media (max-width: 760px) {
  .sister { display: none; }
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 52% minmax(0, 1fr); }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
  .brand span { display: none; }
  .figpick { flex-basis: 100%; order: 3; }
  .figpick:has(select[hidden]) { flex-basis: auto; order: 0; flex-grow: 0; }
  #openModel span { display: none; }
  .barright { margin-left: auto; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 9px; min-width: 0; box-shadow: var(--shadow); }
details.card { gap: 0; }
details.card[open] { gap: 9px; }
details.card > summary { cursor: pointer; font-weight: 600; font-size: 13px; list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 22px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform .15s; }
details.card[open] > summary::after { transform: rotate(-135deg); }
h2 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.row.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.row.three button { padding-inline: 4px; font-size: 12.5px; }
.grow { flex: 1 1 auto; min-width: 0; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--chip); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; cursor: pointer; min-height: 32px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; padding-inline: 18px; }
button.ghost { background: transparent; }
button.icon { width: 34px; padding: 0; }
button.wide { width: 100%; }
.caret { width: 14px; height: 14px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
select { background: var(--chip); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; min-height: 34px; }
textarea { width: 100%; min-height: 56px; resize: vertical; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; background: var(--chip); padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 6px 4px; border-radius: 7px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
.tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.tools button { flex-direction: column; gap: 3px; padding: 7px 2px 5px; font-size: 11.5px; min-height: 52px; line-height: 1.1; }
.tools button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.views { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.views button { padding: 5px 2px; font-size: 12px; min-height: 30px; }
.labels { display: flex; flex-direction: column; gap: 2px; }
.lab { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto auto auto; gap: 6px; align-items: center; padding: 4px 5px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; }
.lab:hover { background: var(--chip); }
.lab.current { border-color: var(--accent); background: var(--accent-soft); }
.lab .dot { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line); padding: 0; overflow: hidden; position: relative; min-height: 0; }
.lab .dot input { position: absolute; inset: -6px; width: 34px; height: 34px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.lab .name { width: 100%; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 2px 4px; }
.lab .name:hover:not([readonly]), .lab .name:focus { border-color: var(--line); background: var(--bg); }
.lab .count { font-family: var(--font-num); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; min-width: 46px; }
.lab button { min-height: 24px; padding: 1px 6px; font-size: 11px; }
.lab .key { font-family: var(--font-num); font-size: 10px; color: var(--muted); }
.sub { font-size: 12px; color: var(--muted); line-height: 1.4; }
.big { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 26px; }
.switch.strong { font-weight: 600; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.val { font-family: var(--font-num); font-size: 12px; color: var(--muted); min-width: 52px; text-align: right; }
#saveStatus.warn, .warn { color: var(--warn); }
.preview-on #view { outline: 3px solid var(--accent); outline-offset: -3px; }
.nomodel #panel > * { opacity: .5; pointer-events: none; }
.nomodel #panel > #poseCheck { opacity: 1; pointer-events: auto; }   /* New body works before any model is loaded */
.nomodel #faceTotal, .nomodel #faceWord, .nomodel #help { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

#healBox { margin-top: 8px; display: grid; gap: 6px; }
#healList { display: grid; gap: 2px; max-height: 220px; overflow: auto; }
#healList label { display: flex; gap: 8px; align-items: center; font-size: 13px; }
#healList .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#coverList { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; margin: 6px 0; }
#coverList .coverRow { display: flex; align-items: center; gap: 6px; text-align: left; font-size: 12px; padding: 3px 6px; }
#coverList .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#turnRing { position: absolute; pointer-events: none; border: 2px dashed rgba(255,255,255,.75); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.35); transform: translate(-50%, -50%); }
#coverList .coverItem { display: flex; gap: 4px; align-items: stretch; }
#coverList .coverItem .coverRow { flex: 1; }
#coverList .coverClose { font-size: 12px; padding: 2px 8px; }

/* the new-garment bar: the garment is made on its own core, so the page stays live under it */
#making { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5; width: min(460px, calc(100% - 32px)); }
.makingcard { background: var(--card, #1f2430); border: 1px solid var(--line, #333a48); border-radius: 12px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; font-size: 13px; }
.makingtrack { grid-column: 1; height: 6px; border-radius: 3px; background: var(--line, #333a48); overflow: hidden; }
#makingBar { height: 100%; width: 0; background: var(--accent, #7aa2e8); transition: width .3s; }
#makingStop { grid-row: 1 / span 2; grid-column: 2; }

/* the garment type card: asked once before a new garment is hung, kept with the cut */
#typeCard, #kindCard { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6; width: min(480px, calc(100% - 32px)); }
.typecard { background: var(--card, #1f2430); border: 1px solid var(--accent, #7aa2e8); border-radius: 12px; padding: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); display: grid; gap: 8px; font-size: 13px; }
#typeCardTitle { font-weight: 600; font-size: 14px; }
#typeCardWhy { color: var(--muted); }
.typebtns { display: flex; gap: 8px; flex-wrap: wrap; }
#kindCardRows .row { gap: 8px; }
