:root {
  --space: #0b0e1f;
  --space-2: #141a33;
  --calico: #e8933a;
  --cream: #fff3e0;
  --purple: #8b6fd0;
  --red: #ff5c5c;
  --panel: rgba(20, 26, 51, 0.88);
  --line: rgba(232, 147, 58, 0.35);
}

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

html, body {
  height: 100%;
  background: var(--space);
  color: var(--cream);
  font-family: 'Nunito', system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------- fundal stelat ---------- */
.stars-bg {
  position: absolute; inset: 0; z-index: 0;
  background-image:
    radial-gradient(1px 1px at 12% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 34% 68%, #ffd9a0 50%, transparent 51%),
    radial-gradient(2px 2px at 58% 12%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 71% 44%, #9db8f0 50%, transparent 51%),
    radial-gradient(2px 2px at 86% 76%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 22% 88%, #ffd9a0 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 28%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 40%, #fff 50%, transparent 51%);
  background-size: 340px 340px;
  animation: drift 90s linear infinite;
}
@keyframes drift { to { background-position: 0 340px; } }
@media (prefers-reduced-motion: reduce) { .stars-bg { animation: none; } }

/* ---------- START ---------- */
#screen-start { overflow-y: auto; }
.start-inner {
  position: relative; z-index: 1;
  max-width: 560px; margin: 0 auto;
  padding: 28px 16px 48px;
  text-align: center;
}
.hero-face {
  width: 110px; height: 110px; border-radius: 50%;
  border: 4px solid var(--calico);
  box-shadow: 0 0 30px rgba(232,147,58,.5);
}
.game-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.35;
  margin: 18px 0 8px;
  color: var(--calico);
  text-shadow: 4px 4px 0 #6b3d10, 0 0 24px rgba(232,147,58,.4);
}
.tagline { color: #c9cff0; font-size: 15px; margin-bottom: 22px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
  backdrop-filter: blur(4px);
}
.panel-label {
  display: block; text-align: left;
  font-weight: 700; font-size: 13px; letter-spacing: .06em;
  text-transform: uppercase; color: #aab3dd; margin-bottom: 8px;
}
#player-name {
  width: 100%; padding: 13px 14px;
  font-family: 'Nunito', sans-serif; font-size: 17px; font-weight: 700;
  background: #0d1126; color: var(--cream);
  border: 2px solid #2a3358; border-radius: 10px;
  outline: none;
}
#player-name:focus { border-color: var(--calico); }

.btn-big {
  display: block; width: 100%;
  margin-top: 12px; padding: 15px;
  font-family: 'Press Start 2P', monospace; font-size: 15px;
  color: #241303; background: linear-gradient(180deg, #ffb45e, var(--calico));
  border: none; border-radius: 10px; cursor: pointer;
  box-shadow: 0 4px 0 #a15f1a;
  transition: transform .06s;
}
.btn-big:active { transform: translateY(3px); box-shadow: 0 1px 0 #a15f1a; }
.btn-big.secondary {
  background: linear-gradient(180deg, #a58ae0, var(--purple));
  box-shadow: 0 4px 0 #5a4392; color: #150b2b;
}

.hint { margin-top: 12px; font-size: 12.5px; color: #9aa3cc; }
.mobile-hint { display: none; }
@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .mobile-hint { display: block; }
}

.panel-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px; color: var(--cream);
  margin-bottom: 14px; letter-spacing: .04em;
}

/* ---------- scoreboard ---------- */
.scoreboard { text-align: left; max-height: 300px; overflow-y: auto; }
.scoreboard.small { max-height: 180px; }
.score-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 8px 6px;
  border-bottom: 1px dashed rgba(255,255,255,.08);
  font-size: 15px;
}
.score-row:first-child { color: #ffd700; font-weight: 900; }
.score-row:nth-child(2) { color: #d8d8d8; font-weight: 700; }
.score-row:nth-child(3) { color: #d69a6b; font-weight: 700; }
.score-rank { font-family: 'Press Start 2P', monospace; font-size: 11px; }
.score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-lvl { font-size: 12px; color: #8f98c4; }
.score-pts { font-weight: 900; color: var(--calico); }
.loading, .board-empty { color: #8f98c4; font-size: 14px; padding: 8px 0; }

.back-link {
  display: inline-block; margin-top: 8px;
  color: #8f98c4; font-size: 14px; text-decoration: none;
}
.back-link:hover { color: var(--cream); }

/* ---------- GAME ---------- */
#screen-game { background: var(--space); touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  font-family: 'Press Start 2P', monospace; font-size: 12px;
  background: linear-gradient(180deg, rgba(11,14,31,.9), transparent);
  pointer-events: none;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.hud-face { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--calico); }
#hud-lives { color: var(--red); }
#hud-level { color: var(--cream); }
#hud-score { color: var(--calico); min-width: 60px; text-align: right; }
#btn-mute, #btn-pause {
  pointer-events: auto;
  background: rgba(255,255,255,.08); color: var(--cream);
  border: 1px solid rgba(255,255,255,.18); border-radius: 8px;
  font-size: 14px; padding: 5px 9px; cursor: pointer;
}

/* ---------- controale mobile ---------- */
#touch-controls { display: none; }
@media (pointer: coarse) { #touch-controls { display: block; } }
#joystick {
  position: absolute; left: 18px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.07);
  border: 2px solid rgba(255,255,255,.18);
  z-index: 6; touch-action: none;
}
#joy-knob {
  position: absolute; left: 38px; top: 38px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(232,147,58,.85);
  box-shadow: 0 0 12px rgba(232,147,58,.6);
}
#btn-fire {
  position: absolute; right: 22px; bottom: calc(30px + env(safe-area-inset-bottom));
  width: 84px; height: 84px; border-radius: 50%;
  font-size: 34px;
  background: radial-gradient(circle at 35% 30%, #ffb45e, var(--calico));
  border: 3px solid #a15f1a;
  z-index: 6; touch-action: none;
}
#btn-fire:active { filter: brightness(1.2); }

/* ---------- banner nivel ---------- */
#banner {
  position: absolute; left: 0; right: 0; top: 40%;
  text-align: center; z-index: 7; pointer-events: none;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(20px, 6vw, 36px);
  color: var(--calico);
  text-shadow: 3px 3px 0 #6b3d10;
  animation: pop .5s ease-out;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

/* ---------- overlay ---------- */
#overlay {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(6, 8, 20, .82);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.overlay-card {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px; text-align: center;
  max-height: 92vh; overflow-y: auto;
}
#overlay-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 20px; color: var(--calico); margin-bottom: 10px;
}
#overlay-text { color: #c9cff0; margin-bottom: 14px; font-size: 15px; }
.overlay-card .btn-big { font-size: 12px; }
.hidden { display: none !important; }
