/* GROVE-1.2: the character studio (src/character-studio.js) and the onboarding's creation
   steps (src/onboarding-studio.js). Tokens only (src/ui-tokens.css): no literal colours,
   radii or font sizes, so ux:lint stays flat. */

.studio {
  display: grid;
  gap: var(--ui-s-3);
  min-width: 0;
}
.studio-stage {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--ui-s-2);
  padding: var(--ui-s-3);
  background: var(--ui-surface-sunk);
  box-shadow: var(--ui-frame-flat);
}
.studio-canvas {
  width: calc(48px * var(--studio-zoom, 4));
  height: calc(44px * var(--studio-zoom, 4));
  image-rendering: pixelated;
  max-width: 100%;
}
.studio--sheet { --studio-zoom: 3; }
.studio--full { --studio-zoom: 5; }
@media (max-width: 720px) { .studio--full, .studio--sheet { --studio-zoom: 3; } }
.studio-controls,
.studio-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--ui-s-2);
}
.studio-turn { color: var(--ui-ink); }
.studio-turn span { font-family: var(--ui-font-body); font-size: var(--ui-fs-20); line-height: 1; }
.studio-modes { display: inline-flex; }
.studio-mode {
  min-height: var(--ui-target);
  padding: 0 var(--ui-s-3);
  border: 0;
  background: transparent;
  color: var(--ui-tab-ink);
  font-family: var(--ui-font-display);
  font-size: var(--ui-fs-16);
  cursor: pointer;
}
.studio-mode[aria-pressed="true"] { background: var(--ui-selected); color: var(--ui-ink-strong); box-shadow: var(--ui-frame-edge); }
.studio-mode:focus-visible,
.studio-tab:focus-visible,
.studio-tile:focus-visible,
.studio-swatch:focus-visible {
  outline: var(--ui-focus-ring-w) solid var(--ui-focus-ring);
  outline-offset: calc(var(--ui-px) * 2);
}
.studio-tools .btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--ui-s-2); min-height: var(--ui-target); }
.studio-glyph { font-family: var(--ui-font-body); font-size: var(--ui-fs-20); line-height: 1; }
.studio-tools { display: grid; grid-template-columns: 1fr 1fr; width: min(100%, 16rem); }
/* Compact (a phone, a phone on its side): one row of tools, glyphs only (named for screen readers). */
@media (max-width: 720px), (max-height: 560px) {
  .studio-stage { gap: var(--ui-s-1); padding: var(--ui-s-2); }
  .studio-controls, .studio-tools { gap: var(--ui-s-1); }
  .studio-tools { display: flex; width: auto; }
  .studio-tools .btn { padding: 0 var(--ui-s-3); }
  .studio-tools .studio-undo .studio-tool-text, .studio-tools .studio-redo .studio-tool-text { display: none; }
  .studio-stage { grid-template-columns: auto auto; grid-template-rows: auto auto; align-items: center; }
  .studio-stage .studio-canvas { grid-row: span 2; }
}
.studio-dice { font-size: var(--ui-fs-20); line-height: 1; }
.studio-undo:disabled,
.studio-redo:disabled { opacity: 0.45; }

/* Category tabs: one row; on the narrowest phones they share it evenly. */
.studio-tabs {
  display: flex;
  gap: var(--ui-s-1);
  padding: var(--ui-s-1);
  background: var(--ui-surface-sunk);
  box-shadow: var(--ui-frame-flat);
}
.studio-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--ui-target);
  padding: 0 var(--ui-s-2);
  border: 0;
  background: transparent;
  color: var(--ui-tab-ink);
  font-family: var(--ui-font-display);
  font-size: var(--ui-fs-16);
  white-space: nowrap;
  cursor: pointer;
}
.studio-tab:hover { color: var(--ui-ink); background: var(--ui-surface); }
.studio-tab[aria-selected="true"] { background: var(--ui-selected); color: var(--ui-ink-strong); box-shadow: var(--ui-frame-edge); }

.studio-panel { display: grid; gap: var(--ui-s-3); min-width: 0; }
.studio-group { display: grid; gap: var(--ui-s-2); min-width: 0; }
.studio-label { font-family: var(--ui-font-display); font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.studio-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: var(--ui-s-2);
}
.studio-tile {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: var(--ui-s-1);
  min-height: var(--ui-target);
  padding: var(--ui-s-2) var(--ui-s-1);
  border: 0;
  background: var(--ui-surface);
  color: var(--ui-ink);
  box-shadow: var(--ui-frame-rest);
  cursor: pointer;
}
.studio-tile canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.studio-tile canvas[height="34"] { width: 48px; height: 68px; }
.studio-tile:hover { background: var(--ui-surface-hi); }
.studio-tile[aria-checked="true"] { background: var(--ui-selected); box-shadow: var(--ui-frame-edge); color: var(--ui-ink-strong); }
.studio-tile-name { font-family: var(--ui-font-body); font-size: var(--ui-fs-12); line-height: 1.2; text-align: center; }
.studio-swatches { display: flex; flex-wrap: wrap; gap: var(--ui-s-2); }
.studio-swatch {
  width: var(--ui-target);
  height: var(--ui-target);
  padding: 0;
  border: 0;
  background: var(--swatch, var(--ui-surface));
  box-shadow: var(--ui-frame-rest);
  cursor: pointer;
}
.studio-swatch.is-auto {
  background: linear-gradient(135deg, var(--ui-surface) 0 45%, var(--ui-line) 45% 55%, var(--ui-surface-sunk) 55%);
}
.studio-swatch[aria-checked="true"] {
  box-shadow: 0 0 0 calc(var(--ui-px) * 2) var(--ui-surface), 0 0 0 calc(var(--ui-px) * 4) var(--ui-ink-strong);
}

/* The stage beside the options when the studio's own box is wide enough (a wide sheet, the
   onboarding card on a laptop): a container query, so the narrow You sheet on a wide screen
   keeps one column. */
.studio-host { container-type: inline-size; min-width: 0; }
@container (min-width: 34rem) {
  .studio { grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); align-items: start; }
  .studio-stage { grid-row: span 2; position: sticky; top: 0; }
}
/* Short landscape screens: a smaller stage, so the options show beside or under it. */
@media (max-height: 560px) and (min-width: 640px) {
  .studio--sheet, .studio--full { --studio-zoom: 2; grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr); align-items: start; }
  .studio--sheet .studio-stage, .studio--full .studio-stage { grid-row: span 2; padding: var(--ui-s-2); }
  .studio-tools .studio-undo, .studio-tools .studio-redo { padding: 0 var(--ui-s-2); }
  #customize-dialog #creator-details-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media (prefers-reduced-motion: reduce) {
  .studio-tile, .studio-swatch { transition: none; }
}

/* ---------- The onboarding's creation steps (arrival-help.js STUDIO_STEPS) ----------
   Your character and your pet are made on one big card in the middle of the screen, over a
   soft scrim (the town still glows behind it); the walk and the first focus that follow are
   the tour card beside you, as before. Phones: the card fills the screen and its actions stay
   pinned at its foot, in thumb reach. */
body.tour-studio::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-tour) - 1);
  background: var(--ui-scrim);
}
/* While you make your character, the HUD steps away (it returns for the walk): nothing on
   screen but the town behind the scrim and the studio card. */
body.tour-studio :is(.topbar, .game-tools, #world-guide, #music-dock, .chat-panel, #chat-toggle, #minimap, .next-step-bar) { visibility: hidden; }
.arrival-help.walkthrough.is-studio {
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) !important;
  width: min(60rem, calc(100vw - 2 * var(--ui-s-4))) !important;
  max-height: calc(100dvh - 2 * var(--ui-s-4)) !important;
  height: auto !important;
  padding: var(--ui-s-4) var(--ui-s-5) 0 !important;
}
.arrival-help.is-studio .walkthrough-create {
  display: grid;
  grid-template-columns: minmax(0, 17rem) minmax(0, 1fr);
  gap: var(--ui-s-4) var(--ui-s-5);
  align-items: start;
}
.arrival-help.is-studio .walkthrough-intro { display: grid; gap: var(--ui-s-2); align-content: start; }
.arrival-help.is-studio .walkthrough-intro h2 { margin: 0; }
.arrival-help.is-studio .walkthrough-intro .walkthrough-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--ui-s-2); }
.arrival-help.is-studio .walkthrough-actions {
  grid-column: 1 / -1;
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  gap: var(--ui-s-2);
  margin: 0 calc(var(--ui-s-5) * -1);
  padding: var(--ui-s-3) var(--ui-s-5) var(--ui-s-4);
  background: var(--ui-surface);
  box-shadow: 0 calc(var(--ui-px) * -1) 0 var(--ui-line);
}
.arrival-help.is-studio .walkthrough-actions .button { min-height: var(--ui-target); }
.walkthrough-pet-stage {
  display: grid;
  place-items: center;
  padding: var(--ui-s-3);
  background: var(--ui-surface-sunk);
  box-shadow: var(--ui-frame-flat);
}
.pet-stage-canvas { width: calc(72px * 4); height: calc(40px * 4); max-width: 100%; image-rendering: pixelated; }
.walkthrough-pet-picks { display: grid; gap: var(--ui-s-2); align-content: start; }
.arrival-help.is-studio .walkthrough-pet .walkthrough-tiles.pets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ui-s-2); }
.arrival-help.is-studio .walkthrough-pet .walkthrough-tile canvas { width: 64px; height: 60px; image-rendering: pixelated; }
.arrival-help.is-studio .walkthrough-pet .walkthrough-tile[aria-checked="true"] { background: var(--ui-selected); }
.arrival-help.is-studio .walkthrough-pet { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

/* Phones and narrow windows: the whole screen, one column, the studio's tabs and options under
   its stage; the welcome's quick starts sit in one row. */
@media (max-width: 720px) {
  .arrival-help.walkthrough.is-studio {
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: 0 !important;
    padding: var(--ui-s-3) var(--ui-s-4) 0 !important;
  }
  .arrival-help.is-studio .walkthrough-create,
  .arrival-help.is-studio .walkthrough-pet { grid-template-columns: minmax(0, 1fr); gap: var(--ui-s-3); }
  .arrival-help.is-studio .walkthrough-actions { margin: 0 calc(var(--ui-s-4) * -1); padding: var(--ui-s-3) var(--ui-s-4) calc(var(--ui-s-3) + env(safe-area-inset-bottom)); }
  .arrival-help.is-studio .walkthrough-actions .button { flex: 1 1 0; }
  .pet-stage-canvas { width: calc(72px * 3); height: calc(40px * 3); }
}
/* A phone on its side: the studio card fills the screen too, the intro beside the studio. */
@media (max-height: 560px) and (min-width: 640px) {
  .arrival-help.walkthrough.is-studio {
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: 0 !important;
    padding: var(--ui-s-2) var(--ui-s-4) 0 !important;
  }
  .arrival-help.is-studio .walkthrough-create { grid-template-columns: minmax(0, 13rem) minmax(0, 1fr); gap: var(--ui-s-2) var(--ui-s-4); }
  .arrival-help.is-studio .walkthrough-lead { display: none; }
  .pet-stage-canvas { width: calc(72px * 2); height: calc(40px * 2); }
  .arrival-help.is-studio .walkthrough-actions { padding: var(--ui-s-2) var(--ui-s-4); }
}
/* A phone on its side: the stage is its own narrow column (picture, then the controls, then the
   tools), so it never squeezes into two columns of its own. */
@media (max-height: 560px) and (min-width: 640px) {
  .studio--sheet, .studio--full { grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); }
  .studio-stage { grid-template-columns: minmax(0, 1fr); }
  .studio-stage .studio-canvas { grid-row: auto; }
  .studio-controls { flex-wrap: nowrap; }
  .studio-controls .studio-turn { min-width: var(--ui-target); width: var(--ui-target); padding: 0; }

}

/* ---------- GROVE-1.3: Adventure → Pet (the playground) ----------
   The stage is 3x (the redrawn pets are drawn 1:1, so they fill it as the old 2x did), and the
   name row carries Rename and Change look (the pet's look lives with its care now, NAV-10). */
#pet-lounge-dialog #lounge-pet { width: min(100%, 360px); height: 180px; }
#pet-lounge-dialog .pet-name-row { grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: var(--ui-s-1); min-width: 0; }
#pet-lounge-dialog .pet-name-row[hidden], #pet-lounge-dialog .pet-rename-form[hidden] { display: none; }
#pet-lounge-dialog .pet-name-row .pet-stage-name { flex: 0 1 auto; }
#pet-lounge-dialog .pet-name-actions { grid-column: 1 / -1; grid-row: 3; display: flex; gap: var(--ui-s-2); }
#pet-lounge-dialog .pet-name-actions[hidden] { display: none; }
#pet-lounge-dialog .pet-name-actions .btn { flex: 1 1 0; min-height: var(--ui-target); }
#pet-lounge-dialog .pet-rename-form { grid-column: 1 / -1; grid-row: 1; display: flex; gap: var(--ui-s-2); align-items: center; min-width: 0; }
#pet-lounge-dialog .pet-rename-form .ui-input { flex: 1 1 auto; min-width: 0; }
#pet-lounge-dialog .pet-rename-form .btn { flex: none; min-height: var(--ui-target); }
/* The narrowest phones (320 px): the stage stacks (picture, controls, tools), nothing wider than the sheet. */
@media (max-width: 380px) {
  .studio-stage { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .studio-stage .studio-canvas { grid-row: auto; }
  .studio-controls, .studio-tools { flex-wrap: wrap; max-width: 100%; }
  .studio-stage > * { min-width: 0; max-width: 100%; }
}
/* The creator's sections are fieldsets, which default to their content's width: let them shrink. */
#customize-dialog fieldset { min-inline-size: 0; min-width: 0; }
:where(.studio) { grid-template-columns: minmax(0, 1fr); }
.studio-host { width: 100%; }

/* Every studio control is a 44 px target, even where the studio is narrow (the You sheet on a
   phone held sideways): the part tabs wrap onto a second row rather than shrink below it. */
.studio-tabs { flex-wrap: wrap; }
.studio-tab, .studio-mode { min-width: var(--ui-target); }
/* GROVE-1.9: Idle measured 43 px wide on a phone: the modes row shrank it; it keeps its size. */
.studio-mode { flex: none; box-sizing: border-box; }
/* (A sheet-wide button reset set min-width: 0 on it; scoped so the 44 px target wins.) */
:is(#sheet-host, #arrival-help, body) .studio-modes > .studio-mode { min-width: var(--ui-target); }
.studio-tools .btn { min-width: var(--ui-target); }

/* GROVE-1.9: equal fifths cut "Extras" at 390 px; each part sizes to its word (the row still
   wraps rather than shrink a target below 44). */
.studio-tab { flex: 1 1 auto; padding-left: var(--ui-s-2); padding-right: var(--ui-s-2); white-space: nowrap; }
