/**
 * PLUR Game - Stylesheet
 * Full-screen canvas, HUD, menus, score overlay
 */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  background: #0a0a1a;
  font-family: 'Space Grotesk', sans-serif;
  color: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
}

/* ---- Canvas ---- */

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
}

/* ---- Loading Screen ---- */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0a0a1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.5s ease;
}

#loading-screen img {
  width: 200px;
  height: auto;
  margin-bottom: 30px;
}

.loading-text {
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  color: #22c55e;
  letter-spacing: 4px;
}

.loading-bar-outer {
  width: 240px;
  height: 4px;
  background: #1a1a2e;
  border-radius: 2px;
  margin-top: 16px;
  overflow: hidden;
}

.loading-bar-inner {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #3b82f6);
  border-radius: 2px;
  animation: loadingFill 1.5s ease forwards;
}

@keyframes loadingFill {
  0% { width: 0%; }
  100% { width: 100%; }
}

/* ---- Animated Ball Tile Background ---- */

@keyframes ballDrift {
  0% {
    background-position: 0% 0%;
    background-size: 100px 100px;
  }
  25% {
    background-size: 108px 108px;
  }
  50% {
    background-position: 15% 30%;
    background-size: 100px 100px;
  }
  75% {
    background-size: 92px 92px;
  }
  100% {
    background-position: 30% 60%;
    background-size: 100px 100px;
  }
}

@keyframes ballRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---- Menu Overlay ---- */

#menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
  background: rgba(10, 10, 26, 0.92);
  padding: 20px;
  overflow: hidden;
}

/* Tiled ball wallpaper layer behind the menu */
#menu-overlay::before {
  content: '';
  position: absolute;
  top: -100%;
  left: -100%;
  width: 300%;
  height: 300%;
  background-image: url('/assets/images/plur-ball.webp');
  background-repeat: repeat;
  background-size: 100px 100px;
  opacity: 0.06;
  animation: ballDrift 120s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

#menu-overlay > * {
  position: relative;
  z-index: 1;
}

.menu-logo {
  width: 280px;
  max-width: 55vw;
  height: auto;
  filter: drop-shadow(0 6px 28px rgba(34, 197, 94, 0.35))
          drop-shadow(0 2px 10px rgba(59, 130, 246, 0.2));
}

/* Glass morphism instructions panel */
.menu-glass {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 20px 28px;
  max-width: 420px;
  width: 90%;
  text-align: center;
}

.menu-subtitle {
  font-family: 'Orbitron', monospace;
  font-size: 15px;
  color: #e2e8f0;
  letter-spacing: 5px;
  margin-bottom: 14px;
  font-weight: 700;
}

.menu-controls {
  color: #94a3b8;
  font-size: 13px;
  text-align: center;
  line-height: 1.9;
}

.menu-controls strong {
  color: #e2e8f0;
}

/* Play button image */
.menu-play-btn {
  display: block;
  max-width: 340px;
  width: 65%;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              filter 0.25s ease;
  filter: drop-shadow(0 6px 24px rgba(0, 0, 0, 0.5));
  cursor: pointer;
  text-decoration: none;
}

.menu-play-btn:hover {
  transform: scale(1.06) translateY(-3px);
  filter: drop-shadow(0 10px 36px rgba(34, 197, 94, 0.35))
          drop-shadow(0 4px 16px rgba(0, 0, 0, 0.5));
}

.menu-play-btn:active {
  transform: scale(0.97);
}

.menu-btn-img {
  width: 100%;
  height: auto;
  display: block;
}

/* Secondary action row */
.menu-action-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.menu-action-btn {
  display: block;
  max-width: 200px;
  width: 38%;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              filter 0.25s ease;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.4));
}

.menu-action-btn:hover {
  transform: scale(1.06) translateY(-2px);
  filter: drop-shadow(0 6px 20px rgba(59, 130, 246, 0.3))
          drop-shadow(0 3px 10px rgba(0, 0, 0, 0.4));
}

.menu-action-btn:active {
  transform: scale(0.97);
}

.menu-btn-img-sm {
  width: 100%;
  height: auto;
  display: block;
}

.menu-attribution {
  position: absolute;
  bottom: 16px;
  font-size: 11px;
  color: #475569;
}

.menu-attribution a {
  color: #64748b;
  text-decoration: none;
}

.menu-attribution a:hover {
  color: #94a3b8;
}

/* ---- Mute Button (fixed bottom-left) ---- */

#mute-btn {
  position: fixed;
  bottom: 10%;
  left: 16px;
  z-index: 55;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: #94a3b8;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

#mute-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* ---- HUD ---- */

#game-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 24px;
  z-index: 20;
  pointer-events: none;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.hud-item {
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  color: #e2e8f0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.hud-life {
  width: 28px;
  height: 28px;
  display: inline-block;
  margin: 0 3px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  transition: opacity 0.3s ease, filter 0.3s ease;
  vertical-align: middle;
}

.hud-life.lost {
  opacity: 0.2;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3)) grayscale(1);
}

/* ---- Center Message ---- */

#hud-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', monospace;
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(34, 197, 94, 0.6);
  z-index: 30;
  display: none;
  text-align: center;
  pointer-events: none;
}

/* ---- Score Submission Overlay ---- */

#score-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 60;
  background: rgba(10, 10, 26, 0.92);
  overflow: hidden;
  padding: 12px;
}

.score-panel {
  position: relative;
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 18px 20px;
  max-width: 440px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.score-panel::-webkit-scrollbar {
  width: 4px;
}

.score-panel::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 2px;
}

/* Background image behind the score panel */
.score-panel::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('/assets/images/neon-abstract.webp');
  background-size: cover;
  background-position: center;
  opacity: 0.08;
  z-index: 0;
  pointer-events: none;
}

.score-panel > * {
  position: relative;
  z-index: 1;
}

.score-header-img {
  width: 55%;
  max-width: 200px;
  height: auto;
  margin: 0 auto 10px;
  display: block;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.4));
}

.score-details {
  display: flex;
  justify-content: space-around;
  margin-bottom: 12px;
}

.score-stat {
  text-align: center;
}

.score-stat-label {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.score-stat-label svg {
  flex-shrink: 0;
}

.score-stat-value {
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  font-weight: 700;
  color: #fbbf24;
  margin-top: 3px;
}

/* ---- Name Entry ---- */

.name-entry {
  margin-bottom: 10px;
}

.name-label {
  font-size: 13px;
  color: #94a3b8;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.name-label svg {
  flex-shrink: 0;
}

#name-display {
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
  letter-spacing: 3px;
}

/* ---- On-Screen Keyboard ---- */

#onscreen-keyboard {
  margin: 8px 0;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 3px;
}

.key-btn {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 600;
  width: 32px;
  height: 34px;
  background: rgba(51, 65, 85, 0.7);
  color: #e2e8f0;
  border: 1px solid rgba(71, 85, 105, 0.5);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.key-btn:hover {
  background: rgba(71, 85, 105, 0.8);
}

.key-btn:active {
  background: #22c55e;
  color: #000000;
  transform: scale(0.95);
}

.key-special {
  width: 56px;
  background: rgba(30, 41, 59, 0.7);
  color: #94a3b8;
}

.key-submit {
  width: 76px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #ffffff;
  border-color: rgba(34, 197, 94, 0.5);
  font-weight: 700;
}

.key-submit:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
}

#submit-status {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 8px;
  min-height: 18px;
}

/* ---- Leaderboard in Score Panel ---- */

.score-leaderboard {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard-title {
  font-family: 'Orbitron', monospace;
  font-size: 13px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 2px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.leaderboard-title svg {
  flex-shrink: 0;
}

.leaderboard-list {
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.leaderboard-list::-webkit-scrollbar {
  width: 4px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 2px;
}

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.leaderboard-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

.leaderboard-row:nth-child(1) .lb-rank {
  color: #fbbf24;
}

.leaderboard-row:nth-child(2) .lb-rank {
  color: #94a3b8;
}

.leaderboard-row:nth-child(3) .lb-rank {
  color: #cd7f32;
}

.lb-rank {
  font-family: 'Orbitron', monospace;
  font-weight: 700;
  font-size: 11px;
  color: #64748b;
  width: 28px;
  text-align: left;
}

.lb-name {
  flex: 1;
  text-align: left;
  color: #e2e8f0;
  font-weight: 500;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-family: 'Orbitron', monospace;
  font-weight: 700;
  font-size: 11px;
  color: #fbbf24;
  text-align: right;
  min-width: 50px;
}

.leaderboard-loading {
  color: #64748b;
  font-size: 12px;
  padding: 10px;
}

#play-again-btn {
  display: block;
  max-width: 180px;
  width: 50%;
  margin: 10px auto 0;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              filter 0.25s ease;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.4));
  -webkit-tap-highlight-color: transparent;
}

#play-again-btn:hover {
  transform: scale(1.06) translateY(-2px);
  filter: drop-shadow(0 6px 20px rgba(34, 197, 94, 0.3))
          drop-shadow(0 3px 10px rgba(0, 0, 0, 0.4));
}

#play-again-btn:active {
  transform: scale(0.97);
}

.play-again-img {
  width: 100%;
  height: auto;
  display: block;
}

/* ---- Touch Controls ---- */

#touch-controls {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  pointer-events: none;
}

#touch-joystick {
  position: fixed;
  bottom: 40px;
  left: 40px;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-knob {
  width: 40px;
  height: 40px;
  background: rgba(34, 197, 94, 0.4);
  border: 2px solid rgba(34, 197, 94, 0.6);
  border-radius: 50%;
  transition: transform 0.05s;
}

#touch-jump {
  position: fixed;
  bottom: 50px;
  right: 40px;
  width: 70px;
  height: 70px;
  background: rgba(59, 130, 246, 0.3);
  border: 2px solid rgba(59, 130, 246, 0.5);
  border-radius: 50%;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 1px;
}

/* ---- Back Link ---- */

#back-link {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  font-size: 11px;
  color: #475569;
  text-decoration: none;
  pointer-events: auto;
}

#back-link:hover {
  color: #94a3b8;
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  .menu-logo {
    width: 200px;
    max-width: 50vw;
  }

  .menu-glass {
    padding: 14px 18px;
  }

  .menu-subtitle {
    font-size: 11px;
    letter-spacing: 3px;
  }

  .menu-controls {
    font-size: 11px;
    line-height: 1.7;
  }

  .menu-play-btn {
    max-width: 260px;
    width: 75%;
  }

  .menu-action-btn {
    max-width: 150px;
    width: 40%;
  }

  .hud-item {
    font-size: 13px;
  }

  #hud-message {
    font-size: 22px;
  }

  .score-panel {
    padding: 14px 12px;
    max-height: 92vh;
  }

  .score-header-img {
    width: 45%;
    max-width: 150px;
    margin-bottom: 8px;
  }

  .score-stat-value {
    font-size: 14px;
  }

  #name-display {
    font-size: 15px;
    padding: 5px 10px;
    min-height: 30px;
  }

  .key-btn {
    width: 24px;
    height: 28px;
    font-size: 11px;
  }

  .key-special {
    width: 40px;
  }

  .key-submit {
    width: 54px;
  }

  #play-again-btn {
    max-width: 140px;
    width: 45%;
  }

  .leaderboard-list {
    max-height: 120px;
  }

  #mute-btn {
    width: 36px;
    height: 36px;
    bottom: 8%;
    left: 10px;
  }

  #mute-btn svg {
    width: 18px;
    height: 18px;
  }
}
