:root {
  --cream: #f7f4ef;
  --sand: #eae0d5;
  --sage: #74c69d;
  --coral: #e07a5f;
  --charcoal: #3c3c3c;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: "Quicksand", sans-serif; 
}

body {
  background: linear-gradient(var(--cream), var(--sand));
  color: var(--charcoal);
  min-height: 100vh;
  text-align: center;
  padding: 0;
  position: relative;
}

/* Back Navigation - Fixed to top-left */
.back-navigation {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
}

.back-button {
  display: inline-block;
  padding: 0.6rem 1rem;
  background: rgba(255, 255, 255, 0.9);
  color: var(--charcoal);
  text-decoration: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.back-button:hover {
  background: white;
  transform: translateX(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.back-button:active {
  background: var(--sage);
  color: white;
  transform: translateX(-2px);
}

/* Screen Container - Centers content */
.screen-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 5rem 1rem 2rem 1rem;
}

/* Individual Screens - CRITICAL: Only one visible at a time */
.screen { 
  display: none !important;
  flex-direction: column; 
  align-items: center; 
  gap: 1.5rem;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.screen.active { 
  display: flex !important;
}

.hidden {
  display: none !important;
}

h1.title { 
  font-size: 3rem; 
  color: var(--charcoal);
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.8rem;
  color: var(--charcoal);
  margin-bottom: 1rem;
}

.subtitle { 
  font-size: 1.2rem; 
  color: #555;
  margin-bottom: 1rem;
}

.btn {
  background: var(--sage);
  color: white;
  border: none;
  padding: 0.8rem 1.6rem;
  border-radius: 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.btn:hover { 
  background: var(--coral); 
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn:active {
  transform: translateY(0);
  background: var(--sage);
  color: white;
}

.btn.secondary { 
  background: #dcd2c4; 
  color: var(--charcoal); 
}

.btn.secondary:active {
  background: var(--sage);
  color: white;
}

.btn.small { 
  padding: 0.5rem 1rem; 
  font-size: 0.9rem; 
}

/* Category Grid */
#category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 500px;
  margin: 1rem 0;
}

.category-card {
  background: white;
  border-radius: 16px;
  padding: 1.2rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.category-card:hover { 
  transform: translateY(-4px); 
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  background: var(--sage);
  color: white;
}

.category-card:active {
  transform: translateY(-2px);
}

/* Game Screen Layout */
#game-screen {
  gap: 1rem;
}

#game-header {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 500px;
  gap: 1rem;
}

#difficulty-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#difficulty-toggle label {
  font-weight: 600;
  font-size: 0.95rem;
}

#difficulty-select {
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 2px solid var(--charcoal);
  background: white;
  font-family: "Quicksand", sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

#difficulty-select:hover {
  border-color: var(--sage);
}

.fade-image {
  width: 240px;
  height: 240px;
  border-radius: 16px;
  object-fit: cover;
  transition: filter 0.4s ease, opacity 0.4s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  /* Prevent blur from being cut off at edges */
  will-change: filter;
}

#word-display { 
  font-size: 2rem; 
  font-weight: 600;
  min-height: 2.5rem;
  margin: 0.5rem 0;
  white-space: pre;
}

#letters-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 500px;
  gap: 0.5rem;
  padding: 0 1rem;
  margin: 1rem 0;
}

.letter-btn {
  width: 44px;
  height: 44px;
  border: 2px solid var(--charcoal);
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.letter-btn:hover {
  background: var(--sage);
  color: white;
  transform: scale(1.08);
}

.letter-btn.used {
  background: #ccc;
  cursor: default;
  color: #888;
  border-color: #999;
}

.letter-btn.used:hover {
  transform: none;
  background: #ccc;
}

.letter-btn:active {
  transform: scale(0.95);
}

#guesses-left {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--coral);
  margin-top: 0.5rem;
}

/* End Screen */
#end-screen {
  gap: 2rem;
}

#end-message {
  font-size: 1.6rem;
  color: var(--charcoal);
  margin: 1rem 0;
}

/* Animations */
@keyframes fadeIn { 
  from { 
    opacity: 0; 
    transform: translateY(10px);
  } 
  to { 
    opacity: 1; 
    transform: translateY(0);
  } 
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}

@keyframes brighten {
  0% { filter: brightness(1) blur(var(--current-blur, 0px)) contrast(var(--current-contrast, 100%)); }
  50% { filter: brightness(1.4) blur(var(--current-blur, 0px)) contrast(var(--current-contrast, 100%)); }
  100% { filter: brightness(1) blur(var(--current-blur, 0px)) contrast(var(--current-contrast, 100%)); }
}

.shake-animation {
  animation: shake 0.5s ease-in-out;
}

.brighten-animation {
  animation: brighten 0.4s ease-in-out;
}

/* Mobile Optimization */
@media (max-width: 600px) {
  .back-navigation {
    top: 0.5rem;
    left: 0.5rem;
  }

  .back-button {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
  }

  .screen-container {
    padding: 4rem 1rem 2rem 1rem;
  }

  h1.title { 
    font-size: 2.4rem; 
  }

  h2 {
    font-size: 1.5rem;
  }
  
  .subtitle {
    font-size: 1rem;
  }
  
  #letters-container {
    max-width: 100%;
    gap: 0.4rem;
  }
  
  .letter-btn {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  
  #word-display {
    font-size: 1.5rem;
  }
  
  .fade-image {
    width: 200px;
    height: 200px;
  }
  
  #category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    max-width: 400px;
  }
  
  .category-card {
    padding: 1rem;
    min-height: 70px;
    font-size: 0.9rem;
  }

  #game-header {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* iPhone SE and smaller */
@media (max-width: 375px) {
  h1.title {
    font-size: 2rem;
  }
  
  .letter-btn {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }
  
  #letters-container {
    gap: 0.3rem;
  }
  
  #word-display {
    font-size: 1.3rem;
  }
  
  .fade-image {
    width: 180px;
    height: 180px;
  }
  
  #category-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Larger screens */
@media (min-width: 768px) {
  .screen-container {
    padding: 6rem 2rem 2rem 2rem;
  }
  
  .fade-image {
    width: 440px;
    height: 440px;
  }

  #category-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
