:root {
  --color-primary: #2d8a4e;
  --color-primary-light: #4caf6a;
  --color-accent: #f59e0b;
  --color-accent-light: #fbbf24;
  --color-bg: #fef9ef;
  --color-text: #1a1a2e;
  --color-card: #ffffff;
  --color-correct: #22c55e;
  --color-incorrect: #ef4444;
  --color-slot: #e2e8f0;
  --color-slot-hover: #cbd5e1;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
  --tile-size: clamp(44px, 10vw, 64px);
  --font-main: 'Nunito', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding: 20px;
}

.screen.active {
  display: flex;
}

/* ---- LOGIN SCREEN ---- */

.login-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
  max-width: 400px;
  width: 100%;
}

.login-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  margin-top: 16px;
}

.btn-guest {
  width: 100%;
  padding: 14px 24px;
}

.login-divider {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  color: #999;
  font-weight: 700;
  font-size: 0.9rem;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #ddd;
}

/* ---- USER BAR ---- */

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 0;
  margin-bottom: 4px;
}

.user-bar.hidden {
  display: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 0.95rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-primary);
}

.user-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 900;
}

/* ---- START SCREEN ---- */

.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  max-width: 400px;
  width: 100%;
}

.title-emoji {
  font-size: 3rem;
  animation: bounce 2s infinite;
}

h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 900;
  color: var(--color-primary);
  text-align: center;
  line-height: 1.1;
}

.subtitle {
  font-size: 1.1rem;
  color: #666;
  font-weight: 700;
}

.stars-display {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--color-accent);
  background: var(--color-card);
  padding: 8px 20px;
  border-radius: 50px;
  box-shadow: var(--shadow);
}

.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 12px;
}

.btn {
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 1.1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.96);
}

.btn-level {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--color-card);
  color: var(--color-text);
  box-shadow: var(--shadow);
  position: relative;
}

.btn-level:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.btn-level.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-level.locked:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.level-emoji {
  font-size: 1.5rem;
}

.lock {
  margin-left: auto;
  font-size: 1.2rem;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  padding: 14px 28px;
  box-shadow: var(--shadow);
}

.btn-primary:hover {
  background: var(--color-primary-light);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--color-card);
  color: var(--color-text);
  padding: 10px 20px;
  box-shadow: var(--shadow);
}

.btn-small {
  background: none;
  color: var(--color-text);
  padding: 8px 12px;
  font-size: 0.95rem;
}

/* ---- GAME SCREEN ---- */

.game-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 500px;
}

.game-info {
  display: flex;
  gap: 16px;
  font-weight: 800;
  font-size: 1rem;
}

#timer-bar-container {
  width: 100%;
  max-width: 500px;
  height: 8px;
  background: var(--color-slot);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s;
}

#timer-bar-container.visible {
  opacity: 1;
}

#timer-bar {
  height: 100%;
  background: var(--color-accent);
  border-radius: 4px;
  width: 100%;
  transition: width 1s linear, background-color 0.3s;
}

#timer-bar.danger {
  background: var(--color-incorrect);
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  flex: 1;
  justify-content: center;
  width: 100%;
  max-width: 500px;
}

.animal-emoji {
  font-size: clamp(4rem, 20vw, 8rem);
  line-height: 1;
  animation: fade-in 0.4s;
}

.letter-slots {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.slot {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 3px dashed var(--color-slot);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.55);
  font-weight: 900;
  transition: border-color 0.2s, background-color 0.2s;
}

.slot.highlight {
  border-color: var(--color-primary);
  background: rgba(45, 138, 78, 0.1);
}

.slot.filled {
  border-style: solid;
  border-color: var(--color-primary);
  background: rgba(45, 138, 78, 0.08);
  color: var(--color-primary);
}

.slot.correct {
  border-color: var(--color-correct);
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-correct);
  animation: bounce 0.4s;
}

.slot.incorrect {
  border-color: var(--color-incorrect);
  background: rgba(239, 68, 68, 0.1);
  animation: shake 0.4s;
}

.letter-pool {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 100%;
  padding: 8px;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--color-card);
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.55);
  font-weight: 900;
  color: var(--color-primary);
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}

.tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.tile.selected {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.tile.dragging {
  position: fixed;
  z-index: 1000;
  transform: scale(1.15);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  opacity: 0.9;
}

.tile.used {
  opacity: 0.3;
  pointer-events: none;
  transform: scale(0.9);
}

.tile.hint {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.game-actions {
  display: flex;
  gap: 12px;
  padding-bottom: 20px;
}

/* ---- RESULT SCREEN ---- */

.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  max-width: 400px;
  text-align: center;
  animation: fade-in 0.4s;
}

.result-content h2 {
  font-size: 2rem;
  color: var(--color-primary);
}

.stars-earned {
  font-size: 2.5rem;
  animation: star-pop 0.5s;
}

.fun-fact {
  font-size: 1.05rem;
  line-height: 1.5;
  color: #555;
  background: var(--color-card);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 700;
}

.result-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ---- SUMMARY SCREEN ---- */

.summary-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
  max-width: 400px;
  text-align: center;
  animation: fade-in 0.4s;
}

.summary-content h2 {
  font-size: 2rem;
  color: var(--color-primary);
}

.summary-stars {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-accent);
}

.summary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--color-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-weight: 700;
}

.summary-item-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- ANIMATIONS ---- */

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes star-pop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 380px) {
  :root {
    --tile-size: 40px;
  }
  .letter-slots, .letter-pool {
    gap: 6px;
  }
}
