/* Avatar Studio — the figure in the middle, the parts beside it.
   Phone first: the figure on top, the parts below; from 900 px the two side by side.
   Colours as tokens, light and dark; the CSP allows no style="": what JS sets goes through
   custom properties (--sw for a swatch). */

:root {
  color-scheme: light;
  --bg: #eef3fb;
  --wall:
    radial-gradient(60% 50% at 6% 0%, #dcd5ff 0%, transparent 62%),
    radial-gradient(52% 46% at 98% 6%, #cdeff0 0%, transparent 62%),
    radial-gradient(70% 50% at 50% 100%, #e3ecff 0%, transparent 66%),
    linear-gradient(180deg, #f3f6fd, #eef3fb 70%);
  --surface: rgba(255, 255, 255, 0.76);
  --surface-solid: #ffffff;
  --tile: #f2f4fb;
  --tile-hover: #e9edf9;
  --ink: #161b2e;
  --muted: #545c76;
  --line: rgba(22, 27, 46, 0.09);
  --line-2: rgba(22, 27, 46, 0.16);
  --accent: #5b47d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 71, 214, 0.12);
  --teal: #12868c;
  --danger: #c2410c;
  --ok: #15805a;
  --shadow: 0 1px 2px rgba(20, 24, 50, 0.05), 0 18px 40px -22px rgba(20, 24, 50, 0.28);
  --shadow-fig: 0 2px 6px rgba(20, 24, 60, 0.08), 0 34px 60px -26px rgba(40, 30, 120, 0.45);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.3, 1.45, .55, 1);
  --ca-accent: #5b47d6; /* the accounts SDK's sheets and buttons */
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1020;
    --wall:
      radial-gradient(60% 50% at 6% 0%, #231b55 0%, transparent 62%),
      radial-gradient(52% 46% at 98% 6%, #0d3a40 0%, transparent 62%),
      radial-gradient(70% 50% at 50% 100%, #131b3c 0%, transparent 66%),
      linear-gradient(180deg, #0c1124, #0b1020 70%);
    --surface: rgba(20, 26, 46, 0.78);
    --surface-solid: #151b31;
    --tile: #1b2240;
    --tile-hover: #222b4f;
    --ink: #eef1fb;
    --muted: #a6aec8;
    --line: rgba(255, 255, 255, 0.08);
    --line-2: rgba(255, 255, 255, 0.16);
    --accent: #6d5bf0;
    --accent-soft: rgba(141, 125, 255, 0.18);
    --teal: #3cc9cf;
    --danger: #fb8a4c;
    --ok: #46d39a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px -22px rgba(0, 0, 0, 0.7);
    --shadow-fig: 0 2px 6px rgba(0, 0, 0, 0.3), 0 34px 60px -26px rgba(0, 0, 0, 0.85);
    --ca-accent: #6d5bf0;
  }
}

* { box-sizing: border-box; }
/* no double-tap zoom and no text selection or callouts on the page (APP_STANDARD §6) */
:where(html, body, body *) { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--wall); background-color: var(--bg); background-attachment: fixed; color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* ---- the bar ------------------------------------------------------------------------------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px clamp(12px, 3vw, 28px); }
.brand { min-width: 0; }
.title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; padding: 0;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .18s var(--ease), background-color .18s, opacity .18s;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .pip { stroke-width: 2.8; }
.icon-btn:hover:not(:disabled) { background: var(--surface-solid); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn:disabled { opacity: .38; cursor: default; }
#random.rolling svg { animation: roll .55s var(--spring); }
@keyframes roll { from { transform: rotate(-200deg) scale(.7); } to { transform: none; } }
.chip-slot { width: 36px; height: 36px; margin-left: 4px; }
@media (max-width: 560px) { .tagline { display: none; } }
@media (max-width: 420px) { #open-help { display: none; } .bar-tools { gap: 4px; } .icon-btn { width: 38px; height: 38px; } }

/* ---- the studio ---------------------------------------------------------------------------- */
.studio { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 0 clamp(12px, 3vw, 28px) 18px; width: 100%; max-width: 1240px; margin: 0 auto; }
.stage { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 4px; }
.figure-wrap { position: relative; width: min(64vw, 300px, 40dvh); aspect-ratio: 1; }
.figure-wrap::before {
  content: ""; position: absolute; inset: -9%; border-radius: 50%;
  background: radial-gradient(closest-side, var(--accent-soft), transparent);
  pointer-events: none;
}
.figure {
  position: relative; width: 100%; height: 100%; border-radius: 50%; cursor: pointer;
  box-shadow: var(--shadow-fig), 0 0 0 6px var(--surface), 0 0 0 7px var(--line);
  transition: transform .35s var(--spring);
}
.figure:active { transform: scale(.97); }
.figure svg { display: block; width: 100%; height: 100%; }
.figure-placeholder { width: 100%; height: 100%; border-radius: 50%; background: linear-gradient(180deg, var(--tile), var(--tile-hover)); }

.moves { display: flex; gap: 8px; max-width: 100%; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: none; scroll-snap-type: x proximity; }
.moves::-webkit-scrollbar { display: none; }
.move {
  flex: none; min-height: 40px; padding: 0 15px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; scroll-snap-align: start;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .2s var(--spring), background-color .18s, color .18s;
}
.move:hover { background: var(--surface-solid); }
.move:active, .move.on { transform: scale(.94); background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.status { margin: 0; min-height: 2.9em; max-width: 36ch; text-align: center; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.status[data-state="saved"]::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.status[data-state="offline"], .status[data-state="error"] { color: var(--danger); }

/* ---- the panel: tabs, then the slots of the tab -------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); overflow: hidden; min-width: 0;
}
.tabs {
  display: flex; gap: 4px; padding: 8px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; background: var(--surface);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 44px; padding: 0 11px; border: 0; border-radius: 16px; background: transparent;
  color: var(--muted); font-size: 14.5px; font-weight: 650; cursor: pointer; white-space: nowrap;
  transition: background-color .2s var(--ease), color .2s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.slots { padding: 6px 16px 20px; }
.slot { padding: 14px 0 6px; }
.slot + .slot { border-top: 1px solid var(--line); }
.slot-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.slot h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.slot .picked { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.colors { display: grid; gap: 8px; margin: 0 0 12px; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row > span { flex: none; width: 92px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.swatches { display: flex; gap: 7px; overflow-x: auto; padding: 4px 3px; scrollbar-width: none; }
.swatches::-webkit-scrollbar { display: none; }
.swatch {
  flex: none; position: relative; width: 34px; height: 34px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 0; background: var(--sw, #ccc);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12), inset 0 -6px 10px -6px rgba(0, 0, 0, 0.25);
  transition: transform .18s var(--spring), box-shadow .18s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--surface-solid), 0 0 0 4.5px var(--accent); }
.swatch.same { background: conic-gradient(from 210deg, var(--sw, #888) 0 50%, var(--surface-solid) 0 100%); }
.swatch.custom { background: conic-gradient(#ff6b6b, #f7c948, #6bd88b, #4ab3ff, #8f6bff, #ff6bd3, #ff6b6b); }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch.custom[aria-pressed="true"]::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--sw); box-shadow: 0 0 0 2px #fff; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 5px; padding: 5px 5px 7px;
  border: 0; border-radius: 20px; background: var(--tile); cursor: pointer; text-align: center;
  transition: transform .22s var(--spring), background-color .18s, box-shadow .18s;
}
.tile:hover { background: var(--tile-hover); transform: translateY(-2px); }
.tile:active { transform: scale(.95); }
.tile img { display: block; width: 100%; aspect-ratio: 1; border-radius: 15px; background: var(--surface-solid); }
.tile span { font-size: 12px; font-weight: 600; color: var(--muted); line-height: 1.2; min-height: 1.2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile[aria-pressed="true"] { box-shadow: inset 0 0 0 2.5px var(--accent); background: var(--accent-soft); }
.tile[aria-pressed="true"] span { color: var(--ink); }
.tile[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 9px; right: 9px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M5 9.4l2.6 2.6L13 6.4' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 18px no-repeat;
  box-shadow: 0 0 0 2px var(--surface-solid);
  animation: pop .3s var(--spring);
}
.tile.none img { opacity: .55; }
@keyframes pop { from { transform: scale(.4); } to { transform: none; } }

/* ---- the games' pieces: earned ones carry the game's colour, locked ones a lock ----------- */
.tile.reward::before { content: ""; position: absolute; top: 10px; left: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--gm, var(--accent)); box-shadow: 0 0 0 2px var(--surface-solid); z-index: 1; }
.tile.locked img { filter: grayscale(0.8); opacity: 0.5; }
.tile.locked span { color: var(--muted); }
.tile.locked::after {
  content: ""; position: absolute; top: calc(50% - 26px); left: calc(50% - 17px); width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-solid) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='6' y='10.5' width='12' height='9' rx='2.2' fill='%235b47d6'/%3E%3Cpath d='M8.6 10.5V8a3.4 3.4 0 0 1 6.8 0v2.5' fill='none' stroke='%235b47d6' stroke-width='2'/%3E%3C/svg%3E") center / 20px no-repeat;
  box-shadow: var(--shadow);
}
.progress { margin: 14px 0 4px; }
.progress b { display: block; font-size: 15px; margin-bottom: 6px; }
.progress .bar { height: 10px; border-radius: 999px; background: var(--tile); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--teal)); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .6s var(--ease); }
.progress p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.unlock-tiles { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); margin: 6px 0 4px; }
.unlock-tiles .tile { cursor: default; }
/* what a game gives, shown as it will be: in colour, a small lock in the corner */
.unlock-tiles .tile.locked img { filter: none; opacity: 1; }
.unlock-tiles .tile.locked span { color: var(--ink); }
.unlock-tiles .tile.locked::after { top: 8px; left: auto; right: 8px; width: 24px; height: 24px; background-size: 15px; }
a.btn { display: inline-grid; place-items: center; text-decoration: none; }
.status[data-state="new"] { color: var(--accent); font-weight: 650; }

/* ---- side by side from 900 px -------------------------------------------------------------- */
@media (min-width: 900px) {
  .studio { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; align-items: start; gap: 28px; padding-top: 8px; }
  .stage { position: sticky; top: 16px; padding-top: 18px; }
  .figure-wrap { width: min(340px, 52dvh); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
}
/* a phone held sideways: the figure smaller, beside nothing */
@media (max-height: 520px) and (orientation: landscape) {
  .studio { display: grid; grid-template-columns: minmax(240px, 34vw) 1fr; align-items: start; }
  .stage { position: sticky; top: 8px; }
  .figure-wrap { width: min(30vw, 62dvh); }
}

/* ---- sheets -------------------------------------------------------------------------------- */
.sheet { border: 0; border-radius: 26px; padding: 22px; width: min(92vw, 440px); max-height: 88dvh; overflow: auto; background: var(--surface-solid); color: var(--ink); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .55); }
.sheet.small { width: min(88vw, 360px); }
.sheet::backdrop { background: rgba(10, 12, 24, 0.42); backdrop-filter: blur(8px); }
.sheet[open] { animation: sheet-in .28s var(--ease); }
@keyframes sheet-in { from { transform: translateY(14px) scale(.98); } to { transform: none; } }
.sheet h2 { margin: 0 0 12px; font-size: 19px; letter-spacing: -0.01em; }
.sheet h3 { margin: 22px 0 6px; font-size: 15px; }
.sheet p { margin: 0 0 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row select { min-height: 40px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--tile); padding: 0 10px; }
.note { color: var(--muted); font-size: 14px; }
.note.small { font-size: 13px; margin-top: 8px; }
.note.error { color: var(--danger); }
.link { color: var(--accent); font-weight: 600; }
.sheet-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.sheet-actions form { margin: 0; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 14px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 650; cursor: pointer; transition: transform .18s var(--spring); }
.btn:active { transform: scale(.96); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px currentColor; }
.version { color: var(--muted); font-size: 13px; }
.switch { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 48px; height: 28px; margin: 0; border-radius: 999px; background: var(--line-2); cursor: pointer; transition: background-color .2s; }
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .25s var(--spring); }
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
