:root {
  --ink: #15161c;
  --paper: #fffefa;
  --lime: #d8fd71;
  --yellow: #f5c518;
  --muted: rgba(255, 254, 250, 0.7);
  --panel: rgba(21, 22, 28, 0.88);
  --display: "Bungee", "Impact", "Arial Black", sans-serif;
  font-family: "Rubik", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #87c9e8;
  color: var(--paper);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.startng-card {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--paper);
  z-index: 5;
}
.startng-card img { width: 44px; height: 44px; border-radius: 50%; background: var(--lime); }
.startng-card b { display: block; font-size: 15px; line-height: 1.1; }
.startng-card span { font-size: 12px; opacity: 0.7; }
.startng-card button {
  margin-left: 8px;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--lime);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.hud {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 5;
}
.stat {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 14px;
  min-width: 78px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.stat .label, .results .label { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; }
.stat b { font-family: var(--display); font-size: 22px; line-height: 1.1; color: var(--yellow); }
.stat.lives b { color: #ff5c5c; letter-spacing: 2px; }
.tag.small { font-size: 13px; }

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--lime);
  font-weight: 700;
  font-size: 16px;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
}
.toast.show { animation: toast 1.6s ease forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  15% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.icon-btn {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  color: var(--paper);
  font-size: 20px;
  cursor: pointer;
  z-index: 5;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(21, 22, 28, 0.35);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.overlay[hidden] { display: none; }
.panel {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: linear-gradient(160deg, rgba(34, 36, 46, 0.95), rgba(16, 17, 22, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 26px 26px 28px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  border-radius: 24px 24px 0 0;
  background: repeating-linear-gradient(90deg, var(--yellow) 0 24px, var(--ink) 24px 48px);
}
.logo { margin-bottom: 8px; }
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--lime);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.panel h1 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 44px;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--paper);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}
.panel h1 span { color: var(--yellow); }
.panel h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 26px;
  line-height: 1.1;
  color: var(--yellow);
}
.legend {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}
.legend li { display: flex; align-items: center; gap: 8px; }
.sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.sw.grass { background: #8fd14f; }
.sw.road { background: #4a4a52; box-shadow: inset 0 0 0 2px #4a4a52, inset 0 0 0 3px #f2f2f2; }
.sw.rail { background: #8a7f72; box-shadow: inset 0 -3px 0 #ff3b30; }
.sw.coin { background: #f5c518; border-radius: 50%; }
.tag { margin: 0 0 14px; color: var(--muted); }
.controls { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  margin: 0 1px;
  border-radius: 5px;
  background: #2b2d38;
  border: 1px solid #454858;
  font-family: inherit;
  font-size: 12px;
  color: var(--paper);
}
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; min-height: 1em; }

button.primary, button.ghost {
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
button.primary {
  background: var(--lime);
  color: var(--ink);
  box-shadow: 0 6px 0 #9ebf3c, 0 12px 24px rgba(216, 253, 113, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
button.primary:hover { transform: translateY(-1px); }
button.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #9ebf3c; }
button.primary.big { font-size: 20px; padding: 14px 44px; font-family: var(--display); letter-spacing: 0.04em; }
button.ghost { background: transparent; color: var(--paper); border: 2px solid var(--lime); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.results {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 4px 0 8px;
}
.results b { font-family: var(--display); font-size: 26px; color: var(--yellow); }

.board {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  text-align: left;
  font-size: 14px;
}
.board li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
}
.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.05); }
.board li.me { background: rgba(216, 253, 113, 0.18); outline: 1px solid rgba(216, 253, 113, 0.5); }
.board .rank { opacity: 0.7; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .num { font-variant-numeric: tabular-nums; opacity: 0.9; }
.board li.note { display: block; text-align: center; opacity: 0.7; }

.dpad {
  position: fixed;
  left: 16px;
  bottom: 16px;
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  z-index: 5;
}
.dpad button {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: var(--panel);
  color: var(--paper);
  font-size: 18px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.dpad button:active { transform: translateY(3px); box-shadow: none; background: #2b2d38; }
.dpad button[data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad button[data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad button[data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad button[data-dir="right"] { grid-column: 3; grid-row: 2; }

@media (pointer: coarse) {
  .dpad { display: grid; }
  .controls { display: none; }
}
@media (max-width: 480px) {
  .startng-card { padding: 6px 12px 6px 6px; gap: 8px; }
  .startng-card img { width: 36px; height: 36px; }
  .startng-card b { font-size: 13px; }
  .stat { min-width: 64px; padding: 6px 10px; }
  .stat b { font-size: 20px; }
  .panel h1 { font-size: 30px; }
}
