:root {
  --primary-color: #ff6b6b;
  --secondary-color: #4ecdc4;
  --tertiary-color: #ffe66d;
  --success-color: #51cf66;
  --error-color: #ff6b6b;
  --neutral-color: #95a5a6;
  --disabled-color: #bdc3c7;
  --text-light: #ffffff;
  --text-dark: #2c3e50;
  --bg-light: #f8f9fa;
  --bg-dark: #1a1a1a;
  --border-radius: 12px;
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  transition: var(--transition);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body.dark-mode {
  background-color: var(--bg-dark);
  color: var(--text-light);
}

/* Page Management */
.page {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.container {
  width: 100%;
  height: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* Home Page */
#home-page {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.home-content {
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.logo-section {
  margin-bottom: 60px;
}

.home-logo {
  width: 200px;
  height: auto;
  margin-bottom: 20px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.game-title {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--text-light);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.game-subtitle {
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 20px;
}

/* Buttons */
.btn {
  padding: 14px 28px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  touch-action: manipulation;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background-color: var(--primary-color);
  color: var(--text-light);
}

.btn-primary:hover {
  background-color: #ff5252;
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: var(--text-light);
}

.btn-secondary:hover {
  background-color: #45b8af;
  box-shadow: 0 4px 15px rgba(78, 205, 196, 0.4);
}

.btn-tertiary {
  background-color: var(--tertiary-color);
  color: var(--text-dark);
}

.btn-tertiary:hover {
  background-color: #ffd54f;
  box-shadow: 0 4px 15px rgba(255, 230, 109, 0.4);
}

.btn-large {
  width: 100%;
  padding: 18px 28px;
  font-size: 1.1rem;
  min-height: 54px;
}

.btn-icon {
  background-color: transparent;
  color: var(--text-dark);
  font-size: 1.5rem;
  padding: 8px;
  min-width: auto;
}

body.dark-mode .btn-icon {
  color: var(--text-light);
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* Game Page */
#game-page {
  background-color: var(--bg-light);
  flex-direction: column;
  padding: 0;
}

body.dark-mode #game-page {
  background-color: var(--bg-dark);
}

.game-header {
  width: 100%;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

body.dark-mode .game-header {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

.guesses-display {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 1.1rem;
}

#hearts-display {
  font-size: 1.5rem;
  letter-spacing: 2px;
}

.game-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stage-container {
  text-align: center;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage-image {
  max-width: 100%;
  height: auto;
  max-height: 250px;
}

.phrase-display {
  text-align: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

body.dark-mode .phrase-display {
  background: rgba(255, 255, 255, 0.05);
}

.phrase {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 8px;
  word-spacing: 16px;
  line-height: 1.4;
  color: var(--text-dark);
  font-family: "Courier New", Courier, monospace;
  word-break: keep-all;
  white-space: normal;
}

body.dark-mode .phrase {
  color: var(--text-light);
}

/* Letters Grid */
.letters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: 8px;
  width: 100%;
  margin: 20px 0;
}

.letter-btn {
  aspect-ratio: 1;
  min-height: 44px;
  min-width: 44px;
  border: 2px solid var(--neutral-color);
  background-color: var(--tertiary-color);
  color: var(--text-dark);
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

.letter-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.letter-btn:active:not(:disabled) {
  transform: translateY(0);
}

.letter-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  background-color: var(--disabled-color);
}

.letter-btn.correct {
  background-color: var(--success-color);
  border-color: var(--success-color);
  color: var(--text-light);
}

.letter-btn.incorrect {
  background-color: var(--error-color);
  border-color: var(--error-color);
  color: var(--text-light);
}

.letter-btn.notguessed {
  background-color: var(--tertiary-color);
  border-color: var(--tertiary-color);
}

.message-display {
  min-height: 40px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  padding: 12px;
  border-radius: var(--border-radius);
  animation: slideIn 0.3s ease;
}

.message-display.success {
  background-color: rgba(81, 207, 102, 0.2);
  color: var(--success-color);
}

.message-display.error {
  background-color: rgba(255, 107, 107, 0.2);
  color: var(--error-color);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Settings Page */
#settings-page {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.settings-content {
  width: 100%;
  max-width: 600px;
  background: rgba(255, 255, 255, 0.95);
  padding: 40px 30px;
  border-radius: var(--border-radius);
  text-align: center;
}

body.dark-mode .settings-content {
  background: rgba(26, 26, 26, 0.95);
  color: var(--text-light);
}

.settings-content h2 {
  margin-bottom: 40px;
  font-size: 2rem;
}

.settings-group {
  margin-bottom: 40px;
  text-align: left;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--border-radius);
  margin-bottom: 16px;
}

body.dark-mode .setting-item {
  background: rgba(255, 255, 255, 0.05);
}

.setting-item label {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.toggle-checkbox {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-label {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--disabled-color);
  transition: var(--transition);
  border-radius: 34px;
}

.toggle-label:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
}

.toggle-checkbox:checked + .toggle-label {
  background-color: var(--primary-color);
}

.toggle-checkbox:checked + .toggle-label:before {
  transform: translateX(26px);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal[style*="display: flex"] {
  display: flex;
}

.modal-content {
  width: 90%;
  max-width: 500px;
}

.end-game-container {
  background: var(--bg-light);
  padding: 40px 30px;
  border-radius: var(--border-radius);
  text-align: center;
  animation: slideIn 0.3s ease;
}

body.dark-mode .end-game-container {
  background: var(--bg-dark);
  color: var(--text-light);
}

.end-game-image {
  margin-bottom: 20px;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.end-game-image img {
  max-width: 100%;
  height: auto;
  max-height: 200px;
}

#end-game-title {
  font-size: 2.5rem;
  margin-bottom: 16px;
  font-weight: 800;
}

.end-game-title.win {
  color: var(--success-color);
  font-size: 3rem;
}

.end-game-title.lose {
  color: var(--error-color);
}

#end-game-message {
  font-size: 1.2rem;
  margin-bottom: 24px;
  font-weight: 600;
}

.revealed-phrase {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 20px 0 30px 0;
  color: var(--text-dark);
  word-break: break-word;
  letter-spacing: 2px;
}

body.dark-mode .revealed-phrase {
  color: var(--text-light);
}

.end-game-container h3 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

#continue-game-btn {
  display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
  .game-title {
    font-size: 2.5rem;
  }

  .phrase {
    font-size: 2rem;
    letter-spacing: 6px;
    word-spacing: 12px;
  }

  .letters-grid {
    grid-template-columns: repeat(auto-fit, minmax(38px, 1fr));
    gap: 6px;
  }

  .letter-btn {
    font-size: 1rem;
  }

  .stage-container {
    min-height: 150px;
  }

  #stage-image {
    max-height: 200px;
  }
}

@media (max-width: 480px) {
  .game-title {
    font-size: 2rem;
  }

  .game-subtitle {
    font-size: 1rem;
  }

  .phrase {
    font-size: 1.6rem;
    letter-spacing: 4px;
    word-spacing: 8px;
  }

  .letters-grid {
    grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
    gap: 5px;
  }

  .letter-btn {
    font-size: 0.9rem;
    min-height: 40px;
    min-width: 40px;
  }

  .btn-large {
    padding: 16px 20px;
    font-size: 1rem;
    min-height: 48px;
  }

  .guesses-display {
    font-size: 1rem;
  }

  #hearts-display {
    font-size: 1.2rem;
  }

  .game-content {
    gap: 16px;
    padding: 16px;
  }

  .stage-container {
    min-height: 120px;
  }

  #stage-image {
    max-height: 150px;
  }

  .settings-content {
    padding: 30px 20px;
  }

  .end-game-container {
    padding: 30px 20px;
  }

  #end-game-title {
    font-size: 2rem;
  }

  .revealed-phrase {
    font-size: 1.5rem;
  }
}

/* Landscape Mode */
@media (max-height: 600px) and (orientation: landscape) {
  .container {
    padding: 16px;
  }

  .game-content {
    padding: 16px;
    gap: 16px;
  }

  .stage-container {
    min-height: 100px;
  }

  #stage-image {
    max-height: 120px;
  }

  .phrase-display {
    padding: 12px;
  }

  .phrase {
    font-size: 1.3rem;
    letter-spacing: 3px;
    word-spacing: 6px;
  }

  .letters-grid {
    gap: 6px;
  }

  .letter-btn {
    font-size: 0.85rem;
    min-height: 36px;
    min-width: 36px;
  }

  .btn-large {
    padding: 12px 20px;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .guesses-display {
    font-size: 0.9rem;
  }

  #hearts-display {
    font-size: 1.2rem;
  }

  .game-header {
    padding: 8px 16px;
    gap: 8px;
  }

  /* Modal in landscape */
  .modal-content {
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .end-game-container {
    padding: 24px 20px;
  }

  .end-game-image {
    margin-bottom: 12px;
    min-height: 100px;
  }

  .end-game-image img {
    max-height: 120px;
  }

  #end-game-title {
    font-size: 2rem;
    margin-bottom: 10px;
  }

  #end-game-message {
    font-size: 1rem;
    margin-bottom: 15px;
  }

  .revealed-phrase {
    font-size: 1.4rem;
    margin: 12px 0 18px 0;
  }

  /* Home page in landscape */
  .home-logo {
    width: 80px;
    margin-bottom: 10px;
  }

  .game-title {
    font-size: 2rem;
    margin-bottom: 5px;
  }

  .game-subtitle {
    font-size: 0.9rem;
    margin-bottom: 15px;
  }

  .logo-section {
    margin-bottom: 20px;
  }

  .button-group {
    gap: 10px;
  }

  .btn-large {
    padding: 10px 16px;
    font-size: 0.9rem;
    min-height: 40px;
  }
}
