/* Base styles */
html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
  width: 100%;
  font-family: Arial, sans-serif;
  background-image: linear-gradient(to bottom, #32BDC8, #135a65);
  background-attachment: fixed;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* Game canvas and container - fixed size to prevent pixelation */
#game-container {
  position: relative;
  width: 320px; /* Original fixed size */
  height: 490px;
  max-width: 320px; /* Never exceed this size */
  max-height: 490px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border-radius: 10px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: #32BDC8;
  object-fit: contain; /* Prevent stretching */
}

/* Game status bar - positioned above game on Y axis */
#game-status {
  width: 320px;
  max-width: 320px;
  padding: 10px;
  background-color: rgba(50, 189, 200, 0.9);
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 10px 10px 0 0;
  margin-bottom: -1px; /* Connect with game container */
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

.game-status-item, .game-status-label, #game-highscore-value {
  margin: 0;
  padding: 0;
  user-select: none;
  color: #fff;
}

#game-highscore-value {
  font-weight: bold;
  font-size: 18px;
}

.game-status-label {
  font-size: 16px;
  margin-right: 8px;
}

.game-status-item {
  display: flex;
  align-items: center;
}

#top-buttons {
  display: flex;
  gap: 10px;
}

.control-button {
  background-color: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 5px;
  color: white;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
}

.control-button:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.control-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Game UI */
#game-ui {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

#game-score {
  color: white;
  font-size: 20px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  margin: 0;
  padding: 5px;
}

#score-center {
  display: flex;
  justify-content: space-between;
  width: 94%;
  padding: 0 10px;
  margin-bottom: 10px;
}

#next {
  margin-right: 5px;
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

#game-next-fruit {
  width: 24px;
  height: 24px;
}

/* Game End Container */
#game-end-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
}

#game-end {
  text-align: center;
  padding: 20px;
  background-color: #fff;
  border-radius: 15px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  max-width: 80%;
  animation: fadeIn 0.5s ease-out;
}

#game-end-title {
  font-weight: 700;
  font-size: 28px;
  color: #0ee9f8;
  margin: 10px 0;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

#game-end-link {
  display: inline-block;
  color: #fff;
  font-size: 18px;
  text-decoration: none;
  background-color: #42858a;
  margin-top: 16px;
  padding: 12px 20px;
  border-radius: 30px;
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  cursor: pointer;
}

#game-end-link:hover {
  background-color: #32BDC8;
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.25);
}

/* Pause Screen */
#pause-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#pause-menu {
  position: relative;
  z-index: 1001;
  text-align: center;
  padding: 20px;
  background-color: #fff;
  border: 4px solid #32BDC8;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  border-radius: 20px;
  pointer-events: initial;
  user-select: initial;
  max-width: 90%;
  width: 280px;
  animation: fadeIn 0.3s ease-out;
}

#pause-menu h1 {
  font-size: 24px;
  margin: 10px 0;
  color: #32BDC8;
  text-shadow: none;
}

#resume-game, #end-game, #logout-button-pause {
  cursor: pointer;
  display: inline-block;
  color: #fff;
  font-size: 16px;
  text-decoration: none;
  background-color: #42858a;
  margin-top: 12px;
  padding: 10px 20px;
  border-radius: 30px;
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  width: auto;
  margin-bottom: 12px;
}

#logout-button-pause {
  background-color: #6b6b6b;
}

#resume-game:hover, #end-game:hover, #logout-button-pause:hover {
  background-color: #32BDC8;
  transform: translateY(-2px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Leaderboard */
#leaderboard, #leaderboard-pause {
  margin-top: 15px;
  background-color: rgba(50, 189, 200, 0.1);
  padding: 10px;
  border-radius: 10px;
}

#leaderboard h2, #leaderboard h3,
#leaderboard-pause h2, #leaderboard-pause h3 {
  font-size: 18px;
  margin: 8px 0;
  color: #42858a;
}

#leaderboard-list, #leaderboard-list-pause {
  list-style: none;
  padding: 0;
  text-align: center;
}

#leaderboard-list li, #leaderboard-list-pause li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #32bdc8;
  background-color: rgba(255, 255, 255, 0.7);
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#leaderboard-list li img, #leaderboard-list-pause li img {
  height: 24px; 
  margin-right: 8px;
}

.name {
  flex-grow: 1;
  text-align: left;
  font-weight: bold;
}

.score {
  font-weight: bold;
  min-width: 50px;
  text-align: right;
  color: #42858a;
}

/* Height Warning */
.height-warning {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(255, 60, 60, 0.8);
  color: white;
  padding: 15px;
  border-radius: 8px;
  font-size: 20px;
  font-weight: bold;
  z-index: 500;
  text-align: center;
  animation: blink 0.8s infinite;
  pointer-events: none;
  width: 80%;
  max-width: 250px;
  box-shadow: 0 0 15px rgba(255, 0, 0, 0.6);
}

.flashing {
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

#gameCanvas.flash {
  animation: flash-red 0.5s infinite;
}

@keyframes flash-red {
  0% { background-color: #32BDC8; }
  50% { background-color: rgba(255, 0, 0, 0.5); }
  100% { background-color: #32BDC8; }
}

/* Login Screen */
#login-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 3000;
  backdrop-filter: blur(5px);
}

.login-container {
  background-color: white;
  padding: 30px;
  border-radius: 20px;
  width: 85%;
  max-width: 350px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: fadeIn 0.5s ease-out;
}

.game-logo {
  width: 120px;
  height: auto;
  margin: 10px auto 20px;
  display: block;
}

.login-container h2 {
  color: #32BDC8;
  margin-top: 0;
  font-size: 28px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.login-form input {
  padding: 12px;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

.login-form input:focus {
  border-color: #32BDC8;
  outline: none;
  box-shadow: 0 0 0 2px rgba(50, 189, 200, 0.2);
}

.auth-buttons {
  display: flex;
  gap: 10px;
}

.login-form button, .guest-option button {
  padding: 12px;
  background-color: #32BDC8;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  transition: all 0.3s;
  flex: 1;
}

.login-form button:hover, .guest-option button:hover {
  background-color: #278f99;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.guest-option {
  border-top: 1px solid #e0e0e0;
  padding-top: 15px;
  margin-top: 5px;
}

.guest-option p {
  color: #888;
  margin: 5px 0 15px;
}

.guest-option button {
  width: 100%;
  background-color: #6b6b6b;
}

.guest-option button:hover {
  background-color: #545454;
}

/* Hide desktop logout button - will show in pause menu */
#user-info, #logout-button {
  display: none;
}

/* Username entry form */
#username-entry {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 2500;
}

#username-input {
  padding: 12px;
  border: 2px solid #32BDC8;
  border-radius: 8px;
  font-size: 16px;
  width: 80%;
  max-width: 300px;
  margin-bottom: 15px;
}

#submitUsernameButton {
  padding: 12px 24px;
  background-color: #32BDC8;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  transition: all 0.3s;
}

#submitUsernameButton:hover {
  background-color: #278f99;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile responsive design */
@media (max-width: 767px) {
  /* Mobile - app-like experience with preserved aspect ratio */
  body, html {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }
  
  .container {
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  
  /* Status bar at top */
  #game-status {
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    position: relative;
    z-index: 10;
  }
  
  /* Game container wrapper with aspect ratio preservation */
  #game-wrapper {
    width: 100%;
    height: calc(100% - 56px); /* Full height minus status bar */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  
  /* Game container maintains aspect ratio */
  #game-container {
    width: auto;
    height: 100%;
    max-width: none;
    max-height: none;
    aspect-ratio: 320 / 490;
    border-radius: 0;
    box-shadow: none;
  }
  
  canvas {
    width: 100%;
    height: 100%;
  }
}

/* This wrapper must be added to your HTML around game-container */
#game-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
}