:root {
  color-scheme: dark;
  --ink: #f7f5e9;
  --green: #46c66a;
  --green-dark: #1f7f3d;
  --yellow: #ffd65a;
  --red: #f15f54;
  --panel: rgba(12, 22, 16, 0.86);
  --control: rgba(242, 246, 238, 0.22);
  --control-border: rgba(255, 255, 255, 0.55);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0c1510;
  color: var(--ink);
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
}

button,
a {
  font: inherit;
}

#gameShell,
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
  background: #79b968;
}

#hud {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  height: max(70px, env(safe-area-inset-top));
  min-height: 70px;
  padding: 7px 184px 7px 84px;
  display: grid;
  grid-template-columns: minmax(110px, 0.65fr) minmax(170px, 1.35fr) minmax(240px, 1fr);
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(8, 16, 11, 0.97), rgba(14, 29, 19, 0.9));
  border-bottom: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 7px 22px rgba(0, 0, 0, 0.25);
}

.hudPanel {
  min-width: 0;
  height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
}

#dayPanel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px 12px;
}

#dayPanel strong {
  color: var(--yellow);
  font-size: clamp(0.9rem, 2vw, 1.15rem);
  letter-spacing: 0.08em;
  line-height: 1.05;
}

#dayPanel span {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.78rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#buildLabel {
  margin-top: 2px;
  color: rgba(255, 214, 90, 0.72);
  font-size: 0.46rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1;
}

#miniMapPanel {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 2px 8px;
}

#miniMap {
  width: min(100%, 210px);
  height: 52px;
}

#routePanel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  padding: 4px 8px;
}

#routePanel > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

#routePanel > div:first-child {
  border-left: 0;
}

.hudCaption {
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

#routePanel strong {
  overflow: hidden;
  max-width: 100%;
  font-size: clamp(0.87rem, 2vw, 1.12rem);
  line-height: 1.1;
  text-overflow: ellipsis;
}

.cornerButton {
  position: fixed;
  z-index: 24;
  top: 14px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-decoration: none;
  cursor: pointer;
}

#arcadeLink {
  left: max(8px, env(safe-area-inset-left));
  width: 42px;
  font-size: 1.05rem;
}

.iconButton {
  width: 38px;
  padding: 0;
  font-size: 1.05rem;
}

#pauseButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 86px);
}

#resetButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 43px);
  overflow: hidden;
  touch-action: none;
  transition: border-color 120ms ease, box-shadow 700ms linear;
}

#resetButton.holding {
  border-color: var(--yellow);
  box-shadow: inset 0 -42px rgba(255, 214, 90, 0.52), 0 0 0 2px rgba(255, 214, 90, 0.16);
}

#screenButton {
  right: max(8px, env(safe-area-inset-right));
}

#cleanButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 129px);
  color: var(--yellow);
}

/* The public arcade supplies the standard corner controls around this iframe.
   Keep direct-file controls available as a fallback, but remove the duplicate
   visual row and release that space whenever the game is embedded. */
html.arcadeEmbedded #arcadeLink,
html.arcadeEmbedded #resetButton,
html.arcadeEmbedded #screenButton,
html.arcadeEmbedded #cleanButton {
  display: none;
}

html.arcadeEmbedded #pauseButton {
  top: 0;
  right: auto;
  left: 0;
  width: 1px;
  min-width: 1px;
  height: 1px;
  min-height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  opacity: 0;
  pointer-events: none;
}

html.arcadeEmbedded #hud {
  padding-right: max(10px, env(safe-area-inset-right));
  padding-left: max(10px, env(safe-area-inset-left));
  grid-template-columns: minmax(110px, 0.65fr) minmax(170px, 1.35fr) minmax(240px, 1fr);
}

body.cleanMode #hud {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
}

body.cleanMode #hud > *:not(#cleanButton),
body.cleanMode #toast {
  opacity: 0;
  pointer-events: none;
}

body.cleanMode #cleanButton {
  right: max(8px, env(safe-area-inset-right));
  opacity: .78;
  pointer-events: auto;
}

#touchDrive {
  --knob-x: 0px;
  --knob-y: 0px;
  position: fixed;
  z-index: 26;
  width: 112px;
  height: 112px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  background: rgba(15, 28, 20, 0.2);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.07), 0 8px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  transition: opacity 100ms ease, transform 100ms ease;
}

#touchDrive.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.touchDriveKnob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background: rgba(255, 214, 90, 0.42);
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.12), 0 4px 14px rgba(0, 0, 0, 0.24);
  transform: translate(calc(-50% + var(--knob-x)), calc(-50% + var(--knob-y)));
}

#controls {
  position: fixed;
  z-index: 30;
  inset: 0;
  pointer-events: none;
}

#dpad {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: clamp(126px, 18vw, 174px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: auto;
}

.driveButton {
  border: 2px solid var(--control-border);
  color: #fff;
  background: var(--control);
  box-shadow: inset 0 0 16px rgba(255, 255, 255, 0.06), 0 5px 18px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  touch-action: none;
  cursor: pointer;
}

.driveButton.active,
.driveButton:active {
  background: rgba(255, 214, 90, 0.54);
  border-color: rgba(255, 255, 255, 0.92);
  transform: scale(0.97);
}

.dpadButton {
  border-radius: 14px;
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: 900;
}

.dpadButton.up { grid-column: 2; grid-row: 1; }
.dpadButton.left { grid-column: 1; grid-row: 2; }
.dpadButton.right { grid-column: 3; grid-row: 2; }
.dpadButton.down { grid-column: 2; grid-row: 3; }

.dpadCenter {
  grid-column: 2;
  grid-row: 2;
  width: 42%;
  height: 42%;
  place-self: center;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
}

#pedals {
  position: absolute;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, clamp(58px, 8vw, 82px));
  grid-template-rows: auto auto;
  gap: 10px;
  align-items: end;
  pointer-events: auto;
}

.pedal {
  height: clamp(60px, 10vh, 86px);
  border-radius: 22px 22px 13px 13px;
  font-size: clamp(0.75rem, 1.7vw, 1rem);
  font-weight: 950;
  letter-spacing: 0.04em;
}

.pedal.gas {
  border-color: rgba(119, 255, 153, 0.72);
}

.pedal.brake {
  border-color: rgba(255, 133, 118, 0.72);
}

.pedal.reverse {
  border-color: rgba(119, 196, 255, 0.78);
}

.action {
  grid-column: 1 / -1;
  height: clamp(48px, 8vh, 64px);
  border-radius: 999px;
  border-color: rgba(255, 214, 90, 0.88);
  background: rgba(255, 186, 48, 0.28);
  font-size: clamp(0.85rem, 2vw, 1.1rem);
  font-weight: 950;
  letter-spacing: 0.06em;
}

.action.ready {
  animation: readyPulse 1s ease-in-out infinite;
  background: rgba(255, 188, 38, 0.62);
}

.action.pickupReady {
  animation: pickupReadyPulse 0.78s ease-in-out infinite;
  border-color: rgba(132, 255, 160, 0.98);
  background: rgba(40, 190, 78, 0.72);
}

@keyframes readyPulse {
  50% { box-shadow: 0 0 0 9px rgba(255, 214, 90, 0.12), 0 5px 18px rgba(0, 0, 0, 0.2); }
}

@keyframes pickupReadyPulse {
  50% {
    background: rgba(70, 221, 106, 0.92);
    box-shadow: 0 0 0 11px rgba(91, 240, 126, 0.18), 0 5px 18px rgba(0, 0, 0, 0.2);
  }
}

#toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: 86px;
  max-width: min(78vw, 520px);
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: rgba(8, 15, 10, 0.84);
  color: #fff;
  font-size: clamp(0.78rem, 2vw, 1rem);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.gameOverlay {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 82px 22px 22px;
  background: radial-gradient(circle at 50% 30%, rgba(34, 76, 42, 0.72), rgba(5, 10, 7, 0.9));
  pointer-events: auto;
}

.gameOverlay.visible {
  display: flex;
}

.overlayCard {
  width: min(92vw, 560px);
  max-height: calc(100vh - 100px);
  overflow: auto;
  padding: clamp(20px, 4vw, 36px);
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(24, 52, 31, 0.97), rgba(10, 23, 14, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.52), inset 0 1px rgba(255, 255, 255, 0.14);
  text-align: center;
}

.startCard {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
}

.startCard::before,
.startCard::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 210px;
  height: 90px;
  border-radius: 50%;
  background: rgba(75, 198, 105, 0.13);
  filter: blur(2px);
  transform: rotate(-18deg);
}

.startCard::before { left: -65px; bottom: 30px; }
.startCard::after { right: -60px; top: 20px; }

.arcadeMark {
  margin: 0 0 8px;
  color: var(--yellow);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0.19em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(2.1rem, 8vw, 5rem);
  line-height: 0.92;
  letter-spacing: -0.055em;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.28);
}

h1 span {
  color: var(--yellow);
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.8rem, 5vw, 3rem);
}

.startCopy,
.controlHint,
.compactCard p,
.monthCard p {
  color: rgba(255, 255, 255, 0.78);
}

.startCopy {
  margin-bottom: 8px;
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
}

.truckBadge {
  width: clamp(54px, 8vw, 78px);
  height: clamp(54px, 8vw, 78px);
  display: grid;
  place-items: center;
  margin: 13px auto;
  border: 3px solid rgba(255, 255, 255, 0.75);
  border-radius: 18px;
  background: var(--green-dark);
  color: #fff;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  transform: rotate(-4deg);
}

.primaryButton,
.secondaryButton {
  min-width: 160px;
  min-height: 50px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 950;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.primaryButton {
  border: 2px solid #fff2ad;
  background: linear-gradient(#ffdd67, #e9a927);
  color: #202014;
  box-shadow: 0 7px 0 #8d5f0f, 0 13px 25px rgba(0, 0, 0, 0.28);
}

.primaryButton:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #8d5f0f, 0 7px 14px rgba(0, 0, 0, 0.25);
}

.secondaryButton {
  border: 2px solid rgba(255, 255, 255, 0.56);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.controlHint {
  margin: 20px 0 0;
  font-size: 0.78rem;
}

.compactCard {
  width: min(90vw, 410px);
}

.compactCard .primaryButton,
.compactCard .secondaryButton {
  display: block;
  width: 100%;
  margin-top: 13px;
}

.summaryStats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 15px 0;
}

.summaryStat {
  padding: 11px 7px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.06);
}

.summaryStat small {
  display: block;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.63rem;
  font-weight: 850;
  letter-spacing: 0.07em;
}

.summaryStat strong {
  display: block;
  margin-top: 3px;
  color: var(--yellow);
  font-size: 1.25rem;
}

.findPanel {
  display: flex;
  align-items: center;
  gap: 15px;
  margin: 14px 0;
  padding: 14px 18px;
  border: 1px solid rgba(255, 214, 90, 0.5);
  border-radius: 16px;
  background: rgba(255, 197, 65, 0.1);
  text-align: left;
}

.findPanel[hidden] {
  display: none;
}

.findSpark {
  color: var(--yellow);
  font-size: 2.1rem;
}

.findPanel div {
  display: flex;
  flex-direction: column;
}

.findPanel small {
  color: var(--yellow);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.findPanel strong {
  font-size: 1.12rem;
}

.findPanel span:last-child {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
}

.summaryActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.summaryActions button {
  flex: 1 1 135px;
}

.firedCard {
  border-color: rgba(241, 95, 84, 0.62);
}

#rotateMessage {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px;
  background: #102318;
  text-align: center;
}

#rotateMessage strong {
  font-size: 1.25rem;
}

#rotateMessage span {
  color: rgba(255, 255, 255, 0.7);
}

.phoneIcon {
  font-size: 3.5rem;
  color: var(--yellow);
  animation: turnPhone 1.7s ease-in-out infinite;
}

@keyframes turnPhone {
  50% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (max-width: 900px) {
  #rotateMessage { display: flex; }
}

@media (max-height: 500px) {
  #hud {
    height: 62px;
    min-height: 62px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .hudPanel { height: 50px; }
  .cornerButton { top: 10px; }
  #toast { top: 70px; }
  .gameOverlay {
    padding: 68px 14px 10px;
  }

  .overlayCard {
    max-height: calc(100dvh - 78px);
    padding: 12px 20px 14px;
    border-radius: 20px;
  }

  .startCard h1 {
    font-size: clamp(2rem, 8.5vw, 3.7rem);
  }

  .startCopy { margin-bottom: 4px; }

  .truckBadge {
    width: 48px;
    height: 48px;
    margin: 6px auto 8px;
    border-radius: 14px;
    font-size: 1.65rem;
  }

  .startCard .primaryButton {
    min-height: 44px;
    padding-block: 9px;
  }

  .controlHint {
    margin: 10px 0 0;
  }
}

@media (max-width: 720px) {
  #hud {
    grid-template-columns: 88px minmax(120px, 1fr) minmax(185px, 1.2fr);
    padding-left: 66px;
    padding-right: 149px;
    gap: 5px;
  }

  #arcadeLink {
    width: 54px;
    font-size: 0.62rem;
  }

  #pauseButton {
    right: calc(max(6px, env(safe-area-inset-right)) + 70px);
  }

  #resetButton { right: calc(max(6px, env(safe-area-inset-right)) + 35px); }
  #screenButton { right: max(6px, env(safe-area-inset-right)); }
  #cleanButton { right: calc(max(6px, env(safe-area-inset-right)) + 105px); }
  body.cleanMode #cleanButton { right: max(6px, env(safe-area-inset-right)); }
  .iconButton { width: 32px; }
  #dayPanel { padding-inline: 8px; }
  .hudCaption { font-size: 0.54rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
