:root {
  --bg-top: #6f7a4e;
  --bg-bottom: #454d31;
  --ink: #f4f1e4;
  --panel: rgba(30, 34, 22, 0.72);
  --accent: #ffd640;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2b2f24;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-top)) 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  gap: 12px;
}

.title {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1px;
  text-align: center;
  flex: 1;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 72px;
  font-size: 20px;
  font-weight: bold;
}
.hud-right { align-items: flex-end; }
.hud-label {
  font-size: 11px;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
}
#lives { color: #ff6b6b; letter-spacing: 2px; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #bfe3e0 url("../assets/bg/street.png") center bottom / cover no-repeat;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#sound-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(30, 34, 22, 0.6);
  color: var(--ink);
  font-size: 20px;
  line-height: 42px;
  text-align: center;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition: transform 0.08s ease, background 0.15s ease;
}
#sound-btn:hover { background: rgba(30, 34, 22, 0.8); }
#sound-btn:active { transform: scale(0.92); }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 23, 15, 0.55);
  backdrop-filter: blur(3px);
  padding: 20px;
}
#overlay.hidden { display: none; }

.card {
  background: var(--panel);
  border: 2px solid rgba(255, 214, 64, 0.4);
  border-radius: 16px;
  padding: 26px 24px;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.card h2 {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 26px;
}
.card p {
  margin: 0 0 20px;
  line-height: 1.5;
  font-size: 15px;
  opacity: 0.92;
}

#start-btn {
  font: inherit;
  font-size: 18px;
  font-weight: bold;
  color: #2b2f24;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 34px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}
#start-btn:hover { filter: brightness(1.05); }
#start-btn:active { transform: scale(0.96); }

.hidden { display: none !important; }

#name-wrap { margin: 0 0 18px; }
#name-input {
  font: inherit;
  font-size: 17px;
  text-align: center;
  width: 100%;
  max-width: 240px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255, 214, 64, 0.4);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  outline: none;
}
#name-input:focus { border-color: var(--accent); }
#name-input.nudge { animation: nudge 0.3s; }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

#greeting { margin: 0 0 18px; font-size: 14px; opacity: 0.9; }
#greeting a { color: var(--accent); }

#leaderboard { margin: 0 0 18px; }
#leaderboard:empty { margin: 0; }
.lb-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 8px;
}
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  text-align: left;
}
.lb-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 15px;
}
.lb-row:nth-child(odd) { background: rgba(255, 255, 255, 0.05); }
.lb-row.lb-me {
  background: rgba(255, 214, 64, 0.22);
  outline: 1px solid rgba(255, 214, 64, 0.55);
}
.lb-rank { width: 2.2em; text-align: right; opacity: 0.7; font-variant-numeric: tabular-nums; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: bold; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-note, .lb-loading, .lb-error {
  margin-top: 8px;
  font-size: 13px;
  opacity: 0.8;
}
.lb-me-note { color: var(--accent); }

#foot {
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  opacity: 0.7;
  background: var(--panel);
}
#foot a { color: var(--accent); }
