/*
 * The 35-car train (includes/pieces/shunt.php): a yard on timetable paper seen from a little above.
 * The locomotive's side is the board (the AIME in flaps); each car is a flatcar carrying a lit box as
 * tall as that year's indexed pay (dark: as earned; light: added by indexing), its year under the
 * rail. The perspective is the road's, so a car shows its roof and one end, which changes as it rolls.
 */

.shunt { --cols: 6; --hmax: 36px; --d: 10px; --earned: #8e1f19; --earned-top: #b83a31; --index: #f0a196; --index-top: #f8cbc4;
	--out-earned: #5c5850; --out-index: #c5bfb3; --out-top: #dcd7cc; --rail: #6c727b; --sleeper: #b9b2a4; --ground: #ece7dc;
	--track: linear-gradient(var(--rail) 0 1.5px, transparent 1.5px calc(100% - 1.5px), var(--rail) calc(100% - 1.5px)), repeating-linear-gradient(90deg, var(--sleeper) 0 4px, transparent 4px 10px); }

/* The locomotive: a board-black hood whose side is the board, the cab at the head. */
.shunt__loco { position: relative; display: grid; grid-template-columns: 74px minmax(0, 1fr); margin: 0 0 4px; padding-bottom: 24px; }
.shunt__loco::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 7px; background: var(--track); }
.shunt__cab { display: block; width: 100%; height: 100%; min-height: 96px; }
.shunt__cab-body { fill: #121417; }
.shunt__cab-glass { fill: #3d4a57; }
.shunt__cab-shine { fill: #6e8094; }
.shunt__cab-door { fill: none; stroke: #2e333a; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.shunt__board { position: relative; display: grid; align-content: center; gap: 4px; min-width: 0; margin-left: -1px; padding: 10px 14px 20px 10px; border-radius: 0 12px 3px 0; background: #121417; }
.shunt__loco::before { content: ""; position: absolute; left: 1px; right: 0; bottom: 30px; height: 7px; background: var(--signal); border-radius: 0 0 3px 3px; z-index: 1; }
.shunt__board-k { font: 700 .95rem/1 var(--board-font); letter-spacing: .18em; color: #c9c4ba; }
.shunt__aime .flaps__cells i, .shunt__aime .flaps__cells i.is-flip b { color: var(--signal); }
.shunt__aime .flaps__cells i { font-size: 1.9rem; }
.shunt__board-sum { font-size: .95rem; line-height: 1.35; color: var(--flap-ink); }
.shunt__vents { display: none; }
.shunt__bogies { position: absolute; left: 6%; right: 6%; bottom: 7px; display: flex; justify-content: space-between; pointer-events: none; }
.shunt__bogies i { width: 70px; height: 17px; border-radius: 3px 3px 0 0;
	background: radial-gradient(circle at 15px 9px, #4b5058 0 6px, #0b0c0e 6px 7.5px, transparent 7.5px), radial-gradient(circle at 55px 9px, #4b5058 0 6px, #0b0c0e 6px 7.5px, transparent 7.5px), linear-gradient(#24272c, #24272c) 0 0 / 100% 5px no-repeat; }

.piece p.shunt__count { margin: 8px 0 14px; font-size: 1.02rem; line-height: 1.45; color: var(--ink); }

/* The yard: roads of cars on paper; cars roll in from the right-hand end of each road. */
.shunt__yard { position: relative; }
.piece p.shunt__road-k { margin: 0 0 4px; font: 700 .95rem/1.3 var(--board-font); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.piece p.shunt__road-k--out { margin-top: 14px; }
.piece .shunt__cars { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); row-gap: 6px; margin: 0; padding: 14px 0 0; list-style: none; overflow: hidden; perspective: 760px; perspective-origin: 40% -60px; }
.piece p.shunt__empty { margin: 4px 0 0; font-size: 1rem; color: var(--ink-2); }

/* One car. */
.piece .shunt__car { position: relative; margin: 0; height: calc(var(--hmax) + 50px); transform-style: preserve-3d; cursor: default; }
.piece .shunt__car::before { content: ""; position: absolute; left: 0; right: 0; bottom: 21px; height: 7px; background: var(--track), var(--ground); }
.shunt__load { position: absolute; left: 4px; right: 4px; bottom: 37px; height: calc(var(--h, 0) * var(--hmax)); transform-style: preserve-3d; }
.shunt__box { position: absolute; inset: 0; transform-style: preserve-3d; }
.shunt__box i { position: absolute; display: block; }
.shunt__box .f-front { inset: 0; transform: translateZ(calc(var(--d) / 2));
	background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .1) 0 1px, transparent 1px 5px),
		linear-gradient(0deg, var(--earned) 0 calc(var(--e) * 100%), #4a0f0b calc(var(--e) * 100%) calc(var(--e) * 100% + 1px), var(--index) calc(var(--e) * 100% + 1px)); }
.shunt__box .f-top { left: 0; right: 0; top: 0; height: var(--d); transform-origin: 50% 0; transform: translateZ(calc(var(--d) / 2)) rotateX(-90deg); background: var(--index-top); }
.shunt__box .f-l, .shunt__box .f-r { top: 0; bottom: 0; width: var(--d); filter: brightness(.7);
	background: linear-gradient(0deg, var(--earned) 0 calc(var(--e) * 100%), var(--index) calc(var(--e) * 100%)); }
.shunt__box .f-l { left: 0; transform-origin: 0 50%; transform: translateZ(calc(var(--d) / 2)) rotateY(90deg); }
.shunt__box .f-r { right: 0; transform-origin: 100% 50%; transform: translateZ(calc(var(--d) / 2)) rotateY(-90deg); }
.piece .shunt__car.is-flat .f-top { background: var(--earned-top); }
.piece .shunt__car.is-soon .f-front { background: repeating-linear-gradient(135deg, var(--earned) 0 4px, #c2483e 4px 7px); }
.piece .shunt__car.is-soon .f-top { background: #d9776d; }

/* The flatcar under the load, its wheels, and the year on the paper below the rail. */
.shunt__deck { position: absolute; left: 1px; right: 1px; bottom: 28px; height: 9px; border-radius: 1px; background: linear-gradient(#5d636c 0 2px, #2d3137 2px); }
.shunt__deck::before { content: ""; position: absolute; left: -2px; right: -2px; top: 4px; height: 2px; background: #2d3137; }
.shunt__deck i { position: absolute; left: 12%; right: 12%; top: 8px; height: 7px;
	background: radial-gradient(circle at 5px 3.5px, #4b5058 0 2.6px, #0b0c0e 2.6px 3.5px, transparent 3.5px) 0 0 / 50% 100% repeat-x; }
.shunt__year { position: absolute; left: 0; right: 0; bottom: 0; font: 700 .95rem/20px var(--board-font); letter-spacing: .02em; text-align: center; color: var(--ink); font-variant-numeric: tabular-nums; }
.piece .shunt__car.is-empty .shunt__year { color: var(--ink-2); }
.piece .shunt__car.is-empty .shunt__deck { background: linear-gradient(#8a8f97 0 2px, #4b5058 2px); }

/* The siding: the same cars in grey. */
.shunt__cars--siding .shunt__car { --earned: var(--out-earned); --index: var(--out-index); --index-top: var(--out-top); --earned-top: #8a857b; }
.shunt__cars--siding .shunt__car.is-soon .f-front { background: repeating-linear-gradient(135deg, #5c5850 0 4px, #8a857b 4px 7px); }
.shunt__cars--siding .shunt__car.is-soon .f-top { background: #a9a397; }
.shunt__cars--siding .shunt__year { color: var(--ink-2); }

/* A car picked by touch, pointer or the slider. */
.piece .shunt__car.is-pick .shunt__year { color: var(--paper); background: var(--ink); border-radius: 4px; }
.piece .shunt__car.is-pick .f-front { outline: 2px solid var(--ink); outline-offset: 1px; }

.piece .shunt__key { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 14px 0 0; padding: 0; list-style: none; font-size: .95rem; line-height: 1.35; color: var(--ink); }
.piece .shunt__key li { margin: 0; display: flex; align-items: center; gap: 8px; }
.piece .shunt__key i { flex: 0 0 auto; width: 16px; height: 16px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }
.piece .shunt__key .k-earned { background: #8e1f19; }
.piece .shunt__key .k-index { background: #f0a196; }
.piece .shunt__key .k-soon { background: repeating-linear-gradient(135deg, #8e1f19 0 3px, #c2483e 3px 6px); }
.piece .shunt__key .k-out { background: linear-gradient(0deg, #5c5850 0 50%, #c5bfb3 50%); }

.piece p.shunt__waybill { margin: 14px 0 0; padding: 10px 14px; border-radius: 6px; background: var(--stone); font-size: 1.02rem; line-height: 1.5; color: var(--ink); box-shadow: inset 4px 0 0 var(--line); }
.js .shunt__ctrl.needs-js { display: grid; }
.shunt__ctrl { grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 10px 18px; margin-top: 14px; }
.shunt__look { display: block; min-width: 0; }
.shunt__look-k { display: block; font: 700 .95rem/1.2 var(--board-font); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }

@media (min-width: 520px) {
	.shunt { --cols: 9; --hmax: 42px; --d: 12px; }
	.shunt__loco { grid-template-columns: 96px minmax(0, 1fr); }
	.shunt__board { grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: 4px 14px; padding: 12px 96px 22px 12px; }
	.shunt__board-sum { font-size: 1rem; }
	.shunt__vents { display: block; position: absolute; right: 18px; top: 14px; bottom: 24px; width: 62px; border-radius: 3px; background: repeating-linear-gradient(90deg, #2a2e34 0 2px, #050607 2px 6px); box-shadow: inset 0 0 0 2px #1d2025; }
	.shunt__bogies i { width: 92px; background: radial-gradient(circle at 18px 9px, #4b5058 0 7px, #0b0c0e 7px 8.5px, transparent 8.5px), radial-gradient(circle at 74px 9px, #4b5058 0 7px, #0b0c0e 7px 8.5px, transparent 8.5px), linear-gradient(#24272c, #24272c) 0 0 / 100% 5px no-repeat; }
}
@media (min-width: 700px) {
	.shunt { --cols: 12; --hmax: 44px; }
}
@media (max-width: 599px) {
	.shunt__ctrl { grid-template-columns: minmax(0, 1fr); }
	.shunt__ctrl .p-btn { justify-self: start; }
}
@media (prefers-color-scheme: dark) {
	.shunt { --ground: #22252a; --sleeper: #4a4f57; --rail: #9aa0a8; --out-index: #8f897d; --out-top: #a8a296;
		--track: linear-gradient(var(--rail) 0 1.5px, transparent 1.5px calc(100% - 1.5px), var(--rail) calc(100% - 1.5px)), repeating-linear-gradient(90deg, var(--sleeper) 0 4px, transparent 4px 10px); }
	.shunt__cab-body, .shunt__board { fill: #0a0b0d; background: #0a0b0d; }
	.shunt__board { box-shadow: inset 0 1px 0 #2b2f35, inset 0 -1px 0 #2b2f35, inset -1px 0 0 #2b2f35; }
}
