/* Next stop, Westlake: the driver's cab. */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.game-head {
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px var(--gutter) 18px;
  display: grid;
  gap: 10px;
}
.game-head h1 {
  font-size: clamp(34px, 9vw, 64px);
}
.game-head .lede {
  max-width: 60ch;
  color: var(--muted);
}

.game {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.cab {
  --cab: #22223b;
  --cab-hi: #34345a;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  grid-template-areas: "hud hud" "view view" "dash lever";
  column-gap: 8px;
  background: linear-gradient(180deg, var(--cab-hi), var(--cab) 30%);
  border-radius: 28px;
  padding: 10px;
  color: #fff6e5;
  box-shadow: 0 30px 60px -30px rgba(18, 20, 36, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
:root[data-theme="dark"] .cab {
  --cab: #0b0c18;
  --cab-hi: #1d2038;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cab {
    --cab: #0b0c18;
    --cab-hi: #1d2038;
  }
}

/* the HUD: a strip of mono readouts, like a cab display */
.hud {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 8px 12px 10px;
  font: 500 12px/1.3 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #cfd7e6;
}
.hud p {
  white-space: nowrap;
  min-width: 0;
}
@media (max-width: 759px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas: "next next mark" "speed speed speed" "time score riders";
    gap: 5px 10px;
    font-size: 11px;
  }
  .hud-next {
    grid-area: next;
  }
  .hud-mark {
    grid-area: mark;
  }
  .hud-speed {
    grid-area: speed;
  }
  .hud-time {
    grid-area: time;
  }
  .hud-score {
    grid-area: score;
    text-align: center;
  }
  .hud-riders {
    grid-area: riders;
  }
  .speedbar {
    max-width: none;
  }
}
.hud strong {
  font-weight: 500;
  color: #fff6e5;
}
.hud-next {
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-next strong {
  color: var(--yellow);
}
.hud-mark,
.hud-score,
.hud-riders {
  text-align: right;
}
.hud-speed {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hud-speed > strong {
  min-width: 2.2ch;
  text-align: right;
  font-size: 15px;
}
.speedbar {
  position: relative;
  flex: 1;
  min-width: 56px;
  max-width: 220px;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 246, 229, 0.12);
  overflow: hidden;
}
.speedbar b {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--door);
  border-radius: 4px;
}
.speedbar b.over {
  background: var(--orange);
}
.speedbar i {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  left: 77%;
  background: #fff6e5;
}
.hud-limit {
  color: #9aa3b8;
}
.hud-time strong.late {
  color: var(--orange);
}

/* the window */
.view {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #0b0c18;
  aspect-ratio: 4 / 3;
  box-shadow: inset 0 0 0 6px #0b0c18;
}
#stage {
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}
#stage:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: -6px;
}
.glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 20px;
  box-shadow: inset 0 0 0 7px #191a2c, inset 0 0 0 9px rgba(255, 255, 255, 0.07), inset 0 14px 40px rgba(0, 0, 0, 0.35);
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.1) 0 18%, transparent 18% 22%, rgba(255, 255, 255, 0.05) 22% 26%, transparent 26%);
}
:root[data-theme="dark"] .glass {
  background: radial-gradient(70% 55% at 18% 92%, rgba(255, 214, 120, 0.12), transparent 70%), linear-gradient(115deg, rgba(255, 255, 255, 0.05) 0 18%, transparent 18%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .glass {
    background: radial-gradient(70% 55% at 18% 92%, rgba(255, 214, 120, 0.12), transparent 70%), linear-gradient(115deg, rgba(255, 255, 255, 0.05) 0 18%, transparent 18%);
  }
}

.toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -10px);
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(11, 12, 24, 0.86);
  color: #fff6e5;
  font: 600 14px/1.35 var(--text);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.warn {
  background: rgba(242, 112, 47, 0.95);
  color: #22223b;
}

/* the cards sit over the window; on a phone the window is too small, so they cover the whole cab */
.card-layer {
  position: absolute;
  inset: 0;
  grid-area: 1 / 1 / -1 / -1;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 12px;
  pointer-events: none;
}
.card-layer .card {
  pointer-events: auto;
}
.card {
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border-radius: 18px;
  padding: 16px 18px 18px;
  box-shadow: 0 20px 40px -18px rgba(0, 0, 0, 0.6);
  display: grid;
  gap: 8px;
}
.card[hidden] {
  display: none;
}
.card .eyebrow {
  color: #1a7a7a;
}
.card h3 {
  font-size: 24px;
}
.card ol {
  margin: 0;
  padding-left: 1.2em;
  display: grid;
  gap: 3px;
  font-size: 14.5px;
  line-height: 1.4;
}
.card .best,
.card .result-best {
  font: 500 12.5px/1.3 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #55556d;
}
.card .btn {
  justify-self: start;
}
.card .btn-line {
  color: var(--ink);
  border-color: var(--ink);
}
.card .btn-line:hover {
  background: var(--ink);
  color: var(--cream);
}
.tally {
  margin: 4px 0 0;
  display: grid;
  gap: 2px;
  font-size: 15px;
}
.tally div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(34, 34, 59, 0.2);
  padding: 3px 0;
}
.tally dd {
  margin: 0;
  font: 500 15px/1.3 var(--mono);
}
.tally .sum {
  border-bottom: 0;
  font-weight: 700;
}
.tally .sum dd {
  font-size: 18px;
  color: #b4471b;
}
.result-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* the dashboard: coffee, doors, lever */
.hud {
  grid-area: hud;
}
.view {
  grid-area: view;
}
.dash {
  grid-area: dash;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 4px 4px;
}
.cup-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cup {
  width: 76px;
  height: 76px;
  flex: none;
}
.cup .mug {
  fill: none;
  stroke: #fff6e5;
  stroke-width: 3;
  stroke-linejoin: round;
}
.cup .saucer {
  fill: #3a3a5c;
}
.cup .coffee {
  fill: #6b3b22;
}
.cup .crema {
  fill: #c98b55;
}
.cup .steam {
  fill: none;
  stroke: rgba(255, 246, 229, 0.45);
  stroke-width: 2;
  stroke-linecap: round;
  animation: steam 2.6s ease-in-out infinite;
}
.cup .splash circle {
  fill: #8a5030;
  opacity: 0;
}
.cup.spilt .splash circle {
  animation: splash 0.8s ease-out;
}
.cup.spilt .splash circle:nth-child(2) {
  animation-delay: 0.05s;
}
.cup.spilt .splash circle:nth-child(3) {
  animation-delay: 0.1s;
}
@keyframes steam {
  0%,
  100% {
    opacity: 0.2;
    transform: translateY(2px);
  }
  50% {
    opacity: 0.8;
    transform: translateY(-3px);
  }
}
@keyframes splash {
  0% {
    opacity: 1;
    transform: translate(0, 0);
  }
  100% {
    opacity: 0;
    transform: translate(0, -14px) scale(0.6);
  }
}
.paused-game .cup .steam {
  animation-play-state: paused;
}
.cup-label {
  font: 500 11.5px/1.35 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #cfd7e6;
}
.cup-label strong {
  display: block;
  font-weight: 500;
  color: #fff6e5;
  font-size: 13px;
}
.cup-label strong.spilt {
  color: var(--orange);
}

.doors-btn {
  min-height: 56px;
  padding: 10px 16px;
  background: #34345a;
  border-color: #4a4a72;
  color: #fff6e5;
  border-radius: 16px;
}
.doors-btn:not(:disabled) {
  background: var(--door);
  border-color: var(--door);
  color: #0d3a24;
  box-shadow: 0 0 0 3px rgba(63, 191, 127, 0.3), 0 0 18px rgba(63, 191, 127, 0.55);
}
.doors-btn:disabled {
  cursor: default;
  opacity: 0.75;
}
.doors-icon {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 4px;
  background: linear-gradient(90deg, transparent 46%, currentColor 46% 54%, transparent 54%);
}

/* the lever: forward (up) for power, back (down) for brake */
.lever-box {
  grid-area: lever;
  justify-self: end;
  padding-top: 10px;
}
.lever {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 190px;
  touch-action: none;
  cursor: grab;
  border-radius: 14px;
  padding: 4px;
}
.lever:focus-visible {
  outline-offset: 2px;
}
.lever-words {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9aa3b8;
  padding: 8px 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  flex-direction: row-reverse;
}
.lever-track {
  position: relative;
  width: 44px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(63, 191, 127, 0.35), rgba(255, 246, 229, 0.08) 45% 55%, rgba(242, 112, 47, 0.4));
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}
.lever-notches {
  position: absolute;
  inset: 12px 0;
  background: repeating-linear-gradient(180deg, rgba(255, 246, 229, 0.35) 0 2px, transparent 2px calc(12.5% - 0.25px));
  -webkit-mask: linear-gradient(90deg, transparent 30%, #000 30% 70%, transparent 70%);
  mask: linear-gradient(90deg, transparent 30%, #000 30% 70%, transparent 70%);
}
.lever-handle {
  position: absolute;
  left: -6px;
  right: -6px;
  top: 50%;
  height: 30px;
  margin-top: -15px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff6e5, #d9cfbb);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  transition: top 0.08s ease-out;
}
.lever-handle::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 13px;
  height: 4px;
  border-radius: 2px;
  background: #22223b;
}
.lever[data-zone="power"] .lever-handle::after {
  background: var(--green);
}
.lever[data-zone="brake"] .lever-handle::after {
  background: var(--orange);
}

@media (max-width: 759px) {
  .dash {
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: 10px;
  }
  .cup {
    width: 62px;
    height: 62px;
  }
  .doors-btn {
    justify-content: center;
  }
}

.game-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 12px 2px 0;
}
.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font: 600 14px/1 var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--door);
  border-color: var(--door);
  color: #0d3a24;
}
.keys {
  font-size: 13.5px;
  color: var(--muted);
}
@media (hover: none) and (pointer: coarse) {
  .keys {
    display: none;
  }
}

/* the postcard */
.postcard-box,
.scoring {
  max-width: var(--max);
  margin: 0 auto;
  padding: 44px var(--gutter) 0;
}
.postcard-box h2,
.scoring h2 {
  font-size: clamp(24px, 5vw, 34px);
  margin-bottom: 16px;
}
.postcard {
  position: relative;
  max-width: 560px;
  border-radius: 6px;
  padding: 22px 22px 24px;
  background: repeating-linear-gradient(135deg, #f2702f 0 10px, #fff6e5 10px 20px, #1f8a8a 20px 30px, #fff6e5 30px 40px);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.postcard > * {
  position: relative;
}
.postcard::before {
  content: "";
  position: absolute;
  inset: 8px;
  background: #fffaf0;
  border-radius: 2px;
}
.postcard .stamp {
  position: absolute;
  right: 22px;
  top: 22px;
  width: 58px;
  height: 66px;
  display: grid;
  place-items: center;
  background: #1f8a8a;
  color: #fff6e5;
  border: 3px dotted #fffaf0;
  outline: 2px solid #1f8a8a;
  font: 800 15px/1 var(--display);
}
.pc-greet {
  font: 800 22px/1.1 var(--display);
  font-stretch: 112%;
  margin: 2px 80px 10px 0;
}
.pc-greet + p {
  margin-right: 72px;
}
.pc-body p + p {
  margin-bottom: 12px;
}
.pc-body .maps-link {
  color: #1a7a7a;
}
.postcard.locked .pc-body {
  filter: blur(5px);
  opacity: 0.55;
  user-select: none;
}
.postcard.locked .pc-body a {
  visibility: hidden;
}
.pc-lock {
  display: none;
}
.postcard.locked .pc-lock {
  display: block;
  position: absolute;
  inset: 8px;
  z-index: 2;
  place-content: center;
  text-align: center;
  font: 700 17px/1.3 var(--display);
  padding: 0 70px;
}
.postcard.locked .pc-lock {
  display: grid;
}

.scoring ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  max-width: 70ch;
}
.scoring li {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.scoring li strong {
  display: block;
  font: 700 15px/1.3 var(--display);
}
.scoring .note {
  margin: 16px 0 48px;
  color: var(--muted);
  max-width: 70ch;
}

@media (min-width: 760px) {
  .hud {
    grid-template-columns: 1.4fr 1fr 1.5fr 1fr 0.8fr 0.8fr;
    font-size: 12.5px;
  }
  .hud-mark,
  .hud-score,
  .hud-riders {
    text-align: left;
  }
  .view {
    aspect-ratio: 16 / 8;
  }
  .cab {
    grid-template-columns: minmax(0, 1fr) 120px;
    grid-template-areas: "hud hud" "view lever" "dash lever";
    column-gap: 12px;
    padding: 12px;
  }
  .view {
    aspect-ratio: 16 / 8.2;
  }
  .card-layer {
    grid-area: view;
  }
  .dash {
    gap: 24px;
    padding: 12px 12px 4px;
  }
  .lever-box {
    align-self: center;
    justify-self: center;
    padding-top: 0;
  }
  .lever {
    height: min(320px, 34vw);
  }
  .card h3 {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lever-handle {
    transition: none;
  }
}
