/* ==========================================================================
   AGENT RANDOMIZER — two team boards, per-slot lock-in, shuffle + reveal
   ========================================================================== */

.teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(10px, 1.6vw, 20px);
  position: relative;
  z-index: 3;
  flex: 1;
  min-height: 0;
}

/* ---------------------------------------------------------------- team --- */

.team {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  background: rgba(11, 18, 25, 0.55);
  backdrop-filter: blur(10px);
  padding-bottom: clamp(8px, 1.5vh, 18px);
  clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px));
  transition: box-shadow 0.45s ease;
}

.team--a { --team: #16d8b4; --team-soft: rgba(22, 216, 180, 0.10); --team-line: rgba(22, 216, 180, 0.45); }
.team--b { --team: #ff4655; --team-soft: rgba(255, 70, 85, 0.10);  --team-line: rgba(255, 70, 85, 0.45); }

/* top accent rail + a faint wash in the team colour */
.team::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--team);
}
.team::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, var(--team-soft), transparent 42%);
}

body.is-spinning .team { box-shadow: 0 34px 100px rgba(0, 0, 0, 0.66); }

.team__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: clamp(9px, 1.7vh, 17px) 20px clamp(8px, 1.4vh, 14px);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1;
  flex: none;
}

.team__tick {
  width: 11px;
  height: 24px;
  background: var(--team);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 38% 100%);
  flex: none;
}

.team__name {
  font-family: var(--font-display);
  font-size: clamp(20px, 3vh, 28px);
  line-height: 1;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--team);
  padding-top: 3px;
}

.team__locks {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}
.team__locks b { color: var(--white); }

/* Five equal rows filling the board; the slots shrink with the window rather
   than pushing the page taller. */
.team__slots {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 0.9vh, 9px);
  padding: clamp(8px, 1.5vh, 14px) clamp(10px, 1.2vw, 16px) 0;
  position: relative;
  z-index: 1;
}

/* ---------------------------------------------------------------- slot --- */

.slot {
  position: relative;
  display: grid;
  grid-template-columns: var(--slot-av) minmax(0, 1fr) 132px;
  gap: clamp(8px, 1vw, 13px);
  align-items: center;
  min-height: 0;
  padding: clamp(6px, 1vh, 10px);
  border: 1px solid var(--line);
  background: rgba(15, 25, 35, 0.7);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
  transition: border-color 0.25s ease, background 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.slot.is-locked {
  border-color: var(--team-line);
  background: rgba(15, 25, 35, 0.92);
}
.slot.is-locked::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--team);
  box-shadow: 0 0 12px var(--team);
}

/* ------------------------------------------------------------- avatar ---- */

.slot__avatar {
  position: relative;
  width: var(--slot-av);
  height: var(--slot-av);
  overflow: hidden;
  background: #0b1219;
  border: 1px solid var(--line);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
}

/* Two stacked layers, each carrying its own portrait + backdrop, cross-faded
   as a unit. `--fade` comes from JS: ~80% of the current frame gap while
   rolling, so the dissolve always lands before the next agent arrives. */
.view--agent { --fade: 320ms; }

.slot__layers { position: absolute; inset: 0; }

.slot__layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--fade) linear;
}
.slot__layer.is-on { opacity: 1; }

.slot__bg {
  position: absolute;
  inset: 0;
  background-size: 150%;
  background-position: center;
  opacity: 0.5;
  filter: saturate(0.85) contrast(1.1);
}

.slot__icon {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 12%;
}

.slot__empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 30px;
  color: rgba(236, 232, 225, 0.2);
}
.slot.has-agent .slot__empty { display: none; }

.slot__avatar::after {   /* scanline veil, matches the map hero */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(236,232,225,0.05) 0 1px, transparent 1px 3px);
}

/* shuffling: a light jitter over the dissolve, not instead of it */
.slot.is-rolling .slot__layers { animation: slot-jitter 0.22s steps(2, end) infinite; }
@keyframes slot-jitter {
  0%   { transform: translate3d(-1px, 0.5px, 0); }
  50%  { transform: translate3d(1px, -0.5px, 0); }
  100% { transform: translate3d(0, 0, 0); }
}
.slot.is-rolling .slot__avatar { border-color: var(--team-line); }

/* reveal */
.slot.is-revealed { animation: slot-pop 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slot-pop {
  0%   { transform: scale(0.965); }
  40%  { transform: scale(1.018); }
  100% { transform: scale(1); }
}

.slot__flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(120deg, var(--team), transparent 70%);
  mix-blend-mode: screen;
}
.slot.is-revealed .slot__flash { animation: slot-flash 0.5s ease-out; }
@keyframes slot-flash {
  0%   { opacity: 0.6; }
  100% { opacity: 0; }
}

/* ---------------------------------------------------------------- body --- */

.slot__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.7vh, 7px);
}

.slot__name {
  width: 100%;
  padding: clamp(2px, 0.5vh, 5px) 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--white);
  font-family: var(--font-cond);
  font-size: clamp(11px, 1.6vh, 14px);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: border-color 0.2s ease;
}
.slot__name::placeholder { color: rgba(236, 232, 225, 0.28); letter-spacing: 0.14em; }
.slot__name:focus { outline: 0; border-bottom-color: var(--team); }

.slot__agent {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

/* Two stacked lines in one grid cell, cross-faded with the portrait. */
.slot__agentname {
  display: grid;
  justify-items: start;
  min-width: 0;
  font-family: var(--font-display);
  font-size: clamp(16px, 2.5vh, 23px);
  line-height: 1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.slot__nameline {
  grid-area: 1 / 1;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity var(--fade) linear;
}
.slot__nameline.is-on { opacity: 1; }

.slot:not(.has-agent) .slot__agentname { color: rgba(236, 232, 225, 0.3); }

/* Role badge. Pinned to the avatar corner so it holds still while the agent
   name underneath changes length every frame of a shuffle. */
.slot__role {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 1;
  width: 22px;
  height: 22px;
  background-color: rgba(11, 18, 25, 0.88);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 13px 13px;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  pointer-events: none;
}

/* ---------------------------------------------------------------- ctrl --- */

.slot__ctrl {
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.7vh, 7px);
  min-height: 0;
}

.pick {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: clamp(2px, 0.5vh, 5px) 8px clamp(2px, 0.5vh, 5px) 5px;
  border: 1px solid var(--line);
  background: rgba(11, 18, 25, 0.9);
  color: var(--white);
  font-family: var(--font-ui);
  font-size: clamp(9px, 1.4vh, 11px);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.pick:hover { border-color: var(--line-strong); background: rgba(20, 32, 44, 0.95); }
.pick[aria-expanded='true'] { border-color: var(--team); }
.pick:disabled { opacity: 0.4; cursor: not-allowed; }

.pick__thumb {
  width: clamp(17px, 2.7vh, 24px);
  height: clamp(17px, 2.7vh, 24px);
  flex: none;
  background: #0b1219 center/cover no-repeat;
  border: 1px solid var(--line);
}
.pick__thumb.is-random {
  background-image: none;
  position: relative;
}
.pick__thumb.is-random::after {
  content: '?';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink-faint);
}

.pick__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pick__caret {
  width: 9px;
  height: 5px;
  flex: none;
  background: var(--ink-soft);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* ============================================== the picker popover ======== */

.agentpanel {
  position: fixed;
  z-index: 60;
  width: 336px;
  max-height: min(462px, 74vh);
  display: flex;
  flex-direction: column;
  background: rgba(11, 18, 25, 0.97);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px) saturate(1.15);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.78);
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  animation: panel-in 0.16s ease-out;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.agentpanel::before {   /* team-coloured rail, matches the board it opened from */
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--red);
}
.agentpanel[data-team='a']::before { background: #16d8b4; }
.agentpanel[data-team='b']::before { background: #ff4655; }

.agentpanel__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 10px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.agentpanel__search {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  background: rgba(15, 25, 35, 0.9);
  color: var(--white);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.agentpanel__search::placeholder { color: rgba(236, 232, 225, 0.3); }
.agentpanel__search:focus { outline: 0; border-color: var(--red); }

.agentpanel__close {
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.agentpanel__close:hover { color: var(--white); border-color: var(--red); }

.agentpanel__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--slate-dim) transparent;
}
.agentpanel__body::-webkit-scrollbar { width: 8px; }
.agentpanel__body::-webkit-scrollbar-thumb { background: var(--slate-dim); }

.agentpanel__empty {
  margin: 0;
  padding: 0 14px 16px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
}

.atile-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.atile-head__icon { width: 13px; height: 13px; opacity: 0.6; }
.atile-head i { flex: 1; height: 1px; background: var(--line); }

.atile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.atile {
  position: relative;
  padding: 0;
  border: 1px solid var(--line);
  background: #0b1219;
  cursor: pointer;
  overflow: hidden;
  color: var(--white);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  transition: border-color 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.atile:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.atile:focus-visible { border-color: var(--red); }

.atile__img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #131f2a center/cover no-repeat;
}
.atile__img--random {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--ink-faint);
}

.atile__name {
  display: block;
  padding: 5px 4px 6px;
  background: rgba(11, 18, 25, 0.92);
  font-family: var(--font-cond);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atile.is-selected { border-color: var(--red); }
.atile.is-selected .atile__name { background: var(--red); color: var(--navy); font-weight: 700; }

.atile--random {
  width: 100%;
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  text-align: left;
  margin-bottom: 2px;
}
.atile--random .atile__img { aspect-ratio: auto; height: 46px; }
.atile--random .atile__name {
  background: transparent;
  text-align: left;
  padding-left: 12px;
  font-size: 13px;
  letter-spacing: 0.2em;
}
.atile--random.is-selected .atile__name { background: transparent; color: var(--red); }

.lock {
  position: relative;
  padding: clamp(3px, 0.75vh, 7px) 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-cond);
  font-size: clamp(9px, 1.4vh, 11px);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.lock:hover { color: var(--white); border-color: var(--line-strong); }

.lock.is-on {
  background: var(--team);
  border-color: var(--team);
  color: var(--navy);
}
.lock:disabled { opacity: 0.35; cursor: not-allowed; }

/* ------------------------------------------------------------ responsive - */

/*
 * On a short desktop screen (a 720p or 768p laptop) the stacked pick+lock is
 * the tallest thing in a slot and sets the floor on how short a row can get.
 * Laying the two controls side by side halves that, which is what lets five
 * rows per board still fit without clipping.
 */
@media (min-width: 900px) and (min-height: 620px) and (max-height: 899px) {
  .slot { grid-template-columns: var(--slot-av) minmax(0, 1fr) auto; }
  .slot__ctrl { flex-direction: row; align-items: center; }
  .pick { width: clamp(102px, 8.4vw, 132px); }
  .lock { padding-inline: 13px; }
}


@media (max-width: 980px) {
  .teams { grid-template-columns: 1fr; gap: 16px; }
  .team__slots { display: flex; flex-direction: column; }
}

@media (max-width: 420px) {
  .agentpanel { width: calc(100vw - 20px); }
  .atile-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 560px) {
  .slot {
    grid-template-columns: 60px minmax(0, 1fr);
    grid-template-areas: "avatar body" "ctrl ctrl";
    row-gap: 10px;
  }
  .slot__avatar { grid-area: avatar; width: 60px; height: 60px; }
  .slot__body   { grid-area: body; }
  .slot__ctrl   { grid-area: ctrl; flex-direction: row; }
  .pick { flex: 1; }
  .lock { padding: 7px 14px; }
  .team__slots { padding: 12px 12px 0; }
  .team__head { padding: 14px 14px 12px; gap: 9px; }
  .team__name { font-size: 21px; }
}
