/* Studio picker: see picker.js for the markup. A card over the whole screen
   to pick a level, a song or a board, a page at a time. From Clatter Lab's
   level picker. Uses the tokens and .button-icon from base.css, and
   .studio-pop from tools.css. */

.studio-picker {
  position: fixed;
  inset: 0;
  z-index: 40; /* over the top bar and tray; under the Menu */
  display: flex;
  align-items: center;
  justify-content: center;
  /* Clear of the notch and home bar */
  padding: calc(var(--content-gap) + env(safe-area-inset-top)) calc(var(--content-gap) + env(safe-area-inset-right))
    calc(var(--content-gap) + env(safe-area-inset-bottom)) calc(var(--content-gap) + env(safe-area-inset-left));
  background: var(--overlay-black-50);
  touch-action: pan-y; /* sideways swipes turn pages (picker.js); up and down scroll the tiles */
}
.studio-picker[hidden] { display: none; }

.studio-picker-panel {
  width: min(640px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--content-gap);
  gap: var(--content-gap);
}

/* A header bar, as in Level Lab's dialogs (.modal-part-header): ‹ World 1 ›
   centered on the panel, ✕ at the far right (room is kept for it on both
   sides, so the title never runs under it). Edit and ✕ sit --space-1 from
   ‹ ›, not a full --content-gap, on purpose: on a phone that room is what
   lets the widest title show in full (chosen 2026-12-01). */
.studio-picker-head {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin: calc(-1 * var(--content-gap));
  margin-bottom: 0;
  padding: var(--content-gap) calc(var(--content-gap) + var(--height-input));
  border-bottom: var(--border-width) var(--border-style) var(--color-border);
}
.studio-picker-close { position: absolute; right: var(--content-gap); }
/* The page's group before its title ("Levels: World 1"): the group in the
   text colour, the title after it dimmer (--color-text-dark). The title
   shrinks first. */
/* The group and title's box, sized by picker.js to the widest page's so ‹ ›
   stay put: the groups in a column as wide as the longest, ending at the
   same spot so the colons line up, then the titles from the left */
.studio-picker-label { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; column-gap: var(--space-1); flex: 0 1 auto; min-width: 0; }
.studio-picker-label .studio-picker-title { grid-column: -2; text-align: left; }
.studio-picker-group { justify-self: end; font-weight: var(--font-weight-bold); color: var(--color-text); white-space: nowrap; }
.studio-picker-group:not([hidden]) + .studio-picker-title { color: var(--color-text-dark); }
.studio-picker-title { font-weight: var(--font-weight-bold); flex: 0 1 auto; min-width: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.studio-picker-prev { margin-left: auto; }
.studio-picker-next { margin-right: auto; }

/* Every page sits in the same spot (one grid cell) and only the open one
   shows. picker.js sets the box's height to the tallest page's (fitHeight),
   so the panel keeps that size from page to page; the pages behind take no
   room, so the box scrolls only as far as the open page goes. Where the
   tallest page is taller than the screen the panel stops at the screen's
   edge: a page that fits shows no scrollbar, and one that doesn't scrolls.
   Laid out as Level Lab's dialog content (.modal-part-content):
   a box that scrolls clips, so it reaches out into the panel's padding on
   every side and pads back in by as much. The tiles keep one gap from the
   header's rule, the panel's sides and the scrollbar, which runs down the
   panel's edge; a focus ring or a corner badge that pokes out of a tile
   isn't cut off. Below, it reaches down to the dots' rule (a footer, the
   header's twin), so the tiles and the scrollbar end on a line. */
.studio-picker-grid {
  display: grid;
  overflow-x: hidden;
  overflow-y: auto;
  margin: calc(-1 * var(--content-gap));
  padding: var(--content-gap);
  touch-action: pan-y;
}
.studio-picker-page {
  grid-area: 1 / 1;
  display: grid;
  /* At least 125px, so a tile with a number, a picture and two lines of
     name always fits square */
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
  align-content: start;
  gap: var(--content-gap);
  visibility: hidden;
}
.studio-picker-page.on { visibility: visible; }
/* A page behind the open one takes no room (it still lays out, so
   fitHeight can measure it). One sliding out keeps its size until it's gone. */
.studio-picker-page:not(.on):not(.slide-out-left):not(.slide-out-right) { height: 0; overflow: hidden; }
/* Changing pages slides them sideways (show in picker.js); the old page
   stays seen until it's out. */
.studio-picker-page.slide-out-left, .studio-picker-page.slide-out-right { visibility: visible; pointer-events: none; }
.studio-picker-page.slide-in-left { animation: studio-picker-in-left 0.25s ease-out; }
.studio-picker-page.slide-in-right { animation: studio-picker-in-right 0.25s ease-out; }
.studio-picker-page.slide-out-left { animation: studio-picker-out-left 0.25s ease-out forwards; }
.studio-picker-page.slide-out-right { animation: studio-picker-out-right 0.25s ease-out forwards; }
@keyframes studio-picker-in-left { from { transform: translateX(calc(100% + var(--content-gap))); } }
@keyframes studio-picker-in-right { from { transform: translateX(calc(-100% - var(--content-gap))); } }
@keyframes studio-picker-out-left { to { transform: translateX(calc(-100% - var(--content-gap))); visibility: hidden; } }
@keyframes studio-picker-out-right { to { transform: translateX(calc(100% + var(--content-gap))); visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .studio-picker-page[class*='slide-'] { animation: none; }
  .studio-picker-page.slide-out-left, .studio-picker-page.slide-out-right { visibility: hidden; height: 0; overflow: hidden; }
}

/* A line across the top of a page (what opens it), and what an empty page says */
.studio-picker-note, .studio-picker-empty { grid-column: 1 / -1; color: var(--color-text-dark); text-align: center; }
.studio-picker-empty { padding: var(--space-4) var(--space-2); }

/* A tile: square, the game's own things inside (a number, a picture, a
   name). .current is the one that's open now. */
.studio-picker-tile {
  position: relative;
  aspect-ratio: 1; /* square */
  padding: var(--space-2);
  background: var(--color-background);
  border: var(--border-width) var(--border-style) var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.studio-picker-tile:disabled { cursor: not-allowed; opacity: 0.4; }
@media (hover: hover) {
  :where(html:not([data-pointer='touch'])) .studio-picker-tile:not(:disabled):hover { border-color: var(--color-accent); } /* see base.css */
}
.studio-picker-tile.current { border-color: var(--color-accent); }

/* Which page is open, out of how many. Each dot is a button to that page,
   bigger than it looks so it's easy to tap. */
/* A footer bar, the header's twin: a rule across the panel, edge to edge,
   that the tiles scroll under. One gap from the rule to the dots and from
   the dots to the panel's edge (each dot's own room is half of it). */
.studio-picker-dots {
  flex: none;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 calc(-1 * var(--content-gap)) calc(-1 * var(--content-gap));
  padding: var(--space-1) var(--content-gap);
  border-top: var(--border-width) var(--border-style) var(--color-border);
}
/* The bar between the game's own pages and the players' (a page's sep) */
.studio-picker-sep { width: 2px; height: var(--space-3); margin: 0 var(--space-1); border-radius: 1px; background: var(--color-border-light); }
.studio-picker-dots[hidden] { display: none; }
.studio-picker-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--space-2) + 2 * var(--space-1));
  height: calc(var(--space-2) + 2 * var(--space-1));
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.studio-picker-dot::after { content: ''; width: var(--space-2); height: var(--space-2); border-radius: 50%; background: var(--color-border-light); transition: background 0.15s ease; }
.studio-picker-dot.on::after { background: var(--color-accent); }
@media (hover: hover) { .studio-picker-dot:not(.on):hover::after { background: var(--color-link-light); } }
.studio-picker-dot:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; border-radius: 50%; }

/* A card (picker.card): a picture and a name, or a + for New and Enter
   Code. The cell around it holds a saved card's round button. A game sets
   the picture's shape and what shows while it draws:
   .studio-picker-pic { aspect-ratio: ...; background: ...; } */
.studio-picker-cell { position: relative; display: flex; }
.studio-picker-card { flex: 1 1 auto; width: 100%; aspect-ratio: auto; display: flex; flex-direction: column; align-items: stretch; gap: var(--space-1); }
.studio-picker-pic { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-border); }
.studio-picker-pic.plus { display: flex; align-items: center; justify-content: center; color: var(--color-text-dark); }
/* Up to two lines, so names don't cut off */
.studio-picker-name { width: 100%; color: var(--color-text-dark); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }

/* Edit, at the left of the head, opposite ✕. With room (picker.js:
   fitEdit), the words, and the head keeps their room on both sides on
   every page; without, an icon button ✕'s size, a pencil, then a blue
   check. Either way the title and chevrons don't move when it comes and
   goes. */
.studio-picker-edit { position: absolute; left: var(--content-gap); }
.studio-picker.edit-words .studio-picker-head { padding-inline: calc(var(--content-gap) + var(--studio-picker-edit-width)); }
.studio-picker.editing .studio-picker-edit.button-icon { color: var(--color-accent); }
/* Each saved card's round button at its top left: share (blue), always
   there until Edit swaps it for delete (a red −). */
.studio-picker-remove, .studio-picker-share {
  position: absolute;
  top: calc(-1 * var(--space-1));
  left: calc(-1 * var(--space-1));
  z-index: 2;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--color-surface);
  border-radius: 50%;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.studio-picker-remove { display: none; background: var(--color-error); color: #fff; }
.studio-picker-remove svg { stroke-width: 3.5; }
.studio-picker-share { display: flex; background: var(--color-accent); color: var(--color-on-accent); }
.studio-picker-share svg { width: 14px; height: 14px; stroke-width: 2.5; }
.studio-picker-share:disabled { opacity: 0.5; cursor: wait; }
.studio-picker.editing .studio-picker-remove { display: flex; }
.studio-picker.editing .studio-picker-share { display: none; }
.studio-picker-cell:has(.studio-picker-ask) :is(.studio-picker-remove, .studio-picker-share) { display: none; }
/* While editing, saved cards wiggle, and no tile opens. */
.studio-picker.editing .studio-picker-tile { cursor: default; }
.studio-picker.editing .studio-picker-cell.saved .studio-picker-tile { animation: studio-picker-wiggle 0.3s ease-in-out infinite alternate; }
.studio-picker.editing .studio-picker-cell.saved:nth-child(even) .studio-picker-tile { animation-delay: -0.15s; }
@keyframes studio-picker-wiggle { from { transform: rotate(-1deg); } to { transform: rotate(1deg); } }
@media (prefers-reduced-motion: reduce) { .studio-picker.editing .studio-picker-cell.saved .studio-picker-tile { animation: none; } }
@media (hover: hover) {
  :where(html:not([data-pointer='touch'])) .studio-picker.editing .studio-picker-tile:not(:disabled):hover { border-color: var(--color-border); }
}
/* "Delete it?" fills the card, which holds still and empties out, so its
   own box frames the question. */
.studio-picker-ask {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2);
  border-radius: var(--radius-lg);
}
.studio-picker.editing .studio-picker-cell.saved:has(.studio-picker-ask) .studio-picker-tile { animation: none; }
.studio-picker-cell:has(.studio-picker-ask) .studio-picker-tile > * { visibility: hidden; }
.studio-picker-question { font-weight: var(--font-weight-bold); }
.studio-picker-warning { font-size: var(--font-size-sm); color: var(--color-text-dark); text-align: center; line-height: 1.2; }
.studio-picker-ask .button { width: 100%; }
.studio-picker-cell.gone { animation: studio-picker-gone 0.25s ease forwards; }
@keyframes studio-picker-gone { to { opacity: 0; transform: scale(0.8); } }
