* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  touch-action: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.3);
  text-align: center;
}
.overlay.hidden { display: none; }

h1 {
  margin: 0;
  font-size: clamp(36px, 9vmin, 84px);
  letter-spacing: 2px;
  color: #ffb74d;
  text-shadow: 0 4px 0 #6d2a10, 0 8px 18px rgba(0, 0, 0, 0.7);
}
h2 { margin: 0 0 6px; font-size: clamp(26px, 6vmin, 44px); }

.title {
  font-size: clamp(40px, 10vmin, 92px);
  line-height: 1.05;
  transform: rotate(-3deg);
}
.title span { display: inline-block; }
.title .run {
  color: #ff7043;
  animation: run-wobble 0.5s ease-in-out infinite alternate;
}
@keyframes run-wobble {
  from { transform: translateY(0) rotate(-4deg); }
  to { transform: translateY(-6px) rotate(4deg); }
}

button {
  font: inherit;
  font-weight: bold;
  font-size: clamp(22px, 5vmin, 34px);
  padding: 12px 44px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(#ff8a50, #e64a19);
  color: #fff;
  box-shadow: 0 5px 0 #7a2810, 0 8px 18px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #7a2810; }
button:focus-visible { outline: 3px solid #ffeb3b; outline-offset: 4px; }
.small-btn { font-size: clamp(18px, 4vmin, 26px); padding: 8px 30px; }

.row { display: flex; gap: 16px; align-items: center; justify-content: center; }
.info { margin: 0; font-size: clamp(18px, 4vmin, 26px); font-weight: bold; }
.info:empty { display: none; }
#menu button:focus-visible, #settings button:focus-visible, #settings input:focus-visible { outline: 3px solid #ffeb3b; outline-offset: 3px; }

/* home screen: title and buttons on the left, leaderboard on the right (below it on tall screens) */
#menu { flex-direction: row; flex-wrap: wrap; gap: 12px 36px; }
.menu-main { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; }
@media (max-aspect-ratio: 1/1) { #menu { flex-direction: column; flex-wrap: nowrap; } }

/* settings (from Zomby Run): volumes 0–100, plus Easy / Hard */
#settings { background: rgba(0, 0, 0, 0.6); }
h2 { color: #ffb74d; text-shadow: 0 3px 0 #6d2a10; }
.slider { display: flex; align-items: center; gap: 12px; width: min(420px, 100%); font-size: clamp(16px, 4vmin, 24px); }
.slider-name { width: 5.5em; text-align: left; }
.slider input { flex: 1; accent-color: #ff7043; height: 28px; }
.slider-val { width: 2.5em; text-align: right; }
.level { background: rgba(255, 255, 255, 0.15); box-shadow: none; border: 3px solid rgba(255, 255, 255, 0.5); }
.level.on { background: linear-gradient(#ff8a50, #e64a19); border-color: #ffcc80; }

/* leaderboard (from Zomby Run): top 5 on the home screen */
.lb {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  width: clamp(210px, 26vw, 290px); padding: 10px 12px 12px;
  border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 16px; background: rgba(0, 0, 0, 0.5);
}
.lb[hidden] { display: none; }
.lb h3, .board-box h2 { margin: 0; color: #ffb74d; text-align: center; text-shadow: 0 2px 0 #6d2a10; }
.lb h3 { font-size: clamp(18px, 4vmin, 26px); }
.lb .small-btn { align-self: center; padding: 6px 22px; font-size: clamp(14px, 3vmin, 18px); }
.lb-rows { list-style: none; margin: 0; padding: 0; }
.lb-rows li { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: 8px; font-size: clamp(14px, 3.2vmin, 19px); }
.lb-rows li:nth-child(odd) { background: rgba(255, 255, 255, 0.08); }
.lb-rows li.me { background: rgba(255, 138, 80, 0.35); box-shadow: inset 0 0 0 2px #ffb74d; font-weight: bold; }
.lb-rows .rank { flex: none; width: 2.4em; text-align: right; opacity: 0.8; }
.lb-rows .name { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-rows .pts { flex: none; font-variant-numeric: tabular-nums; }

/* leaderboard: the full list in its own window */
#board { background: rgba(0, 0, 0, 0.6); }
.board-box {
  position: relative; display: flex; flex-direction: column; gap: 8px;
  width: min(480px, 100%); max-height: 100%; padding: 12px 12px 14px;
  border: 3px solid rgba(255, 183, 77, 0.6); border-radius: 18px; background: #24130d;
}
.board-box h2 { font-size: clamp(24px, 6vmin, 40px); }
.close-btn {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.6); border-radius: 50%; background: rgba(255, 255, 255, 0.12);
  box-shadow: none; color: #fff; font-size: 20px; line-height: 1;
}
.board-body { display: flex; gap: 8px; min-height: 0; }
.board-list { flex: 1; min-width: 0; max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); overflow-y: auto; touch-action: pan-y; }
.board-nav { display: flex; flex-direction: column; gap: 6px; }
.board-nav-gap { flex: 1; }
.board-nav button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.15); box-shadow: none; color: #fff; }
.board-nav button:disabled { opacity: 0.3; cursor: default; }
.board-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* game over: nickname for a new record */
.record { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 4px; }
.record[hidden], .record-msg[hidden] { display: none; }
.record-title {
  margin: 0; font-size: clamp(22px, 5.5vmin, 38px); font-weight: bold; color: #ffd600;
  text-shadow: 0 3px 0 #5a3d00, 0 6px 14px rgba(0, 0, 0, 0.5);
  animation: record-pop 0.6s ease-out both, record-wiggle 1.4s ease-in-out 0.6s infinite;
}
#record-name {
  width: min(320px, 80vw); padding: 8px 14px; border: 3px solid rgba(255, 255, 255, 0.7); border-radius: 12px;
  background: rgba(0, 0, 0, 0.45); color: #fff; font: inherit; font-size: clamp(18px, 4.5vmin, 26px); text-align: center;
  user-select: text; -webkit-user-select: text;
}
#record-name::placeholder { color: rgba(255, 255, 255, 0.55); }
#record-name.bad { border-color: #ff5252; animation: record-shake 0.4s; }
.record-msg { margin: -2px 0 0; color: #ff8a80; font-weight: bold; font-size: clamp(15px, 3.6vmin, 20px); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); }
.save-btn:disabled { opacity: 0.5; cursor: default; }
@keyframes record-pop { from { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } to { transform: scale(1); } }
@keyframes record-wiggle { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) scale(1.05); } }
@keyframes record-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* short screens (phones held sideways): everything a bit tighter */
@media (max-height: 500px) {
  .overlay { gap: 6px; padding: 8px 16px; }
  .lb { padding: 8px 10px 10px; gap: 4px; }
  .lb-rows li { height: 28px; }
  .board-list { max-height: calc(100vh - 90px); max-height: calc(100dvh - 90px); }
}
.hint { margin: 0; font-size: clamp(13px, 2.8vmin, 18px); opacity: 0.85; }
.credit { margin: 6px 0 0; font-size: clamp(12px, 2.4vmin, 16px); opacity: 0.7; }

.exit-btn {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 22px;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: none;
  z-index: 2;
}
.exit-btn.hidden { display: none; }
