/* Grove Prix — UI chrome. The world is drawn on <canvas>; everything here
   is menus + HUD laid over it. */

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

[hidden] { display: none !important; }

:root {
  --ink: #f3efe2;
  --dim: #b9b4a2;
  --green: #7cb542;
  --green-dark: #3f6b1f;
  --gold: #ffd166;
  --bg: #10150e;
  --panel: rgba(16, 22, 13, 0.92);
  --line: rgba(243, 239, 226, 0.14);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: #1b241a;
}

/* ---------------- overlays ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(124, 181, 66, 0.14), transparent 55%),
    linear-gradient(180deg, rgba(9, 13, 8, 0.94), rgba(9, 13, 8, 0.97));
  text-align: center;
  overflow-y: auto;
  z-index: 20;
}
.overlay--pause { background: rgba(9, 13, 8, 0.78); }

.brand-kicker {
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
}
.brand {
  font-family: "Bungee", "Space Grotesk", sans-serif;
  font-size: clamp(2.6rem, 9vw, 5.2rem);
  line-height: 1;
  color: var(--green);
  text-shadow: 0 4px 0 var(--green-dark), 0 10px 30px rgba(124, 181, 66, 0.35);
  transform: rotate(-2deg);
}
.brand-sub { color: var(--gold); letter-spacing: 0.12em; font-size: 0.95rem; }

h2 {
  font-family: "Bungee", sans-serif;
  font-weight: 400;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  color: var(--gold);
}
h3 { color: var(--gold); margin: 10px 0 6px; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; min-width: 240px; }

.btn {
  font: 700 1rem "Space Grotesk", sans-serif;
  color: var(--ink);
  background: rgba(243, 239, 226, 0.08);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: rgba(243, 239, 226, 0.16); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--green);
  border-color: var(--green-dark);
  color: #101507;
  box-shadow: 0 4px 0 var(--green-dark);
}
.btn--primary:hover { background: #8cc653; }
.btn--gold {
  background: var(--gold);
  border-color: #a8791a;
  color: #241b05;
  box-shadow: 0 4px 0 #a8791a;
}
.btn--gold:hover { background: #ffdc85; }
.btn--ghost { background: transparent; }

.back-link {
  margin-top: 20px;
  color: var(--dim);
  font-size: 0.85rem;
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }

/* how-to card */
.overlay--card { gap: 16px; }
.rules {
  max-width: 620px;
  text-align: left;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.95rem;
  color: #ddd8c6;
}
.rules b { color: var(--ink); }
kbd {
  font: 600 0.8rem "Space Grotesk", sans-serif;
  background: rgba(243, 239, 226, 0.12);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---------------- select screens ---------------- */
.overlay--wide { justify-content: flex-start; padding-top: max(26px, 4vh); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 200px));
  justify-content: center;
  gap: 12px;
  width: min(1080px, 96vw);
  margin-top: 6px;
}

.kart-card, .track-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px 12px;
  color: var(--ink);
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.kart-card:hover, .track-card:hover { transform: translateY(-2px); border-color: rgba(243, 239, 226, 0.4); }
.kart-card.is-sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 8px 26px rgba(255, 209, 102, 0.25); }

.kart-card__art { display: block; margin: 0 auto; }
.kart-card__name, .track-card__name { font-weight: 700; font-size: 1rem; margin-top: 2px; }
.kart-card__desc, .track-card__blurb { font-size: 0.74rem; color: var(--dim); margin-top: 6px; line-height: 1.35; }

.kart-card__bars { display: flex; flex-direction: column; gap: 3px; margin-top: 7px; }
.statbar { display: flex; align-items: center; gap: 6px; }
.statbar span { font-size: 0.6rem; letter-spacing: 0.08em; color: var(--dim); width: 26px; text-align: left; }
.statbar__track { flex: 1; height: 6px; background: rgba(243, 239, 226, 0.1); border-radius: 3px; overflow: hidden; }
.statbar__fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); border-radius: 3px; }

.track-card__map { display: block; margin: 0 auto; border-radius: 8px; }
.track-card__meta { font-size: 0.72rem; color: var(--gold); margin-top: 3px; }

.diff { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.diff__label { color: var(--dim); font-size: 0.9rem; }
.diff__row { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.diff__row button {
  font: 600 0.85rem "Space Grotesk", sans-serif;
  color: var(--dim);
  background: transparent;
  border: 0;
  padding: 8px 16px;
  cursor: pointer;
}
.diff__row button + button { border-left: 1px solid var(--line); }
.diff__row button.is-sel { background: var(--green); color: #101507; }

.row-buttons { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }

/* ---------------- results ---------------- */
.results-sub { color: var(--gold); }
.results { border-collapse: collapse; margin-top: 4px; }
.results th, .results td { padding: 5px 14px; font-size: 0.92rem; }
.results th { color: var(--dim); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.results td:first-child { color: var(--gold); font-weight: 700; }
.results tr.is-you td { color: var(--green); font-weight: 700; }
.results tbody tr:nth-child(odd) { background: rgba(243, 239, 226, 0.05); }

.cup-list { list-style-position: inside; color: var(--dim); display: flex; flex-direction: column; gap: 2px; }
.cup-list .is-you { color: var(--green); font-weight: 700; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

.hud__top {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: calc(100vw - 190px);
}
.hud__pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.hud__pos { color: var(--gold); font-size: 1.15rem; min-width: 64px; text-align: center; }
.hud__track { color: var(--dim); font-weight: 500; }

.hud__item {
  position: absolute;
  top: 64px;
  left: 12px;
  width: 66px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: 14px;
}
.hud__item--full { border-style: solid; border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 209, 102, 0.35); }

#hud-minimap {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(9, 13, 8, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
}

#hud-count {
  position: absolute;
  top: 32%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: "Bungee", sans-serif;
  font-size: clamp(3rem, 11vw, 6.5rem);
  color: var(--gold);
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.45), 0 12px 40px rgba(255, 209, 102, 0.4);
}

#hud-wrong {
  position: absolute;
  top: 48%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: "Bungee", sans-serif;
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: #ff6b5e;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
  animation: blink 0.5s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

#hud-msg {
  position: absolute;
  bottom: 18%;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

/* ---------------- touch controls ---------------- */
#touch { display: none; }
#touch.is-on { display: block; }
.touch__cluster {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
  align-items: flex-end;
  pointer-events: auto;
}
.touch__cluster--left { left: 14px; }
.touch__cluster--right { right: 14px; }
.touch__btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: rgba(16, 22, 13, 0.7);
  color: var(--ink);
  font-size: 1.6rem;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.touch__btn:active { background: rgba(124, 181, 66, 0.45); }
.touch__btn--small { width: 56px; height: 56px; font-size: 1.1rem; }

@media (max-width: 640px) {
  .hud__track { display: none; }
  #hud-minimap { width: 108px; height: 108px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 165px)); }
}
