/* MONSTER MASH MOTORS — The Mud Wash (site/src/js/games/wash.js).
   Arena-bill style: poster paper, chunky black-outlined buttons with hard
   offset shadows, Bangers for labels and sound words, Lexend for anything a
   grown-up reads. Big picture buttons (64 px and up), visible focus, works
   from 320 px wide, portrait and landscape. Everything is scoped to .mw. */

@font-face { font-family: 'Anton'; src: url('../fonts/Anton-Regular.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Bangers'; src: url('../fonts/Bangers-Regular.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Lexend'; src: url('../fonts/Lexend-Variable.woff2') format('woff2'); font-weight: 300 800; font-display: swap; }

.mw {
  --mw-paper: #F4EBDD;
  --mw-paper-hi: #FFF9EE;
  --mw-key: #15110F;
  --mw-orange: #FB652D;
  --mw-blue: #6AB9D7;
  --mw-blue-deep: #1E6A96;
  --mw-gold: #FFE14A;
  --mw-green: #35C24A;
  --mw-stone: #8A7D6D;
  --mw-shadow: 4px 4px 0 var(--mw-key);
  --mw-radius: 14px;
  --mw-bangers: 'Bangers', 'Anton', Impact, sans-serif;
  --mw-anton: 'Anton', Impact, sans-serif;
  --mw-text: 'Lexend', system-ui, sans-serif;
  position: relative;
  display: grid;
  grid-template-areas: "bar" "view" "tools" "how";
  grid-template-rows: auto minmax(220px, 1fr) auto auto;
  gap: 8px;
  height: clamp(520px, calc(100svh - var(--mw-offset, 76px)), 980px);
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px;
  box-sizing: border-box;
  color: var(--mw-key);
  font-family: var(--mw-text);
  background:
    radial-gradient(circle at 1px 1px, rgba(21, 17, 15, 0.07) 1px, transparent 1.6px) 0 0 / 7px 7px,
    var(--mw-paper);
  border: 3px solid var(--mw-key);
  border-radius: 18px;
  box-shadow: 6px 6px 0 var(--mw-key);
  -webkit-tap-highlight-color: transparent;
}
.mw *, .mw *::before, .mw *::after { box-sizing: border-box; }
.mw-vh { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mw-ico { display: block; width: 100%; height: 100%; overflow: visible; }

/* ------------------------------------------------------------ buttons */
:where(.mw) button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.mw-btn, .mw-big, .mw-tool, .mw-go, .mw-pick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  min-width: 56px;
  padding: 6px 12px;
  border: 3px solid var(--mw-key);
  border-radius: var(--mw-radius);
  background: var(--mw-paper-hi);
  box-shadow: var(--mw-shadow);
  color: var(--mw-key);
  font-family: var(--mw-text);
  font-weight: 700;
  font-size: 19px;
  line-height: 1;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.mw-btn .mw-ico, .mw-big .mw-ico { width: 34px; height: 34px; flex: none; }
.mw-btn:active, .mw-big:active, .mw-tool:active, .mw-go:active, .mw-pick:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--mw-key); }
.mw-big { min-height: 72px; padding: 8px 20px; font-family: var(--mw-bangers); font-weight: 400; font-size: 30px; letter-spacing: 0.04em; background: var(--mw-gold); }
.mw-big .mw-ico { width: 44px; height: 44px; }
.mw button:focus-visible, .mw-canvas:focus-visible {
  outline: 5px solid var(--mw-blue-deep);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--mw-paper-hi), var(--mw-shadow);
}

/* ---------------------------------------------------------------- bar */
.mw-bar {
  grid-area: bar;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "trucks meter stars pause";
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.mw-btn-trucks { grid-area: trucks; }
.mw-btn-pause { grid-area: pause; }
.mw-btn-trucks span, .mw-btn-pause span { display: none; }
@media (min-width: 760px) { .mw-btn-trucks span, .mw-btn-pause span { display: inline; } }
.mw-btn-pause .mw-ico { width: 28px; height: 28px; }
/* Narrow screens: the meter gets a whole row of its own. */
@media (max-width: 599px) {
  .mw-bar { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "trucks stars pause" "meter meter meter"; row-gap: 6px; }
  .mw-stars { justify-self: center; }
}

.mw-meter {
  grid-area: meter;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.mw-meter-ico { width: 34px; height: 34px; flex: none; }
.mw-meter-track {
  position: relative;
  flex: 1;
  height: 34px;
  min-width: 60px;
  border: 3px solid var(--mw-key);
  border-radius: 999px;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(21, 17, 15, 0.16) 1.2px, transparent 1.8px) 0 0 / 6px 6px,
    var(--mw-paper-hi);
  box-shadow: 3px 3px 0 var(--mw-key);
}
.mw-meter-fill {
  --mw-fill: var(--mw-green);
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background:
    repeating-linear-gradient(-45deg, rgba(255, 249, 238, 0.28) 0 7px, transparent 7px 16px),
    var(--mw-fill);
  border-right: 3px solid var(--mw-key);
  transition: transform 0.18s linear;
}
.mw-meter-tick {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--mw-key);
  opacity: 0.35;
  border-radius: 2px;
}
.mw-meter-num {
  flex: none;
  min-width: 3.1em;
  text-align: right;
  font-family: var(--mw-bangers);
  font-size: 26px;
  -webkit-text-stroke: 1px var(--mw-key);
  color: var(--mw-paper-hi);
  text-shadow: 2px 2px 0 var(--mw-orange), 3px 3px 0 var(--mw-key);
}
.mw-meter.is-pop .mw-meter-track { animation: mw-pop 0.5s ease; }

.mw-stars {
  grid-area: stars;
  display: flex;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  flex: none;
}
.mw-star { position: relative; width: 40px; height: 48px; }
.mw-star-ico { position: absolute; left: 2px; top: 0; width: 36px; height: 36px; }
.mw-star-ico .mw-ico { position: absolute; inset: 0; }
.mw-star-ico .mw-ico-star:not(.off) { opacity: 0; transform: scale(0.4); transition: opacity 0.2s, transform 0.3s cubic-bezier(.3, 1.8, .5, 1); }
.mw-star.is-on .mw-star-ico .mw-ico-star:not(.off) { opacity: 1; transform: scale(1); }
.mw-star-tool { position: absolute; right: -2px; bottom: 0; width: 20px; height: 20px; }
.mw-star.is-pop .mw-star-ico { animation: mw-pop 0.6s ease; }

/* --------------------------------------------------------------- view */
.mw-view {
  grid-area: view;
  position: relative;
  min-height: 0;
  border: 3px solid var(--mw-key);
  border-radius: var(--mw-radius);
  overflow: hidden;
  background: var(--mw-paper);
}
.mw-canvas, .mw-bg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.mw-bg { pointer-events: none; }
.mw-canvas:focus-visible { outline-offset: -6px; }
.mw[data-state="wash"] .mw-view.is-hovering .mw-canvas,
.mw[data-state="clean"] .mw-view.is-hovering .mw-canvas { cursor: none; }

.mw-say {
  position: absolute;
  z-index: 3;
  max-width: min(78%, 330px);
  padding: 10px 14px;
  border: 3px solid var(--mw-key);
  border-radius: 18px;
  background: var(--mw-paper-hi);
  box-shadow: var(--mw-shadow);
  pointer-events: none;
  animation: mw-in 0.25s ease;
}
.mw-say p { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.3; }
.mw-say::after {
  content: "";
  position: absolute;
  left: var(--tail, 30px);
  bottom: -14px;
  width: 22px;
  height: 22px;
  background: var(--mw-paper-hi);
  border-right: 3px solid var(--mw-key);
  border-bottom: 3px solid var(--mw-key);
  transform: skewX(-20deg) rotate(45deg);
}

.mw-go {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  min-height: 76px;
  padding: 8px 22px 8px 14px;
  font-family: var(--mw-bangers);
  font-weight: 400;
  font-size: 40px;
  letter-spacing: 0.04em;
  background: var(--mw-green);
  color: var(--mw-paper-hi);
  -webkit-text-stroke: 1.5px var(--mw-key);
  text-shadow: 3px 3px 0 var(--mw-key);
  animation: mw-breathe 1.6s ease-in-out infinite;
}
.mw-go .mw-ico { width: 48px; height: 48px; }

/* ------------------------------------------------------------- panels */
.mw-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
  overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(21, 17, 15, 0.08) 1px, transparent 1.6px) 0 0 / 7px 7px,
    rgba(244, 235, 221, 0.97);
}
.mw-panel[hidden], .mw-say[hidden], .mw-go[hidden], .mw-toast[hidden], .mw-after[hidden], .mw-tools[hidden], .mw-loading[hidden] { display: none; }
.mw-panel-title {
  margin: 4px 0 2px;
  font-family: var(--mw-anton);
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 3px 2px 0 var(--mw-blue), -2px -1px 0 var(--mw-orange);
}
.mw-panel-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.mw-paused { justify-content: center; }
.mw-picker { z-index: 8; border-radius: 15px; }

.mw-pick-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 980px;
  margin: 0;
  padding: 0 4px 8px;
  list-style: none;
}
@media (min-width: 640px) { .mw-pick-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.mw-pick-item.is-featured { grid-column: 1 / -1; }
.mw-pick {
  position: relative;
  flex-direction: column;
  width: 100%;
  min-height: 128px;
  padding: 8px 8px 10px;
  gap: 2px;
  background: var(--mw-paper-hi);
}
.mw-pick-item.is-featured .mw-pick { flex-direction: row; min-height: 150px; gap: 14px; background: #E9F4DF; }
.mw-pick-pic { display: block; width: 100%; max-width: 230px; height: auto; aspect-ratio: 16 / 12; opacity: 0; transition: opacity 0.3s; }
.mw-pick-pic.is-ready { opacity: 1; }
.mw-pick-item.is-featured .mw-pick-pic { width: 52%; max-width: 330px; }
.mw-pick-name { font-family: var(--mw-anton); font-size: 24px; letter-spacing: 0.02em; text-transform: uppercase; }
.mw-pick-item.is-featured .mw-pick-name { font-size: 34px; }
.mw-pick-tag {
  display: inline-block;
  padding: 3px 9px 4px;
  border: 2px solid var(--mw-key);
  border-radius: 999px;
  background: var(--mw-gold);
  font-size: 17px;
  transform: rotate(-3deg);
}
.mw-pick-item.is-featured .mw-pick-tag { position: absolute; top: 8px; left: 8px; font-size: 22px; background: var(--mw-orange); color: var(--mw-paper-hi); -webkit-text-stroke: 0.8px var(--mw-key); }
.mw-pick-item.is-featured .mw-pick > span:not(.mw-pick-tag) { display: block; }
.mw-pick-stars { display: flex; gap: 2px; height: 22px; }
.mw-pick-stars .mw-ico { width: 22px; height: 22px; }
/* Wide screens: Mudslide big on the left, the other six in two rows beside him. */
@media (min-width: 980px) {
  .mw-pick-list { grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: 1180px; }
  .mw-pick-item.is-featured { grid-column: span 2; grid-row: span 2; }
  .mw-pick-item.is-featured .mw-pick { flex-direction: column; height: 100%; gap: 6px; }
  .mw-pick-item.is-featured .mw-pick-pic { width: 92%; max-width: 440px; }
  .mw-pick-item.is-featured .mw-pick-name { font-size: 40px; }
}
/* Short landscape screens: everyone on one or two rows. */
@media (orientation: landscape) and (max-height: 560px) {
  .mw-pick-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mw-pick-item.is-featured { grid-column: span 2; grid-row: auto; }
  .mw-pick-item.is-featured .mw-pick { flex-direction: row; height: auto; min-height: 120px; }
  .mw-pick-item.is-featured .mw-pick-pic { width: 52%; max-width: 330px; }
  .mw-pick { min-height: 104px; }
  .mw-pick-name { font-size: 20px; }
  .mw-pick-item.is-featured .mw-pick-name { font-size: 26px; }
  .mw-panel-title { font-size: 26px; margin: 0; }
}

.mw-toast {
  position: absolute;
  z-index: 6;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: min(90%, 300px);
  padding: 8px 14px 8px 58px;
  border: 3px solid var(--mw-key);
  border-radius: 16px;
  background: var(--mw-gold);
  box-shadow: var(--mw-shadow);
  font-size: 17px;
  text-align: center;
  pointer-events: none;
  animation: mw-in 0.3s ease;
}
.mw-toast b { font-family: var(--mw-bangers); font-size: 24px; font-weight: 400; letter-spacing: 0.04em; }
.mw-toast small { font-size: 14px; }
.mw-toast-burst {
  position: absolute;
  left: 10px;
  top: 50%;
  width: 38px;
  height: 38px;
  margin-top: -19px;
  background: var(--mw-orange);
  border: 3px solid var(--mw-key);
  clip-path: polygon(50% 0, 61% 30%, 95% 25%, 72% 50%, 95% 75%, 61% 70%, 50% 100%, 39% 70%, 5% 75%, 28% 50%, 5% 25%, 39% 30%);
}

.mw-loading { position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(244, 235, 221, 0.6); }
.mw-loading span { width: 22px; height: 22px; border: 3px solid var(--mw-key); border-radius: 50%; background: var(--mw-paper-hi); animation: mw-bob 0.9s ease-in-out infinite; }
.mw-loading span:nth-child(2) { animation-delay: 0.15s; }
.mw-loading span:nth-child(3) { animation-delay: 0.3s; }

/* -------------------------------------------------------------- tools */
.mw-tools {
  grid-area: tools;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 520px) { .mw-tools { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.mw-tool {
  position: relative;
  flex-direction: column;
  gap: 2px;
  min-height: 76px;
  padding: 6px 4px 6px;
  font-size: 18px;
}
.mw-tool-ico { width: 44px; height: 44px; }
.mw-tool kbd {
  position: absolute;
  top: 3px;
  left: 6px;
  font-family: var(--mw-text);
  font-size: 12px;
  font-weight: 700;
  opacity: 0.55;
}
.mw-tool[aria-pressed="true"] {
  background: var(--mw-gold);
  transform: translate(-2px, -3px);
  box-shadow: 6px 7px 0 var(--mw-key);
}
.mw-tool[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -14px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  background: var(--mw-orange);
  border: 3px solid var(--mw-key);
  border-radius: 50%;
}
.mw-tool-no { position: absolute; right: 4px; top: 4px; width: 26px; height: 26px; display: none; }
.mw-tool.is-locked { background: #E4DCCD; color: #6C645B; }
.mw-tool.is-locked .mw-tool-ico { opacity: 0.45; filter: grayscale(0.7); }
.mw-tool.is-locked .mw-tool-no { display: block; }
.mw-tool.is-hint { animation: mw-wiggle 0.9s ease-in-out 3; background: #FFF3B8; }
.mw-tool.is-nudge { animation: mw-shake 0.45s ease; }

.mw-after {
  grid-area: tools;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}
.mw-after-stars { display: flex; gap: 4px; margin: 0 6px 0 0; }
.mw-after-star { width: 52px; height: 52px; }
.mw-after-star.is-on { animation: mw-pop 0.5s ease both; animation-delay: calc(var(--i) * 0.28s + 0.2s); }
.mw-next-pic { width: 76px; height: 46px; object-fit: contain; }

.mw-how {
  grid-area: how;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin: 0;
  font-size: 16px;
}
.mw-how-step { display: inline-flex; align-items: center; gap: 4px; }
.mw-how-step .mw-ico { width: 26px; height: 26px; }
.mw-how-step b { font-weight: 600; }

.mw-fail { padding: 16px; border: 3px solid #15110F; border-radius: 14px; background: #FFF9EE; font-size: 18px; }

/* ------------------------------------------------------------- states */
/* The truck picker is a page of its own: in the flow and as tall as it
   needs, so a small phone scrolls the page, never a box inside the game. */
.mw[data-state="picker"] {
  height: auto;
  min-height: clamp(520px, calc(100svh - var(--mw-offset, 76px)), 980px);
  grid-template-areas: "pick";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto;
}
.mw[data-state="picker"] > .mw-bar,
.mw[data-state="picker"] > .mw-view,
.mw[data-state="picker"] > .mw-tools,
.mw[data-state="picker"] > .mw-after,
.mw[data-state="picker"] > .mw-how { display: none; }
.mw[data-state="picker"] > .mw-picker { position: relative; inset: auto; grid-area: pick; overflow: visible; justify-content: center; }
.mw[data-state="loading"] .mw-tools { visibility: hidden; }
.mw[data-state="arrive"] .mw-tools,
.mw[data-state="exit"] .mw-tools,
.mw[data-state="outside"] .mw-tools { opacity: 0.55; pointer-events: none; }

/* A phone on its side: tools in a column beside the bay. */
@media (orientation: landscape) and (max-height: 620px) and (min-width: 560px) {
  .mw {
    grid-template-areas: "bar tools" "view tools" "how tools";
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100svh - 12px);
    min-height: 300px;
  }
  .mw-tools { grid-template-columns: repeat(2, 78px); align-content: center; }
  .mw-btn-trucks span, .mw-btn-pause span { display: none; }
  .mw-tool { min-height: 72px; }
  .mw-after { flex-direction: column; flex-wrap: nowrap; justify-content: center; width: 200px; }
  .mw-after .mw-big { font-size: 22px; min-height: 64px; }
  .mw-how { font-size: 14px; }
  .mw-how-step .mw-ico { width: 20px; height: 20px; }
  .mw[data-state="picker"] { min-height: 0; }
}
@media (max-width: 380px) {
  .mw { padding: 6px; gap: 6px; border-width: 2px; box-shadow: 4px 4px 0 var(--mw-key); }
  .mw-btn, .mw-tool { font-size: 16px; }
  .mw-meter-num { font-size: 21px; min-width: 2.6em; }
  .mw-star { width: 30px; height: 40px; }
  .mw-star-ico { width: 28px; height: 28px; }
  .mw-star-tool { width: 16px; height: 16px; }
  .mw-meter-ico { display: none; }
  .mw-how { font-size: 14px; gap: 2px 10px; }
  .mw-pick-name { font-size: 20px; }
  .mw-pick-item.is-featured .mw-pick-name { font-size: 26px; }
  .mw-big { font-size: 24px; padding: 8px 14px; }
}

/* ---------------------------------------------------------- animation */
@keyframes mw-pop { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 70% { transform: scale(0.96); } 100% { transform: scale(1); } }
@keyframes mw-in { from { opacity: 0; transform: translateY(6px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes mw-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes mw-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes mw-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes mw-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.mw-toast[hidden] { display: none; }
.mw.is-reduced *, .mw.is-reduced *::before, .mw.is-reduced *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .mw *, .mw *::before, .mw *::after { animation: none !important; transition: none !important; }
}
