/* =====================================================================
   The Continental Rails player board and its carriages on the printed art
   (src/ui/cr-player-board.js). Loaded after style.css. Every class starts
   `cb`, so nothing here touches the second edition's board (`pb`).
   ===================================================================== */

/* The strip is a size container: 100cqw is its own width, so the board and up to three carriages
   always fit across it (the height gives way) and the page never scrolls sideways. */
.region--trains { container-type: inline-size; }

/* The board picture is 2.358 times as wide as it is high and each carriage is square, so a strip with n carriages is
   2.358 + n heights wide (--cb-units), plus the gaps, the colour bar and the strip's own padding (62px). */
.cb { display: flex; flex-direction: column; gap: 4px; border-left: 7px solid var(--pc); padding-left: var(--s2); --piece-size: 18px;
  --cb-full: 170px; --cb-h: min(var(--cb-full), calc((100cqw - 62px) / var(--cb-units))); }
@media (min-width: 1700px) and (min-height: 1000px) { .cb { --cb-full: 210px; } }
@media (max-width: 1340px), (max-height: 820px) { .cb { --cb-full: 150px; } }
.cb__head { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 12px; }
.cb__head .train__stats { gap: 3px 12px; }
.cb__store { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r2); padding: 1px 8px; background: var(--card); }
.cb__store.is-over { border-color: var(--refuse); background: var(--refuse-bg); }

.cb__row { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.cb__eng, .cb__car { position: relative; height: var(--cb-h); flex: none; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 1px var(--wood-900); background: var(--wood-700); padding: 0; }
.cb__eng { aspect-ratio: 3501 / 1485; }
.cb__car { aspect-ratio: 1; }
.cb__engimg, .cb__carimg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cb__car.is-active-step, .cb__eng.is-active-step { z-index: 1; }

/* ---- pieces laid on the printed spaces: all placed by left/top in percent of the picture, centred on the space ---- */
.cb__h, .cb__p, .cb__s, .cb__hat, .cb__u, .cb__lid, .cb__w, .cb__k { position: absolute; transform: translate(-50%, -50%); }
/* A track's overlay covers the whole board, so it must never take a click itself (the last legal one would win every click,
   whichever track was meant): only its own house spaces and its production number do. */
.cb__t { position: absolute; inset: 0; pointer-events: none; }
.cb__t.is-out { filter: none; }
.cb__t.is-legal .cb__h, .cb__t.is-legal .cb__p { pointer-events: auto; cursor: pointer; outline: 2px solid var(--hl); border-radius: 4px; }
.cb__t.is-illegal .cb__h, .cb__t.is-illegal .cb__p { pointer-events: auto; cursor: help; }
.cb__h { width: 4%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; --piece-size: 100%; }
.cb__h .piece { width: 100%; height: 100%; }
.cb__p { min-width: 4%; padding: 0 2px; aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--brass-light); color: var(--ink);
  border: 1px solid var(--brass-dark); font: 700 calc(var(--cb-h) * .062)/1 var(--font); box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
/* a station on its space hides the printed number, as the piece does on the real board; its VP stays in the corner */
.cb__s { width: 4.6%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; --piece-size: 78%; }
.cb__s.has-station { background: #6a5660; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45); }
.cb__s .piece { width: 78%; height: 78%; }
.cb__vp { position: absolute; right: 7%; bottom: 3%; font: 700 calc(var(--cb-h) * .05)/1 var(--font); color: #fff; text-shadow: 0 1px 2px #000; pointer-events: none; }
.cb__s.is-next { outline: 2px solid var(--brass-light); outline-offset: 1px; border-radius: 4px; }
.cb__s.is-placed { opacity: 0; }
/* the printed hats stay on the picture: a space with no hat is covered with the same dark as an empty storage space */
.cb__hat { width: 3.5%; aspect-ratio: 1; border-radius: 3px; }
.cb__hat.is-empty { background: #4a3a31; box-shadow: inset 0 2px 5px rgba(0, 0, 0, .55); }

/* stored items and the lids over spaces the capacity does not reach */
.cb__u { width: 3.7%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.cb__u--car { width: 11.2%; }
.cb__lid { width: 3.7%; aspect-ratio: 1; border-radius: 3px; background: repeating-linear-gradient(45deg, #3a2e28 0 3px, #2a201b 3px 6px); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); pointer-events: auto; cursor: help; }
.cb__lid.cb__u--car { width: 11.2%; }
.cb__img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
.cb__u .tile { --tile-w: 100%; width: 100%; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
.cb__u.is-legal { outline: 2px solid var(--hl); outline-offset: 1px; border-radius: 4px; animation: pulse 1.4s ease-in-out infinite; cursor: pointer; }
.cb__u.is-illegal { cursor: help; }
.cb__u.is-out { filter: none; }
.cb__u.is-over { outline: 2px solid var(--refuse); border-radius: 4px; }

/* the extra spaces of a storage carriage, in the heading */
.cb__extra { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: var(--r2); padding: 1px 6px; background: var(--card); }
.cb__extralabel { font-size: var(--fs-xs); color: var(--ink-soft); margin-right: 3px; }
.cb__extra .cb__u, .cb__extra .cb__e { position: static; transform: none; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: var(--r1); background: #fff; flex: none; }
.cb__extra .cb__e { background: #4a3a31; border-color: var(--wood-900); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .55); }
.cb__extra .cb__u { padding: 1px; }

/* carriage: specialist faces in the windows, the upgrade tile on the plate */
.cb .cslot.cb__w { width: 25.7%; height: 28.4%; min-height: 0; border: 0; border-radius: 0; background: none; padding: 0; display: flex; align-items: center; justify-content: center; color: #fff; }
.cb__face { height: 100%; width: auto; max-width: 100%; object-fit: contain; display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); }
/* the face says what a specialist does; its name is in the tooltip and for screen readers */
.cb__wn { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cb .cslot.is-acting { outline: 3px solid var(--hl); box-shadow: 0 0 0 2px var(--hl-edge), 0 0 10px 2px var(--hl); border-radius: 4px; }
.cb .cslot.cb__k { width: 33.9%; height: 11.1%; min-height: 0; border: 0; background: none; padding: 0; display: flex; align-items: center; justify-content: center; }
.cb .cslot.cb__k.has-upgrade { background: none; }
.cb__kimg { width: 100%; height: 100%; object-fit: contain; border-radius: 3px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); }
.cb__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cb__carno { position: absolute; left: 6px; bottom: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--signal-red); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center; }

/* A narrow strip (a phone, or a tablet with three carriages): the board takes a row, the carriages the next, each as large as the width allows. */
@container (max-width: 700px) {
  .cb { --cb-eh: min(var(--cb-full), calc((100cqw - 30px) / 2.358)); --cb-ch: min(var(--cb-full), calc((100cqw - 30px - 12px) / 3)); }
  .cb__row { flex-wrap: wrap; align-items: flex-start; }
  .cb__eng { height: var(--cb-eh); }
  .cb__car { height: var(--cb-ch); }
}
