* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #14140f;
  font-family: 'Courier New', Courier, monospace;
  overscroll-behavior: none;
}

#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(94vw, 420px, calc((100vh - 40px) * 120 / 176));
  padding: 12px 0;
}

#game-root {
  container-type: inline-size;
  position: relative;
  width: 100%;
  aspect-ratio: 120 / 176;
  background: #000;
  outline: 4px solid #0a0a0a;
  overflow: hidden;
}

.hidden { display: none !important; }

.pixel-btn {
  font-family: inherit;
  font-size: clamp(11px, 2.6vw, 15px);
  font-weight: bold;
  letter-spacing: 0.5px;
  background: #f8f4e3;
  color: #1a1a1a;
  border: 3px solid #1a1a1a;
  border-radius: 0;
  padding: 6px 16px;
  cursor: pointer;
  box-shadow: 3px 3px 0 #1a1a1a;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.pixel-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #1a1a1a;
}

#road-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4%;
  background: rgba(20, 16, 10, 0.78);
}

.box {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: #f8f4e3;
  border: 3px solid #1a1a1a;
  padding: 3% 4%;
  color: #1a1a1a;
  font-size: clamp(9px, 2.2vw, 13px);
  line-height: 1.4;
  text-align: center;
}

.box h1 { margin: 0; font-size: clamp(14px, 4vw, 24px); }
.box .sub { margin: 2px 0 8px; opacity: 0.7; }
.box p { margin: 0 0 6px; }
.box .keys { font-size: 0.85em; opacity: 0.8; margin-top: 8px; }
.box .best { font-weight: bold; min-height: 1.4em; }

/* Touch controls: the whole road is the control surface (swipe / tap); no buttons. */
body.touch #game-root { touch-action: none; }

#touch-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  background: rgba(20, 16, 10, 0.55);
  pointer-events: none;
  animation: hint-pulse 1.6s ease-in-out infinite;
}

#touch-hint > span {
  display: block;
  color: #f8f4e3;
  font-weight: bold;
  text-align: center;
  font-size: clamp(11px, 3.4cqw, 16px);
  line-height: 1.35;
  text-shadow: 1px 1px 0 #1a1a1a;
}

@keyframes hint-pulse {
  50% { opacity: 0.6; }
}

/* Instructions screen: white page, centered Arial text, small picture after each rule. */
.overlay.intro { padding: 0; background: #fff; }

.overlay.intro .box {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  background: #fff;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(13px, 2.5cqw, 18px);
  line-height: 1.25;
}

.overlay.intro h1 { font-size: clamp(26px, 7.2cqw, 52px); font-weight: normal; margin-bottom: 0.4em; }
.overlay.intro .sub { display: none; }
.overlay.intro #overlay-body p { margin: 0; }
.overlay.intro #overlay-body p.gap { height: 1.25em; }
.overlay.intro #overlay-body img { height: 1.4em; width: auto; margin-left: 0.5em; vertical-align: middle; }
.overlay.intro .keys { font-size: 0.8em; opacity: 0.6; }
.overlay.intro .best { margin: 0.6em 0 0; }
.overlay.intro .pixel-btn { margin-top: 0.6em; }

body.touch .overlay.intro .keys { display: none; }

/* Leaderboard name field and status line on the game-over card. */
#name-row { margin: 6px 0; }
#name-row label { display: block; margin-bottom: 4px; font-size: 0.9em; }
.name-fields { display: flex; gap: 6px; justify-content: center; }
.name-fields input {
  flex: 1;
  min-width: 0;
  max-width: 14em;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 16px; /* 16px stops iPhone Safari zooming into the field */
  border: 2px solid #1a1a1a;
  background: #fff;
  color: #1a1a1a;
}
.lb-status { min-height: 1.4em; font-size: 0.85em; margin: 2px 0 6px; }
