* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c1126;
  font-family: ui-rounded, 'Hiragino Maru Gothic ProN', Quicksand, Comfortaa, 'Trebuchet MS',
    'Segoe UI', sans-serif;
  color: #eef2ff;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.hidden {
  display: none !important;
}

/* ===== overlays ===== */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20, 28, 64, 0.82), rgba(8, 11, 26, 0.94));
  z-index: 20;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overflow-y: auto;
  touch-action: pan-y;
}

/* Auto margins centre the content but let it scroll from the top when it doesn't fit. */
.overlay > * {
  margin: auto;
}

.panel {
  width: min(92vw, 400px);
  background: rgba(18, 24, 52, 0.92);
  border: 2px solid rgba(120, 140, 255, 0.25);
  border-radius: 22px;
  padding: 28px 26px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.logo {
  font-size: 2.3rem;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffd166, #ef7bff, #5ee1ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo span {
  font-weight: 300;
}

.tagline {
  margin: 6px 0 18px;
  opacity: 0.7;
  font-size: 0.95rem;
}

#nameInput {
  width: 100%;
  padding: 12px 16px;
  font-size: 1.05rem;
  font-family: inherit;
  border-radius: 12px;
  border: 2px solid rgba(120, 140, 255, 0.35);
  background: rgba(10, 14, 32, 0.9);
  color: #fff;
  outline: none;
  text-align: center;
}

#nameInput:focus {
  border-color: #5ee1ff;
}

/* ===== skin picker ===== */

.skin-section {
  margin: 16px 0 6px;
}

#skinPreview {
  width: 260px;
  height: 90px;
  max-width: 100%;
}

.skin-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.skin-row.small {
  gap: 10px;
}

.skin-label {
  font-size: 0.8rem;
  opacity: 0.6;
  min-width: 52px;
  text-align: right;
}

.chips {
  display: flex;
  gap: 6px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
}

.swatch.sel {
  border-color: #fff;
}

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 2px solid rgba(120, 140, 255, 0.3);
  background: rgba(10, 14, 32, 0.8);
  color: #cfd6ff;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}

.chip.sel {
  border-color: #5ee1ff;
  color: #fff;
  background: rgba(40, 90, 140, 0.5);
}

/* ===== buttons ===== */

.big-btn {
  margin-top: 18px;
  width: 100%;
  padding: 14px;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: inherit;
  color: #102;
  background: linear-gradient(180deg, #7ef0a8, #3ecf73);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 0 #2a9c52, 0 10px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.05s;
}

.big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #2a9c52;
}

.text-btn {
  margin-top: 12px;
  background: none;
  border: none;
  color: #9fb0ff;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}

.hint {
  margin-top: 14px;
  font-size: 0.75rem;
  opacity: 0.55;
}

.error {
  margin-top: 10px;
  color: #ff8080;
  font-size: 0.85rem;
}

/* ===== death screen ===== */

.death-title {
  font-size: 1.8rem;
  margin-bottom: 18px;
  color: #ffd166;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  background: rgba(10, 14, 32, 0.8);
  border-radius: 14px;
  padding: 14px 8px;
}

.stat span {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #5ee1ff;
}

.stat label {
  font-size: 0.75rem;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.best-line {
  margin-top: 14px;
  color: #ffd166;
  font-weight: 700;
}

/* ===== high scores (start menu) ===== */

.menu-cols {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
  padding: 16px 0;
}

.hs-panel {
  width: min(92vw, 300px);
  padding: 22px 20px;
}

/* Too narrow for side by side (400 + 18 + 300 px): stacked, it matches the menu panel. */
@media (max-width: 740px) {
  .hs-panel {
    width: min(92vw, 400px);
  }
}

.hs-title {
  font-size: 1.25rem;
  color: #ffd166;
  margin-bottom: 12px;
}

.hs-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.hs-tab {
  flex: 1;
  padding: 7px 0;
  border-radius: 10px;
  border: 2px solid rgba(120, 140, 255, 0.3);
  background: rgba(10, 14, 32, 0.8);
  color: #9fb0ff;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.hs-tab.sel {
  border-color: #5ee1ff;
  color: #fff;
}

.hs-list {
  list-style: none;
  text-align: left;
  font-size: 0.92rem;
}

.hs-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 4px;
  border-bottom: 1px solid rgba(120, 140, 255, 0.12);
}

.hs-list li:last-child {
  border-bottom: none;
}

.hs-list li.me {
  color: #ffd166;
  font-weight: 700;
}

.hs-place {
  width: 1.6em;
  text-align: right;
  opacity: 0.55;
}

.hs-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hs-list b {
  font-variant-numeric: tabular-nums;
  color: #5ee1ff;
}

.hs-empty {
  opacity: 0.6;
  font-size: 0.9rem;
  padding: 10px 0;
}

/* ===== HUD ===== */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
}

#scorePanel {
  position: absolute;
  left: 14px;
  top: 14px;
  background: rgba(12, 17, 38, 0.72);
  border-radius: 14px;
  padding: 10px 16px;
  min-width: 130px;
}

.score-line {
  font-size: 1.25rem;
}

.players-line {
  font-size: 0.8rem;
  opacity: 0.7;
}

#boostBar {
  margin-top: 8px;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

#boostFill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, #ffd166, #ff7b9c);
  transition: width 0.2s;
}

#boostFill.active {
  background: linear-gradient(90deg, #5ee1ff, #7ef0a8);
}

#boostFill.charged {
  background: linear-gradient(90deg, #ffd166, #fff1b8);
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.8);
}

#leaderboard {
  position: absolute;
  right: 14px;
  top: 14px;
  list-style: none;
  background: rgba(12, 17, 38, 0.72);
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 170px;
  font-size: 0.82rem;
}

#leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  opacity: 0.85;
}

#leaderboard li.me {
  color: #ffd166;
  font-weight: 700;
  opacity: 1;
}

#leaderboard li b {
  font-weight: 400;
  opacity: 0.8;
}

#borderWarn {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(255, 77, 94, 0.22);
  border: 1px solid rgba(255, 77, 94, 0.9);
  color: #ffd0d5;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  animation: border-warn 0.6s ease-in-out infinite alternate;
}

@keyframes border-warn {
  from {
    opacity: 0.55;
  }
  to {
    opacity: 1;
  }
}

#fxChips {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 18px;
  display: flex;
  gap: 8px;
}

.fx-chip {
  background: rgba(12, 17, 38, 0.8);
  border: 1px solid rgba(140, 160, 255, 0.4);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  color: #cfe6ff;
}

/* A food multiplier a higher one is overriding (its timer still runs). */
.fx-chip.overridden {
  opacity: 0.45;
  text-decoration: line-through;
}

#minimap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 150px;
  height: 150px;
}

/* ===== touch controls ===== */

#joyBase {
  position: absolute;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  transform: translate(-50%, -50%);
}

#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%);
}

#boostBtn {
  position: absolute;
  right: 26px;
  bottom: 180px;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 123, 156, 0.25);
  border: 2px solid rgba(255, 123, 156, 0.7);
  color: #ffb3c6;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

#debugGrowBtn {
  position: absolute;
  left: 14px;
  top: 112px;
  pointer-events: auto;
  cursor: pointer;
  background: rgba(255, 169, 77, 0.16);
  border: 1px dashed rgba(255, 169, 77, 0.8);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffd2a1;
}

#debugGrowBtn:active {
  background: rgba(255, 169, 77, 0.4);
}

#debugGrowBtn kbd {
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid rgba(255, 210, 161, 0.6);
  border-radius: 4px;
  font: inherit;
  font-size: 0.7rem;
}

#boostBtn.pressed {
  background: rgba(255, 123, 156, 0.55);
  color: #fff;
}

@media (max-width: 700px) {
  #leaderboard {
    min-width: 130px;
    font-size: 0.72rem;
    max-height: 130px;
    overflow: hidden;
  }

  #minimap {
    width: 110px;
    height: 110px;
  }

  #scorePanel {
    padding: 8px 12px;
    min-width: 100px;
  }

  .score-line {
    font-size: 1rem;
  }
}
