/* Rattle Junction Express: the game's own overlay. Everything is scoped to .rj (the host element). */
.rj {
  --ink: #1A1A1A; --paper: #FFFDF7; --red: #E8452C; --yellow: #FFC531; --blue: #3A86FF; --green: #3BB273;
  --wob: 18px 22px 16px 24px / 22px 16px 24px 18px;
  position: relative; overflow: hidden; background: var(--paper); color: var(--ink);
  font-family: Nunito, "Trebuchet MS", system-ui, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.rj *, .rj *::before, .rj *::after { box-sizing: border-box; }
.rj [hidden] { display: none !important; }
.rj .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rj-stage { position: absolute; inset: 0; }
.rj-canvas { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
.rj-hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.rj-hud > * { pointer-events: auto; }
.rj-count {
  display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px; background: #fff;
  border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 0 3px 0 var(--ink);
  font: 700 26px/1 Fredoka, sans-serif; min-width: 92px; transform: rotate(-2deg);
}
.rj-ico { width: 28px; height: 28px; fill: currentColor; stroke: none; }
.rj-ico--crayon { width: 30px; height: 30px; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.rj-meter {
  flex: 1 1 auto; max-width: 360px; margin: 0 auto; padding: 7px 10px 6px; background: #fff;
  border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 0 3px 0 var(--ink); transform: rotate(0.6deg);
}
.rj-meter__slots { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.rj-meter__slots i {
  display: block; height: 16px; border: 2.5px solid var(--ink); border-radius: 6px 8px 5px 7px; background: #fff;
}
.rj-meter__slots i.is-on { background: var(--c); }
/* each crayon colour carries its own pattern so the meter never relies on colour alone */
.rj-meter__slots i.rj-pat--red { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.55) 0 3px, transparent 3px 7px); }
.rj-meter__slots i.rj-pat--yellow { background-image: radial-gradient(circle, rgba(26,26,26,.35) 1.6px, transparent 2px); background-size: 7px 7px; }
.rj-meter__slots i.rj-pat--blue { background-image: repeating-linear-gradient(90deg, rgba(255,255,255,.6) 0 2px, transparent 2px 6px); }
.rj-meter__slots i.rj-pat--green { background-image: radial-gradient(circle, rgba(255,255,255,.8) 1.5px, transparent 2px); background-size: 6px 6px; }
.rj-meter__stages { display: flex; justify-content: space-between; list-style: none; margin: 6px 2px 0; padding: 0; }
.rj-meter__stages li { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 2.5px dashed #b9b4a8; background: #fff; }
.rj-stage-ico { width: 22px; height: 22px; fill: none; stroke: #b9b4a8; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rj-meter__stages li.is-done { border: 2.5px solid var(--ink); background: var(--c); }
.rj-meter__stages li.is-done .rj-stage-ico { stroke: var(--ink); fill: rgba(255,255,255,.55); }
.rj-hud__btns { display: flex; gap: 8px; }
.rj-iconbtn {
  width: 52px; height: 52px; display: grid; place-items: center; padding: 0; cursor: pointer; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 0 3px 0 var(--ink);
}
.rj-iconbtn .rj-ico__line { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.rj-iconbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.rj button:focus-visible, .rj input:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }

.is-bump { animation: rj-bump .42s cubic-bezier(.3,1.6,.5,1); }
.is-lost { animation: rj-lost .5s ease-out; }
@keyframes rj-bump { 0% { transform: scale(1) } 35% { transform: scale(1.18) rotate(-3deg) } 100% { transform: scale(1) } }
@keyframes rj-lost { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-5px) } 60% { transform: translateX(4px) } }

/* ---------- banner ---------- */
.rj-banner {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); pointer-events: none;
  font: 700 clamp(34px, 8vw, 64px)/1.05 Fredoka, sans-serif; color: #fff; text-align: center; white-space: nowrap;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink), 3px 4px 0 var(--ink), -3px 4px 0 var(--ink);
  opacity: 0;
}
.rj-banner.is-bump { animation: rj-banner 1.5s cubic-bezier(.3,1.5,.5,1) forwards; }
@keyframes rj-banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-6deg) }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg) }
  30% { transform: translate(-50%, -50%) scale(1) rotate(-1deg) }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-1deg) }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(.96) rotate(-1deg) }
}

/* ---------- on-screen buttons ---------- */
.rj-pad {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
}
.rj-pad button {
  pointer-events: auto; width: 84px; height: 84px; display: grid; place-items: center; cursor: pointer; color: var(--ink);
  background: rgba(255,255,255,.92); border: 3.5px solid var(--ink); border-radius: var(--wob); box-shadow: 0 4px 0 var(--ink);
  touch-action: none;
}
.rj-pad button[data-a="jump"] { background: var(--yellow); }
.rj-pad .rj-ico { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.rj-pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- cards ---------- */
.rj-card {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: rgba(255, 253, 247, .55); touch-action: pan-y;
}
.rj-card__in {
  width: min(460px, 100%); text-align: center; padding: 20px 22px 22px; background: var(--paper);
  border: 4px solid var(--ink); border-radius: 28px 34px 26px 36px / 34px 26px 36px 28px; box-shadow: 0 6px 0 var(--ink);
  animation: rj-card-in .45s cubic-bezier(.3,1.4,.5,1);
}
@keyframes rj-card-in { from { opacity: 0; transform: translateY(24px) scale(.94) rotate(-1.5deg) } to { opacity: 1; transform: none } }
.rj-h { font: 700 clamp(28px, 7vw, 40px)/1.05 Fredoka, sans-serif; margin: 4px 0 6px; letter-spacing: .2px; }
.rj-lead { font-size: 19px; font-weight: 700; margin: 0 0 12px; }
.rj-start__art { width: min(240px, 60%); height: auto; display: block; margin: -6px auto 0; }
.rj-how { display: flex; justify-content: center; gap: 10px; list-style: none; padding: 0; margin: 0 0 6px; }
.rj-how li { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 14px; font-weight: 700; line-height: 1.2; }
.rj-how__ico { width: 40px; height: 40px; padding: 6px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; background: #fff; border: 2.5px solid var(--ink); border-radius: 50%; }
.rj-keys { font-size: 13px; color: #5b5750; margin: 2px 0 12px; }
.rj-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 58px; padding: 10px 26px; cursor: pointer;
  font: 700 24px/1 Fredoka, sans-serif; color: var(--ink); background: #fff;
  border: 4px solid var(--ink); border-radius: var(--wob); box-shadow: 0 5px 0 var(--ink); transition: transform .08s;
}
.rj-btn--go { background: var(--yellow); min-width: 220px; font-size: 28px; }
.rj-btn--go:disabled { background: #F3EFE4; color: #6d685e; font-size: 18px; cursor: progress; }
.rj-btn--plain { font-size: 19px; min-height: 52px; padding: 8px 18px; }
.rj-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.rj-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 14px; }
.rj-toggles { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 16px; font-weight: 700; font-size: 15px; }
.rj-toggles label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 32px; }
.rj-toggles input { width: 22px; height: 22px; accent-color: var(--green); }

.rj-end__kicker { font-weight: 800; font-size: 18px; margin: 0; color: #5b5750; }
.rj-end__h { font-size: clamp(30px, 7.6vw, 44px); }
.rj-end__coloured { font-weight: 700; font-size: 17px; margin: 0 0 6px; }
.rj-sticker { margin: 8px auto 0; }
.rj-ticket { width: min(300px, 86%); height: auto; filter: drop-shadow(0 5px 0 rgba(26,26,26,.18)); animation: rj-stick 0.9s .25s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes rj-stick { from { opacity: 0; transform: scale(.3) rotate(-25deg) } to { opacity: 1; transform: scale(1) rotate(-4deg) } }
.rj-sticker__label { margin: 4px 0 0; font-size: 17px; }

.rj--calm .is-bump, .rj--calm .is-lost, .rj--calm .rj-card__in, .rj--calm .rj-ticket { animation-duration: .01s; }
.rj--calm .rj-banner.is-bump { animation: rj-fade 1.5s linear forwards; }
@keyframes rj-fade { 0% { opacity: 0 } 15%, 80% { opacity: 1 } 100% { opacity: 0 } }
@media (prefers-reduced-motion: reduce) {
  .rj .is-bump, .rj .is-lost, .rj .rj-card__in, .rj .rj-ticket { animation-duration: .01s; }
  .rj .rj-banner.is-bump { animation: rj-fade 1.5s linear forwards; }
}

@media (max-width: 520px) {
  .rj-count { font-size: 22px; min-width: 76px; padding: 5px 10px 5px 6px; }
  .rj-iconbtn { width: 46px; height: 46px; }
  .rj-meter { padding: 5px 7px 5px; }
  .rj-meter__slots { gap: 3px; }
  .rj-meter__slots i { height: 13px; border-width: 2px; }
  .rj-meter__stages li { width: 24px; height: 24px; }
  .rj-stage-ico { width: 17px; height: 17px; }
  .rj-hud { gap: 7px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .rj-start__art { display: none; }
  .rj-card__in { padding: 14px 18px; }
}
