/* PELMENI PANIC — global styles */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  --bg-0: #1a1320;
  --bg-1: #2b1a35;
  --accent: #ff5277;
  --accent-2: #ffd166;
  --cream: #fff4d6;
  --good: #6bd968;
  --bad: #ff4d6d;
  --ink: #f8e9c1;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: 'Press Start 2P', monospace, system-ui;
  font-size: 14px;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background:
    radial-gradient(ellipse at top, #4b2a5e 0%, #2b1a35 45%, #1a1320 100%);
  display: block;
}

/* ----- HUD ----- */
#hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 10px);
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  z-index: 5;
  pointer-events: none;
  text-shadow: 2px 2px 0 #000;
}
#hud .hud-row {
  background: rgba(20, 10, 30, 0.65);
  border: 2px solid var(--ink);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
  font-size: 10px;
}
#hud .hud-label {
  color: var(--accent-2);
  font-size: 7px;
  letter-spacing: 1px;
}
#hud #lives { color: var(--bad); letter-spacing: 2px; }
#hud #score { color: var(--ink); }
#hud #speed { color: var(--good); }

/* ----- Screens ----- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 12px;
  background:
    radial-gradient(ellipse at center, rgba(80, 30, 90, 0.65) 0%, rgba(15, 8, 22, 0.92) 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.hidden { display: none !important; }

.panel {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #2b1a35 0%, #1a1320 100%);
  border: 4px solid var(--ink);
  outline: 4px solid #000;
  box-shadow: 0 0 0 8px rgba(0,0,0,0.4), 0 10px 0 0 #000;
  padding: 18px 16px 22px;
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--accent); }

.title {
  font-size: clamp(28px, 7vw, 48px);
  line-height: 1.05;
  color: var(--accent-2);
  text-shadow:
    3px 3px 0 var(--accent),
    6px 6px 0 #000;
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.title.gameover {
  color: var(--bad);
  text-shadow: 3px 3px 0 #000, 6px 6px 0 #3a0a18;
  animation: shake 0.5s ease-in-out 2;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.tagline {
  font-size: 10px;
  color: var(--accent);
  margin: 8px 0 14px;
  letter-spacing: 2px;
}
.story {
  font-size: 9px;
  line-height: 1.7;
  color: var(--ink);
  opacity: 0.85;
  margin-bottom: 18px;
}
.controls-hint {
  font-size: 7px;
  color: var(--ink);
  opacity: 0.7;
  margin-top: 10px;
  letter-spacing: 1px;
}

/* ----- Nickname input ----- */
.nick-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}
.nick-row label {
  font-size: 9px;
  color: var(--accent-2);
  letter-spacing: 1px;
}
#nick {
  font-family: inherit;
  font-size: 14px;
  text-align: center;
  background: #0d0714;
  color: var(--cream);
  border: 3px solid var(--ink);
  outline: none;
  padding: 10px 14px;
  width: min(220px, 80%);
  text-transform: uppercase;
  letter-spacing: 2px;
  caret-color: var(--accent);
}
#nick:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 82, 119, 0.25);
}

/* ----- Buttons ----- */
.btn {
  font-family: inherit;
  font-size: 14px;
  padding: 14px 22px;
  background: var(--accent);
  color: #fff;
  border: 3px solid #000;
  box-shadow: 0 6px 0 0 #6b1a30, 0 6px 0 3px #000;
  cursor: pointer;
  letter-spacing: 2px;
  transition: transform 0.06s, box-shadow 0.06s;
  text-shadow: 2px 2px 0 #6b1a30;
}
.btn:hover { filter: brightness(1.08); }
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 0 #6b1a30, 0 2px 0 3px #000;
}

/* ----- Leaderboard ----- */
.lb-title {
  font-size: 11px;
  color: var(--accent-2);
  margin: 22px 0 12px;
  letter-spacing: 1px;
}
.leaderboard {
  max-height: 240px;
  overflow-y: auto;
  background: #0d0714;
  border: 3px solid var(--ink);
  padding: 8px;
  font-size: 9px;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
.leaderboard::-webkit-scrollbar { width: 6px; }
.leaderboard::-webkit-scrollbar-thumb { background: var(--accent); }

.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px dashed rgba(248, 233, 193, 0.15);
  align-items: center;
}
.lb-row:last-child { border-bottom: none; }
.lb-row .rank { color: var(--accent-2); text-align: right; }
.lb-row .nick { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pts { color: var(--good); }
.lb-row.me { background: rgba(255, 82, 119, 0.18); border-radius: 2px; }
.lb-row.me .nick { color: var(--accent); }
.lb-row.gold .rank { color: #ffd166; }
.lb-row.silver .rank { color: #d9d9d9; }
.lb-row.bronze .rank { color: #cd7f32; }

.lb-empty {
  text-align: center;
  color: var(--ink);
  opacity: 0.6;
  padding: 14px;
  font-size: 9px;
}

/* ----- Final stats ----- */
.final-stats {
  background: #0d0714;
  border: 3px solid var(--ink);
  padding: 14px;
  margin: 12px auto 18px;
  display: grid;
  gap: 8px;
  font-size: 10px;
}
.final-stats > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.final-stats .hud-label {
  color: var(--accent-2);
  font-size: 9px;
}
#final-score { color: var(--good); }
#final-cream { color: var(--cream); }

/* ----- Responsive tweaks ----- */
@media (max-height: 720px) {
  .leaderboard { max-height: 180px; }
  .panel { padding: 14px 12px 16px; }
  .story { margin-bottom: 12px; }
  .lb-title { margin: 14px 0 8px; }
}
@media (max-height: 560px) {
  .leaderboard { max-height: 120px; }
  .title { font-size: clamp(22px, 6vw, 36px); }
  .story { display: none; }
  .nick-row { margin-bottom: 10px; }
}
@media (max-width: 420px) {
  body { font-size: 12px; }
  #hud .hud-row { padding: 4px 6px; min-width: 56px; font-size: 9px; }
  #hud .hud-label { font-size: 6px; }
  .btn { font-size: 12px; padding: 12px 16px; }
}
@media (min-width: 1400px) {
  body { font-size: 16px; }
  .panel { width: min(640px, 90%); }
}
