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

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Segoe UI', 'Helvetica Neue', system-ui, sans-serif;
  background: #0a0e27;
  color: #fff;
  overflow: hidden;
  user-select: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Екрани */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #1a1f4e 0%, #0a0e27 100%);
}

.screen.active { display: flex; }

/* Зорі для меню */
#menu-screen::before,
#levels-screen::before,
#player-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 60% 70%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 80% 20%, #fff, transparent),
    radial-gradient(1px 1px at 30% 80%, #fff, transparent),
    radial-gradient(2px 2px at 75% 50%, #fff, transparent),
    radial-gradient(1px 1px at 10% 60%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 90% 90%, #fff, transparent);
  background-size: 100% 100%;
  opacity: 0.6;
  pointer-events: none;
}

.menu-card {
  background: rgba(20, 24, 60, 0.85);
  border: 2px solid #4a6dff;
  border-radius: 20px;
  padding: 40px 50px;
  max-width: 520px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 50px rgba(74, 109, 255, 0.4);
  backdrop-filter: blur(10px);
  z-index: 1;
}

.menu-card.wide { max-width: 720px; }

.player-card { max-width: 480px; }

.profile-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 18px rgba(255, 140, 66, 0.55));
}

.player-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.player-form label {
  color: #cfd8ff;
  font-weight: 700;
}

.player-form input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #4a6dff;
  border-radius: 10px;
  background: rgba(5, 8, 30, 0.75);
  color: #fff;
  font: inherit;
  font-size: 1.1rem;
  outline: none;
}

.player-form input:focus {
  border-color: #ffd23f;
  box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.15);
}

.form-error {
  min-height: 1.2em;
  color: #ff8d98;
  font-size: 0.9rem;
}

.game-title {
  font-size: 2.8em;
  margin-bottom: 8px;
  background: linear-gradient(90deg, #ff8c42, #ffd23f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(255, 140, 66, 0.5);
}

.subtitle {
  color: #8b9dff;
  margin-bottom: 30px;
  font-size: 1.1em;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 25px;
}

.btn {
  padding: 14px 28px;
  font-size: 1.1em;
  border: 2px solid #4a6dff;
  background: rgba(74, 109, 255, 0.2);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
  font-family: inherit;
}

.btn:hover {
  background: rgba(74, 109, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(74, 109, 255, 0.4);
}

.btn.primary {
  background: linear-gradient(90deg, #ff8c42, #ff6b6b);
  border-color: #ff8c42;
  font-size: 1.3em;
}

.btn.primary:hover {
  background: linear-gradient(90deg, #ff6b6b, #ff8c42);
  box-shadow: 0 4px 20px rgba(255, 140, 66, 0.6);
}

.btn.danger {
  border-color: #ff4757;
  background: rgba(255, 71, 87, 0.2);
}

.btn.danger:hover {
  background: rgba(255, 71, 87, 0.4);
}

.btn.small {
  padding: 6px 14px;
  font-size: 0.9em;
}

.stats {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 20px;
  font-size: 0.95em;
  line-height: 1.8;
}

.stats span {
  color: #ffd23f;
  font-weight: 700;
}

.controls-hint {
  color: #8b9dff;
  font-size: 0.85em;
  border-top: 1px solid rgba(74, 109, 255, 0.3);
  padding-top: 15px;
}

.controls-hint h3 {
  margin-bottom: 6px;
  color: #fff;
  font-size: 1em;
}

.hint {
  color: #8b9dff;
  font-size: 0.9em;
  margin: 10px 0 20px;
}

/* Сітка рівнів */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
  margin: 20px 0;
  max-height: 420px;
  overflow-y: auto;
  padding: 5px;
}

.level-btn {
  aspect-ratio: 1;
  border: 2px solid #4a6dff;
  background: rgba(74, 109, 255, 0.2);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1em;
  font-weight: 700;
  font-family: inherit;
  position: relative;
  transition: all 0.15s;
}

.level-btn:hover {
  transform: scale(1.05);
  background: rgba(74, 109, 255, 0.5);
}

.level-btn.completed {
  background: linear-gradient(135deg, #51cf66, #2f9e44);
  border-color: #51cf66;
}

.level-btn.locked {
  background: rgba(50, 50, 70, 0.5);
  border-color: #444;
  color: #666;
  cursor: not-allowed;
}

.level-btn.locked:hover {
  transform: none;
  background: rgba(50, 50, 70, 0.5);
}

.level-btn .star {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.7em;
}

/* Ігровий екран */
#game-screen {
  background: #000;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  image-rendering: pixelated;
  background: #6cb9ff;
}

#hud {
  position: fixed;
  top: 15px;
  left: 15px;
  display: flex;
  gap: 14px;
  z-index: 10;
  pointer-events: none;
}

.hud-item {
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 1.1em;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.hud-item span { color: #ffd23f; }

#btn-pause {
  position: fixed;
  top: 15px;
  right: 15px;
  z-index: 10;
}

/* Оверлей паузи / результату */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.overlay.hidden { display: none; }

.overlay-card {
  background: rgba(20, 24, 60, 0.95);
  border: 2px solid #4a6dff;
  border-radius: 20px;
  padding: 35px 45px;
  text-align: center;
  min-width: 320px;
  max-width: 90%;
}

.overlay-card h2 {
  margin-bottom: 12px;
  font-size: 2em;
  background: linear-gradient(90deg, #ffd23f, #ff8c42);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-card p {
  margin-bottom: 20px;
  color: #cfd8ff;
  font-size: 1.05em;
  line-height: 1.5;
}

/* Скроллбар */
.levels-grid::-webkit-scrollbar { width: 8px; }
.levels-grid::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 4px; }
.levels-grid::-webkit-scrollbar-thumb { background: #4a6dff; border-radius: 4px; }

@media (max-width: 600px) {
  .menu-card { padding: 25px 20px; }
  .game-title { font-size: 2em; }
  #hud { gap: 6px; }
  .hud-item { padding: 5px 10px; font-size: 0.9em; }
}
