:root {
  --panel-bg: rgba(16, 28, 19, 0.92);
  --panel-border: rgba(255, 255, 255, 0.14);
  --accent: #7ed957;
  --accent-dark: #3d8b37;
  --gold: #ffd94d;
  --danger: #ff5a5a;
  --text: #f2f5ef;
  --muted: #b9c6b4;
  --hud-bg: rgba(12, 20, 14, 0.62);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #101c13;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-container, #game-container canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
  pointer-events: none; z-index: 5;
}
#hud.hidden { display: none; }

#stats {
  display: flex; gap: 8px;
  background: var(--hud-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#stats span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
#stats b { color: var(--text); font-variant-numeric: tabular-nums; }
#stat-gifts b { color: var(--gold); }

#hud-buttons { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--hud-bg);
  color: var(--text);
  font-size: 17px; font-weight: 700;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.icon-btn:hover { background: rgba(40, 60, 44, 0.8); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.muted { color: var(--danger); text-decoration: line-through; }

/* ---------- Toast + damage ---------- */
#toast {
  position: fixed; left: 50%; bottom: 110px;
  transform: translateX(-50%);
  background: rgba(10, 16, 11, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 16px; font-weight: 700;
  z-index: 6; pointer-events: none;
  transition: opacity 0.25s ease;
  white-space: nowrap;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.hidden { opacity: 0; }
#toast.warn { border-color: var(--danger); color: #ffc9c9; }

#damage-flash {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 30, 30, 0.55) 100%);
  opacity: 0; transition: opacity 0.12s ease;
}

/* ---------- Touch controls ---------- */
#touch-controls.hidden { display: none; }
#joystick {
  position: fixed; left: 22px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 124px; height: 124px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.25);
  z-index: 7;
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(126, 217, 87, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.6);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
#btn-jump {
  position: fixed; right: 22px; bottom: calc(30px + env(safe-area-inset-bottom));
  width: 92px; height: 92px; border-radius: 50%;
  background: rgba(126, 217, 87, 0.9);
  border: 3px solid rgba(255, 255, 255, 0.55);
  color: #0e2410; font-weight: 800; font-size: 15px;
  z-index: 7; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  font-family: inherit;
}
#btn-jump:active { transform: scale(0.93); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(5, 10, 6, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
}
.overlay.hidden { display: none; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 28px 30px;
  max-width: 520px; width: 100%;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}
.panel h1 {
  font-size: 34px; letter-spacing: 0.5px;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  margin: 6px 0 8px;
}
.tagline { color: var(--muted); margin-bottom: 16px; font-size: 15px; }
.howto { text-align: left; margin: 0 auto 16px; max-width: 430px; line-height: 1.55; font-size: 14.5px; }
.howto li { margin: 6px 0 6px 18px; }
.howto b { color: var(--gold); }
kbd {
  background: #243024; border: 1px solid #4a5f4c; border-bottom-width: 3px;
  border-radius: 6px; padding: 1px 7px; font-size: 13px; font-family: inherit;
  white-space: nowrap;
}
.controls-grid {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 18px; font-size: 14px; color: var(--muted);
}
.controls-grid div { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.controls-grid span:last-child { opacity: 0.85; }
.touch-hint { color: var(--accent); font-weight: 700; }

.big-btn {
  background: linear-gradient(180deg, #8bea63, #54b04a);
  border: none; border-radius: 12px;
  color: #0d240f; font-weight: 800; font-size: 18px;
  padding: 13px 34px; cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 0 #2c6e28, 0 8px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.big-btn:hover { filter: brightness(1.06); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #2c6e28; }
.big-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.fineprint { margin-top: 14px; font-size: 12.5px; color: var(--muted); }

#win-stats {
  display: flex; gap: 10px; justify-content: center;
  margin: 6px 0 4px; flex-wrap: wrap;
}
#win-stats div {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 10px 18px; min-width: 110px;
}
#win-stats div b { display: block; font-size: 22px; color: var(--gold); }
#win-stats div span { font-size: 12.5px; color: var(--muted); }

.dino-badge svg { filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5)); }

@media (max-width: 560px) {
  .panel { padding: 22px 18px; }
  .panel h1 { font-size: 27px; }
  #stats { font-size: 13px; padding: 7px 11px; }
  #toast { bottom: 170px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast, .big-btn, .icon-btn { transition: none; }
}
