/* Random Group Maker. JS sets --fs (name size), --cols, --ic (name columns
   inside a card) and --gap on .gm-area from the space available. */

.gm {
  display: flex; flex-direction: column; align-items: center; gap: clamp(4px, 1.4cqmin, 16px);
  padding: clamp(8px, 2.4cqmin, 26px) clamp(8px, 2.4cqmin, 26px) calc(clamp(36px, 8.4cqmin, 84px) + 2 * clamp(8px, 2.6cqmin, 28px));
}
.gm-top { flex: none; max-width: 94%; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-print-head { display: none; }
.gm-area { --fs: 18px; --gap: 10px; --cols: 2; --ic: 1; position: relative; flex: 1 1 0; min-height: 0; width: 100%; }
.gm-hint { flex: none; text-align: center; color: color-mix(in srgb, var(--stage-ink) 55%, transparent); font-size: clamp(12px, 2.6cqmin, 24px); }

.gm-chip { position: relative; transform-origin: 0 0; list-style: none; }
.gm-chip.is-flying { z-index: 3; }
.gm-chip-name { pointer-events: none; }

/* ---- before grouping: everyone in a cloud ---- */
.gm-cloud {
  list-style: none; margin: 0; padding: 0; height: 100%;
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: calc(var(--fs) * .5);
  font-size: var(--fs);
}
.gm-cloud .gm-chip {
  padding: .3em .85em; border-radius: 999px; line-height: 1.25; font-weight: 600; cursor: pointer; user-select: none;
  background: color-mix(in srgb, var(--cat) 12%, var(--stage-bg)); border: 1px solid color-mix(in srgb, var(--cat) 30%, transparent);
  transition: background .15s, opacity .15s, transform .1s;
}
.gm-cloud .gm-chip:hover { background: color-mix(in srgb, var(--cat) 22%, var(--stage-bg)); }
.gm-cloud .gm-chip:active { transform: scale(.96); }
.gm-cloud .gm-chip:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.gm-cloud .gm-chip.is-absent {
  opacity: .5; background: transparent; border-style: dashed; border-color: color-mix(in srgb, var(--stage-ink) 30%, transparent);
  text-decoration: line-through; text-decoration-thickness: .08em;
}

/* ---- the groups ---- */
.gm-grid {
  height: 100%; display: grid; gap: var(--gap); font-size: var(--fs);
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr);
}
.gm-card {
  --gc: #e03131;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-radius: calc(var(--fs) * .7);
  background: color-mix(in srgb, var(--gc) 7%, var(--stage-bg));
  border: max(2px, calc(var(--fs) * .1)) solid color-mix(in srgb, var(--gc) 50%, transparent);
  box-shadow: 0 calc(var(--fs) * .15) calc(var(--fs) * .5) color-mix(in srgb, var(--gc) 16%, transparent);
}
.gm-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5em;
  padding: .32em .55em .32em .7em; margin: -1px -1px 0;
  border-radius: calc(var(--fs) * .6) calc(var(--fs) * .6) 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--gc) 88%, #fff), var(--gc));
  color: #fff; font: 650 1.05em/1.2 var(--font-display);
}
.gm-card.is-light .gm-card-head { color: #1d1d22; }
.gm-card-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-card-n {
  flex: none; min-width: 1.7em; padding: .05em .45em; border-radius: 999px; text-align: center;
  font-size: .8em; font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, .26);
}
.gm-card.is-light .gm-card-n { background: rgba(0, 0, 0, .12); }
.gm-list {
  margin: 0; padding: .4em .5em; min-height: 0;
  display: grid; grid-template-columns: repeat(var(--ic), minmax(0, 1fr)); column-gap: .6em; row-gap: .1em; align-content: start;
}
.gm-card .gm-chip {
  justify-self: start; max-width: 100%; padding: .1em .35em; border-radius: .35em; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550;
}
.gm-card .gm-chip.is-flying { background: color-mix(in srgb, var(--gc) 16%, var(--stage-bg)); }
.gm-chip.is-leader { font-weight: 700; }
.gm-chip.is-leader .gm-chip-name::before { content: "★"; color: #f2a900; margin-right: .22em; }

/* ---- empty class ---- */
.gm-empty { display: none; }
.gm.is-empty .gm-area, .gm.is-empty .gm-top { display: none; }
.gm.is-empty .gm-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3cqmin;
  color: color-mix(in srgb, var(--stage-ink) 65%, transparent); font-size: clamp(14px, 4cqmin, 34px); text-align: center;
}
.gm-empty p { margin: 0; }

.gm-count {
  justify-content: center; min-width: 6.4em; min-height: clamp(36px, 8.4cqmin, 84px); cursor: pointer;
  font-variant-numeric: tabular-nums; transition: background .12s;
}
.gm-count:hover { background: color-mix(in srgb, var(--cat) 24%, var(--stage-bg)); }

/* ---- settings: who's here ---- */
.gm-here { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 10px; max-height: 260px; overflow: auto; padding: 2px; }
.gm-here-item { display: flex; align-items: center; gap: 7px; min-height: 30px; font-size: .9rem; cursor: pointer; }
.gm-here-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-here-item input { flex: none; margin: 0; }
.gm-here-item:has(input:not(:checked)) span { color: var(--muted); text-decoration: line-through; }
.gm-here-btns { margin-top: 8px; }

@container (max-width: 560px) {
  .gm-extra { display: none; }
}
@container (max-height: 400px) {
  .gm-hint { display: none; }
}
@container (max-height: 300px) {
  .gm-top { display: none; }
}

/* ---- print: just the groups ---- */
@media print {
  .stage:has(.gm) { container-type: normal; overflow: visible; height: auto !important; min-height: 0 !important; }
  .gm { position: static; display: block; padding: 0; color: #000; }
  .gm-print-head { display: block; margin: 0 0 12pt; font: 600 18pt/1.2 var(--font-display); }
  .gm-top, .gm-hint, .gm-empty, .gm-cloud { display: none !important; }
  .gm-area { position: static; height: auto; --fs: 13pt; --gap: 10pt; }
  .gm-grid { height: auto; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: auto; }
  .gm-card { break-inside: avoid; box-shadow: none; background: #fff; }
  .gm-card-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .gm-list { overflow: visible; }
}
