/* =====================================================================
   The character maker (creatorCard in js/screens.js).

   One card with three parts that never scroll away:
     the stage    the character, big, with the name plate under it
     the steps    1 Body · 2 Face · 3 Hair · 4 Clothes · 5 About me, a progress bar under them
     the buttons  Surprise me sits on the stage; Back / Continue at the foot
   Only the options of the step in view scroll, so a change is seen as it is made.

   The card answers to its own width, not the window's (it is a full screen
   for an invitation and a dialog in the office):
     narrow  stage on top, options under it; pictures in swipeable strips
     wide    stage on the left, tabs and options on the right; pictures in a grid
   ===================================================================== */

.card.creator {
  container: creator / inline-size;
  --px: 3;                                   /* pixels per sprite pixel on the option pictures */
  display: flex; flex-direction: column; overflow: hidden; padding: 0;
  width: min(920px, 100%); height: min(720px, calc(100dvh - 32px)); max-height: none;
}

/* ---- where it lives */
.screen:has(.card.creator) { overflow: hidden; align-items: center; padding: var(--s-4); }
.screen .card.creator { margin: 0; }
@media (max-width: 639px) {
  .screen:has(.card.creator) { align-items: stretch; padding: 0; }
  .screen .card.creator { width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; }
}
/* in the office, on a phone, it is a sheet from the bottom, tall enough to keep the stage and a few options */
.app.phone ~ .modal .card.creator { width: 100%; height: min(94dvh, 780px); max-height: none; padding: 0; border-radius: 20px 20px 0 0; }

/* ---- top: the title, or the invitation */
.cr-top { flex: none; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-1); }
.cr-title { flex: 1; min-width: 0; }
.card.creator .cr-top h2 { margin: 0; font-size: var(--fs-title); line-height: var(--lh-snug); overflow-wrap: anywhere; }
.card.creator .cr-top p { margin: 2px 0 0; font-size: var(--fs-small); line-height: var(--lh-snug); color: var(--ink-muted); }
.cr-invite { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: var(--s-3); }
.cr-invite canvas { margin: 0; }
.cr-invite-text { flex: 1; min-width: 0; }
.card.creator .cr-invite .fine { font-size: var(--fs-small); }
.cr-lede { display: none; }
.cr-more { display: none; }
.cr-lang { flex: none; font-size: var(--fs-small); }

/* ---- the two halves */
.cr-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cr-side { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- the stage */
.cr-stage {
  position: relative; flex: 0 0 clamp(190px, 34dvh, 320px);
  display: flex; flex-direction: column; overflow: hidden;
  margin: var(--s-2) var(--s-3) 0;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: var(--r-lg);
  /* a bright set inside the dark card: its own paper tokens, so the buttons and the name plate on it read dark-on-light */
  --ink: #1d1a22; --ink-muted: #4f4752; --ink-placeholder: #6a6270;
  --surface: #fffaf3; --surface-2: #f3ebdf; --surface-3: #e6dccd; --surface-input: #fffdf8;
  --edge: 1px solid rgba(29, 26, 34, 0.28); --field-edge: rgba(29, 26, 34, 0.3);
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 60% at 50% 62%, rgba(255, 255, 255, 0.55), transparent 70%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.10) 0 2px, transparent 2px 18px),
    linear-gradient(#b9cde6, #dbe6f3);
}
.card.creator .cr-eyebrow { position: absolute; z-index: 1; top: 14px; inset-inline-start: 14px; margin: 0; font-size: 12px; font-weight: var(--fw-heavy); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); pointer-events: none; max-width: calc(100% - 170px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.creator .cr-dice { position: absolute; z-index: 1; top: 8px; inset-inline-end: 8px; width: auto; }
.cr-figure { flex: 1; min-height: 0; display: flex; align-items: center; gap: var(--s-1); padding: var(--s-6) var(--s-2) 0; direction: ltr; }
.cr-figure .turn { flex: none; width: var(--tap); min-width: var(--tap); padding: 0; border-radius: 50%; }
.cr-figure .turn .px { width: 20px; height: 20px; }
.cr-actor { position: relative; flex: 1; align-self: stretch; min-width: 0; touch-action: pan-y; cursor: grab; }
.cr-actor canvas { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); image-rendering: pixelated; }
/* the little stage the character stands on */
.cr-actor::before {
  content: ''; position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  width: min(86%, 240px); height: 26px; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, #fff6e8 0 52%, #e6d2b4 54% 100%);
  box-shadow: 0 3px 0 rgba(59, 40, 48, 0.38);
}
.cr-nameplate { flex: none; display: flex; justify-content: center; padding: var(--s-1) var(--s-3) var(--s-3); }
.card.creator input.cr-name {
  width: min(100%, 300px); min-height: var(--tap); margin: 0; padding: 0 var(--s-4);
  border: var(--edge); border-radius: var(--r-pill); background: var(--surface-input); box-shadow: var(--sh-1);
  color: var(--ink); text-align: center; font: inherit; font-size: var(--fs-body); font-weight: var(--fw-bold);
}
.card.creator input.cr-name::placeholder { font-weight: var(--fw-regular); color: var(--ink-placeholder); }

/* ---- the steps: numbered, the one in view filled in, the ones seen ticked; a bar under them fills as you go */
.cr-progress { flex: none; padding: var(--s-2) var(--s-3) 0; border-bottom: 1px solid var(--surface-3); }
.cr-steps { display: flex; gap: 2px; margin: 0; padding: 0; list-style: none; }
.cr-steps li { flex: 1 1 0; min-width: 0; display: flex; }
.cr-step {
  position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: var(--tap); padding: 4px 2px 6px;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink-muted);
  font: inherit; font-size: 12px; font-weight: var(--fw-bold); line-height: 1.15; cursor: pointer;
}
.cr-step-num {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--field-edge); background: var(--surface); color: var(--ink-muted); font-size: 13px;
}
.cr-step-num .px { display: none; width: 14px; height: 14px; }
.cr-step-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) { .cr-step:not(:disabled):hover { background: var(--surface-2); color: var(--ink); } }
.cr-step[aria-current="step"] { color: var(--ink); }
.cr-step[aria-current="step"] .cr-step-num { background: var(--selected); border-color: #1d1a22; color: #1d1a22; }
.cr-step.done .cr-step-num { border-color: var(--ink-muted); color: var(--ink); }
.cr-step.done .cr-step-n { display: none; }
.cr-step.done .cr-step-num .px { display: block; }
.cr-step:disabled { cursor: not-allowed; opacity: 0.45; }
.cr-bar { height: 4px; margin: 2px 0 0; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.cr-bar-fill { display: block; height: 100%; width: 20%; border-radius: inherit; background: var(--selected); transition: width 0.2s ease; }
[dir="rtl"] .cr-bar { transform: scaleX(-1); }
.cr-dot { position: absolute; top: 2px; inset-inline-end: calc(50% - 22px); width: 10px; height: 10px; border-radius: 50%; background: var(--rose-ink); border: 2px solid var(--surface); }

/* the step's own heading: where you are, what it is for */
.cr-step-head { display: grid; gap: 2px; }
.card.creator .cr-step-count { margin: 0; font-size: 12px; font-weight: var(--fw-bold); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }
.card.creator .cr-step-title { margin: 0; font-size: var(--fs-title); line-height: var(--lh-snug); outline: none; }
.cr-note { padding: var(--s-2) var(--s-3); border-radius: var(--r-md); background: var(--surface-2); }

/* step 1: female or male, two big pictures */
.cr-bodies { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.cr-body {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2); min-width: 0; padding: var(--s-3) var(--s-2);
  border: 2px solid var(--field-edge); border-radius: var(--r-lg); background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: var(--fs-body); font-weight: var(--fw-bold); cursor: pointer;
}
.cr-body canvas { display: block; width: calc(var(--px) * 20px); height: calc(var(--px) * 28px); image-rendering: pixelated; }
@media (hover: hover) { .cr-body:hover { border-color: var(--ink-muted); } }
.cr-body[aria-checked="true"] { background: var(--selected); border-color: #1d1a22; color: #1d1a22; }

/* step 5: the choices so far, each with Change */
.cr-review { display: grid; gap: 0; margin: 0; border: 1px solid var(--surface-3); border-radius: var(--r-md); }
.cr-review-row { display: grid; grid-template-columns: minmax(64px, auto) 1fr auto; align-items: center; gap: var(--s-2); padding: 6px var(--s-2) 6px var(--s-3); }
.cr-review-row + .cr-review-row { border-top: 1px solid var(--surface-3); }
.cr-review dt { font-size: var(--fs-small); font-weight: var(--fw-bold); }
.cr-review dd { margin: 0; min-width: 0; font-size: var(--fs-small); color: var(--ink-muted); overflow-wrap: anywhere; }
.card.creator .cr-change { width: auto; min-height: 36px; }

/* the stage before female or male is chosen: a question, not a character */
.cr-ask { display: none; }
.cr-stage.is-empty .cr-figure { visibility: hidden; }
.cr-stage.is-empty .cr-ask {
  display: grid; place-items: center; position: absolute; inset: 0 0 64px; z-index: 1; margin: 0; padding: var(--s-4);
  text-align: center; font-weight: var(--fw-bold); color: var(--ink-muted);
}

/* ---- the options */
.cr-panels { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s-3) var(--s-4) var(--s-4); }
.cr-panel { display: grid; gap: var(--s-4); align-content: start; }
.cr-group { display: grid; gap: var(--s-2); min-width: 0; }
.card.creator .cr-label { margin: 0; font-size: var(--fs-small); font-weight: var(--fw-bold); color: var(--ink); }
.cr-panel .fine { margin: 0; }
.cr-panel .claim-host:empty { display: none; }

/* pictures: each shows the option on the character as it is now */
.cr-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: var(--s-2); }
.cr-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px;
  min-height: 86px; padding: 6px 4px;
  border: 2px solid var(--field-edge); border-radius: var(--r-md); background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 12px; font-weight: var(--fw-semibold); line-height: 1.15; text-align: center; cursor: pointer;
}
.cr-tile canvas { flex: none; display: block; image-rendering: pixelated; }
.cr-tile-name { overflow-wrap: anywhere; }
@media (hover: hover) { .cr-tile:hover { border-color: var(--ink-muted); } .cr-tile[aria-checked="true"]:hover { border-color: #1d1a22; } }
.cr-tile[aria-checked="true"] { background: var(--selected); border-color: #1d1a22; color: #1d1a22; }

/* colours */
.cr-swatches { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cr-swatches button {
  position: relative; width: 40px; height: 40px; padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.4); border-radius: var(--r-sm); box-shadow: var(--sh-1); cursor: pointer;
}
.cr-swatches button::before { content: ''; position: absolute; inset: -3px; }   /* a 46px hit area */
.cr-swatches button[aria-checked="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.cr-swatches button[aria-checked="true"]::after {
  content: ''; position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; transform: translate(-50%, -50%);
  border-radius: 50%; background: #1d1a22; border: 2px solid #fff;
}
.cr-swatches button canvas { display: block; margin: auto; image-rendering: pixelated; }
.cr-swatches button:has(canvas) { width: auto; min-width: 40px; height: auto; min-height: 40px; padding: 2px; background: #fffdf8; }
.cr-swatches button:has(canvas)[aria-checked="true"]::after { display: none; }

.card.creator .choice-row .btn { min-width: 0; flex: 1 1 auto; }

/* about me */
.cr-things { padding-top: var(--s-3); border-top: 1px solid var(--surface-3); }
.cr-things .cr-label { font-size: var(--fs-body); }

/* ---- the foot */
.cr-foot { flex: none; display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-4) calc(var(--s-3) + var(--safe-b)); border-top: 1px solid var(--surface-3); background: var(--surface); }
.card.creator .cr-error { margin: 0; font-size: var(--fs-small); font-weight: var(--fw-semibold); color: var(--danger); }
.cr-error:empty { display: none; }
.cr-foot .row { display: flex; gap: var(--s-2); justify-content: flex-end; margin: 0; }
.cr-foot .row .btn[hidden] { display: none; }
.cr-foot .row .btn { flex: 1 1 0; min-height: var(--tap); }
.cr-foot .row .btn.primary { flex: 2 1 0; }

/* ---- short windows (a phone on its side, a small laptop): the header shrinks so the options keep their room */
@media (max-height: 600px) {
  .cr-lede { display: none !important; }
  .card.creator .cr-eyebrow { display: none; }
  .cr-top { padding-top: var(--s-3); padding-bottom: 0; }
  .cr-stage { margin-bottom: var(--s-3); }
}
@media (max-height: 700px) {
  .cr-stage { flex-basis: clamp(170px, 31dvh, 320px); }
  /* the step keeps its count and title; the hint gives its room to the options */
  .cr-step-head .fine { display: none; }
  .cr-panel { gap: var(--s-3); }
  .cr-body { flex-direction: row; justify-content: center; padding: var(--s-2); }
}

/* ---- narrow: pictures in strips you swipe, so a whole group is one short row */
@container creator (max-width: 699px) {
  .cr-tiles {
    display: flex; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
    margin-inline: calc(var(--s-4) * -1); padding: 2px var(--s-4) 6px;
  }
  .cr-tiles::-webkit-scrollbar { display: none; }
  .cr-tile { flex: 0 0 82px; scroll-snap-align: start; }
  .cr-tiles { scroll-padding-inline: var(--s-4); }
  .card.creator .cr-top h2 { font-size: var(--fs-body); }
}

/* ---- wide: the stage on the left */
@container creator (min-width: 700px) {
  .card.creator { --px: 4; }
  .cr-top { padding: var(--s-5) var(--s-5) var(--s-2); }
  .card.creator .cr-top h2 { font-size: var(--fs-h2); }
  .cr-lede { display: block; }
  .cr-more { display: inline; }
  .cr-main { flex-direction: row; }
  .cr-stage { flex: 0 0 min(340px, 40%); margin: var(--s-2) 0 var(--s-5) var(--s-5); }
  .cr-progress { padding-inline: var(--s-5); }
  .cr-step { font-size: var(--fs-small); }
  .cr-panels { padding-inline: var(--s-5); }
  .cr-foot { padding-inline: var(--s-5); padding-bottom: calc(var(--s-4) + var(--safe-b)); }
  .cr-foot .row { justify-content: space-between; }
  .cr-foot .row .btn, .cr-foot .row .btn.primary { flex: 0 1 auto; min-width: 140px; }
  .cr-foot .row .btn.primary { margin-inline-start: auto; }
  .cr-tiles { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .cr-tile { min-height: 110px; }
}

/* ---- Arabic: the sprites do not mirror, so the stage keeps its own left and right */
[dir="rtl"] .cr-stage .cr-figure { direction: ltr; }
@media (prefers-reduced-motion: reduce) { .cr-actor { cursor: default; } }
/* the arrows that turn the character are directions, not reading order: they keep left on the left */
[dir="rtl"] .cr-figure .turn .px-mirror { transform: none; }
