@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --yellow: #F2D544;
  --black: #000000;
  --font: 'Press Start 2P', monospace;
  --max-w: 430px;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--black);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}

#game-wrapper {
  position: relative; width: 100%;
  /* Keep a portrait column: width never exceeds ~9:16 of the viewport height,
     so a short/wide window letterboxes instead of going landscape. */
  max-width: min(var(--max-w), 56vh);
  height: 100%; margin: 0 auto; overflow: hidden;
  background: var(--yellow);
}

#game-canvas {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated; image-rendering: crisp-edges;
  touch-action: none;
}

/* Overlays */
.overlay {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  z-index: 10; background: var(--yellow);
  cursor: pointer;
}
.overlay.hidden { display: none; }
.overlay-content { text-align: center; padding: 2rem; }

#gameover-screen {
  background: transparent;
  justify-content: center;
  cursor: default;
}
#gameover-screen .overlay-content {
  position: absolute;
  left: 0; right: 0;
  padding: 0 1.5rem;
  width: 100%;
  /* `top` is set in JS (resize) so the buttons sit just below the love/money bars */
}
.gameover-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  width: 100%;
}
.gameover-buttons .btn {
  margin-top: 0;
  padding: 12px 18px;
  font-size: 9px;
  flex: 1;
  max-width: 180px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.title {
  font-family: var(--font); color: var(--black);
  font-size: 42px;
  letter-spacing: 0.25em; margin-bottom: 2rem;
}
.title-diggin {
  position: relative; top: -16px;
}
.desc {
  font-family: var(--font); color: var(--black);
  font-size: 10px;
  line-height: 2.5; margin-bottom: 3rem;
  letter-spacing: 0.05em;
}
.hint {
  font-family: var(--font); color: var(--black);
  font-size: 8px;
  letter-spacing: 0.2em; margin-bottom: 3.5rem;
  opacity: 0.5;
}
.tap-hint {
  font-family: var(--font); color: var(--black);
  font-size: 10px;
  letter-spacing: 0.2em; opacity: 0.6;
  animation: blink 1.5s steps(2, start) infinite;
}
.final-love, .final-money {
  font-family: var(--font); color: var(--black);
  font-size: 16px;
  margin-bottom: 1rem; letter-spacing: 0.1em;
}

@keyframes blink { 0%,100%{opacity:0.6} 50%{opacity:0} }

/* Custom pixel icons in UI */
.pixel-icon {
  width: 24px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
  shape-rendering: crispEdges;
  margin-right: 6px;
}
.pixel-icon.arrow {
  width: 14px;
  height: 14px;
  margin-right: 4px;
}

/* Top-left HUD: help button below the canvas-drawn player name.
   top/left are set proportionally in JS (resize) to track the canvas scale. */
#hud-left {
  position: absolute; top: 48px; left: 18px; z-index: 5;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
}

/* Help button + popup */
.help-btn {
  width: 22px; height: 22px;
  font-family: var(--font); font-size: 11px;
  background: var(--yellow); color: var(--black);
  border: 2px solid var(--black);
  cursor: pointer; padding: 0; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  image-rendering: pixelated;
}
.help-btn:active { transform: scale(0.95); }

#help-screen { background: rgba(242, 213, 68, 0.9); }
.help-content {
  background: var(--yellow);
  border: 3px solid var(--black);
  padding: 24px 22px;
  max-width: 280px;
}
.help-title {
  font-family: var(--font); color: var(--black);
  font-size: 14px; letter-spacing: 0.2em; margin-bottom: 18px;
}
.help-goal {
  font-family: var(--font); color: var(--black);
  font-size: 9px; line-height: 2; margin-bottom: 20px;
}
.help-cmds { display: inline-block; text-align: left; }
.help-cmds p {
  font-family: var(--font); color: var(--black);
  font-size: 9px; line-height: 2.4; letter-spacing: 0.1em;
}
.help-note {
  font-family: var(--font); color: var(--black);
  font-size: 9px; line-height: 2; letter-spacing: 0.1em;
  margin-top: 20px; padding-top: 16px;
  border-top: 2px solid rgba(0, 0, 0, 0.15);
  opacity: 0.7;
}

.help-content .btn { margin-top: 22px; }

/* Name entry on start screen */
/* Start screen: name input + START button on one row, equal height */
.start-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 340px;
  margin: 1rem auto 0;
}
.name-input {
  font-family: var(--font);
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--black);
  background: var(--yellow);
  border: 2px solid var(--black);
  outline: none;
  padding: 12px 14px;
  flex: 1 1 auto;
  min-width: 0;
  image-rendering: pixelated;
}
.name-input::placeholder { color: var(--black); opacity: 0.35; }

.start-row #btn-start {
  margin-top: 0;
  flex: 0 0 auto;
  padding: 12px 28px;
}

/* Custom pixel button in UI */
.btn {
  font-family: var(--font);
  background: var(--black);
  color: var(--yellow);
  border: none;
  padding: 16px 32px;
  font-size: 10px;
  cursor: pointer;
  margin-top: 1rem;
  letter-spacing: 0.2em;
  transition: opacity 0.2s ease;
  image-rendering: pixelated;
  text-transform: uppercase;
}
.btn:hover {
  opacity: 0.8;
}
.btn:active {
  transform: scale(0.98);
}
.gameover-buttons .btn {
  margin-top: 0;
  padding: 12px 18px;
  font-size: 9px;
  flex: 1;
  max-width: 180px;
  white-space: nowrap;
}

/* Desktop centering */
@media (min-width: 431px) {
  body { display: flex; align-items: center; justify-content: center; }
  #game-wrapper {
    height: 100vh; max-height: 932px;
    border-left: 1px solid rgba(0,0,0,0.08);
    border-right: 1px solid rgba(0,0,0,0.08);
  }
}
