/* ============================================================
   Poly Worlds — UI styles (v3, no auth)
   Sunset gradient theme + simple name-picker popup.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --sunset-1: #3b1f5a;
  --sunset-2: #ff7e5f;
  --sunset-3: #feb47b;
  --grass:    #5b8c3e;
  --ink:      #1a1326;
  --paper:    #fffaf5;
  --accent:   #ff5e7e;
  --muted:    #8a8a9a;
  --line:     #ebe6df;
  --shadow:   0 20px 60px -20px rgba(60, 30, 80, 0.35);
}

html, body {
  width: 100%; height: 100%;
  background: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ===================== LOBBY SCREEN ===================== */
#lobbyScreen {
  background: linear-gradient(180deg, var(--sunset-1) 0%, var(--sunset-2) 55%, var(--sunset-3) 100%);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
}

.lobby-bg { position: absolute; inset: 0; pointer-events: none; }
.lobby-bg .sun {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff1c1 0%, #ffae5a 50%, transparent 70%);
  filter: blur(2px);
  opacity: 0.85;
}
.lobby-bg .hills {
  position: absolute;
  bottom: 25%;
  left: 0; right: 0;
  height: 120px;
  background: linear-gradient(180deg, #5a3a1a 0%, #3a2a1a 100%);
  clip-path: polygon(
    0 60%, 10% 50%, 20% 55%, 30% 30%, 40% 50%, 50% 35%,
    60% 45%, 70% 25%, 80% 50%, 90% 40%, 100% 55%, 100% 100%, 0 100%
  );
  opacity: 0.7;
}
.lobby-bg .grass-bg {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 25%;
  background: linear-gradient(180deg, #5b8c3e 0%, #2e6b2a 100%);
}

.lobby-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
}

.logo { text-align: center; margin-bottom: 36px; }
.logo-icon { width: 80px; height: 80px; margin: 0 auto 18px; }
.logo-icon svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 8px 20px rgba(0,0,0,0.3)); }
.logo-icon.small { width: 44px; height: 44px; margin: 0 auto 10px; }
.logo h1 {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.tagline {
  color: rgba(255,255,255,0.85);
  font-size: 15px;
  margin-top: 8px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.btn {
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--sunset-2), var(--accent));
  color: #fff;
  box-shadow: 0 6px 20px -6px rgba(255, 94, 126, 0.6);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.primary.large { padding: 16px 36px; font-size: 16px; border-radius: 12px; }
.btn.ghost { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3); }
.btn.ghost.dark { background: #f3eeea; color: var(--ink); border-color: var(--line); }
.btn.ghost.small { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

.lobby-foot {
  margin-top: 18px;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
}

/* ===================== NAME PICKER MODAL ===================== */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 19, 38, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 100;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -48%) scale(0.96);
  background: var(--paper);
  border-radius: 22px;
  padding: 28px 28px 22px;
  width: 92%;
  max-width: 380px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 101;
}
.modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}
.modal.standalone {
  position: fixed;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
  text-align: center;
  max-width: 460px;
}

.modal-header { text-align: center; margin-bottom: 20px; }
.modal-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.4px;
}

.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal form label { display: flex; flex-direction: column; gap: 5px; }
.modal form label span { font-size: 12px; font-weight: 600; color: var(--muted); }
.modal form input {
  border: 2px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  transition: border 0.15s;
}
.modal form input:focus {
  outline: none;
  border-color: var(--sunset-2);
}

.err { color: var(--accent); font-size: 13px; min-height: 18px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.modal-foot {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin-top: 14px;
}

/* ===================== LOADING OVERLAY ===================== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(26, 19, 38, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.overlay.open { display: flex; }
.loader { text-align: center; }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--sunset-2);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingMsg { font-size: 14px; color: rgba(255,255,255,0.85); }

/* ===================== FATAL SCREEN ===================== */
#fatalScreen {
  background: linear-gradient(160deg, #2a1638, #1a1326);
  align-items: center; justify-content: center; padding: 24px;
}

/* ===================== GAME SCREEN ===================== */
#gameScreen.game {
  background: #000;
  overflow: hidden;
}
#gameCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}

/* HUD top */
.hud-top {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; gap: 10px; align-items: stretch;
  pointer-events: none;
  z-index: 10;
}
.hud-card {
  background: rgba(20, 14, 30, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 8px 12px;
  border-radius: 10px;
  color: #fff;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.hud-label {
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.hud-value { font-size: 14px; font-weight: 700; }
.hud-spacer { flex: 1; }
.hud-top .btn.ghost { pointer-events: auto; }

/* HUD bottom */
.hud-bottom {
  position: absolute; bottom: 24px; left: 0; right: 0;
  display: flex; justify-content: center;
  pointer-events: none;
  z-index: 10;
}
.controls-hint {
  background: rgba(20, 14, 30, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 8px 14px;
  border-radius: 10px;
  display: flex; gap: 18px;
  color: rgba(255,255,255,0.85);
  font-size: 12px;
}
.controls-hint b { color: #fff; }

/* Touch joystick */
.joystick {
  display: none;
  position: absolute; left: 24px; bottom: 24px;
  width: 110px; height: 110px;
  background: rgba(20, 14, 30, 0.5);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  z-index: 10;
}
.joystick.active { border-color: rgba(255, 126, 95, 0.6); }
.joystick-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 50px; height: 50px;
  background: linear-gradient(135deg, #ff7e5f, #ff5e7e);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.08s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.jump-btn {
  display: none;
  position: absolute; right: 24px; bottom: 24px;
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff7e5f, #ff5e7e);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.3);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  z-index: 10;
}

@media (pointer: coarse) {
  .joystick, .jump-btn { display: block; }
  .controls-hint { display: none; }
}
