:root{
  color-scheme:dark;
  --page:#161618;--surface:#1e1e21;--raised:#29292d;--raised-hover:#333338;--line:#2f2f33;
  --edge:0 0 0 1px rgba(255,255,255,.08);
  --text:#f4f1ec;--muted:#9b98a1;--primary:#c9dcf7;--primary-hover:#b9d1f4;--on-primary:#16161a;--ring:#f4f1ec;
  --radius:14px;--tabbar:64px;--credit:36px;
  --ease-out:cubic-bezier(.23,1,.32,1);--press:scale(.96);
  --safe-b:env(safe-area-inset-bottom,0px);--safe-t:env(safe-area-inset-top,0px);
}
*{box-sizing:border-box;margin:0}
html,body{height:100%;background:var(--page);color:var(--text)}
body{font-family:ui-rounded,"SF Pro Rounded",system-ui,-apple-system,"Segoe UI",sans-serif;font-size:13px;line-height:1.4;-webkit-font-smoothing:antialiased}
button{font:inherit;color:inherit;background:none;border:none;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation;display:inline-flex;align-items:center;justify-content:center;gap:6px;font-weight:650;position:relative;transition:background .15s var(--ease-out),color .15s var(--ease-out),transform .12s var(--ease-out),opacity .15s,box-shadow .15s}
button:active:not(:disabled){transform:var(--press)}
button:disabled{opacity:.35;cursor:default}
button:focus-visible{outline:2px solid var(--primary);outline-offset:2px}

.editor{
  min-height:100dvh;max-width:520px;margin:0 auto;padding:var(--safe-t) 0 0;
  display:flex;flex-direction:column;background:var(--page);
}

.notice{display:flex;justify-content:space-between;align-items:center;gap:12px;margin:12px 16px 0;padding:8px 8px 8px 16px;background:var(--raised);border-radius:999px;font-size:13px}
.notice[hidden]{display:none}
.notice p{margin:0;text-wrap:pretty}
.notice button{height:32px;padding:0 12px;background:var(--text);color:var(--page);font-size:12px;border-radius:999px;flex:none}

.masthead{display:flex;align-items:center;gap:10px;padding:12px 16px 8px;flex-wrap:wrap}
.wordmark{margin:0;display:inline-flex;align-items:center;gap:6px;font-size:18px;font-weight:750;letter-spacing:-.015em;flex:1}
.brand-mark{flex:none;transition:transform .32s cubic-bezier(.34,1.56,.64,1)}
.masthead:hover .brand-mark{transform:rotate(-10deg) scale(1.08)}
.wordmark-tag{background:var(--primary);color:var(--on-primary);font-size:13px;font-weight:800;border-radius:999px;padding:1px 7px 2px}

.mode-tabs{order:3;width:100%;margin:0;padding:4px;display:flex;gap:2px;border-radius:999px;box-shadow:inset 0 0 0 1px rgba(255,255,255,.06);background:var(--page)}
.mode-tabs button{flex:1;height:36px;border-radius:999px;color:var(--muted);font-size:13px;z-index:1}
.mode-tabs button[aria-selected="true"]{background:var(--text);color:var(--on-primary)}

.pill{height:38px;padding:0 14px;border-radius:999px;background:var(--raised);font-size:14px}
.pill:hover{background:var(--raised-hover)}
.pill.quiet{background:transparent;color:var(--muted)}
.pill.quiet:hover{color:var(--text);background:var(--raised)}
.pill.copy-link[data-copied="true"]{background:var(--primary);color:var(--on-primary)}

.stage{
  display:grid;justify-items:center;gap:14px;padding:12px 16px 16px;position:relative;flex:none;
  background:radial-gradient(circle at 1px 1px, rgba(255,255,255,.07) 1px, transparent 0) 0 0/22px 22px, var(--page);
}
.stage-frame{
  width:min(72vw,320px);aspect-ratio:1;border-radius:9%;overflow:hidden;position:relative;
  box-shadow:var(--edge),0 24px 48px -24px rgba(0,0,0,.7);background:transparent;
}
.stage-frame[data-booth="false"]{background:var(--raised)}
.character,.character svg,#preview{width:100%;height:100%;display:block}

.history-bar,.toolbar{
  display:flex;align-items:center;gap:8px;padding:6px;border-radius:999px;background:var(--raised);
  box-shadow:var(--edge),0 10px 28px -12px rgba(0,0,0,.65);
}
.hist-btn{width:40px;height:40px;border-radius:999px;color:var(--text)}
.hist-btn:hover:not(:disabled){background:var(--raised-hover)}
.hist-random{height:40px;padding:0 18px;background:transparent;color:var(--text);font-size:14px;font-weight:700}
.hist-random:hover{background:var(--raised-hover)}
.toast{font-size:12px;color:var(--muted);min-height:1em}
.toast[hidden]{display:none}

.dock{background:var(--surface);border-radius:28px 28px 0 0;box-shadow:var(--edge),0 -12px 40px -12px rgba(0,0,0,.55);flex:1;display:flex;flex-direction:column;min-height:0;overflow:hidden}
.tabbar{display:flex;gap:4px;overflow-x:auto;scrollbar-width:none;height:var(--tabbar);padding:12px 16px 8px;background:var(--surface);position:sticky;top:0;z-index:1}
.tabbar::-webkit-scrollbar{display:none}
.tab{flex:0 0 auto;height:34px;padding:0 14px;border-radius:999px;color:var(--muted);font-size:13px}
.tab[aria-selected="true"]{background:var(--text);color:var(--on-primary)}
.dock-body{flex:1;overflow-y:auto;min-height:0;scrollbar-width:thin;scrollbar-color:var(--raised) transparent}
.tray{padding:4px 16px 16px;display:grid;gap:4px}
.section{margin-bottom:22px}
.section-label{display:flex;align-items:baseline;gap:8px;font-size:13px;font-weight:700;margin-bottom:10px}
.section-detail{font-size:12px;color:var(--muted);font-weight:600}
.tiles{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px 8px}
.tile{display:flex;flex-direction:column;align-items:stretch;gap:6px;min-width:0;padding:0;background:none;text-align:center}
.tile-art{aspect-ratio:1;border-radius:var(--radius);background:var(--raised);overflow:hidden;box-shadow:inset 0 0 0 1px rgba(255,255,255,.1)}
.tile-art svg{width:100%;height:100%;display:block}
.tile[aria-checked="true"] .tile-art{box-shadow:0 0 0 2px var(--surface),0 0 0 4px var(--ring)}
.tile-label{font-size:12px;font-weight:600;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tile[aria-checked="true"] .tile-label{color:var(--text)}
.seg{display:inline-flex;padding:4px;border-radius:999px;background:var(--page);box-shadow:inset 0 0 0 1px rgba(255,255,255,.06);gap:2px}
.seg button{height:34px;min-width:72px;padding:0 14px;border-radius:999px;color:var(--muted);font-size:13px}
.seg button[aria-checked="true"]{background:var(--text);color:var(--on-primary)}
.swatches{display:flex;flex-wrap:wrap;gap:10px}
.swatch{width:36px;height:36px;border-radius:999px;padding:0;background:var(--raised);box-shadow:inset 0 0 0 1px rgba(255,255,255,.12)}
.swatch .chip{width:100%;height:100%;border-radius:inherit;display:block}
.swatch[aria-checked="true"]{box-shadow:0 0 0 2px var(--surface),0 0 0 4px var(--ring)}
.swatch.is-match{background:conic-gradient(from 180deg,#F9E2CE,#FDD5CB,#F0C8C1,#F9E2CE);position:relative}
.swatch.is-match::after{content:"";position:absolute;inset:8px;border-radius:999px;background:var(--raised)}
.swatch:disabled{opacity:.35}
.hint{margin-top:10px;padding:10px 12px;border-radius:12px;background:var(--raised);color:var(--muted);font-size:12px;font-weight:600}
.downloads{display:flex;gap:8px;padding:12px 16px calc(12px + var(--safe-b));background:var(--surface);border-top:1px solid var(--line)}
.download{flex:1;height:48px;border-radius:14px;background:var(--raised)}
.download.primary{background:var(--primary);color:var(--on-primary);font-weight:700;font-size:14px;box-shadow:inset 0 1px rgba(255,255,255,.45),0 8px 20px -10px rgba(169,196,240,.55)}
.download.primary:hover{background:var(--primary-hover)}
.credit{height:var(--credit);color:var(--muted);font-size:11px;opacity:.7;display:flex;justify-content:center;align-items:center;gap:.3em;font-weight:600;margin:0;background:var(--surface)}
.credit a{color:inherit;text-decoration:underline;text-underline-offset:2px}

@media (min-width:640px){
  .tiles{grid-template-columns:repeat(5,minmax(0,1fr))}
}
/* Desktop parity: stage | dock */
@media (min-width:960px){
  .editor{
    max-width:none;height:100dvh;padding:max(16px,var(--safe-t)) 24px 24px;
    display:grid;column-gap:24px;
    grid-template:
      "notice notice" auto
      "masthead masthead" auto
      "stage dock" minmax(0,1fr)
      / minmax(0,1fr) minmax(380px,440px);
  }
  .notice{grid-area:notice;margin:8px 0 0}
  .masthead{grid-area:masthead;padding:20px 4px;flex-wrap:nowrap}
  .mode-tabs{order:0;width:auto;min-width:220px;flex:0}
  .wordmark{flex:1;margin-right:auto}
  .stage{
    grid-area:stage;align-content:center;min-height:0;padding:24px;border-radius:28px;
    box-shadow:var(--edge);
  }
  .stage-frame{width:min(100%,calc(100dvh - 280px),560px);border-radius:6%}
  .dock{grid-area:dock;border-radius:28px}
  .tabbar{padding:16px 20px 8px}
  .tray{padding:8px 20px 20px}
  .downloads{padding:14px;position:static}
}
