:root {
  --fg: #f4f4f2;
  --dim: rgba(244, 244, 242, 0.65);
  --panel: rgba(18, 18, 18, 0.72);
  --line: rgba(255, 255, 255, 0.18);
  --font: "Helvetica Neue", "Inter", "Segoe UI", Roboto, Arial, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1c1c1c;
  color: var(--fg);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD: dashboard cluster, top centre ---------- */
#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
}
.dash {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: clamp(10px, 2.4vw, 22px);
  padding: 6px clamp(12px, 2.6vw, 22px);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(10, 10, 12, 0.55), rgba(10, 10, 12, 0.3));
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.dash-side { display: flex; flex-direction: column; gap: 3px; min-width: clamp(64px, 12vw, 104px); }
.dash-side:first-child { align-items: flex-end; text-align: right; }
.lbl { font-size: 9px; letter-spacing: 0.22em; color: rgba(255, 255, 255, 0.55); }
#dist {
  font-size: clamp(14px, 2.4vw, 18px);
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dash-main { text-align: center; line-height: 1; }
#speed {
  font-size: clamp(30px, 5.6vw, 46px);
  font-weight: 300;
  letter-spacing: -0.02em;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.unit { font-size: 10px; letter-spacing: 0.24em; color: rgba(255, 255, 255, 0.6); margin-top: 2px; }
#speedbar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  overflow: hidden;
}
#speedbar-fill {
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 4px;
}
#speedbar.max #speedbar-fill {
  background: linear-gradient(90deg, #ff2fd0, #ffb300, #00e5ff, #ff2fd0);
  background-size: 300% 100%;
  animation: rainbow 1s linear infinite;
}
#hud.max .dash { border-color: rgba(255, 255, 255, 0.5); box-shadow: 0 0 24px rgba(255, 80, 200, 0.35); }
@keyframes rainbow { to { background-position: 300% 0; } }

#mute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
}
#mute.off { opacity: 0.5; text-decoration: line-through; }

#hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: min(92vw, 640px);
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.8s;
}
#hint span {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
#hint.fade { opacity: 0; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.55));
  cursor: pointer;
}
.panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: hidden;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(16px, 4vh, 32px) clamp(16px, 4vw, 36px);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
h1 {
  font-size: clamp(34px, 9vw, 64px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  font-style: italic;
}
h2 {
  font-size: clamp(30px, 7vw, 52px);
  font-weight: 900;
  letter-spacing: 0.03em;
  font-style: italic;
  line-height: 1;
}
.tag {
  margin-top: 8px;
  color: var(--dim);
  font-size: clamp(13px, 2.2vw, 16px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.controls {
  list-style: none;
  margin: clamp(12px, 3vh, 24px) 0 clamp(8px, 2vh, 14px);
  display: grid;
  gap: 8px;
  text-align: left;
}
.controls li {
  display: grid;
  grid-template-columns: 112px 1fr;
  align-items: center;
  gap: 12px;
  font-size: clamp(13px, 2.2vw, 15px);
}
.controls b {
  display: inline-block;
  text-align: center;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  font-size: 12px;
  letter-spacing: 0.08em;
}
.controls span { color: var(--dim); }
.keys { color: var(--dim); font-size: 12px; }
kbd {
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}
.start {
  margin-top: clamp(12px, 3vh, 22px);
  font-weight: 900;
  letter-spacing: 0.2em;
  font-size: clamp(15px, 2.6vw, 18px);
}
.blink { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.best { margin-top: 8px; color: var(--dim); font-size: 13px; letter-spacing: 0.06em; }
.rotate-hint { display: none; margin-top: 10px; color: var(--dim); font-size: 12px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: clamp(14px, 3vh, 22px);
}
.stats div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 4px;
}
.stats span {
  display: block;
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.stats b {
  display: block;
  margin-top: 4px;
  font-size: clamp(16px, 3.4vw, 22px);
  font-variant-numeric: tabular-nums;
}
#go-retry.wait { visibility: hidden; animation: none; }

@media (orientation: portrait) and (max-width: 600px) {
  .rotate-hint { display: block; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .controls li { grid-template-columns: 96px 1fr; }
}
@media (max-height: 420px) {
  .controls { gap: 4px; margin: 10px 0 6px; }
  .controls b { padding: 3px 6px; }
  .tag { margin-top: 4px; }
  .rotate-hint { display: none; }
}

/* ---------- Credits (bottom of start / game-over screens) ---------- */
.overlay::before { content: ''; flex: 1 1 0; min-height: 8px; }
.credits {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding: 12px 0 max(6px, env(safe-area-inset-bottom));
  text-align: center;
  cursor: default;
}
.credits a { color: inherit; }
.maker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  opacity: 0.85;
  transition: opacity 0.2s;
}
.maker:hover, .maker:focus-visible { opacity: 1; }
.maker span { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
.maker img { display: block; width: clamp(96px, 16vw, 140px); height: auto; }
.inspired { font-size: 11px; color: var(--dim); letter-spacing: 0.04em; }
.inspired a { text-decoration: underline; text-underline-offset: 2px; }
.inspired a:hover { color: #fff; }
@media (max-height: 420px) {
  .overlay { padding: 8px 16px; }
  .panel { padding: 12px 20px; }
  h1 { font-size: 38px; }
  h2 { font-size: 32px; }
  .keys { display: none; }
  .start { margin-top: 8px; }
  .best { margin-top: 2px; }
  .stats { margin-top: 10px; }
  .stats div { padding: 6px 4px; }
  .credits { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-end; column-gap: 18px; row-gap: 2px; padding-top: 6px; }
  .maker img { width: 84px; }
}
