:root {
  --ink: #292a23;
  --paper: #fffefa;
  --lime: #d8fd71;
  --sun: #ffd43b;
  --heart: #ff4d6d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

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

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
  z-index: 2;
}
.hud > * { pointer-events: auto; }

.startng-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: min(320px, 52vw);
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
.startng-card img {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--lime);
  object-fit: cover;
}
.startng-card .who { min-width: 0; }
.startng-card b,
.startng-card span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.startng-card b { font-size: 16px; }
.startng-card span { font-size: 12px; opacity: .7; }
.startng-card button {
  flex: none;
  margin-left: 4px;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--lime);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.hud-right {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(41, 42, 35, .85);
  font-weight: 800;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.in-menu .chip { display: none; }

.hud-powers {
  position: absolute;
  top: 100%;
  right: 12px;
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.chip.power {
  position: relative;
  overflow: hidden;
  height: 34px;
  padding: 0 12px 0 10px;
  font-size: 15px;
}
.chip.power svg { width: 18px; height: 18px; fill: currentColor; }
.chip.power::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: calc(var(--left, 1) * 100%);
  background: currentColor;
}
.chip.power.shield { color: #74c0fc; }
.chip.power.magnet { color: #ff8787; }
.chip.power.slow { color: #b197fc; }
.chip.power.ending { animation: blink .25s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.powers-legend {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: min(340px, 100%);
  margin: 0 auto 11px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  font-size: 12px;
  font-weight: 700;
}
.pw { display: inline-flex; align-items: center; gap: 5px; }
.pu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff inset;
}
.pu svg { width: 11px; height: 11px; fill: #fff; }
.pu.shield { background: #4dabf7; }
.pu.magnet { background: #ff6b6b; }
.pu.slow { background: #9775fa; }
.chip.score {
  position: relative;
  min-width: 72px;
  justify-content: center;
  color: var(--sun);
}
.chip.score.beat {
  color: var(--lime);
  box-shadow: inset 0 0 0 2px rgba(216, 253, 113, .55);
}
.chip.score.beat::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 10px;
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-bottom: 6px solid var(--lime);
}
.chip svg { width: 18px; height: 18px; }
.chip svg.full { fill: var(--heart); }
.chip svg.empty { fill: rgba(255, 255, 255, .22); }
.coin-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a3, #ffd43b 55%, #e0a100);
  box-shadow: inset 0 0 0 2px #c47f00;
}
.chain {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(41, 42, 35, .85);
  color: var(--paper);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.muted #mute-waves { display: none; }
.icon-btn:not(.muted) #mute-cross { display: none; }
.icon-btn:not(.music-off) #music-cross { display: none; }
.icon-btn.expanded #fs-enter { display: none; }
.icon-btn:not(.expanded) #fs-exit { display: none; }
.icon-btn.denied { color: var(--heart); box-shadow: 0 0 0 3px rgba(255, 77, 109, .7); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.panels {
  position: fixed;
  left: 0;
  right: 0;
  top: 72px;
  bottom: 31vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  pointer-events: none;
  z-index: 1;
}
.panel {
  pointer-events: auto;
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 22px 16px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, .09);
  background: rgba(38, 39, 32, .93);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .07);
  text-align: center;
  scrollbar-width: thin;
}
.panel.compact { width: min(300px, 100%); }

h1 {
  margin: 0 0 5px;
  font-size: clamp(32px, 8vw, 48px);
  line-height: 1;
  letter-spacing: -1px;
  color: var(--sun);
  text-shadow: 0 4px 0 #b4561b;
}
h1 span { color: var(--lime); text-shadow: 0 4px 0 #5d7a1c; }
h2 {
  margin: 18px 0 8px;
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .7;
}
.over-title {
  margin-top: 0;
  font-size: 40px;
  letter-spacing: -1px;
  text-transform: none;
  opacity: 1;
  color: var(--sun);
  text-shadow: 0 4px 0 #b4561b;
}
.tagline { margin: 0 auto 12px; max-width: 42ch; font-size: 13.5px; line-height: 1.4; opacity: .72; }
.howto {
  display: grid;
  gap: 7px;
  width: min(340px, 100%);
  margin: 0 auto 11px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  opacity: .88;
}
.howto li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 9px;
  align-items: center;
}
.howto .ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  justify-self: center;
  border-radius: 9px;
  background: rgba(255, 255, 255, .08);
}
.howto .ic svg { width: 15px; height: 15px; fill: currentColor; }
.howto .keys { width: 34px; }
.howto .life { color: #ff8787; }
.howto .coin::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a3, #ffd43b 55%, #e0a100);
  box-shadow: inset 0 0 0 2px #c47f00;
}
kbd {
  display: inline-block;
  min-width: 16px;
  margin: 0 1px;
  padding: 0 3px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .14);
  border-bottom: 2px solid rgba(0, 0, 0, .35);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, .14);
  color: var(--paper);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.btn.primary {
  padding: 13px 40px;
  background: var(--lime);
  color: var(--ink);
  font-size: 19px;
  box-shadow: 0 5px 0 #8fb336;
}
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #8fb336; }
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-row .btn { flex: 1 1 0; }
.menu-actions { margin-top: 0; }
.menu-actions .btn.primary { flex: 1.4 1 0; padding: 13px 10px; }
.menu-actions .btn { font-size: 14px; }
.btn:focus-visible, .icon-btn:focus-visible, .startng-card button:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 2px;
}

.signin-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 0;
  font-size: 12px;
  opacity: .85;
}
.signin-prompt .btn {
  flex: none;
  padding: 5px 12px;
  background: rgba(216, 253, 113, .16);
  box-shadow: inset 0 0 0 1px rgba(216, 253, 113, .45);
  color: var(--lime);
  font-size: 12px;
  font-weight: 800;
}
.best {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 212, 59, .14);
  box-shadow: inset 0 0 0 1px rgba(255, 212, 59, .3);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--sun);
}

.results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 12px;
}
.results div {
  padding: 10px 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .07);
}
.results span { display: block; font-size: 12px; opacity: .7; }
.results b { font-size: 24px; font-variant-numeric: tabular-nums; }
.save-msg { min-height: 1.4em; margin: 0 0 12px; font-weight: 700; color: var(--lime); }
#over-signin { display: block; margin: 0 auto 14px; background: var(--lime); color: var(--ink); }

.board {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  font-size: 14px;
}
.board li {
  display: grid;
  grid-template-columns: 26px 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 12px;
}
.board li:nth-child(odd) { background: rgba(255, 255, 255, .05); }
.board li.me { background: rgba(216, 253, 113, .18); box-shadow: inset 0 0 0 1px rgba(216, 253, 113, .55); }
.board li.note { display: block; text-align: center; opacity: .7; background: none; }
.board .rank { font-weight: 800; opacity: .7; }
.board .dot { width: 10px; height: 10px; border-radius: 50%; }
.board .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 700; }
.board .num { text-align: right; font-variant-numeric: tabular-nums; }
.board .num b { color: var(--sun); }
.board .num small { display: block; font-size: 11px; opacity: .65; }

@media (max-width: 520px) {
  .startng-card { padding-right: 10px; }
  .startng-card img { width: 36px; height: 36px; }
  .startng-card b { font-size: 14px; }
  .chip { height: 34px; padding: 0 10px; font-size: 15px; }
  .icon-btn { width: 34px; height: 34px; }
  .panels { top: 64px; bottom: 26vh; }
  .panel { padding: 18px 16px 14px; }
}
@media (max-height: 660px) {
  .panel { padding-top: 16px; }
  h1 { font-size: 30px; }
  .tagline { display: none; }
}
@media (max-height: 520px) {
  .panels { top: 60px; bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .chip.power.ending { animation: none; }
  .btn.primary:active { transform: none; }
}
