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

:root {
  --text-color: #ffffff;
  --text-grey: #9a9aa5;

  --primary-color: #674fc9;
  --secondary-color: #6751be;
}

/* Prevent zoom on double-click */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

input,
textarea,
select {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: 16px; /* Prevents zoom on iOS */
  touch-action: manipulation;
}

/* Prevent double-tap zoom on buttons */
button {
  touch-action: manipulation;
}

/* Prevent double-tap zoom on letter boxes */
.letter-box {
  touch-action: manipulation;
}

/* Additional mobile input optimizations */
.letter-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}

/* Prevent iOS Safari from adding rounded corners to inputs */
.letter-input {
  -webkit-border-radius: 0;
  border-radius: 0;
}

/* Token Spending Animations */
@keyframes tokenSpend {
  0% {
    transform: scale(1);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }
  50% {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }
}

@keyframes letterReveal {
  0% {
    transform: scale(0.8);
    opacity: 0;
    background: #f0f0f0;
  }
  50% {
    transform: scale(1.1);
    background: #34495e;
  }
  100% {
    transform: scale(1.05);
    opacity: 1;
    background: #34495e;
  }
}

@keyframes tokenGlow {
  0% {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }
  50% {
    box-shadow: 0 5px 25px rgba(103, 79, 201, 0.6),
      0 0 20px rgba(103, 79, 201, 0.4);
  }
  100% {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }
}

@keyframes particleFloat {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-20px) scale(0);
    opacity: 0;
  }
}

@keyframes tokenBounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

/* Token button animation classes */
.token-btn.spending {
  animation: tokenSpend 0.6s ease-in-out;
}

.token-btn.glowing {
  animation: tokenGlow 0.8s ease-in-out;
}

.token-btn.bouncing {
  animation: tokenBounce 0.8s ease-in-out;
}

/* Letter reveal animation */
.letter-box.revealing {
  animation: letterReveal 0.8s ease-out;
}

/* Particle effect */
.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #674fc9;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFloat 1s ease-out forwards;
}

/* Token counter animation */
@keyframes counterPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
    color: #674fc9;
  }
  100% {
    transform: scale(1);
  }
}

.counter-pulse {
  animation: counterPulse 0.6s ease-in-out;
}

/* Success animation for correct reveals */
@keyframes successGlow {
  0% {
    box-shadow: 0 0 0 rgba(76, 175, 80, 0);
  }
  50% {
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
  }
  100% {
    box-shadow: 0 0 0 rgba(76, 175, 80, 0);
  }
}

.letter-box.success-glow {
  animation: successGlow 0.8s ease-in-out;
}

body {
  font-family: "Inter", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #1b2733 0%, #2c3e50 100%);
  min-height: 100vh;
  color: #333;
}

.container {
  min-width: 400px;
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 300px; /* Add space for fixed bottom section */
}

header {
  text-align: center;
  margin-bottom: 10px;
  color: white;
}

header h1 {
  font-size: 1.25rem;
  margin-bottom: 5px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
  font-size: 0.9rem;
  color: var(--text-grey);
}

.game-stats {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 15px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  margin-bottom: 20px;
}

.stat {
  text-align: center;
  min-width: 100px;
}

.label {
  display: block;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 5px;
  font-size: 0.8rem;
  opacity: 0.9;
}

.value {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text-color);
}

.word-display {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 20px 0px;
  border-radius: 15px;
}

.total-used-tokens {
  text-align: center;
  color: #ffd700;
}

.submit-section {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  align-items: center;
  gap: 10px;
}

.submit-section .value {
  font-size: 1rem;
  font-weight: normal;
}

.submit-section .btn {
  /* min-width: 150px; */
  padding: 10px 20px;
  font-size: 1.1rem;
}

.word-container {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.letter-box {
  width: 60px;
  height: 60px;
  border: 3px solid #34495e;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: bold;
  background: white;
  color: #333;
  transition: all 0.3s ease;
}

.letter-box.revealed {
  background: #34495e;
  color: white;
  transform: scale(1.05);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.revealed-letter {
  font-size: 1.8rem;
  font-weight: bold;
  line-height: 1;
}

.token-value {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.6rem;
  font-weight: bold;
  color: #ffd700;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.letter-box.hidden {
  background: #f0f0f0;
  color: transparent;
}

.letter-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 30px; /* Prevents zoom on mobile */
  font-weight: bold;
  color: #333;
  outline: none;
  text-transform: uppercase;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.letter-input:focus {
  background: rgba(52, 73, 94, 0.1);
}

.letter-input:disabled {
  background: #f0f0f0;
  color: #999;
  cursor: not-allowed;
  border: 2px dashed #ccc;
}

.letter-input.revealed {
  background: #34495e;
  color: white;
  font-weight: bold;
}

.bottom-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* background: linear-gradient(135deg, #1b2733 0%, #2c3e50 100%); */
  padding: 20px;
  z-index: 1000;
  /* box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3); */
  max-width: 500px;
  margin: 0 auto;
}

.token-trading {
  /* background: rgba(255, 255, 255, 0.95); */
  padding: 15px;
  border-radius: 15px;
  margin-bottom: 10px;
  color: #9a9aa5;
  margin-bottom: 15px; /* Space before game controls */
}

.token-trading .value {
  font-weight: normal;
  color: #ffd700;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 5px 10px;
}

.token-trading h3 {
  text-align: center;
  margin-bottom: 20px;
  color: var(--text-grey);
  font-size: 0.9rem;
  font-weight: 400;
}

.token-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
}

.token-btn {
  padding: 10px 15px;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(45deg, #2c3e50, #34495e);
  color: white;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.token-text {
  font-size: 1.5rem;
}

.letters-text {
  font-size: 0.8rem;
  font-weight: normal;
  opacity: 0.9;
}

.token-btn:hover {
  transform: translateY(-2px);
}

.token-btn:disabled,
.token-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(100%);
  display: none;
}

.token-btn {
  color: white;
}

.game-controls {
  display: none;
  justify-content: center;
  gap: 20px;
  margin-bottom: 0; /* Remove bottom margin since it's in fixed section */
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn-primary {
  background: linear-gradient(45deg, #6257dc, #373abf);
  color: white;
}

.btn-secondary {
  background: linear-gradient(45deg, #5d6d7e, #85929e);
  color: white;
}

.btn-success {
  color: #ffd700;
  background: rgba(0, 0, 0, 0.3);
}

.btn-success.success {
  background: linear-gradient(45deg, #4caf50, #45a049);
  color: white;
  font-weight: bold;
  animation: successPulse 0.6s ease-in-out;
}

@keyframes successPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.message {
  text-align: center;
  padding: 5px;
  margin-bottom: 30px;
  border-radius: 5px;
  font-weight: normal;
  min-height: 20px;
  color: white;
}

.message.success {
  background: rgba(76, 175, 80, 1);
}

.message.error {
  background: rgba(244, 67, 54, 1);
}

.message.info {
  background: rgba(33, 150, 243, 1);
}

.rules {
  background: rgba(255, 255, 255, 0.95);
  padding: 25px;
  border-radius: 15px;
}

.rules h3 {
  margin-bottom: 15px;
  color: #333;
}

.rules ul {
  list-style: none;
  padding-left: 0;
}

.rules li {
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  position: relative;
  padding-left: 25px;
}

.rules li:before {
  content: "•";
  color: #34495e;
  font-weight: bold;
  position: absolute;
  left: 0;
}

.rules li:last-child {
  border-bottom: none;
}

.virtual-keyboard {
  background: #000000;
  padding: 10px;
  border-radius: 15px;
  margin: 5px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  margin-bottom: 5px; /* Add space before token trading section */
  margin-top: 25px;
}

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

.keyboard-row:last-child {
  margin-bottom: 0;
}

.key {
  width: 40px;
  height: 50px;
  background: #333333;
  color: white;
  border: 1px solid #000000;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  touch-action: manipulation;
}

.key:hover {
  background: #444444;
  transform: scale(1.05);
}

.key:active {
  background: #555555;
  transform: scale(0.95);
}

.key.special-key {
  width: 60px;
  font-size: 0.8rem;
}

.key.special-key[data-key="BACKSPACE"] {
  width: 60px;
}

.key.special-key[data-key="BACKSPACE"] svg {
  width: 16px;
  height: 16px;
}

.key.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.help-icon {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--text-color);
}

.help-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.help-icon svg {
  width: 20px;
  height: 20px;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.modal-content {
  background: linear-gradient(135deg, #1b2733 0%, #2c3e50 100%);
  margin: 5% auto;
  padding: 0;
  border-radius: 15px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 25px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  color: var(--text-color);
  margin: 0;
  font-size: 1.5rem;
}

.close {
  color: var(--text-grey);
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s ease;
}

.close:hover {
  color: var(--text-color);
}

.modal-body {
  padding: 25px;
}

.modal-body .rules {
  background: transparent;
  padding: 0;
  margin: 0;
}

.modal-body .rules h3 {
  color: var(--text-color);
  margin-bottom: 15px;
  font-size: 1.2rem;
}

.modal-body .rules ul {
  list-style: none;
  padding-left: 0;
}

.modal-body .rules li {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  padding-left: 30px;
  color: var(--text-color);
}

.modal-body .rules li:before {
  content: "•";
  color: var(--primary-color);
  font-weight: bold;
  position: absolute;
  left: 0;
  font-size: 1.2rem;
}

.modal-body .rules li:last-child {
  border-bottom: none;
}

@media (max-width: 600px) {
  .container {
    padding: 15px;
  }

  header h1 {
    font-size: 1.1rem;
  }

  .game-stats {
    /* flex-direction: column; */
    gap: 15px;
  }

  .token-buttons {
    gap: 10px;
  }

  .token-btn {
    /* min-width: 100px; */
    padding: 10px 15px;
  }

  .letters-text {
    font-size: 0.7rem;
  }

  .letter-box {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }

  .revealed-letter {
    font-size: 1.5rem;
  }

  .token-value {
    width: 14px;
    height: 14px;
    font-size: 0.5rem;
    top: 1px;
    right: 1px;
  }

  .letter-input {
    font-size: 16px; /* Keep 16px to prevent zoom on mobile */
  }

  .game-controls {
    flex-direction: column;
    align-items: center;
  }

  .key {
    width: 35px;
    height: 45px;
    font-size: 0.9rem;
  }

  .key.special-key {
    width: 50px;
    font-size: 0.7rem;
  }

  .key.special-key[data-key="BACKSPACE"] {
    width: 50px;
  }
}

@media (max-width: 600px) {
  .modal-content {
    margin: 10% auto;
    width: 95%;
    max-height: 85vh;
  }

  .modal-header {
    padding: 15px 20px;
  }

  .modal-header h2 {
    font-size: 1.3rem;
  }

  .modal-body {
    padding: 20px;
  }

  .help-icon {
    top: 15px;
    right: 15px;
    width: 28px;
    height: 28px;
  }

  .help-icon svg {
    width: 18px;
    height: 18px;
  }
}
