/* Traffic Jam (/traffic-jam): only what is the game's own - the parking board, its exit and the vehicles. Tiles,
   buttons, fields and the accent come from the app kit (css/app-kit, docs/app-kit.md), the button row from
   css/app-kit/games.css (every game). Loaded only on this page (StylePaths). */

.traffic-jam-frame {
    --tj-wall: clamp(10px, 2.4vw, 20px);
    position: relative;
    width: min(100%, calc(100vh - 280px));
    min-width: min(100%, 250px);
    margin-inline: auto;
    padding: var(--tj-wall);
    border-radius: 22px;
    background: #475569;
    box-sizing: border-box;
}

.traffic-jam-landing-app[data-theme="dark"] .traffic-jam-frame {
    background: #334155;
}

.traffic-jam-board {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    background: #e2e8f0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.traffic-jam-landing-app[data-theme="dark"] .traffic-jam-board {
    background: #1e293b;
}

.tj-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
}

.tj-cell {
    border: 1px solid rgba(100, 116, 139, 0.25);
}

/* The exit: a gap in the right wall at the red car's row, with an arrow. */
.tj-exit {
    position: absolute;
    right: calc(-1 * var(--tj-wall) - 1px);
    top: calc(var(--tj-row) * 100% / 6 + 4px);
    width: calc(var(--tj-wall) + 2px);
    height: calc(100% / 6 - 8px);
    background: inherit;
}

.tj-exit::after {
    content: "";
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    border-style: solid;
    border-width: 10px 0 10px 14px;
    border-color: transparent transparent transparent #e11d48;
    transform: translateY(-50%);
}

/* A vehicle: positioned in squares (--tj-x, --tj-y, --tj-len), the body is its ::before. */
.tj-car,
.tj-ghost {
    position: absolute;
    left: calc(var(--tj-x) * 100% / 6);
    top: calc(var(--tj-y) * 100% / 6);
    width: calc(100% / 6);
    height: calc(100% / 6);
    padding: 0;
    border: 0;
    background: none;
    box-sizing: border-box;
}

.tj-car.is-h,
.tj-ghost.is-h {
    width: calc(var(--tj-len) * 100% / 6);
}

.tj-car.is-v,
.tj-ghost.is-v {
    height: calc(var(--tj-len) * 100% / 6);
}

.tj-car {
    z-index: 2;
    cursor: grab;
    transition: left 150ms ease, top 150ms ease, transform 600ms ease-in, opacity 600ms ease-in;
    -webkit-tap-highlight-color: transparent;
}

.tj-car::before {
    content: "";
    position: absolute;
    inset: 7%;
    border-radius: 18%;
    background: var(--tj-color);
    box-shadow: inset 0 -4px 0 rgba(15, 23, 42, 0.22), 0 3px 6px rgba(15, 23, 42, 0.25);
}

.tj-car.is-h::before {
    inset: 7% calc(7% / var(--tj-len));
    border-radius: calc(18% / var(--tj-len)) / 18%;
}

.tj-car.is-v::before {
    inset: calc(7% / var(--tj-len)) 7%;
    border-radius: 18% / calc(18% / var(--tj-len));
}

/* The windscreen: a dark band near the front. */
.tj-car::after {
    content: "";
    position: absolute;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.3);
}

.tj-car.is-h::after {
    top: 25%;
    bottom: 25%;
    right: calc(30% / var(--tj-len));
    width: calc(16% / var(--tj-len));
}

.tj-car.is-v::after {
    left: 25%;
    right: 25%;
    top: calc(30% / var(--tj-len));
    height: calc(16% / var(--tj-len));
}

.tj-car.is-red::before {
    box-shadow: inset 0 -4px 0 rgba(15, 23, 42, 0.22), 0 0 0 3px rgba(255, 255, 255, 0.55), 0 3px 8px rgba(225, 29, 72, 0.45);
}

.tj-car:focus-visible {
    outline: none;
}

.tj-car:focus-visible::before {
    outline: 3px solid var(--ak-accent);
    outline-offset: 2px;
}

.tj-car.is-dragging {
    z-index: 3;
    cursor: grabbing;
    transition: none;
}

.tj-car.is-stuck {
    cursor: default;
}

/* The Hint (and the move Solve plays next): the vehicle pulses and its target is outlined. */
.tj-car.is-hint::before {
    animation: tj-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes tj-pulse {
    from { box-shadow: 0 0 0 3px var(--ak-info); }
    to { box-shadow: 0 0 0 6px var(--ak-info), 0 0 18px var(--ak-info); }
}

.tj-ghost {
    z-index: 1;
    pointer-events: none;
}

.tj-ghost::before {
    content: "";
    position: absolute;
    inset: 7%;
    border: 3px dashed var(--ak-info);
    border-radius: 14%;
}

/* Solved: the red car drives out through the exit. */
.traffic-jam-board.is-out .tj-car.is-red {
    transform: translateX(160%);
    opacity: 0;
}

.traffic-jam-board.is-solving,
.traffic-jam-board.is-making {
    pointer-events: none;
}

.traffic-jam-board.is-making {
    opacity: 0.55;
}

.traffic-jam-status.is-solved {
    color: var(--ak-success);
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .tj-car { transition: none; }
    .tj-car.is-hint::before { animation: none; box-shadow: 0 0 0 4px var(--ak-info); }
}
