/* JOUST BUILD V20 — thicker rocky cliffs, lava-troll island, rounder sprites */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #000;
  color: #fc6;
  font-family: "Press Start 2P", "Courier New", monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-wrapper {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Landscape playfield fills available width/height */
#canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100%;
  aspect-ratio: 876 / 720;
  object-fit: contain;
  background: #000;
  /* Smooth bilinear scale — never pixelated / never crisp-edges */
  image-rendering: auto;
  image-rendering: smooth;
  -ms-interpolation-mode: bicubic;
  touch-action: none;
}

/* HUD overlaid on game (classic bottom feel, but readable on top) */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,0.65), transparent);
}

.hud-block { text-align: center; min-width: 70px; }
.hud-block .label {
  color: #c84;
  font-size: clamp(6px, 1.2vw, 9px);
  margin-bottom: 4px;
}
#score, #high-score, #wave, #lives {
  color: #ffe080;
  font-size: clamp(9px, 1.8vw, 14px);
  text-shadow: 0 0 6px #a60;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 4, 0, 0.78);
  text-align: center;
  gap: 12px;
  padding: 16px;
  pointer-events: auto;
}
#overlay.hidden { display: none; }

#overlay-title {
  color: #ffe040;
  font-size: clamp(22px, 6vw, 48px);
  letter-spacing: 8px;
  text-shadow: 0 0 16px #f80, 3px 0 0 #c40, -3px 0 0 #08f;
}
#overlay-sub {
  color: #0ff;
  font-size: clamp(10px, 2vw, 14px);
  animation: blink 0.85s steps(1) infinite;
}
#overlay-hint { color: #ffd0a0; font-size: clamp(7px, 1.4vw, 10px); letter-spacing: 0.5px; }
#overlay-controls {
  color: #ca8;
  font-size: clamp(6px, 1.2vw, 9px);
  line-height: 1.9;
  max-width: 90%;
  margin-top: 8px;
}

#mobile-controls {
  display: none;
  flex: 0 0 auto;
  width: 100%;
  justify-content: space-between;
  align-items: stretch;
  gap: 10px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: #120800;
  border-top: 2px solid #432;
  touch-action: none;
}
.mobile-col {
  display: flex;
  gap: 8px;
  align-items: center;
}
.mobile-col.mid { flex: 1; justify-content: center; }
.mobile-col.side { flex-direction: column; gap: 6px; }

.mobile-btn {
  min-width: 72px;
  height: 64px;
  border: 2px solid #864;
  border-radius: 16px;
  background: #241408;
  color: #fc8;
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
  touch-action: none;
}
.mobile-btn.flap {
  min-width: min(200px, 42vw);
  height: 72px;
  border-radius: 20px;
  border-color: #fa0;
  color: #ffc;
  font-size: 16px;
  background: #3a2008;
  box-shadow: 0 0 12px rgba(255,160,0,0.18);
}
.mobile-btn.small {
  min-width: 52px;
  height: 40px;
  font-size: 12px;
}
.mobile-btn:active {
  background: #864;
  color: #210;
  transform: scale(0.97);
}
.mobile-btn.flap:active { background: #fa0; color: #000; }

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Phones: always show touch; short landscape / tall portrait both work */
@media (max-width: 1100px), (pointer: coarse), (max-height: 700px) {
  #mobile-controls { display: flex; }
  #canvas-wrap {
    /* leave room for touch bar */
    max-height: calc(100dvh - 96px);
  }
  #game {
    max-height: calc(100dvh - 96px);
  }
}

/* Prefer landscape: if portrait phone, still playable but prompt via size */

/* === Dual orientation (portrait + landscape) === */
@media (orientation: portrait) and (max-width: 900px) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }
  #game-wrapper {
    max-height: 100dvh;
    overflow: hidden;
    justify-content: flex-start;
    gap: 4px;
    padding: 4px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  #canvas-wrap, #hud, #footer, #mobile-controls {
    width: min(100vw - 8px, calc((100dvh - 210px) * 0.9)) !important;
    max-width: 100vw;
  }
  #game {
    width: 100% !important;
    height: auto !important;
    max-height: calc(100dvh - 210px) !important;
  }
  #mobile-controls {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }
  #game-wrapper {
    max-height: 100dvh;
    overflow: hidden;
    gap: 2px;
    padding: 2px 4px;
    padding-left: max(4px, env(safe-area-inset-left));
    padding-right: max(4px, env(safe-area-inset-right));
  }
  #canvas-wrap {
    width: min(70vw, calc((100dvh - 12px) * 1.2), 100vw - 140px) !important;
  }
  #game {
    max-height: calc(100dvh - 12px) !important;
  }
  #hud, #footer {
    font-size: 10px;
  }
  #mobile-controls {
    display: flex !important;
  }
  .mobile-btn, .dpad-btn {
    min-width: 42px !important;
    width: 42px !important;
    height: 42px !important;
    font-size: 12px !important;
  }
}
