/* Co-op (js/sections/coop.js): two commander slots like the title screen's squad panel. Each slot is a
   canvas window onto the field with its header and controls on top; its player colour arrives as --pc.
   Open: dim, dashed. Inbound: dashed in his colour. Ready: lit, solid, with the controls of his device. */

.coop__slots { max-width: 1040px; margin-inline: auto; }
.coop__slots [hidden] { display: none !important; }

.coop__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 1.2vw, 18px); }

.coop__slot {
  --cut: 12px;
  --foot-h: 104px;
  position: relative; min-width: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) var(--foot-h);
  height: clamp(420px, 33vw, 470px);
  background: var(--bg-1);
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
  container-type: inline-size;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.coop__stage { position: absolute; inset: 0; width: 100%; height: 100%; }
.coop__spot { grid-row: 2; }

/* header: P1 · state (shape + word + colour) · device */
.coop__head {
  grid-row: 1; position: relative; z-index: 2; pointer-events: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 16px 16px 0 18px;
  /* a shade under the labels so they read on a lit slot: inside the frame and the focus ring, below the cut */
  background: linear-gradient(rgba(5, 6, 7, 0.45), transparent) 8px var(--cut) / calc(100% - 16px) 100% no-repeat;
}
.coop__tag { font-family: var(--f-display); font-weight: 800; font-size: 1.45rem; line-height: 1; letter-spacing: 0.02em; color: var(--pc); transition: color var(--d-med) var(--ease-out); }
.coop__state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: var(--t-small); color: var(--bone-3); }
.coop__state svg { width: 14px; height: 14px; flex: none; }
.coop__dev { margin-left: auto; font-size: var(--t-small); color: var(--bone-2); white-space: nowrap; }
/* an open seat's name is bone, like the game's empty squad slots, until he is in */
.coop__slot[data-state='open'] .coop__tag { color: var(--bone-3); }
.coop__slot[data-state='open']:is(:hover, :focus-within) .coop__tag { color: var(--pc); }
/* the state word in bone, its shape in his colour */
.coop__slot:not([data-state='open']) .coop__state { color: var(--bone); }
.coop__slot:not([data-state='open']) .coop__state svg { color: var(--pc); }
.coop__slot[data-state='inbound'] .coop__state svg { animation: coop-bob 0.9s var(--ease-in-out) infinite; }

/* empty slot: the whole slot is the button */
.coop__join {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 12px max(20px, calc(var(--foot-h) / 2 - 30px)); text-align: center;
}
.coop__join:focus-visible { outline: 2px solid var(--amber); outline-offset: -6px; }
.coop__call { display: grid; justify-items: center; gap: 9px; }
.coop__chips { display: inline-flex; align-items: center; gap: 6px; }
.coop__go {
  font-family: var(--f-display); font-weight: 700; font-size: 0.95rem; letter-spacing: var(--track-prompt);
  text-transform: uppercase; color: var(--bone-3); transition: color var(--d-fast) ease;
}
.coop__or { font-size: var(--t-micro); color: var(--bone-3); margin-top: -4px; }
.coop__any { color: var(--bone-3); transition: color var(--d-fast) ease, border-color var(--d-fast) ease; }
.coop__slot.is-next .coop__go { color: var(--amber); }
.coop__slot.is-next .coop__any { color: var(--amber); border-color: rgba(255, 177, 46, 0.55); }
.coop__join:hover .coop__go, .coop__join:focus-visible .coop__go { color: var(--pc); }
.coop__slots.is-kbm .coop__any { display: none; }
.coop__k--a { position: relative; }
.coop__slots.is-pad .coop__slot.is-next .coop__k--a::after {
  content: ''; position: absolute; inset: -1px; z-index: -1; border-radius: 50%; background: rgba(236, 230, 217, 0.5); opacity: 0;
  animation: coop-pulse 1.1s var(--ease-out) infinite;
}

/* controls of a ready slot: the game's input prompts, each chip over its action like a pad legend */
.coop__foot {
  grid-row: 3; position: relative; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; padding: 0 12px 18px;
}
.coop__keys { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px 2px; }
.coop__keys li {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-family: var(--f-display); font-weight: 600; font-size: 0.75rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--bone-2); white-space: nowrap;
  animation: coop-rise var(--d-slow) var(--ease-out) both; animation-delay: calc(var(--k, 0) * 60ms + 60ms);
}
.coop__keys .key { transition: background var(--d-fast) ease, color var(--d-fast) ease, border-color var(--d-fast) ease, box-shadow var(--d-fast) ease; }
.coop__keys li.is-on .key { background: var(--pc); border-color: var(--pc); color: var(--bg-0); box-shadow: 0 0 14px color-mix(in srgb, var(--pc) 55%, transparent); }
.coop__note { font-size: var(--t-micro); line-height: 1.35; color: var(--bone-3); text-align: center; text-wrap: balance; }

/* pad buttons, shaped like the game's (src/fe/components/keyhint.js) */
.coop__k--a, .coop__k--face, .coop__k--stick { width: 26px; min-width: 26px; padding: 0; border-radius: 50%; border-bottom-width: 1px; }
.coop__k--a { background: var(--bone); border-color: var(--bone); color: var(--bg-0); }
.coop__k--stick { font-size: 0.72rem; box-shadow: inset 0 0 0 3px rgba(236, 230, 217, 0.06); }
.coop__k--trigger { border-radius: 10px 10px 3px 3px; }

/* ---------- squad bar ---------- */
.coop__bar {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px;
  margin-top: clamp(16px, 2vw, 24px); padding: 18px 0 0; min-height: 74px;
  border-top: 1px solid var(--line);
}
.coop__squad { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.coop__eyebrow::after { display: none; }
.coop__pips { display: inline-flex; gap: 4px; }
.coop__pips i { width: 18px; height: 6px; box-shadow: inset 0 0 0 1px var(--line-3); transition: background var(--d-med) var(--ease-out), box-shadow var(--d-med) var(--ease-out); }
.coop__pips i.on { background: var(--pc); box-shadow: inset 0 0 0 1px var(--pc); }
.coop__count { font-weight: 600; font-size: var(--t-small); color: var(--bone-2); font-variant-numeric: tabular-nums; }
.coop__status { flex: 1 1 220px; min-width: 0; font-size: var(--t-small); color: var(--bone-3); }
.coop__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-left: auto; }
.coop__won {
  font-family: var(--f-display); font-weight: 800; font-size: clamp(1.9rem, 3.4vw, 2.6rem); line-height: 0.95;
  letter-spacing: 0.01em; text-transform: uppercase; color: var(--bone);
}
.coop__won em { font-style: normal; color: var(--amber); }

.coop__bar.is-ready {
  padding: 18px 20px; border-top-color: transparent;
  background: linear-gradient(90deg, rgba(255, 177, 46, 0.13), rgba(255, 177, 46, 0.03) 55%, transparent 90%);
  box-shadow: inset 3px 0 0 var(--amber);
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
}
.coop__bar.is-ready .coop__eyebrow, .coop__bar.is-ready .coop__count { display: none; }
/* the banner says it; the line stays for screen readers */
.coop__bar.is-ready .coop__status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.coop__bar.is-ready .coop__won { animation: coop-stamp 560ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.coop__bar.is-ready .coop__cta { animation: coop-rise var(--d-slow) var(--ease-out) 200ms both; }

@keyframes coop-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes coop-stamp { 0% { opacity: 0; transform: scale(1.9) rotate(-7deg); } 55% { opacity: 1; } 100% { opacity: 1; transform: none; } }
@keyframes coop-pulse { from { opacity: 1; transform: none; } 60%, to { opacity: 0; transform: scale(1.46); } }
@keyframes coop-bob { 0%, 100% { transform: translateY(-1px); } 50% { transform: translateY(2px); } }

@container (max-width: 299px) {
  .coop__keys { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* narrow slots (a phone's two side by side): the device under the name, smaller chips */
@container (max-width: 230px) {
  .coop__head { padding: 12px 10px 0 12px; gap: 0 8px; }
  .coop__tag { font-size: 1.2rem; }
  .coop__dev { margin-left: 0; flex-basis: 100%; font-size: var(--t-micro); }
  .coop__join { padding-left: 8px; padding-right: 8px; }
  .coop__go { font-size: 0.85rem; }
  .coop__foot { padding: 0 8px 12px; gap: 8px; }
  .coop__keys { gap: 8px 2px; }
  .coop__keys li { gap: 3px; font-size: 0.7rem; letter-spacing: 0.06em; }
  .coop__keys .key { height: 22px; min-width: 22px; font-size: 0.7rem; padding: 0 5px; }
  .coop__keys .coop__k--face, .coop__keys .coop__k--stick { width: 22px; padding: 0; }
  .coop__note { padding: 0 4px; }
}

@media (max-width: 760px) {
  .coop__slot { height: 360px; --foot-h: 148px; }
  .coop__bar { gap: 10px 16px; }
  .coop__actions { margin-left: 0; width: 100%; }
  .coop__bar.is-ready .coop__cta { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .coop__keys li, .coop__bar.is-ready .coop__won, .coop__bar.is-ready .coop__cta, .coop__slot[data-state='inbound'] .coop__state svg,
  .coop__slots.is-pad .coop__slot.is-next .coop__k--a::after { animation: none; }
}
:root[data-motion='off'] :is(.coop__keys li, .coop__bar.is-ready .coop__won, .coop__bar.is-ready .coop__cta, .coop__slot[data-state='inbound'] .coop__state svg),
:root[data-motion='off'] .coop__slots.is-pad .coop__slot.is-next .coop__k--a::after { animation: none; }
