/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #228b22 0%, #1a5a1a 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Screen containers */
.screen {
  width: 800px;
  height: 600px;
  position: relative;
}

.hidden {
  display: none !important;
}

/* Menu Screen */
#menu-screen {
  background: linear-gradient(180deg, #2d5a2d 0%, #1a3d1a 100%);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.45);
}

.footer-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.footer-avatar img.hidden {
  display: none;
}

.footer-avatar img:not([src]),
.footer-avatar img[src=""] {
  display: none;
}

#auth-avatar-fallback {
  font-size: 16px;
  line-height: 1;
}

/* Account footer */
.account-footer {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(800px, 92vw);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.55);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  z-index: 120;
  align-items: center;
}

.account-footer button {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font-weight: 600;
  font-size: 14px;
  height: 40px;
  padding: 0 12px;
  line-height: 1;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.account-footer .footer-profile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
}

.footer-profile-text {
  display: inline-block;
}

.account-footer button:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

.account-footer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.menu-content {
  text-align: center;
  color: white;
  padding: 28px 32px;
}

.title-section {
  margin-bottom: 24px;
}

.title-emoji {
  font-size: 64px;
  display: block;
  margin-bottom: 6px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

h1 {
  font-size: 48px;
  font-weight: bold;
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
  margin-bottom: 6px;
  color: #ffd700;
}

.subtitle {
  font-size: 18px;
  color: #90ee90;
  font-style: italic;
}

/* Profile Selection */
.profile-selection {
  margin-bottom: 18px;
  position: relative;
}

.profile-selection h2 {
  font-size: 20px;
  margin-bottom: 8px;
  color: #90ee90;
}

.profile-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 46px;
}

.profile-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border 0.2s ease;
}

.profile-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
}

.profile-btn.selected {
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.35);
}

.profile-btn.add {
  font-size: 24px;
  font-weight: 800;
  color: #ffd700;
  border-color: rgba(255, 215, 0, 0.6);
  background: linear-gradient(
    180deg,
    rgba(255, 215, 0, 0.18) 0%,
    rgba(255, 215, 0, 0.05) 100%
  );
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}

.profile-stats {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.9);
  color: #d9f8d9;
  font-size: 13px;
  text-align: left;
  min-width: 280px;
  max-width: 360px;
  max-height: 130px;
  overflow: auto;
  z-index: 5;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.profile-stats h4 {
  font-size: 14px;
  color: #ffd700;
  margin-bottom: 6px;
}

.profile-stats ul {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-stats li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 6px 8px;
}

.profile-stats .stat-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-stats .stat-score {
  font-weight: 700;
  color: #ffffff;
}

.profile-stats .stat-highlight {
  color: #ffd700;
}

.profile-stats .stat-accuracy {
  font-weight: 700;
  color: #90ee90;
}

/* Language Selection */
.language-selection {
  margin-bottom: 24px;
}

.language-selection h2 {
  font-size: 20px;
  margin-bottom: 12px;
  color: #90ee90;
}

.lang-buttons {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.lang-btn {
  background: linear-gradient(180deg, #4caf50 0%, #388e3c 100%);
  border: none;
  border-radius: 15px;
  padding: 16px 32px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.lang-btn.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
  background: linear-gradient(180deg, #2f6b32 0%, #27552a 100%);
}

.lang-btn.is-disabled:hover {
  transform: none;
  box-shadow: none;
  background: linear-gradient(180deg, #2f6b32 0%, #27552a 100%);
}

.lang-btn:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  background: linear-gradient(180deg, #5dbf61 0%, #43a047 100%);
}

.lang-btn:active {
  transform: translateY(-2px);
}

.lang-btn .flag {
  font-size: 40px;
}

.lang-btn .lang-name {
  font-size: 16px;
  font-weight: bold;
  color: white;
}

/* Difficulty Selection */
.difficulty-selection {
  margin-bottom: 18px;
}

.difficulty-selection h2 {
  font-size: 20px;
  margin-bottom: 10px;
  color: #90ee90;
}

.difficulty-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.difficulty-btn {
  background: linear-gradient(
    180deg,
    rgba(20, 60, 20, 0.9) 0%,
    rgba(12, 40, 12, 0.9) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: white;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.difficulty-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.difficulty-btn.selected {
  background: linear-gradient(180deg, #6edb7a 0%, #2f8f4b 100%);
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.35),
    0 0 0 3px rgba(110, 219, 122, 0.25);
}

.difficulty-btn:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(255, 215, 0, 0.4),
    0 10px 22px rgba(0, 0, 0, 0.3);
}

/* Profile modal */
.profile-modal {
  min-width: 360px;
}

.profile-modal.message-mode .profile-form {
  display: none;
}

.profile-modal.message-mode .modal-buttons {
  margin-top: 10px;
}

.profile-modal-message {
  font-size: 16px;
  color: #90ee90;
  margin-bottom: 18px;
}

/* Stats modal */
.stats-modal {
  min-width: 520px;
  max-width: 680px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin: 20px 0 10px;
  text-align: left;
}

.stats-section h3 {
  font-size: 16px;
  color: #ffd700;
  margin-bottom: 10px;
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  line-height: 1.2;
}

.stats-list .stats-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stats-list .stats-value {
  font-weight: 700;
  color: #ffffff;
}

.stats-empty {
  font-size: 16px;
  color: #90ee90;
  margin-bottom: 10px;
}

/* Ranking modal */
.ranking-modal {
  min-width: 420px;
  max-width: 560px;
}

.ranking-nickname-section {
  margin: 16px 0;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
}

.ranking-login-msg {
  font-size: 14px;
  color: #90ee90;
  text-align: center;
  margin: 0;
}

.ranking-nickname-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.ranking-nickname-label {
  font-size: 14px;
  color: #90ee90;
}

.ranking-nickname-value {
  font-size: 16px;
  font-weight: 700;
  color: #ffd700;
}

.ranking-edit-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.ranking-edit-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.ranking-nickname-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ranking-nickname-form label {
  font-size: 14px;
  color: #90ee90;
  text-align: left;
}

.ranking-nickname-form input {
  border-radius: 10px;
  border: none;
  padding: 10px 12px;
  font-size: 16px;
}

.ranking-nickname-hint {
  font-size: 12px;
  color: rgba(144, 238, 144, 0.7);
  font-style: italic;
  margin: 0;
}

.ranking-nickname-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 4px;
}

.ranking-btn-small {
  padding: 8px 24px;
  font-size: 14px;
}

.ranking-user-rank {
  margin: 12px 0;
  padding: 10px 16px;
  background: rgba(255, 215, 0, 0.12);
  border: 1px solid rgba(255, 215, 0, 0.25);
  border-radius: 10px;
  font-size: 15px;
  color: #ffd700;
  font-weight: 600;
  text-align: center;
}

.ranking-list-section {
  margin: 16px 0 8px;
  text-align: left;
}

.ranking-list-section h3 {
  font-size: 16px;
  color: #ffd700;
  margin-bottom: 10px;
  text-align: center;
}

.ranking-empty {
  font-size: 14px;
  color: #90ee90;
  text-align: center;
}

.ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  counter-reset: ranking;
}

.ranking-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 14px;
  line-height: 1.3;
}

.ranking-list li.is-current-user {
  background: rgba(255, 215, 0, 0.12);
  border: 1px solid rgba(255, 215, 0, 0.25);
}

.ranking-position {
  font-weight: 800;
  color: #ffd700;
  min-width: 28px;
  text-align: center;
}

.ranking-position.top-1 { font-size: 18px; }
.ranking-position.top-2 { font-size: 16px; }
.ranking-position.top-3 { font-size: 15px; }

.ranking-emoji {
  font-size: 20px;
}

.ranking-name {
  flex: 1;
  color: #ffffff;
  font-weight: 600;
}

.ranking-score {
  font-weight: 700;
  color: #90ee90;
  white-space: nowrap;
}

.ranking-details {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.profile-form label {
  font-size: 14px;
  color: #90ee90;
  text-align: left;
}

#profile-name {
  border-radius: 10px;
  border: none;
  padding: 10px 12px;
  font-size: 16px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.emoji-option {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.1);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s ease,
    border 0.2s ease,
    background 0.2s ease;
}

.emoji-option:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.2);
}

.emoji-option.selected {
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(110, 219, 122, 0.25);
}

/* Instructions */
.instructions {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 15px;
  padding: 14px;
}

.instructions h3 {
  font-size: 18px;
  color: #ffd700;
  margin-bottom: 10px;
}

.instructions p {
  font-size: 14px;
  color: #90ee90;
  margin-bottom: 5px;
}

/* Game Screen */
#game-screen {
  position: relative;
}

#game-canvas {
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  display: block;
  position: relative;
  z-index: 2;
}

/* Responsive layout for mobile and small screens */
@media (max-width: 900px), (max-height: 700px) {
  body {
    align-items: flex-start;
    padding: 12px;
  }

  .screen {
    width: min(100vw, 800px);
    height: min(100svh, 600px);
  }

  #game-screen,
  #menu-screen {
    width: 100%;
    height: 100%;
  }

  #game-canvas {
    width: 100%;
    height: auto;
    max-height: 100%;
  }

  .menu-content {
    padding: 20px 18px;
  }

  .title-emoji {
    font-size: 52px;
  }

  h1 {
    font-size: 38px;
  }

  .subtitle {
    font-size: 16px;
  }

  .lang-btn {
    padding: 12px 22px;
  }

  .lang-btn .flag {
    font-size: 34px;
  }

  .difficulty-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .profile-btn {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .profile-stats {
    max-width: 320px;
  }

  .stats-modal {
    min-width: 320px;
    width: min(92vw, 520px);
  }

  .ranking-modal {
    min-width: 320px;
    width: min(92vw, 480px);
  }

  .account-footer {
    width: min(92vw, 640px);
    bottom: 12px;
  }
}

@media (max-height: 500px) {
  .screen {
    height: min(100svh, 520px);
  }

  .title-emoji {
    font-size: 46px;
  }

  h1 {
    font-size: 32px;
  }

  .instructions {
    padding: 10px;
  }
}

#pause-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3;
}

#pause-btn:hover {
  background: rgba(0, 0, 0, 0.7);
  transform: scale(1.1);
}

.mobile-keyboard-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-content {
  background: linear-gradient(180deg, #2d5a2d 0%, #1a3d1a 100%);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  color: white;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  min-width: 350px;
}

.modal-content h2 {
  font-size: 36px;
  color: #ffd700;
  margin-bottom: 20px;
}

.modal-content p {
  font-size: 18px;
  color: #90ee90;
  margin-bottom: 10px;
}

.stats {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 15px;
  margin: 20px 0;
}

.stats p {
  margin: 5px 0;
}

.stats span {
  font-weight: bold;
  color: #ffd700;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 25px;
}

.primary-btn,
.secondary-btn {
  padding: 15px 40px;
  font-size: 18px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.primary-btn {
  background: linear-gradient(180deg, #4caf50 0%, #388e3c 100%);
  color: white;
}

.primary-btn:hover {
  background: linear-gradient(180deg, #5dbf61 0%, #43a047 100%);
  transform: translateY(-2px);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Victory styling */
.modal-content.victory h2 {
  color: #ffd700;
}

.modal-content.victory::before {
  content: "🎉";
  font-size: 60px;
  display: block;
  margin-bottom: 20px;
}

/* Game over styling */
.modal-content.game-over h2 {
  color: #ff6b6b;
}

.modal-content.game-over::before {
  content: "😢";
  font-size: 60px;
  display: block;
  margin-bottom: 20px;
}
