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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Screen Management */
.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: 1rem;
  transition: opacity 0.3s ease;
}

.screen.hidden {
  display: none;
}

/* Main Menu */
.menu-container {
  max-width: 600px;
  width: 100%;
  text-align: center;
}

.game-title {
  font-size: 3rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.game-subtitle {
  font-size: 1.25rem;
  margin-bottom: 2rem;
  opacity: 0.8;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.category-btn {
  padding: 1.5rem 1rem;
  font-size: 1.125rem;
  font-weight: 600;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.category-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

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

.stats-container {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 2rem;
  font-size: 1rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.875rem;
  opacity: 0.7;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
}

.settings-btn {
  padding: 0.75rem 2rem;
  font-size: 1.125rem;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-btn:hover {
  opacity: 0.8;
}

/* Game Screen */
.game-container {
  max-width: 900px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.back-btn, .hint-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.back-btn:hover, .hint-btn:hover {
  opacity: 0.8;
}

.category-display {
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

/* Cipher Display */
.cipher-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  min-height: 200px;
  padding: 1rem;
}

.word-group {
  display: inline-flex;
  gap: 0.25rem;
}

.letter-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  position: relative;
}

.cipher-letter {
  font-size: 1.5rem;
  font-weight: bold;
  min-width: 2rem;
  text-align: center;
  user-select: none;
}

.letter-line {
  width: 100%;
  height: 2px;
  margin: 0.125rem 0;
}

.solution-letter {
  font-size: 1.25rem;
  font-weight: 600;
  min-width: 2rem;
  text-align: center;
  min-height: 1.75rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}

.solution-letter.empty:hover {
  opacity: 0.7;
}

.solution-letter.selected {
  transform: scale(1.2);
  position: relative;
}

.solution-letter.selected::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 3px solid currentColor;
  border-radius: 0.25rem;
  animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.solution-letter.solved {
  font-weight: bold;
}

.punctuation {
  font-size: 1.5rem;
  margin: 0 0.25rem;
  align-self: flex-end;
  padding-bottom: 0.5rem;
}

/* Author */
.author-container {
  text-align: center;
  font-size: 1.125rem;
  font-style: italic;
  opacity: 0.8;
}

.author-label {
  margin-right: 0.5rem;
}

/* Keyboard */
.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.key-btn {
  padding: 1rem;
  min-width: 2.5rem;
  font-size: 1.25rem;
  font-weight: bold;
  border: 2px solid currentColor;
  border-radius: 0.375rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.key-btn:hover:not(.used) {
  opacity: 0.8;
  transform: scale(1.05);
}

.key-btn:active:not(.used) {
  transform: scale(0.95);
}

.key-btn.used {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.action-btn {
  padding: 1rem 2rem;
  font-size: 1.125rem;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  opacity: 0.8;
}

/* Settings Screen */
.settings-container {
  max-width: 600px;
  width: 100%;
  padding: 2rem;
}

.settings-title {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 2rem;
  text-align: center;
}

.settings-section {
  margin-bottom: 2rem;
}

.settings-section-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.theme-btn {
  padding: 1.25rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-btn:hover {
  opacity: 0.8;
  transform: scale(1.02);
}

.theme-btn.active {
  font-weight: bold;
  box-shadow: 0 0 0 3px currentColor inset;
}

.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.125rem;
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 2.5rem;
  height: 1.5rem;
  cursor: pointer;
}

.close-settings-btn {
  width: 100%;
  padding: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
  border: 2px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  cursor: pointer;
  margin-top: 2rem;
  transition: all 0.2s ease;
}

.close-settings-btn:hover {
  opacity: 0.8;
}

/* Celebration */
.celebration-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 9999;
}

.celebration-overlay.hidden {
  display: none;
}

.celebration-message {
  font-size: 4rem;
  font-weight: bold;
  text-align: center;
  animation: celebrate 2.5s ease-in-out;
  position: relative;
  z-index: 10000;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

@keyframes celebrate {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  50% { transform: scale(1.2) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

#celebration-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
  .game-title {
    font-size: 2.5rem;
  }
  
  .category-grid {
    grid-template-columns: 1fr;
  }
  
  .cipher-letter {
    font-size: 1.25rem;
  }
  
  .solution-letter {
    font-size: 1rem;
  }
  
  .key-btn {
    min-width: 2rem;
    padding: 0.75rem;
    font-size: 1rem;
  }
  
  .celebration-message {
    font-size: 3rem;
  }
}
