/*
  Characters: the tile grid and the reference strip.

  A character is mostly its pictures, so both views lead with the picture and
  let the text sit under it. The tile is taller than a dataset tile for the same
  reason: a face at 72px is not a face.
*/

.cast-tile {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), transform var(--t-fast);
}

.cast-tile:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
}

.cast-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 5;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--s3);
  color: var(--fg-3);
}

.cast-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Reference strip ------------------------------------------------------ */

.cast-refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-3);
}

.cast-ref {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: var(--sp-2);
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* The cover is one of the references, so it is marked rather than repeated. */
.cast-ref.is-cover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.cast-ref a {
  display: block;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--s3);
}

.cast-ref img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cast-ref select {
  max-width: 110px;
}

/* "Use a character" on the create form ---------------------------------- */

.cast-bar-refs {
  display: flex;
  gap: 4px;
}

/*
  One person in a cast. Indented under its number so a list of them reads as a
  list, where a stack of bare dropdowns reads as unrelated questions.
*/
.cast-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cast-row + .cast-row {
  margin-top: 6px;
}

.cast-row .cast-bar-refs {
  padding-left: 26px;
  align-items: center;
}

/* Quieter than the field it sits beside: taking someone out of a cast is not
   the thing the row is for. */
.cast-out {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  align-self: center;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-dim);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.cast-out:hover {
  background: var(--s3);
  color: var(--fg);
}

.cast-num {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 20px;
  height: 20px;
  align-self: center;
  border-radius: 999px;
  background: var(--s3);
  color: var(--fg-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.cast-bar-refs img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

/* A reference whose file has been moved or deleted. */
.cast-gone {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 12px;
  color: var(--warn, var(--fg-3));
}

/* ------------------------------------------------------ growing a pack

   The empty slot at the end of the reference grid, and the dialog behind it
   (js/views/character-make.js). Dashed like the "new folder" chip, so it reads
   as a thing that is not a reference yet rather than as one of the real ones.
*/
.cast-make {
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 180px;
  border-style: dashed;
  color: var(--fg-3);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  transition: border-color var(--t-fast), color var(--t-fast),
    background var(--t-fast);
}

.cast-make:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--fg);
}

.make-card {
  max-width: 560px;
}

/* A field is a stretching column, and the segmented control is inline-flex, so
   left alone it spans the dialog with its two buttons huddled at one end. */
.make-card .seg {
  align-self: flex-start;
}

/* The picture that came back. Capped by height rather than width: a portrait is
   the common case and one sized to the dialog's width would push its own verdict
   buttons off the bottom of the screen. */
.make-shot {
  display: grid;
  place-items: center;
  max-height: 46vh;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
}

.make-shot img {
  max-width: 100%;
  max-height: 46vh;
  object-fit: contain;
}

/* ------------------------------------------------- who is in this picture

   The face-finding overlay (js/views/people.js). Opened from the library, from
   a clip on the Studio timeline, and from a character's reference strip, so it
   lives here rather than in any one page's stylesheet — characters.css is
   loaded app-wide and the thing it belongs to is characters.

   Laid out as picture / status / list from the top: the picture is the evidence,
   the list is the decisions, and the list is what grows, so it gets the scroll.
*/
.who {
  position: fixed;
  inset: 0;
  z-index: 86;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto minmax(0, auto);
  gap: var(--sp-2);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: rgba(6, 7, 10, .96);
  backdrop-filter: blur(6px);
  animation: fade var(--t-med);
}

.who-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.who-head h2 {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  font-size: 16px;
}

.who-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0 var(--sp-4);
}

/* Sized in script from the picture's own dimensions; the canvas is stretched
   over it so boxes can be drawn in the coordinates the server reported. */
.who-frame {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
  /* The picture is a drawing surface. Crosshair says so before the hint under it
     is read, and touch-action stops a drag on a tablet being taken as a scroll
     before the pointer handlers ever see it. */
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.who-frame img,
.who-boxes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.who-boxes {
  pointer-events: none;
}

/* The rectangle being dragged.

   Positioned in percentages so it stays over the same part of the picture when
   the window is resized and the stage rescales everything under it. Marked out
   in white against the green of the detected boxes, because the two mean
   different things: one is what a model thinks, the other is what you said. */
.who-pick {
  position: absolute;
  pointer-events: none;
  border: 2px solid #fff;
  border-radius: 2px;
  /* Dims everything outside it without a second element to maintain: a huge
     spread shadow is cheaper than four mask divs and resizes for free. */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
}

.who-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  color: var(--fg-3);
  font-size: 12.5px;
  text-align: center;
}

.who-hint .icon {
  width: 15px;
  height: 15px;
  flex: none;
}

.who-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 24px;
  padding: 0 var(--sp-4);
  text-align: center;
}

.who-rows {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-height: 42vh;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
}

.who-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--s2);
}

/* A face too small to make a usable reference. Still listed — it was found, and
   saying so is better than silently dropping it — but visibly not the offer. */
.who-row.is-tiny {
  opacity: .6;
}

/* The hand-drawn one. Sits at the top of the list and is marked, because it is
   the only row that changes under you — dragging again moves this rectangle
   rather than adding another — and that is much less alarming when it is
   obvious which row the rectangle belongs to. */
.who-row.is-mine {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.who-thumb {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: var(--r-sm);
  background: var(--s3);
}

.who-verdict {
  display: flex;
  align-items: center;
  min-height: 20px;
}

@media (max-width: 640px) {
  .who-rows {
    max-height: 46vh;
  }

  .who-row {
    align-items: flex-start;
  }

  .who-thumb {
    width: 52px;
    height: 52px;
  }
}

/*
  Picking one picture out of somebody's pack.

  Two screens in one card: the people, then their pictures. The list borrows the
  ordinary tile so it looks like every other "choose one of these" in the app,
  and the pack is a grid of thumbnails because that is the only way to tell nine
  references apart — a list of filenames would be nine rows of nothing.
*/
.who-pick-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  overflow-y: auto;
  min-height: 160px;
}

.who-pick-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

/* The cover in place of the tile's icon: a face is a better handle on a person
   than a glyph that stands for all of them. */
.who-pick-face {
  width: 38px;
  height: 38px;
  flex: none;
  object-fit: cover;
  border-radius: var(--r-md);
  background: var(--s3);
}

.who-pick-refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.who-pick-ref {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--s1);
  cursor: pointer;
  text-align: left;
}

.who-pick-ref:hover {
  border-color: var(--accent);
}

.who-pick-ref img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

/* The one the slot was probably asking for. An outline rather than a badge:
   it is a suggestion about order, and anything louder would read as the only
   allowed answer. */
.who-pick-ref.best {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
