/* Fill the iframe or window, never scroll or zoom the host page. */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2b3a2c;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* The playfield. main.js letterboxes it if the frame is extremely wide or tall. */
#stage {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

/* ---------- Menu overlay (tip card, results, level select) ---------- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 34px 16px 16px; /* room for the ribbon on tall cards */
  box-sizing: border-box;
  background: rgba(20, 28, 34, 0.45);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  color: #26313a;
  overflow-y: auto;
}
#overlay[hidden] { display: none; }

#overlay .card {
  position: relative;
  margin: auto; /* centers when it fits, scrolls from the top when it doesn't */
  flex-shrink: 0;
  width: min(460px, 100%);
  background: #fffaf0;
  border: 4px solid #26313a;
  border-radius: 24px;
  padding: 44px 28px 18px;
  text-align: center;
  box-shadow: 0 8px 0 #26313a;
  box-sizing: border-box;
}
#overlay .card.wide { width: min(760px, 100%); }

/* Ribbon banner title */
#overlay .ribbon {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: #f28c28;
  color: #fff;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.5px;
  padding: 8px 34px;
  white-space: nowrap;
  border: 4px solid #26313a;
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 50%, 100% 100%, 0 100%, 14px 50%);
}
#overlay .ribbon.win { background: #3fae55; }
#overlay .ribbon.lose { background: #e5483b; }

#overlay h1 { margin: 4px 0 8px; font-size: 26px; font-weight: 900; }
#overlay h2 { margin: 18px 0 8px; font-size: 17px; font-weight: 800; text-align: left; color: #4a5866; }
#overlay .maneuver {
  margin: 8px 0 4px;
  padding: 8px 12px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
  color: #26313a;
  background: #fdf1d8;
  border-left: 5px solid #f28c28;
  border-radius: 8px;
  text-align: left;
}
#overlay .assist { margin: 12px 0 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 10px; }
#overlay .assist .assist-label { font-weight: 800; font-size: 15px; color: #4a5866; }
#overlay .assist small { flex-basis: 100%; font-size: 13px; color: #6f7c86; }
#overlay .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1f3a27;
  color: #fbf3e6;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
#overlay .badge.mini { position: absolute; top: 6px; right: 6px; padding: 1px 6px; font-size: 10px; }
#overlay .spotter-label { display: block; font-size: 11px; font-weight: 900; letter-spacing: 0.6px; color: #c45f10; text-transform: uppercase; margin-bottom: 2px; }
#overlay .tip { font-size: 18px; font-weight: 600; line-height: 1.35; margin: 6px 0 14px; }
#overlay .par { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 15px; color: #4a5866; }
#overlay .best { margin-top: 10px; font-size: 15px; color: #4a5866; display: flex; gap: 8px; justify-content: center; align-items: center; }
#overlay .hint { margin: 12px 0 0; font-size: 13px; color: #8a96a0; }
#overlay .note { margin: 8px 0 0; font-size: 14px; color: #8a6a20; font-weight: 700; }
#overlay .note.good { color: #2f8f45; }

#overlay .buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
#overlay .btn {
  min-width: 120px;
  min-height: 56px;
  padding: 0 22px;
  font: inherit;
  font-size: 19px;
  font-weight: 900;
  color: #26313a;
  background: #fff;
  border: 4px solid #26313a;
  border-radius: 16px;
  box-shadow: 0 5px 0 #26313a;
  cursor: pointer;
}
#overlay .btn.primary { background: #f28c28; color: #fff; }
#overlay .btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #26313a; }
#overlay .btn:disabled { opacity: 0.45; cursor: default; }
#overlay .btn:focus-visible { outline: 3px solid #3fe0ff; outline-offset: 2px; }

#overlay .stars { display: flex; gap: 6px; justify-content: center; }
#overlay .stars.big { font-size: 54px; margin: 4px 0 6px; }
#overlay .stars.small { font-size: 18px; gap: 2px; }
#overlay .star { color: #d8d2c4; line-height: 1; }
#overlay .star.on { color: #f2c230; text-shadow: 0 2px 0 #b8860b; }

#overlay table.stats { margin: 8px auto 0; border-collapse: collapse; font-size: 18px; }
#overlay table.stats td { padding: 4px 12px; text-align: left; }
#overlay table.stats td.ok { color: #2f8f45; font-weight: 900; }
#overlay table.stats td.miss { color: #c0392b; font-weight: 900; }
#overlay table.stats td.parcol { color: #8a96a0; font-size: 15px; }

#overlay .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
#overlay .level {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 84px;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  color: #26313a;
  background: #fff;
  border: 3px solid #26313a;
  border-radius: 14px;
  box-shadow: 0 4px 0 #26313a;
  cursor: pointer;
}
#overlay .level .num {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #26313a;
  color: #fff;
  font-weight: 900;
  font-size: 15px;
}
#overlay .level .name { font-weight: 800; font-size: 16px; }
#overlay .level.locked { opacity: 0.5; cursor: default; }
#overlay .level:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #26313a; }

/* Debug level jump menu (?debug=1) */
#debugJump, #debugRec {
  position: fixed;
  top: 64px;
  left: 14px;
  z-index: 5;
  font: 13px ui-monospace, Consolas, monospace;
  padding: 4px;
}
#debugRec { left: 200px; }

/* Results / fail sit low so the parked rig stays visible */
#overlay.low { background: rgba(20, 28, 34, 0.2); padding-bottom: 24px; }
#overlay.low .card { margin: auto auto 0; }
#overlay.title { background: rgba(20, 28, 34, 0.35); }

#overlay .card.narrow { width: min(340px, 100%); }
#overlay .menu { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
#overlay .menu .row { display: flex; gap: 12px; }
#overlay .menu .row .btn { flex: 1; min-width: 0; }
#overlay .btn small { font-size: 12px; font-weight: 700; opacity: 0.7; }
#overlay .btn.danger { background: #e5483b; color: #fff; }
#overlay .rig { margin: -4px 0 6px; font-size: 15px; font-weight: 700; color: #8a6a20; }
/* Tip card rig picker (garage rigs) */
#overlay .rig-pick { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 8px; margin: -4px 0 6px; }
#overlay .rig-pick .rig { margin: 0; min-width: 0; }
#overlay .rig-pick .nav-btn.small { width: 34px; height: 34px; font-size: 24px; flex: none; }
#overlay .rig-pick .rig-status { flex-basis: 100%; font-size: 13px; font-weight: 600; color: #6f7c86; }
#overlay .rig-pick .rig-status.bad { color: #c0392b; font-weight: 800; }
#overlay .rig-pick.unfit .rig { color: #9aa3ab; text-decoration: line-through; }
#overlay .rules { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
#overlay .rules span { background: #ffe6c7; color: #8a4b0f; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 800; }
#overlay h2 small { display: block; font-size: 13px; font-weight: 600; color: #8a96a0; }
#overlay .select-head { text-align: right; font-weight: 900; color: #b8860b; margin-top: -10px; }

/* Title card */
#overlay .title-card { width: min(420px, 100%); padding-top: 28px; }
#overlay .logo { line-height: 0.9; margin: 6px 0 4px; }
#overlay .logo-top { font-size: 30px; font-weight: 900; letter-spacing: 4px; color: #26313a; }
#overlay .logo-big {
  font-size: 92px;
  font-weight: 900;
  color: #f28c28;
  text-shadow: 0 5px 0 #26313a;
  -webkit-text-stroke: 3px #26313a;
}
#overlay .tagline { margin: 10px 0 14px; font-size: 15px; font-weight: 600; color: #4a5866; }
#overlay .icon-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 48px;
  height: 48px;
  font-size: 22px;
  background: #fff;
  border: 3px solid #26313a;
  border-radius: 14px;
  cursor: pointer;
}

/* Settings */
#overlay .settings .setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 2px dashed #e6dccb;
  text-align: left;
}
#overlay .settings .label { font-weight: 800; font-size: 16px; }
#overlay .settings .label small { display: block; font-weight: 600; font-size: 12px; color: #8a96a0; }
#overlay .seg { display: flex; flex-shrink: 0; border: 3px solid #26313a; border-radius: 12px; overflow: hidden; }
#overlay .seg-btn {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  color: #26313a;
  background: #fff;
  border: 0;
  border-left: 3px solid #26313a;
  cursor: pointer;
}
#overlay .seg-btn:first-child { border-left: 0; }
#overlay .seg-btn.on { background: #f28c28; color: #fff; }
@media (max-width: 560px) {
  #overlay .settings .setting { flex-direction: column; align-items: stretch; }
  #overlay .seg { justify-content: stretch; }
  #overlay .seg-btn { flex: 1; }
}

/* ---------- Top bar buttons (pause, zoom, guide, fullscreen, rig) ---------- */
#topbtns {
  position: absolute;
  top: 8px;
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 2;
}
#topbtns[hidden] { display: none; }
#topbtns .hbtn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #dfe6eb;
  background: #3a464f;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  touch-action: none;
}
#topbtns .hbtn[hidden] { display: none; }
#topbtns .hbtn svg { width: 22px; height: 22px; }
#topbtns .hbtn .g { font: 900 18px ui-rounded, "Segoe UI", system-ui, sans-serif; }
#topbtns .hbtn.on { color: #26313a; background: #f2c230; }
#topbtns .hbtn.pause { color: #fff; background: #f28c28; }
#topbtns .hbtn:active { transform: translateY(1px); filter: brightness(0.9); }
#topbtns.touch { top: 4px; }
#topbtns.touch .hbtn { width: 56px; height: 56px; border-radius: 14px; }
#topbtns.touch .hbtn svg { width: 28px; height: 28px; }

/* ---------- Touch controls ---------- */
#touch {
  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(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#touch[hidden] { display: none; }
#touch > * { pointer-events: auto; }
#touch button { touch-action: none; -webkit-tap-highlight-color: transparent; }
#touch button *, #touch .wheel * { pointer-events: none; } /* fingers always land on the control itself */

#touch .arrows { display: flex; gap: 14px; }
#touch .arrow {
  width: 84px;
  height: 84px;
  padding: 10px;
  background: #f28c28;
  border: 4px solid #8a4b0f;
  border-radius: 20px;
  box-shadow: 0 5px 0 #8a4b0f;
}
#touch .arrow svg { width: 100%; height: 100%; }
#touch .arrow.down { background: #df7a17; transform: translateY(3px); box-shadow: 0 2px 0 #8a4b0f; }
/* Spotter wheel hint (Full assist): the arrow to press glows green. */
#touch .arrow.hint { background: #4cc764; border-color: #22672f; box-shadow: 0 5px 0 #22672f, 0 0 0 0 rgba(76, 199, 100, 0.7); animation: hintPulse 1s ease-out infinite; }
#touch .arrow.hint.down { box-shadow: 0 2px 0 #22672f; animation: none; }
@keyframes hintPulse { to { box-shadow: 0 5px 0 #22672f, 0 0 0 14px rgba(76, 199, 100, 0); } }
#touch .wheel { position: relative; }
#touch .wheel.hint-left::after, #touch .wheel.hint-right::after {
  position: absolute; top: -6px; font: 900 30px/1 system-ui, sans-serif; color: #4cc764;
  text-shadow: 0 2px 0 #22672f; animation: hintNudge 0.8s ease-in-out infinite alternate;
}
#touch .wheel.hint-left::after { content: '\21BA'; left: -8px; }
#touch .wheel.hint-right::after { content: '\21BB'; right: -8px; }
@keyframes hintNudge { to { transform: translateY(-4px); } }

#touch .wheel { display: none; width: 150px; height: 150px; touch-action: none; }
#touch .wheel-rot { width: 100%; height: 100%; filter: drop-shadow(0 4px 0 rgba(0,0,0,0.35)); }
#touch .wheel-rot svg { width: 100%; height: 100%; }
#touch.use-wheel .arrows { display: none; }
#touch.use-wheel .wheel { display: block; }

#touch .pedals { position: relative; display: flex; align-items: flex-end; gap: 12px; }
#touch .shifter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: #1f262c;
  border: 3px solid #f4f1e8;
  border-radius: 36px;
}
#touch .gear {
  width: 56px;
  height: 56px;
  padding: 0;
  font: 900 24px ui-rounded, "Segoe UI", system-ui, sans-serif;
  color: #8e9aa4;
  background: #3a434b;
  border: 0;
  border-radius: 50%;
}
#touch .gear.on { color: #fff; background: #f28c28; }
#touch.gear-indicator .gear { pointer-events: none; }

#touch .pedal {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  padding: 10px;
  background: linear-gradient(135deg, #eef1f4, #a9b0b7 60%, #8e959c);
  border: 3px solid #4d555c;
  border-radius: 12px;
  box-shadow: 0 5px 0 #3c4349;
}
#touch .pedal span { display: block; background: #5f676e; border-radius: 3px; }
#touch .pedal.brake { width: 96px; height: 66px; flex-direction: column; }
#touch .pedal.brake span { width: 62px; height: 6px; }
#touch .pedal.gas { width: 66px; height: 128px; }
#touch .pedal.gas span { width: 6px; height: 96px; }
#touch .pedal.down { filter: brightness(0.85); transform: translateY(3px); box-shadow: 0 2px 0 #3c4349; }

/* Portrait: a bit smaller, shifter sits above the pedals. */
@media (orientation: portrait) {
  #touch .arrow { width: 68px; height: 68px; padding: 8px; }
  #touch .arrows { gap: 12px; }
  #touch .wheel { width: 132px; height: 132px; }
  #touch .shifter { position: absolute; right: 0; bottom: calc(100% + 14px); }
  #touch .pedal.brake { width: 84px; height: 60px; }
  #touch .pedal.brake span { width: 54px; }
  #touch .pedal.gas { width: 60px; height: 112px; }
  #touch .pedal.gas span { height: 82px; }
}

/* ---------- GreetRV brand: title lockup ---------- */
#overlay.title { background: rgba(31, 58, 39, 0.82); }
#overlay .title-card {
  width: min(460px, 100%);
  background: #fbf3e6;
  border-color: #1d1a15;
  box-shadow: 0 8px 0 #1d1a15;
  padding-top: 22px;
}
#overlay .presents { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 2px 0 10px; }
#overlay .presents img { width: 144px; height: auto; }
#overlay .presents span { font: 800 12px/1 ui-rounded, "Segoe UI", system-ui, sans-serif; letter-spacing: 3px; color: #6b5f4a; }
#overlay .lockup { display: flex; align-items: center; justify-content: center; gap: 16px; }
#overlay .app-icon { width: 112px; height: 112px; flex-shrink: 0; }
#overlay .wordmark { text-align: left; line-height: 0.86; }
#overlay .wordmark .w1, #overlay .wordmark .w2 {
  font-family: "Arial Black", "Segoe UI Black", ui-rounded, system-ui, sans-serif;
  font-weight: 900;
  letter-spacing: -2px;
}
#overlay .wordmark .w1 { font-size: 54px; color: #1d1a15; }
#overlay .wordmark .w2 { font-size: 64px; color: #c54818; }
#overlay .tagline { margin: 14px 0 14px; font-size: 16px; font-weight: 700; color: #3b3c37; }
#overlay .tag-stars { color: #f6a146; letter-spacing: 2px; -webkit-text-stroke: 0.6px #6b4a1a; }
#overlay .title-card .btn.primary { background: #c54818; }
@media (max-width: 420px) {
  #overlay .app-icon { width: 84px; height: 84px; }
  #overlay .wordmark .w1 { font-size: 40px; }
  #overlay .wordmark .w2 { font-size: 48px; }
}

/* Level intro card on short landscape screens (phones): wider and tighter so
   Start stays on screen without scrolling. */
@media (max-height: 520px) and (orientation: landscape) {
  #overlay .card.intro { width: min(640px, 100%); padding: 30px 22px 14px; }
  #overlay .card.intro h1 { font-size: 22px; margin: 0 0 2px; }
  #overlay .card.intro .maneuver { font-size: 15px; padding: 6px 10px; margin: 4px 0; }
  #overlay .card.intro .tip { font-size: 15px; margin: 4px 0 8px; }
  #overlay .card.intro .par { font-size: 14px; }
  #overlay .card.intro .buttons { margin-top: 10px; flex-wrap: nowrap; }
  #overlay .card.intro .btn { min-height: 46px; min-width: 0; font-size: 17px; }
  #overlay .card.intro .hint { display: none; }
  #overlay .card.intro .assist { margin-top: 6px; }
  #overlay .card.intro .assist small { display: none; }
}

/* ---------- Results: stars pop in ---------- */
#overlay .stars.pop .star.on { animation: star-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
#overlay .stars.pop .star.on:nth-child(1) { animation-delay: 0.25s; }
#overlay .stars.pop .star.on:nth-child(2) { animation-delay: 0.53s; }
#overlay .stars.pop .star.on:nth-child(3) { animation-delay: 0.81s; }
@keyframes star-pop {
  from { transform: scale(0) rotate(-40deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

/* ---------- Garage ---------- */
#overlay .garage .preview { display: flex; align-items: center; justify-content: center; gap: 8px; }
#overlay .garage canvas {
  width: min(560px, 100%);
  height: auto;
  aspect-ratio: 560 / 220;
  min-width: 0;
  flex: 1;
  background: #4a5059;
  border: 3px solid #26313a;
  border-radius: 14px;
}
#overlay .nav-btn {
  flex-shrink: 0;
  width: 48px;
  height: 56px;
  font: 900 32px/1 ui-rounded, system-ui, sans-serif;
  color: #26313a;
  background: #fff;
  border: 3px solid #26313a;
  border-radius: 12px;
  cursor: pointer;
}
#overlay .swatches { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
#overlay .swatch {
  width: 44px;
  height: 44px;
  background: var(--c);
  border: 3px solid #26313a;
  border-radius: 50%;
  cursor: pointer;
}
#overlay .swatch.on { outline: 4px solid #f28c28; outline-offset: 2px; }
#overlay .paint-name { margin: 8px 0 0; font-weight: 800; color: #4a5866; }
