/* ==========================================================================
   Spline Rider — interface styles
   The game itself is drawn on the canvas; this file styles the DOM layers
   on top of it (HUD, menus, toasts, touch pedals).
   ========================================================================== */

:root {
  --ink: #23324a;
  --ink-soft: #5b6b84;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #e8463a;
  --accent-dark: #b8322a;
  --gold: #ffcc33;
  --sky: #5ab3f0;
  --good: #3fae4a;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(20, 40, 70, 0.28);
  --font: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #5ab3f0;
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app,
#stage {
  position: fixed;
  inset: 0;
}

canvas {
  display: block;
}

[hidden] {
  display: none !important;
}

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

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}

.hud__group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud__group--left {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.hud__group--center {
  flex-direction: column;
  gap: 0;
}

.hud__group--right {
  justify-content: flex-end;
}

.hud__distance {
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18), 0 0 18px rgba(0, 0, 0, 0.15);
  font-variant-numeric: tabular-nums;
}

.hud__hint {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  min-height: 1em;
}

.gauge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.gauge__icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.gauge__bar {
  width: clamp(100px, 16vw, 170px);
  height: 12px;
  border-radius: 999px;
  background: #e3e8ef;
  overflow: hidden;
}

.gauge__fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform-origin: left center;
  transition: transform 0.15s linear;
}

.gauge__fill--fuel {
  background: linear-gradient(90deg, #ff9f1c, #ffd23f 60%, #8bdc5b);
}

.gauge__fill--boost {
  background: linear-gradient(90deg, #4d7cff, #8fd3ff);
}

.gauge__bar.is-low .gauge__fill--fuel {
  background: #e23b3b;
  animation: blink 0.6s steps(2, start) infinite;
}

.gauge__bar.is-active .gauge__fill--boost {
  background: linear-gradient(90deg, #ff7a1a, #ffe14d);
}

.progress {
  position: relative;
  width: clamp(180px, 30vw, 340px);
  height: 10px;
  margin: 6px 0 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
}

.progress__fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #ffffff;
  transform: scaleX(0);
  transform-origin: left center;
}

.progress__car,
.progress__goal {
  position: absolute;
  top: 50%;
  font-size: 18px;
  line-height: 1;
  transform: translate(-50%, -55%);
}

.progress__car {
  left: 0;
  transform: translate(-50%, -55%) scaleX(-1);
}

.progress__goal {
  left: 100%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.chip--kills.pulse {
  animation: pulse 0.25s ease-out;
}

.icon-button {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font: 600 15px var(--font);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.icon-button:hover {
  background: #fff;
}

/* --- Toasts --------------------------------------------------------------- */

.toasts {
  position: fixed;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: toast 1.8s ease-out forwards;
}

.toast strong {
  font-size: 24px;
  color: var(--good);
}

.toast span {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
}

.toast--info strong {
  color: #2d84d6;
}

.toast--warn strong {
  color: var(--accent);
}

/* --- Screens & panels ------------------------------------------------------ */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 40, 70, 0.15), rgba(20, 40, 70, 0.45));
  overflow-y: auto;
}

.panel {
  width: min(440px, 100%);
  padding: 28px 28px 24px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.35s ease-out;
}

.panel--menu {
  width: min(520px, 100%);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title {
  margin: 0;
  font-size: clamp(46px, 11vw, 68px);
  font-weight: 700;
  line-height: 0.95;
  color: var(--accent);
  text-shadow: 0 4px 0 var(--accent-dark);
}

.title--small {
  font-size: clamp(36px, 8vw, 48px);
}

.title span {
  display: block;
  color: var(--sky);
  text-shadow: 0 4px 0 #2d84d6;
}

.lead {
  margin: 14px auto 18px;
  max-width: 38ch;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.panel__title {
  margin: 0 0 6px;
  font-size: 34px;
  color: var(--ink);
}

.panel__subtitle {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

.panel__best {
  margin: 4px 0 16px;
  color: var(--ink-soft);
}

.button {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  background: #e9eef5;
  color: var(--ink);
  font: 600 18px var(--font);
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.button:hover {
  filter: brightness(1.05);
}

.button:active {
  transform: translateY(2px);
}

.button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid #2d84d6;
  outline-offset: 2px;
}

.button--primary {
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  box-shadow: 0 5px 0 var(--accent-dark);
}

.button--primary:active {
  box-shadow: 0 2px 0 var(--accent-dark);
}

.button--ghost {
  background: transparent;
  color: var(--ink-soft);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls {
  display: grid;
  gap: 6px;
  margin: 20px 0 14px;
  text-align: left;
  font-size: 14px;
  color: var(--ink-soft);
}

.control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control span {
  margin-right: 8px;
}

kbd {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid #d5dce6;
  box-shadow: 0 2px 0 #d5dce6;
  font: 600 13px var(--font);
  text-align: center;
  color: var(--ink);
}

.records,
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0;
}

.records > div,
.stats > div {
  padding: 10px;
  border-radius: 12px;
  background: #f1f5fa;
}

.records__label,
.stats dt {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.records strong,
.stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

.badge {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--gold);
  font-weight: 700;
  color: #6b4a00;
  animation: pulse 0.9s ease-in-out infinite;
}

/* --- Level select ---------------------------------------------------------- */

.panel--levels {
  width: min(880px, 100%);
}

.level-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 16px 0 6px;
}

.level-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border-radius: 16px;
  background: #f1f5fa;
  text-align: left;
  border: 3px solid transparent;
}

.level-card--sunset {
  border-color: #f4a259;
}

.level-card--dusk {
  border-color: #7d5a85;
}

.level-card--night {
  border-color: #26324f;
}

.level-card.is-locked {
  opacity: 0.55;
}

.level-card__number {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.level-card__name {
  margin: 0;
  font-size: 24px;
}

.level-card__tagline,
.level-card__car {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.level-card__car strong {
  color: var(--ink);
}

.level-card__best {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: #2f6f3e;
  min-height: 1.2em;
}

.level-card .button {
  margin-top: auto;
}

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

.pedals {
  display: none;
}

@media (pointer: coarse) {
  body.is-playing .pedals {
    position: fixed;
    inset: auto 0 0 0;
    display: flex;
    justify-content: space-between;
    padding: 0 18px max(18px, env(safe-area-inset-bottom));
    pointer-events: none;
  }
}

.pedal {
  pointer-events: auto;
  width: clamp(96px, 26vw, 140px);
  height: clamp(96px, 26vw, 140px);
  border: 0;
  border-radius: 24px;
  color: #fff;
  font: 700 18px var(--font);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  opacity: 0.85;
  touch-action: none;
}

.pedal--gas {
  background: var(--good);
}

.pedal--brake {
  background: var(--accent);
}

.pedal--boost {
  align-self: flex-end;
  width: clamp(80px, 20vw, 110px);
  height: clamp(80px, 20vw, 110px);
  margin: 0 auto 0 14px;
  background: #4d7cff;
}

body:not(.has-boost) .pedal--boost {
  visibility: hidden;
}

.pedal.is-pressed {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  opacity: 1;
}

/* --- Small screens --------------------------------------------------------- */

@media (max-width: 640px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    padding-inline: 12px;
  }
  .hud__group--center {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .chip--speed {
    display: none;
  }
  .toasts {
    top: 36%;
    width: calc(100% - 32px);
  }
}

/* --- Animations ------------------------------------------------------------ */

@keyframes blink {
  to {
    opacity: 0.35;
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.12);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
}

@keyframes toast {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.9);
  }
  12% {
    opacity: 1;
    transform: translateY(0) scale(1.04);
  }
  20% {
    transform: scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .badge,
  .chip--kills.pulse,
  .gauge__bar.is-low .gauge__fill--fuel {
    animation: none;
  }
}
