:root {
  --asphalt: #23262b;
  --asphalt-2: #2f3339;
  --hivis: #ffd400;
  --orange: #ff7a1a;
  --red: #e5322d;
  --green: #2ecc71;
  --paper: #f7f3e6;
  --ink: #1b1d20;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--asphalt);
}

body {
  font-family: "Nunito", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--paper);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
}

.back-link {
  color: var(--hivis);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}

.title {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mute-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(247, 243, 230, 0.35);
  background: transparent;
  color: rgba(247, 243, 230, 0.9);
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-btn[hidden] { display: none; }
.mute-btn.is-muted { color: rgba(247, 243, 230, 0.4); }

/* ---------- HUD ---------- */
.hud {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 12px 8px;
}

.stat {
  background: var(--asphalt-2);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stat-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(247, 243, 230, 0.6);
}
.stat-value {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
  line-height: 1.1;
  color: var(--hivis);
  white-space: nowrap;
}
.stat-value small { font-size: 0.65em; font-weight: 700; opacity: 0.75; }
.stat-jam .stat-value.warn { color: var(--orange); }
.stat-jam .stat-value.danger { color: var(--red); }

.meter {
  grid-column: 1 / -1;
  position: relative;
  height: 16px;
  border-radius: 8px;
  background: #15171a;
  overflow: hidden;
  border: 1px solid rgba(247, 243, 230, 0.15);
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--hivis) 55%, var(--red));
  background-size: 100vw 100%;
  transition: width 0.25s linear;
}
.meter.flash { animation: flash 0.5s steps(2) infinite; }
@keyframes flash { 50% { border-color: var(--red); box-shadow: 0 0 10px var(--red); } }
.meter-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px #000;
}

/* ---------- stage / map ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border-top: 3px solid var(--hivis);
  border-bottom: 3px solid var(--hivis);
}
.map { position: absolute; inset: 0; background: #e8e6df; }
.leaflet-tile-pane { filter: grayscale(0.75) contrast(0.9) brightness(1.08); }
.leaflet-container { font-family: "Nunito", sans-serif; }
.leaflet-control-attribution { font-size: 9px; }

.floaters { position: absolute; inset: 0; pointer-events: none; z-index: 800; overflow: hidden; }
.floater {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  animation: rise 1.1s ease-out forwards;
}
.floater.bad { color: var(--red); }
@keyframes rise {
  from { opacity: 1; margin-top: 0; }
  to { opacity: 0; margin-top: -50px; }
}

/* ---------- roadworks markers ---------- */
.wk { background: none; border: none; }
.wk-inner {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  pointer-events: auto;
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

.wk-badge {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--hivis);
  border: 3px solid var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
}
.wk-legit .wk-badge { background: #6ec6ff; border-style: dashed; }
.wk-boss .wk-badge { background: var(--red); width: 54px; height: 54px; margin: -5px 0 0 -5px; font-size: 30px; animation: bossy 0.6s ease-in-out infinite alternate; }
@keyframes bossy { to { transform: scale(1.08) rotate(-4deg); } }
.wk-inner.hit { animation: shake 0.22s; }
@keyframes shake {
  25% { transform: translateX(-5px) rotate(-6deg); }
  75% { transform: translateX(5px) rotate(6deg); }
}
.wk-inner.die { animation: die 0.3s ease-in forwards; }
@keyframes die { to { transform: scale(1.5); opacity: 0; } }

.wk-pips {
  position: absolute;
  left: 50%;
  top: -9px;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
}
.wk-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  border: 1.5px solid #fff;
}
.wk-legit .wk-pip { background: var(--green); }

.wk-label {
  position: absolute;
  left: 50%;
  top: 46px;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  pointer-events: none;
}

.wk-timer {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 3px solid var(--green);
  animation: legit-timer 7s linear forwards;
  opacity: 0.8;
}
@keyframes legit-timer { to { border-color: transparent; transform: scale(0.85); } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(20, 22, 26, 0.6);
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.game.is-paused *:not(.countdown-num) { animation-play-state: paused !important; }

.card {
  width: 100%;
  max-width: 420px;
  margin: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  padding: 0 20px 18px;
  overflow: hidden;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}
.chevrons {
  height: 18px;
  margin: 0 -20px 14px;
  background: repeating-linear-gradient(-45deg, var(--hivis) 0 14px, var(--ink) 14px 28px);
}
.card-title {
  margin: 0 0 4px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 2.2rem;
  line-height: 1;
  text-transform: uppercase;
  color: var(--orange);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
}
.card-title.small { font-size: 1.6rem; }
.card-lead { margin: 6px 0 10px; font-weight: 800; }

.howto {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  text-align: left;
  font-size: 0.9rem;
}
.howto li { padding: 4px 0 4px 20px; position: relative; }
.howto li::before { content: "\1F6A7"; position: absolute; left: 0; font-size: 0.8rem; top: 6px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; border: 1px solid var(--ink); }
.dot.g { background: var(--green); }
.dot.y { background: var(--hivis); }
.dot.r { background: var(--red); }

.diff { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 0 6px; }
.diff-btn {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
  background: #e9e3cd;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 5px 2px;
  cursor: pointer;
}
.diff-btn.active { background: var(--hivis); box-shadow: 0 3px 0 var(--ink); transform: translateY(-2px); }
.diff-btn.insane.active { background: var(--red); color: #fff; }
.diff-note { margin: 0 0 12px; font-size: 0.8rem; font-weight: 700; color: #6b6d72; }
.link-btn {
  display: block;
  margin: 12px auto 0;
  background: none;
  border: none;
  color: #6b6d72;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

.btn {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--hivis);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 26px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.fine { font-size: 0.68rem; color: #6b6d72; margin: 12px 0 0; }

.release {
  font-style: italic;
  font-size: 0.92rem;
  margin: 8px 0 12px;
  padding: 8px 10px;
  background: #e9e3cd;
  border-left: 4px solid var(--orange);
  text-align: left;
}
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.results .stat-label { display: block; color: #6b6d72; }
.big { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 1.6rem; line-height: 1.1; }
.rank { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 1.15rem; margin: 4px 0 0; color: var(--orange); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.best-note { margin: 2px 0 12px; font-size: 0.85rem; font-weight: 700; }

/* ---------- ticker ---------- */
.ticker {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  min-height: 34px;
  background: var(--asphalt-2);
}
.ticker-tag {
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 0 10px;
  display: flex;
  align-items: center;
}
.ticker-text {
  flex: 1;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  min-width: 0;
  line-height: 1.2;
}

@media (min-width: 700px) {
  .title { font-size: 1.4rem; }
  .stat-value { font-size: 1.5rem; }
  .ticker-text { font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .wk-boss .wk-badge, .meter.flash { animation: none; }
}

/* ---------- combo, countdown, help ---------- */
.combo {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 850;
  pointer-events: none;
  padding: 2px 14px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: var(--hivis);
  color: var(--ink);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.1rem;
  text-transform: uppercase;
  white-space: nowrap;
}
.combo[hidden] { display: none; }
.combo[data-level="3"], .combo[data-level="4"] { background: var(--orange); }
.combo[data-level="5"] { background: var(--red); color: #fff; }
.combo.bump { animation: pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1); }

.stage.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 840;
  pointer-events: none;
  box-shadow: inset 0 0 40px 6px rgba(255, 190, 0, 0.75);
  animation: flashout 0.35s ease-out forwards;
}
@keyframes flashout { to { opacity: 0; } }

.overlay.countdown { background: rgba(20, 22, 26, 0.35); z-index: 950; }
.countdown-num {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 7rem;
  color: var(--hivis);
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  animation: pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.overlay.help { z-index: 960; }

.diff-over { margin: 14px 0 0; }
.diff-over .diff-btn { font-size: 0.8rem; padding: 4px 2px; }

@media (prefers-reduced-motion: reduce) {
  .stage.flash::after, .combo.bump, .countdown-num { animation: none; }
}
