/* Get Home Before Dark — styles */
:root {
  --bg-deep: #0a0f1c;
  --bg-mid: #131c2e;
  --bg-soft: #1a2540;
  --ink: #e6ecf5;
  --ink-dim: #9aa8c2;
  --accent: #f6c14b;
  --accent-hot: #ff6b4a;
  --frog: #6ad36a;
  --frog-shadow: #2f7a3a;
  --water: #1a3a6e;
  --water-deep: #0e264a;
  --road: #2a2a2a;
  --road-line: #ffd84a;
  --safe: #4d8a4d;
  --safe-edge: #2d5a2d;
  --danger: #d04040;
  --card: rgba(20, 28, 50, 0.92);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  /* never wider than the viewport — prevents horizontal scroll at 390px */
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% -10%, rgba(246, 193, 75, 0.12), transparent 50%),
    radial-gradient(circle at 90% 110%, rgba(106, 211, 106, 0.10), transparent 50%),
    linear-gradient(180deg, #050a16 0%, #0a0f1c 60%, #050a16 100%);
}

.app {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 10px 8px 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 6px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  min-width: 0; /* allow ellipsis instead of overflow */
}
.hud-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  white-space: nowrap;
}
.hud-value {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  min-width: 0;
}
.hud-value-lives { letter-spacing: -0.05em; }
.hud-cell-destination .hud-value { color: var(--accent); }
.hud-cell-time .hud-value { color: var(--frog); }

/* Stage */
.stage {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
#board {
  display: block;
  width: 100%;
  max-width: 416px;
  height: auto;
  /* aspect-ratio scales by width and never distorts; on 390px viewport the
     board fits with 13px slack on each side so the HUD never overflows. */
  aspect-ratio: 416 / 448;
  background: #0a0f1c;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  image-rendering: pixelated;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 10, 22, 0.85);
  backdrop-filter: blur(4px);
  z-index: 5;
  border-radius: 10px;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 22px 18px;
  text-align: center;
  max-width: 340px;
  width: 92%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.overlay-title {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.overlay-tagline {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--frog);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.overlay-subtitle {
  margin: 0 0 14px;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.4;
}
.overlay-tips {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.6;
  text-align: left;
}

/* Pause overlay stats grid */
.pause-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin: 0 0 14px;
  padding: 0;
}
.pause-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 6px 8px;
}
.pause-stat dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  margin: 0;
}
.pause-stat dd {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--bg-soft);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  margin: 4px;
  min-width: 100px;
  min-height: 44px;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: #243155; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}
.btn-primary:hover { background: #ffd05a; }

/* Touch controls — always render and always sized above 44px hit target */
.touch-controls {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin: 4px auto 0;
}
.touch-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.touch-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  width: 64px;
  height: 56px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s ease, background 0.15s ease;
}
.touch-btn:active {
  transform: scale(0.92);
  background: var(--accent);
  color: #1a1a1a;
}
.touch-action {
  font-size: 14px;
  width: 120px;
  height: 48px;
  letter-spacing: 0.04em;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 6px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 4px 10px;
}
.swatch { font-size: 14px; }

/* -------------------------------------------------------------------------
 * Responsive tweaks
 *
 * Mobile-first tweaks apply via @media (max-width: 480px) so 390px is in range.
 * Below 390px the HUD and touch controls continue to fit because everything
 * is percentage- or minmax-based; the only true overflow risk is the HUD
 * on extremely narrow phones, so we tighten font sizes further below.
 * ------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .app { padding: 8px 6px 18px; gap: 10px; }
  .hud { font-size: 11px; padding: 6px 4px; gap: 2px; }
  .hud-value { font-size: 13px; }
  .hud-label { font-size: 9px; }
  .touch-btn { width: 60px; height: 54px; font-size: 20px; }
  .touch-action { width: 108px; height: 44px; font-size: 13px; }
  .btn { min-width: 90px; padding: 9px 14px; min-height: 44px; }
  .overlay-card { padding: 18px 14px; }
  .overlay-title { font-size: 19px; }
  .pause-stat dd { font-size: 14px; }
}

@media (max-width: 380px) {
  .hud-value { font-size: 12px; }
  .hud-label { font-size: 8px; }
  .legend { font-size: 11px; }
}

/* Coarse pointer (touch) — always show the touch controls, regardless of
 * viewport width, so phones get them automatically and they remain
 * tappable on a desktop with a touch screen. */
@media (hover: none), (pointer: coarse) {
  .touch-controls { display: grid; }
}
/* Fine pointer (mouse) — hide the touch controls on desktop unless the
 * viewport is narrow; that way they don't visually clutter a desktop. */
@media (hover: hover) and (pointer: fine) {
  @media (min-width: 900px) {
    .touch-controls { display: none; }
  }
}

@media (min-width: 720px) {
  .app { padding: 18px 16px 32px; }
  .hud { font-size: 14px; padding: 10px 14px; gap: 6px; }
  .hud-value { font-size: 17px; }
  .touch-btn { width: 72px; height: 60px; font-size: 24px; }
}