/* Four suit lanes share the available height. Their permanent labels stay
   outside the ten placement targets, even when the whole suit is on the table. */
.table-game.game-cinquillo .foundation {
  grid-template-columns: var(--suit-label-width, 112px) minmax(0, 1fr);
  gap: clamp(3px, 1cqw, 10px);
  background: rgb(16 57 42 / 20%);
  border-radius: 7px;
}
.table-game.game-cinquillo .suit-label {
  justify-content: center; gap: 5px; padding: 3px;
  color: var(--pop-ink); background: var(--pop-paper);
  border: 1px solid var(--pop-ink); border-radius: 6px;
  box-shadow: 1px 2px 0 var(--pop-felt-edge);
  font: clamp(15px, 2.5cqw, 21px)/1 var(--pop-title);
}
.game-cinquillo .suit-label .suit-art { width: 30px; height: 30px; object-fit: contain; }
.game-cinquillo .suit-label span { display: inline; }
.game-cinquillo .card-slot:not(.filled) .slot-rank { color: var(--pop-paper); }
.game-cinquillo .card-slot:not(.filled):not(.anchor) .slot-rank { opacity: .8; }

/* Only the exposed part of a skipped place gets ink, even in an overlapping row. */
.table-game.game-cinquillo .card-slot.blocked-slot:not(.filled) {
  width: min(100%, var(--sequence-card)); height: auto; max-height: 100%; aspect-ratio: 110 / 156;
  display: grid; place-items: center; opacity: 1; border: 1px dashed var(--pop-paper);
  background: repeating-linear-gradient(-45deg, #203e33 0 5px, #527261 5px 7px);
}
.blocked-rank {
  padding: 1px 3px; border-radius: 3px; color: var(--pop-paper); background: #263d33;
  font: clamp(13px, 2.8cqw, 24px)/1 var(--pop-title);
}
.game-cinquillo .hand-card.blocked-card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  --strike: transparent 48%, #a92e39 48.5% 51.5%, transparent 52%;
  background:
    linear-gradient(to bottom right, var(--strike)),
    linear-gradient(to bottom left, var(--strike)),
    rgb(222 54 64 / 26%);
  mix-blend-mode: multiply;
}
.table-game.game-cinquillo .foundations:has(> .stock-pile) {
  grid-template-columns: clamp(46px, 6vw, 78px) minmax(0, 1fr); column-gap: 4px;
}
.game-cinquillo .foundations > .stock-pile {
  grid-column: 1; grid-row: 1 / span 4; place-self: center; margin: 0;
  --stock-card: clamp(34px, 4.5vw, 62px);
}
.game-cinquillo .foundations > .stock-pile ~ .foundation { grid-column: 2; }
.game-cinquillo .stock-pile:has(.stock-action:enabled) { outline: 2px solid var(--pop-paper); border-radius: 5px; }
@container (max-width: 600px) {
  .game-cinquillo .foundation { --suit-label-width: 56px; }
  .table-game.game-cinquillo .suit-label { flex-direction: column; gap: 1px; font-size: 14px; }
  .game-cinquillo .suit-label .suit-art { width: 22px; height: 22px; }
}
@container (max-height: 205px) {
  .game-cinquillo .foundation { --suit-label-width: 72px; }
  .table-game.game-cinquillo .suit-label { flex-direction: row; gap: 2px; font-size: 14px; padding: 2px; }
  .game-cinquillo .suit-label .suit-art { width: 18px; height: 18px; }
}

body[data-screen="game"] .table-game.game-cinquillo .game:has(> .opponents:not(:empty)) {
  --seat-label: calc(var(--seat-avatar) + 8px);
  --seat-gutter: clamp(116px, 14vw, 184px);
}
/* Keep the pass in the hand's layout so a raised card cannot cover it. */
body[data-screen="game"]:is(:not([data-remote-role]), [data-remote-surface="hand"]) .table-game.game-cinquillo .controller {
  display: grid; grid-template: "owner fan pass" auto / minmax(0, 1fr) minmax(0, 4fr) fit-content(25%);
  align-items: center; gap: 8px;
}
body[data-screen="game"] .game-cinquillo .controller .hand-heading { grid-area: owner; align-self: center; }
.game-cinquillo .controller > .hand { grid-area: fan; }
.game-cinquillo #pass { grid-area: pass; justify-self: end; max-width: 100%; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
body[data-remote-surface="table"] .game-cinquillo #pass { display: none; }

/* Place the far player beside their fan to leave more height for the four runs. */
@media (min-width: 701px) and (min-height: 501px) {
  body[data-screen="game"] .table-game.game-cinquillo .game:has(.opponent[data-edge="top"]) {
    --seat-top: calc(max(var(--seat-depth), var(--seat-label)) + 6px);
  }
  body[data-screen="game"] .game-cinquillo .opponents .opponent[data-edge="top"] {
    width: min(360px, 100cqw / (var(--top-seats) + 1) - 8px);
    --seat-fan: 50%;
  }
  body[data-screen="game"] .game-cinquillo .opponent[data-edge="top"] .opponent-identity {
    inset: 50% 0 auto auto; transform: translateY(-50%); width: 50%;
  }
}

@media (min-width: 701px) and (min-height: 501px) and (max-height: 650px) {
  body[data-screen="game"] .table-game.game-cinquillo { --seat-avatar: 36px; --seat-name: 18px; --hand-card: 66px; }
  body[data-screen="game"] .table-game.game-cinquillo .game:has(> .opponents:not(:empty)) {
    --seat-depth: 48px; --seat-reveal: var(--seat-depth); --seat-back: 28px;
  }
}

/* On compact tables the rivals share the far edge, leaving the entire
   width below for the suits. Each fan still faces its original seat. */
@media (max-width: 700px), (max-height: 500px) {
  body[data-screen="game"]:not([data-remote-role]) .table-game.game-cinquillo { --hand-card: 68px; }
  body[data-screen="game"]:not([data-remote-role="display"]) .table-game.game-cinquillo .game:has(> .opponents:not(:empty)) {
    --seat-depth: 44px; --seat-back: 27px;
    --seat-band: calc(var(--seat-label) + 54px);
    padding: var(--seat-band) 2px 2px;
  }
  body[data-screen="game"]:not([data-remote-role="display"]) .game-cinquillo .game > .opponents {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    inset: 0 0 auto; height: var(--seat-band); gap: 3px;
  }
  body[data-screen="game"]:not([data-remote-role="display"]) .game-cinquillo .opponents .opponent {
    position: relative; inset: auto; width: 100%; height: 100%; transform: none;
    --seat-fan: min(110px, 100cqw / 3 - 8px);
  }
  body[data-screen="game"]:not([data-remote-role="display"]) .game-cinquillo .opponents .opponent .opponent-identity {
    inset: 0 0 auto; width: 100%; height: var(--seat-label);
  }
  body[data-screen="game"]:not([data-remote-role="display"]) .game-cinquillo .opponents .opponent .mini-hand {
    left: 50%; top: calc(var(--seat-label) + 26px);
    transform: translate(-50%, -50%) rotate(var(--fan-facing, 180deg));
  }
  body[data-screen="game"]:not([data-remote-role="display"]) .game-cinquillo .opponents .opponent:is([data-edge="left"], [data-edge="right"]) {
    --seat-fan: 50px;
  }
  .game-cinquillo .opponent[data-edge="left"] { --fan-facing: 90deg; }
  .game-cinquillo .opponent[data-edge="right"] { --fan-facing: -90deg; }
  body[data-screen="game"]:is(:not([data-remote-role]), [data-remote-surface="hand"]) .table-game.game-cinquillo .controller {
    grid-template: "owner pass" auto "fan fan" auto / minmax(0, 1fr) fit-content(50%); gap: 12px 8px;
  }
}
@media (max-height: 700px) and (orientation: landscape) {
  /* The phone rotates its felt; its suit labels read in screen coordinates. */
  body[data-remote-role="controller"][data-remote-surface="table"] .game-cinquillo .suit-label { transform: rotate(90deg); }
}
@media (orientation: landscape) and (max-height: 500px) {
  body[data-screen="game"]:not([data-remote-role]) .table-game.game-cinquillo .table-scene {
    grid-template: minmax(0, 1fr) / minmax(0, 1fr) min(30vw, 250px);
  }
  body[data-screen="game"]:not([data-remote-role]) .game-cinquillo .feedback-rail { position: absolute; inset: 0 0 auto; }
  body[data-screen="game"]:not([data-remote-role]) .game-cinquillo .game { grid-area: 1 / 1; }
  body[data-screen="game"]:not([data-remote-role]) .table-game.game-cinquillo .controller {
    grid-area: 1 / 2; align-self: center;
    grid-template: "owner" auto "fan" auto "pass" auto / minmax(0, 1fr); gap: 0;
  }
  body[data-screen="game"]:not([data-remote-role]) .game-cinquillo .controller .hand-heading { margin-bottom: 12px; }
  body:not([data-remote-role]) .game-cinquillo #pass { justify-self: center; padding: 5px 10px; line-height: 1.1; }
}
