* {
  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;
}

#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(94vw, 640px);
}

#game-root {
  position: relative;
  width: 100%;
  aspect-ratio: 160 / 144;
  background: #000;
  outline: 4px solid #0a0a0a;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
}

.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;
}

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

/* Intro screens */
#screen-intro {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #2b2f1f;
  color: #f2ead2;
  padding: 4%;
}

#intro-text {
  font-size: clamp(10px, 2.4vw, 15px);
  line-height: 1.5;
  overflow-y: auto;
}

#intro-text p {
  margin: 0;
  padding-bottom: 0.5em;
}

#intro-text p.blank-line {
  height: 1.5em;
  padding-bottom: 0;
}

#screen-intro .intro-button-row {
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
}

/* Map */
#screen-map {
  background: #000;
}

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

/* Road mini-game */
#screen-road {
  background: #000;
}

#road-controls {
  margin-top: 14px;
  width: min(94vw, 640px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.road-lane-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.road-lane-btns .dpad-btn {
  width: 40px;
  height: 40px;
}

.road-action-btns {
  display: flex;
  gap: 10px;
}

.road-action-btn {
  min-width: 72px;
}

#road-lose-overlay {
  display: flex;
  align-items: flex-end;
  padding: 3%;
}

.road-lose-box {
  width: 100%;
  background: #f8f4e3;
  border: 3px solid #1a1a1a;
  padding: 8px 10px;
  color: #1a1a1a;
  font-size: clamp(9px, 2.2vw, 13px);
  line-height: 1.4;
}

#road-lose-text {
  margin-bottom: 6px;
}

#map-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-size: clamp(7px, 1.7vw, 11px);
  font-weight: bold;
  white-space: nowrap;
  color: #f8f4e3;
  text-shadow:
    1px 0 #1a1a1a, -1px 0 #1a1a1a,
    0 1px #1a1a1a, 0 -1px #1a1a1a,
    1px 1px #1a1a1a, -1px -1px #1a1a1a,
    1px -1px #1a1a1a, -1px 1px #1a1a1a;
}

/* Virtual d-pad (touch controls), shown below the game canvas */
#dpad {
  margin-top: 14px;
  width: 132px;
  max-width: 34vw;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 6px;
}

.dpad-btn {
  font-family: inherit;
  font-size: clamp(14px, 4vw, 20px);
  background: #f8f4e3;
  color: #1a1a1a;
  border: 2px solid #1a1a1a;
  border-radius: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 2px 2px 0 #1a1a1a;
}

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

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

/* Dialogue overlay */
#dialogue-overlay {
  display: flex;
  align-items: flex-end;
  padding: 3%;
}

.dialogue-box {
  width: 100%;
  background: #f8f4e3;
  border: 3px solid #1a1a1a;
  padding: 8px 10px;
  color: #1a1a1a;
  font-size: clamp(9px, 2.2vw, 13px);
  line-height: 1.4;
}

#dialogue-speaker {
  font-weight: bold;
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

#dialogue-text p {
  margin: 0.3em 0;
  white-space: pre-line;
}

.line-speech::before {
  content: '"';
}
.line-speech::after {
  content: '"';
}

.line-action {
  font-style: italic;
  opacity: 0.8;
}

.line-narration {
  font-style: italic;
}

#dialogue-choices {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.dialogue-choice {
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  background: #fff;
  border: 2px solid #1a1a1a;
  padding: 4px 8px;
  cursor: pointer;
}

.dialogue-choice::before {
  content: '\25B8  ';
}

.dialogue-choice:hover {
  background: #e8e0c8;
}

#dialogue-input-form {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

#dialogue-input-field {
  flex: 1;
  font-family: inherit;
  font-size: inherit;
  border: 2px solid #1a1a1a;
  padding: 4px 6px;
}

#dialogue-continue {
  margin-top: 6px;
  text-align: right;
  cursor: pointer;
  font-size: inherit;
}

#dialogue-continue::after {
  content: '\25B8 next';
}

@keyframes dialogue-flash {
  0% { background: #fff6cc; }
  100% { background: #f8f4e3; }
}

.dialogue-flash {
  animation: dialogue-flash 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .dialogue-flash {
    animation: none;
  }
}

/* Main menu / landing screen — antique hand-drawn map of Mexico */
#screen-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7%;
  padding: 9%;
  overflow: hidden;
  background-color: #d8c096;
  background-image:
    radial-gradient(ellipse at 18% 12%, rgba(120, 82, 40, 0.28), transparent 55%),
    radial-gradient(ellipse at 86% 22%, rgba(90, 58, 26, 0.24), transparent 50%),
    radial-gradient(ellipse at 74% 88%, rgba(120, 82, 40, 0.30), transparent 55%),
    radial-gradient(ellipse at 26% 78%, rgba(150, 110, 60, 0.22), transparent 52%),
    radial-gradient(circle at 50% 45%, rgba(247, 238, 214, 0.35), transparent 60%),
    linear-gradient(135deg, #e7d6ac 0%, #d8c096 45%, #c2a366 100%);
}

/* Weathered paper grain */
#screen-menu::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.14;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

/* Decorative Aztec-style stepped-fret border, drawn with border-image */
.menu-greca {
  position: absolute;
  inset: 5px;
  z-index: 3;
  pointer-events: none;
  border: 13px solid transparent;
  border-image-source: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%235a3a1a' stroke-linecap='square'%3E%3Cpath stroke-width='1.5' d='M1 1H47V47H1Z'/%3E%3Cpath stroke-width='1.5' d='M15 15H33V33H15Z'/%3E%3Cg stroke-width='2'%3E%3Cpath d='M0 12H4V4H12V12H20V4H28V12H36V4H44V12H48'/%3E%3Cpath d='M0 36H4V44H12V36H20V44H28V36H36V44H44V36H48'/%3E%3Cpath d='M12 0V4H4V12H12V20H4V28H12V36H4V44H12V48'/%3E%3Cpath d='M36 0V4H44V12H36V20H44V28H36V36H44V44H36V48'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  border-image-slice: 16;
  border-image-repeat: round;
}

.menu-compass {
  position: absolute;
  right: 7%;
  bottom: 7%;
  width: clamp(38px, 11vw, 70px);
  height: auto;
  z-index: 2;
  opacity: 0.72;
}

.menu-content {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9%;
  width: 100%;
}

.menu-title {
  margin: 0;
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 700;
  font-size: clamp(20px, 7vw, 44px);
  letter-spacing: 0.14em;
  color: #4a3016;
  transform: rotate(-1.5deg);
  text-shadow:
    1px 1px 0 rgba(247, 238, 214, 0.55),
    2px 3px 4px rgba(74, 48, 22, 0.32);
}

.menu-title-sub {
  display: block;
  margin-top: 0.15em;
  font-size: 0.42em;
  letter-spacing: 0.4em;
  color: #6b4a2a;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(7px, 2.4vw, 14px);
  width: 100%;
}

.menu-btn {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(9px, 2.3vw, 15px);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #1a1a1a;
  background: #f5ecd7;
  border: 3px solid #6b4a2a;
  border-radius: 1px;
  padding: 8px 16px;
  min-width: 66%;
  max-width: 92%;
  text-align: center;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(74, 48, 22, 0.55);
}

.menu-btn:hover {
  background: #fdf6e6;
}

.menu-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(74, 48, 22, 0.55);
}

/* Game over */
#screen-gameover {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
}
