/* Hill Hopper — UI chrome over the canvas scene. */

:root {
  --panel: linear-gradient(180deg, rgba(18, 24, 34, 0.8), rgba(12, 17, 26, 0.72));
  --panel-line: rgba(255, 255, 255, 0.14);
  --text: #f2f6fa;
  --muted: #9fb2c8;
  --accent: #ffd166;
  --gas: #43c15c;
  --brake: #ef5350;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e1420;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- top HUD ---------- */

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
}

.hud-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.hud-group.right {
  justify-content: flex-end;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 7px 12px;
  color: var(--text);
  box-shadow: 0 6px 18px rgba(4, 8, 14, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
}

.gauge {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 86px;
}

.chip-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.chip-value {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.unit {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}

/* status pill */
.status {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 9px 14px;
  border-radius: 999px;
  transition: background-color 0.25s, border-color 0.25s, color 0.25s;
}

.status[data-state="driving"] {
  color: #8ff0b0;
  border-color: rgba(53, 194, 110, 0.55);
  background: linear-gradient(180deg, rgba(24, 54, 38, 0.8), rgba(16, 38, 27, 0.75));
}

.status[data-state="crashed"] {
  color: #ffb3b5;
  border-color: rgba(239, 83, 80, 0.6);
  background: linear-gradient(180deg, rgba(66, 24, 26, 0.85), rgba(46, 16, 18, 0.8));
}

.status[data-state="outOfFuel"] {
  color: #ffd9a0;
  border-color: rgba(255, 176, 32, 0.6);
  background: linear-gradient(180deg, rgba(64, 46, 16, 0.85), rgba(44, 32, 12, 0.8));
}

/* fuel */
.fuel-chip {
  padding: 7px 10px;
}

.fuel-chip.flash {
  animation: fuel-flash 0.45s ease-out;
}

@keyframes fuel-flash {
  0% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.75); }
  100% { box-shadow: 0 0 0 14px rgba(255, 209, 102, 0); }
}

.fuel-bar {
  position: relative;
  display: inline-block;
  width: clamp(64px, 12vw, 120px);
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.fuel-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #95e06c, #3fae5a);
  transition: width 0.15s linear;
}

.fuel-fill.low {
  background: linear-gradient(90deg, #ff8a5c, #ef4444);
  animation: fuel-low 0.9s ease-in-out infinite;
}

@keyframes fuel-low {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.fuel-text {
  font-size: 13px;
  font-weight: 800;
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* seed */
.seed-chip {
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, transform 0.1s;
}

.seed-chip:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.seed-chip:active {
  transform: translateY(1px);
}

.seed-text {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

/* icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 0.15s, transform 0.1s, background-color 0.15s;
}

.icon-btn:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.icon-btn:active {
  transform: translateY(1px) scale(0.97);
}

.icon-btn:focus-visible,
.pedal:focus-visible,
.seed-chip:focus-visible,
.big-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.icon-btn.accent {
  color: #33270c;
  background: linear-gradient(180deg, #ffd166, #f0b23e);
  border-color: rgba(0, 0, 0, 0.2);
}

.icon-btn .slash {
  display: none;
}

.icon-btn.muted .slash {
  display: block;
}

.icon-btn.muted .wave {
  display: none;
}

/* ---------- vehicle badge / hint / toast ---------- */

.vehicle-chip {
  position: absolute;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
}

.vehicle-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #43c15c;
  transition: background-color 0.2s;
}

.vehicle-chip[data-mode="air"]::before {
  background: #4ea3f0;
}

.vehicle-chip[data-mode="crashed"]::before {
  background: #ef5350;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(66px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2;
  font-size: 12px;
  font-weight: 600;
  color: #dbe7f3;
  white-space: nowrap;
  max-width: 94vw;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: opacity 0.6s, transform 0.6s;
}

.hint.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
}

.hint b {
  color: var(--accent);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(118px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 3;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- pedals ---------- */

.pedals {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.pedal {
  pointer-events: auto;
  touch-action: none;
  width: 94px;
  height: 94px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(4, 8, 14, 0.45), inset 0 -8px 14px rgba(0, 0, 0, 0.28), inset 0 6px 10px rgba(255, 255, 255, 0.18);
  transition: transform 0.08s, filter 0.08s, box-shadow 0.08s;
}

.pedal.gas {
  background: radial-gradient(circle at 35% 28%, #6fe089, #2f9e4a 72%);
}

.pedal.brake {
  background: radial-gradient(circle at 35% 28%, #ff8a80, #c93a36 72%);
}

.pedal.pressed,
.pedal:active {
  transform: translateY(4px) scale(0.95);
  filter: brightness(1.2);
  box-shadow: 0 6px 14px rgba(4, 8, 14, 0.5), inset 0 -4px 10px rgba(0, 0, 0, 0.35);
}

/* ---------- end overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 16, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(400px, 92vw);
  background: linear-gradient(180deg, rgba(20, 26, 38, 0.96), rgba(13, 18, 27, 0.96));
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  padding: 26px 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: card-pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes card-pop {
  from { transform: scale(0.85) translateY(12px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.overlay-card h2 {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.overlay[data-state="crashed"] h2 {
  color: #ff8a80;
}

.overlay[data-state="outOfFuel"] h2 {
  color: #ffd166;
}

.overlay-reason {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 12px 18px;
  margin: 0 0 14px;
}

.stats dt {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats dd {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.overlay-seed {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
}

.overlay-seed span {
  color: var(--text);
  font-weight: 700;
}

.big-btn {
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffd166, #f0b23e);
  color: #33270c;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(240, 178, 62, 0.3), inset 0 -4px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.08s, filter 0.08s;
}

.big-btn:hover {
  filter: brightness(1.05);
}

.big-btn:active {
  transform: translateY(2px);
}

/* ---------- error banner ---------- */

.error-banner {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  max-width: 92vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: #7c2d2d;
  color: #ffe3e3;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- responsive ---------- */

@media (max-width: 620px) {
  .chip-value {
    font-size: 16px;
  }

  .gauge {
    min-width: 70px;
  }

  .chip {
    padding: 6px 10px;
    border-radius: 12px;
  }

  .pedal {
    width: 78px;
    height: 78px;
  }

  .pedal svg {
    width: 26px;
    height: 26px;
  }

  .hint {
    font-size: 11px;
    bottom: calc(60px + env(safe-area-inset-bottom));
  }

  .vehicle-chip {
    bottom: calc(22px + env(safe-area-inset-bottom));
  }

  .toast {
    bottom: calc(104px + env(safe-area-inset-bottom));
  }

  .stats dd {
    font-size: 17px;
  }
}

@media (max-height: 480px) {
  .pedal {
    width: 64px;
    height: 64px;
  }

  .hint {
    display: none;
  }

  .overlay-card {
    padding: 16px 20px;
  }

  .overlay-card h2 {
    font-size: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fuel-fill.low,
  .overlay-card {
    animation: none;
  }
}
