/* Base styles */
body {
  margin: 0;
  padding: 0;
  background-color: #000;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  /* Prevent multi-touch gestures */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#muteBtn {
  position: fixed;
  top: 24px;
  right: 32px;
  width: 54px;
  height: 54px;
  background: rgba(30, 30, 30, 0.7);
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #fff;
  cursor: pointer;
  z-index: 1000;
  transition: background 0.2s, transform 0.1s;
}

#muteBtn:hover {
  background: rgba(60, 60, 60, 0.9);
  transform: scale(1.08);
}

#backToMenuBtn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  padding: 14px 24px;
  background: rgba(30, 30, 30, 0.7);
  border: 2px solid #00aaff;
  border-radius: 28px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  font-size: 18px;
  font-weight: bold;
  font-family: Arial, sans-serif;
  color: #00aaff;
  cursor: pointer;
  z-index: 1000;
  display: none;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s, border-color 0.2s;
  opacity: 0;
  animation: fadeInBtn 0.3s ease-out forwards;
}

#backToMenuBtn:hover {
  background: rgba(60, 60, 60, 0.9);
  border-color: #0088cc;
  transform: scale(1.08);
}

#backToMenuBtn:active {
  transform: scale(0.95);
}

@keyframes fadeInBtn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#startScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding-top: 340px;
  background-color: transparent;
  z-index: 999;
  font-family: Arial, sans-serif;
  color: white;
}

#startScreen img#titleCard {
  width: 380px;
  margin-bottom: 16px;
}

#startForm {
  background-color: #fff;
  padding: 28px 36px;
  border-radius: 28px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: fadeIn 0.6s ease-out;
}

#startForm label {
  font-size: 22px;
  color: #222;
  font-weight: bold;
}

#usernameInput {
  font-size: 18px;
  padding: 14px 16px;
  border: 2px solid #00aaff;
  border-radius: 14px;
  width: 260px;
  text-align: center;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  transition: border-color 0.2s;
}

#usernameInput:focus {
  border-color: #0088cc;
  outline: none;
}

#startBtn {
  font-size: 22px;
  padding: 16px 40px;
  background: #00aaff;
  color: white;
  font-weight: bold;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  min-width: 220px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
  transition: background 0.3s ease, transform 0.15s ease, box-shadow 0.15s ease;
  animation: popIn 0.5s ease-out;
}

#startBtn:hover {
  background: #0090dd;
  transform: scale(1.08);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

#startBtn:active {
  transform: scale(0.95);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.3);
}

#leaderboard {
  margin-top: 20px;
  color: #fff;
  font-size: 16px;
  max-width: 300px;
  text-align: center;
}

/* Animations */
@keyframes popIn {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(30px); }
  100% { opacity: 1; transform: translateY(0); }
}

#sealIdInput {
  font-size: 18px;
  padding: 14px 16px;
  border: 2px solid #00aaff;
  border-radius: 14px;
  width: 260px;
  text-align: center;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  transition: border-color 0.2s;
}

#sealIdInput:focus {
  border-color: #0088cc;
  outline: none;
}

/* Random Seal Button */
#randomSealBtn {
  font-size: 18px;
  padding: 12px 28px;
  background: linear-gradient(135deg, #00aaff 0%, #0088cc 100%);
  color: white;
  font-weight: bold;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  min-width: 200px;
  box-shadow: 0 6px 16px rgba(0, 170, 255, 0.3);
  transition: background 0.3s ease, transform 0.15s ease, box-shadow 0.15s ease;
  font-family: Arial, sans-serif;
}

#randomSealBtn:hover {
  background: linear-gradient(135deg, #0088cc 0%, #006699 100%);
  transform: scale(1.08);
  box-shadow: 0 8px 20px rgba(0, 170, 255, 0.4);
}

#randomSealBtn:active {
  transform: scale(0.95);
}

/* Seal Preview Modal */
#sealPreviewModal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease-out;
}

#sealPreviewContent {
  background: white;
  padding: 32px;
  border-radius: 28px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  max-width: 500px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: popIn 0.4s ease-out;
}

#sealPreviewContent h2 {
  margin: 0;
  font-size: 28px;
  color: #222;
  font-family: Arial, sans-serif;
}

#sealPreviewImage {
  width: 300px;
  height: 300px;
  background: #f0f0f0;
  border-radius: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  border: 3px solid #00aaff;
}

#previewSealImg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
}

#previewLoader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #666;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e0e0e0;
  border-top: 4px solid #00aaff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

#previewSealId {
  font-size: 20px;
  color: #333;
  font-weight: bold;
  margin: 0;
}

#previewSealId span {
  color: #00aaff;
}

#previewButtons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#previewButtons button {
  font-size: 16px;
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: bold;
  font-family: Arial, sans-serif;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#acceptSealBtn {
  background: #00cc66;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 204, 102, 0.3);
}

#acceptSealBtn:hover {
  background: #00aa55;
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0, 204, 102, 0.4);
}

#shuffleSealBtn {
  background: #00aaff;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 170, 255, 0.3);
}

#shuffleSealBtn:hover {
  background: #0088cc;
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0, 170, 255, 0.4);
}

#closePreviewBtn {
  background: #ff4444;
  color: white;
  box-shadow: 0 4px 12px rgba(255, 68, 68, 0.3);
}

#closePreviewBtn:hover {
  background: #cc0000;
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(255, 68, 68, 0.4);
}

#previewButtons button:active {
  transform: scale(0.95);
}

/* Leaderboard Screen */
#leaderboardScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 3000;
  animation: fadeIn 0.3s ease-out;
}

#leaderboardContent {
  background: linear-gradient(135deg, #0a1929 0%, #1e3a5f 100%);
  border: 3px solid #00aaff;
  border-radius: 28px;
  padding: 40px 32px;
  max-width: 700px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 170, 255, 0.3);
  position: relative;
  animation: popIn 0.4s ease-out;
}

/* Mobile leaderboard optimization: Small phones (320-480px) */
@media (max-width: 480px) {
  #leaderboardContent {
    padding: 20px 12px;  /* Reduce from 40px 32px */
    width: 95%;  /* Increase from 90% to maximize space */
    max-width: 100%;  /* Allow full width on tiny screens */
  }

  #leaderboardLogo {
    max-width: 200px !important;  /* Smaller logo on mobile */
    max-height: 100px !important;
  }

  #closeLeaderboardBtn {
    width: 36px;  /* Reduce from 40px */
    height: 36px;
    font-size: 20px;  /* Reduce from 24px */
    top: 12px;
    right: 12px;
  }

  .leaderboard-header {
    font-size: 16px;  /* Increase from 14px */
    padding: 10px 12px;  /* Reduce from 12px 16px */
  }

  .col-rank {
    font-size: 18px;  /* Increase from 16px */
  }

  .col-username {
    font-size: 18px;  /* Increase from 16px */
  }

  .col-score {
    font-size: 20px;  /* Increase from 18px */
  }

  .leaderboard-row {
    padding: 12px 8px;  /* Reduce from 14px 16px */
    grid-template-columns: 45px 1fr 85px;  /* Reduce rank: 60→45px, score: 100→85px */
  }

  /* Seal leaderboard specific */
  .seal-header {
    font-size: 15px;  /* Increase from 14px */
  }

  .col-seal-stats {
    font-size: 14px;  /* Increase from 12px */
  }

  /* Seal leaderboard */
  .seal-list .leaderboard-row {
    grid-template-columns: 40px 100px 1fr;  /* Reduce rank: 60→40px, seal: 120→100px */
  }

  /* Allow username wrapping on very small screens if needed */
  .col-username {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Keep ellipsis but with more space available */
  }

  #leaderboardTabs {
    gap: 6px;  /* Reduce from 8px */
    margin-bottom: 16px;  /* Reduce from 24px */
  }

  .tab-btn {
    padding: 10px 16px;  /* Reduce from 12px 24px */
    font-size: 15px;  /* Reduce from 16px */
  }

  .user-rank-display {
    padding: 12px;  /* Reduce from 14px 16px */
    margin-top: 12px;  /* Reduce from 16px */
    font-size: 15px;  /* Reduce from 16px */
  }

  .user-rank-display strong {
    font-size: 16px;  /* Reduce from 18px */
  }
}

/* Mobile leaderboard optimization: Tablets (481-768px) */
@media (max-width: 768px) and (min-width: 481px) {
  #leaderboardContent {
    padding: 28px 20px;  /* Moderate reduction */
    width: 92%;
  }

  #leaderboardLogo {
    max-width: 250px !important;
    max-height: 125px !important;
  }

  .leaderboard-header {
    font-size: 15px;
  }

  .col-rank, .col-username {
    font-size: 17px;
  }

  .col-score {
    font-size: 19px;
  }

  .leaderboard-row {
    grid-template-columns: 50px 1fr 90px;  /* Moderate reduction */
  }

  .seal-list .leaderboard-row {
    grid-template-columns: 50px 110px 1fr;
  }

  .tab-btn {
    padding: 11px 20px;
    font-size: 15px;
  }
}

#leaderboardContent h1 {
  margin: 0 0 24px 0;
  font-size: 36px;
  color: #ffffff;
  text-align: center;
  font-family: Arial, sans-serif;
  text-shadow: 0 2px 8px rgba(0, 170, 255, 0.5);
}

#closeLeaderboardBtn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  color: white;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#closeLeaderboardBtn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: #00aaff;
  transform: scale(1.1);
}

/* Tab Navigation */
#leaderboardTabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  justify-content: center;
}

.tab-btn {
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.6);
  font-family: Arial, sans-serif;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
  color: rgba(255, 255, 255, 0.8);
}

.tab-btn.active {
  background: #00aaff;
  border-color: #00aaff;
  color: white;
}

/* Tab Content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Leaderboard Header */
.leaderboard-header {
  display: grid;
  grid-template-columns: 60px 1fr 100px;
  padding: 12px 16px;
  background: rgba(0, 170, 255, 0.2);
  border-radius: 12px;
  margin-bottom: 12px;
  font-family: Arial, sans-serif;
  font-weight: bold;
  color: #00aaff;
  font-size: 14px;
  text-transform: uppercase;
}

.seal-header {
  grid-template-columns: 60px 120px 1fr;
}

/* Leaderboard List */
.leaderboard-list {
  max-height: 450px;
  overflow-y: auto;
  padding-right: 8px;
}

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

.leaderboard-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
  background: #00aaff;
  border-radius: 4px;
}

.leaderboard-list::-webkit-scrollbar-thumb:hover {
  background: #0088cc;
}

/* Leaderboard Row */
.leaderboard-row {
  display: grid;
  grid-template-columns: 60px 1fr 100px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  margin-bottom: 8px;
  font-family: Arial, sans-serif;
  color: white;
  transition: all 0.2s ease;
  align-items: center;
}

.leaderboard-row:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.leaderboard-row.current-user {
  background: rgba(0, 204, 102, 0.2);
  border: 2px solid #00cc66;
}

/* Top 3 Special Styling */
.leaderboard-row.rank-1 .col-rank {
  color: #ffd700; /* Gold */
  font-size: 18px;
}

.leaderboard-row.rank-2 .col-rank {
  color: #c0c0c0; /* Silver */
  font-size: 17px;
}

.leaderboard-row.rank-3 .col-rank {
  color: #cd7f32; /* Bronze */
  font-size: 16px;
}

.col-rank {
  font-weight: bold;
  text-align: center;
  font-size: 16px;
}

.col-username {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-score {
  font-weight: bold;
  text-align: right;
  color: #00aaff;
  font-size: 18px;
}

/* Seal Leaderboard */
.seal-list .leaderboard-row {
  grid-template-columns: 60px 120px 1fr;
}

.col-seal {
  display: flex;
  align-items: center;
  gap: 12px;
}

.seal-image {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border: 2px solid #00aaff;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.1);
}

.seal-id {
  font-weight: bold;
  color: #00aaff;
}

.col-seal-stats {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seal-total-score {
  font-weight: bold;
  color: #00aaff;
  font-size: 18px;
}

.seal-games-played {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

/* User Rank Display */
.user-rank-display {
  margin-top: 16px;
  padding: 14px 16px;
  background: rgba(0, 204, 102, 0.2);
  border: 2px solid #00cc66;
  border-radius: 12px;
  text-align: center;
  font-family: Arial, sans-serif;
  color: #00cc66;
  font-weight: bold;
  font-size: 16px;
}

.user-rank-display.not-ranked {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
}

/* Loader in leaderboard */
.leaderboard-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px;
  color: rgba(255, 255, 255, 0.6);
}

/* Empty State */
.leaderboard-empty {
  text-align: center;
  padding: 40px;
  color: rgba(255, 255, 255, 0.6);
  font-family: Arial, sans-serif;
}

/* View Leaderboard Button on Main Menu */
#viewLeaderboardBtn {
  font-size: 18px;
  padding: 12px 28px;
  background: #00cc66;
  color: white;
  font-weight: bold;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  min-width: 200px;
  box-shadow: 0 6px 16px rgba(0, 204, 102, 0.3);
  transition: background 0.3s ease, transform 0.15s ease, box-shadow 0.15s ease;
  font-family: Arial, sans-serif;
  margin-top: 8px;
}

#viewLeaderboardBtn:hover {
  background: #00aa55;
  transform: scale(1.08);
  box-shadow: 0 8px 20px rgba(0, 204, 102, 0.4);
}

#viewLeaderboardBtn:active {
  transform: scale(0.95);
}

/* Loading Screen */
#loadingScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #0a1929 0%, #1e3a5f 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out;
}

#loadingScreen.hidden {
  opacity: 0;
  pointer-events: none;
}

#loadingContent {
  text-align: center;
  color: white;
  font-family: Arial, sans-serif;
}

.loading-logo {
  margin-bottom: 24px;
}

.seal-spinner {
  width: 80px;
  height: 80px;
  margin: 0 auto;
  border: 8px solid rgba(255, 255, 255, 0.2);
  border-top: 8px solid #00aaff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loadingContent h2 {
  font-size: 32px;
  margin: 0 0 24px 0;
  color: #00aaff;
  text-shadow: 0 2px 8px rgba(0, 170, 255, 0.5);
}

.loading-bar-container {
  width: 300px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin: 0 auto 16px auto;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.loading-bar {
  height: 100%;
  background: linear-gradient(90deg, #00aaff, #00cc66);
  width: 0%;
  transition: width 0.3s ease-out;
  border-radius: 10px;
}

#loadingStatus {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.8);
  margin: 8px 0;
}

#loadingPercentage {
  font-size: 24px;
  font-weight: bold;
  color: #00aaff;
  margin: 8px 0;
}

/* Disable hover effects on touch devices */
@media (hover: none) and (pointer: coarse) {
  #muteBtn:hover,
  #backToMenuBtn:hover,
  #startBtn:hover,
  #randomSealBtn:hover,
  #viewLeaderboardBtn:hover,
  #acceptSealBtn:hover,
  #shuffleSealBtn:hover,
  #closePreviewBtn:hover,
  .tab-btn:hover,
  .leaderboard-row:hover {
    transform: none;
    background: inherit;
  }
}