/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

:root {
  --accent:   #ff6622;
  --accent2:  #44aaff;
  --danger:   #e53030;
  --gold:     #ffdd00;
  --gem:      #44eeff;
  --bg:       #080810;
  --surface:  #10101e;
  --border:   rgba(255,255,255,0.08);
  --text:     #ffffff;
  --muted:    #666688;
  --font-display: 'Bebas Neue', 'Impact', sans-serif;
  --font-mono:    'Share Tech Mono', 'Courier New', monospace;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-mono);
  color: var(--text);
  touch-action: none;
}

/* ─── Canvas ─────────────────────────────────────────────────── */
#gameCanvas {
  display: block; position: fixed; inset: 0;
  width: 100%; height: 100%;
}

/* ─── Damage flash ───────────────────────────────────────────── */
#flash {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 30%, var(--danger) 100%);
  opacity: 0; transition: opacity 0.08s ease; z-index: 10;
}

/* ─── Bonus message ──────────────────────────────────────────── */
#bonusMsg {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: clamp(20px, 5vw, 30px);
  letter-spacing: 3px;
  color: var(--gem);
  text-shadow: 0 0 24px var(--gem);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 60;
  white-space: nowrap;
}

/* ═══ UNIFIED HUD ════════════════════════════════════════════════
   Anchored top-left to top-right, two stacked rows.
   No overlap possible because it's one box.
════════════════════════════════════════════════════════════════ */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, rgba(0,0,0,0.65) 0%, transparent 100%);
  padding: 0 0 6px;
}

/* Row shared styles */
.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

/* Row 1 — score · lives · speed */
.hud-row-top {
  padding: 12px 20px 4px;
  gap: 0;
}

/* Row 2 — coins · diamonds */
.hud-row-bot {
  padding: 0 20px 8px;
  justify-content: center;
  gap: 32px;
}

/* Cell base */
.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hud-left  { align-items: flex-start; min-width: 80px; }
.hud-right { align-items: flex-end;   min-width: 80px; }
.hud-centre{ align-items: center; flex: 1; }

.hud-label {
  font-size: 8px;
  letter-spacing: 3px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 1px;
}

.hud-value {
  font-family: var(--font-display);
  line-height: 1;
}

.hud-score { font-size: 34px; color: var(--text);    text-shadow: 0 0 16px rgba(255,102,34,.4); }
.hud-speed { font-size: 26px; color: var(--accent2); text-shadow: 0 0 12px rgba(68,170,255,.5); }
.hud-coin  { font-size: 24px; color: var(--gold);    text-shadow: 0 0 10px rgba(255,200,0,.5); }
.hud-gem   { font-size: 24px; color: var(--gem);     text-shadow: 0 0 10px rgba(68,238,255,.5); }

/* Lives */
#livesBox {
  display: flex; gap: 7px; align-items: center; padding-top: 2px;
}
.heart {
  display: inline-block; width: 18px; height: 18px;
  background: var(--danger);
  clip-path: polygon(50% 85%, 15% 50%, 5% 35%, 5% 20%, 20% 5%, 35% 5%, 50% 18%, 65% 5%, 80% 5%, 95% 20%, 95% 35%, 85% 50%);
  transition: opacity .3s, transform .3s;
  filter: drop-shadow(0 0 4px var(--danger));
}
.heart.lost { opacity: .15; filter: none; }

/* Coin/gem cells inline labels */
.hud-coin-cell, .hud-gem-cell {
  align-items: center;
  min-width: 60px;
}

/* ─── Mobile D-pad ───────────────────────────────────────────── */
#mobileControls {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 30;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  pointer-events: all;
}
.dpad-row    { display: flex; align-items: center; gap: 2px; }
.dpad-center {
  width: 52px; height: 52px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border); border-radius: 4px;
}
.dpad-btn {
  width: 52px; height: 52px;
  background: rgba(15,15,30,.85);
  border: 1px solid rgba(255,255,255,.15); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: rgba(255,255,255,.6);
  cursor: pointer;
  transition: background .1s, color .1s, transform .08s;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  touch-action: none; -webkit-user-select: none;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: rgba(255,102,34,.25);
  border-color: var(--accent); color: var(--accent);
  transform: scale(.94);
}

/* ─── Overlay / Menu ─────────────────────────────────────────── */
#overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,8,16,.92);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: opacity .4s ease;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

#overlayContent {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 24px 20px;
  max-width: 420px; width: 100%; position: relative; z-index: 1;
}

.overlay-eyebrow {
  font-size: 10px; letter-spacing: 5px; color: var(--muted); margin-bottom: 8px;
}
.overlay-title {
  font-family: var(--font-display);
  font-size: clamp(72px, 18vw, 110px);
  line-height: .9; letter-spacing: 4px; color: var(--text);
  text-shadow: 0 0 40px rgba(255,102,34,.3), 0 2px 0 rgba(0,0,0,.5);
}
.overlay-title span {
  color: var(--accent);
  text-shadow: 0 0 40px rgba(255,102,34,.7), 0 2px 0 rgba(0,0,0,.5);
}
.overlay-sub {
  font-size: 11px; letter-spacing: 4px; color: var(--muted);
  margin: 14px 0 32px;
}

.controls-grid {
  display: grid; grid-template-columns: repeat(4,1fr);
  gap: 8px; width: 100%; max-width: 360px; margin-bottom: 36px;
}
.ctrl-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.ctrl-key  { font-family: var(--font-display); font-size: 16px; color: var(--accent); letter-spacing: 1px; }
.ctrl-desc { font-size: 8px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }

#startBtn {
  font-family: var(--font-display); font-size: 22px; letter-spacing: 4px;
  background: var(--accent); color: #000;
  border: none; padding: 16px 56px; border-radius: 4px; cursor: pointer;
  transition: transform .1s, background .2s, box-shadow .2s;
  box-shadow: 0 0 30px rgba(255,102,34,.4), 0 4px 0 rgba(0,0,0,.4);
}
#startBtn:hover  { background: #ff8844; box-shadow: 0 0 40px rgba(255,102,34,.6), 0 4px 0 rgba(0,0,0,.4); transform: translateY(-2px); }
#startBtn:active { transform: translateY(1px); box-shadow: 0 0 20px rgba(255,102,34,.4), 0 2px 0 rgba(0,0,0,.4); }

.best-score { font-size: 11px; letter-spacing: 3px; color: var(--muted); margin-top: 20px; }
.best-score span { color: var(--gold); }

#overlay::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background: repeating-linear-gradient(0deg,transparent,transparent 2px,rgba(0,0,0,.04) 2px,rgba(0,0,0,.04) 4px);
  pointer-events: none;
}

/* ─── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive: small phones ───────────────────────────────── */
@media (max-width: 480px) {
  .hud-row-top { padding: 8px 12px 2px; }
  .hud-row-bot { padding: 0 12px 6px; gap: 20px; }
  .hud-score  { font-size: 26px; }
  .hud-speed  { font-size: 20px; }
  .hud-coin, .hud-gem { font-size: 18px; }
  .hud-label  { font-size: 7px; letter-spacing: 2px; }
  .heart      { width: 15px; height: 15px; }
  #livesBox   { gap: 5px; }
  .dpad-btn   { width: 58px; height: 58px; font-size: 20px; }
  .dpad-center{ width: 58px; height: 58px; }
}

@media (max-width: 360px) {
  .dpad-btn   { width: 50px; height: 50px; font-size: 17px; }
  .dpad-center{ width: 50px; height: 50px; }
  .hud-score  { font-size: 22px; }
}

/* ─── Landscape mobile ───────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  #mobileControls { bottom: 8px; right: 16px; left: auto; transform: none; }
  .dpad-btn   { width: 44px; height: 44px; font-size: 15px; }
  .dpad-center{ width: 44px; height: 44px; }
  .hud-row-top{ padding: 6px 12px 2px; }
  .hud-score  { font-size: 22px; }
  .hud-speed  { font-size: 18px; }
  .hud-coin, .hud-gem { font-size: 16px; }
}