/* DESIGN SYSTEM & CONSTANTS */
:root {
  --font-logo: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Playful Neon Color Palette */
  --bg-dark: #090d16;
  --bg-card: rgba(22, 30, 49, 0.7);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  
  --color-primary: #a855f7;
  --color-secondary: #06b6d4;
  --color-accent: #ec4899;
  
  --color-success: #10b981;
  --color-error: #ef4444;
  
  --gradient-primary: linear-gradient(135deg, #a855f7, #ec4899);
  --gradient-secondary: linear-gradient(135deg, #06b6d4, #3b82f6);
  --gradient-success: linear-gradient(135deg, #10b981, #059669);
  
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-neon-glow: 0 0 20px rgba(168, 85, 247, 0.3);
  --shadow-success-glow: 0 0 20px rgba(16, 185, 129, 0.4);
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 0;
}

/* Floating background glow effects */
.bg-glow {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  background: var(--color-primary);
  top: -10%;
  left: -10%;
  animation: float-slow 20s infinite alternate;
}

.bg-glow-2 {
  background: var(--color-secondary);
  bottom: -10%;
  right: -10%;
  animation: float-slow 25s infinite alternate-reverse;
}

.bg-glow-3 {
  background: var(--color-accent);
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
}

@keyframes float-slow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(60px, 40px) scale(1.1); }
}

/* APP STRUCTURE */
.app-container {
  width: 100%;
  max-width: 900px;
  min-height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.header-controls {
  display: flex;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-img {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.4);
  filter: brightness(1.2) contrast(1.1);
}

.logo-icon {
  font-size: 2rem;
  animation: bounce-logo 3s ease-in-out infinite;
}

@keyframes bounce-logo {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(8deg); }
}

.logo h1 {
  font-family: var(--font-logo);
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* BUTTONS */
button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  transition: var(--transition-smooth);
  touch-action: manipulation;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 12px;
  border-radius: var(--radius-md);
  width: 48px;
  height: 48px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  border-color: var(--color-primary);
}

.primary-btn {
  background: var(--gradient-primary);
  color: white;
  padding: 16px 36px;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  box-shadow: var(--shadow-neon-glow);
}

.primary-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.5);
}

.primary-btn:active {
  transform: translateY(-1px) scale(1.0);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  border-color: var(--text-muted);
}

.action-btn {
  background: var(--gradient-secondary);
  color: white;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3);
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(6, 182, 212, 0.5);
}

.pulse-anim {
  animation: button-pulse 2s infinite;
}

@keyframes button-pulse {
  0% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.6); }
  70% { box-shadow: 0 0 0 15px rgba(168, 85, 247, 0); }
  100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0); }
}

/* SCREEN MANAGEMENT */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.screen {
  display: none;
  width: 100%;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transform: translateY(0);
}

/* SCREEN 1: HOME DESIGN */
.welcome-box {
  text-align: center;
  margin-bottom: 32px;
}

.welcome-box h2 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 12px;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-box p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  width: 100%;
  margin-bottom: 40px;
}

@media (min-width: 768px) {
  .setup-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.setup-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.setup-card h3 {
  font-size: 1.2rem;
  margin-bottom: 20px;
  font-weight: 700;
  color: var(--text-main);
  border-left: 4px solid var(--color-primary);
  padding-left: 10px;
}

/* Mode Selection Cards */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mode-option {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition-smooth);
  touch-action: manipulation;
}

.mode-option:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.2);
}

.mode-option.active {
  border-color: var(--color-primary);
  background: rgba(168, 85, 247, 0.08);
}

.mode-content {
  display: flex;
  gap: 16px;
  align-items: center;
}

.mode-icon {
  font-size: 2rem;
}

.mode-content h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-main);
}

.mode-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.hidden-radio {
  display: none;
}

/* Category Grid */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.category-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  padding: 16px 12px;
  border-radius: var(--radius-md);
  flex-direction: column;
  gap: 8px;
  color: var(--text-main);
  transition: var(--transition-spring);
  touch-action: manipulation;
}

.category-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-2px);
  border-color: var(--color-secondary);
}

.category-btn.active {
  background: rgba(6, 182, 212, 0.12);
  border-color: var(--color-secondary);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

.cat-emoji {
  font-size: 1.8rem;
}

.cat-name {
  font-size: 0.9rem;
  font-weight: 700;
}

/* SCREEN 2: GAMEPLAY */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
}

.stat-item {
  display: flex;
  flex-direction: column;
  min-width: 90px;
  position: relative;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Timer styles */
#stat-timer-container {
  min-width: 120px;
  position: relative;
}

.timer-progress-bg {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  margin-top: 6px;
  overflow: hidden;
}

.timer-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  transition: width 1s linear;
}

.lives-hearts {
  font-size: 1.15rem;
  letter-spacing: 2px;
}

/* Puzzle Area Styles */
.puzzle-container {
  width: 100%;
  background: rgba(13, 20, 35, 0.8);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: inset 0 4px 30px rgba(0, 0, 0, 0.3);
  margin-bottom: 24px;
}

.word-hint-container {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-secondary);
  height: 20px;
}

.hidden-hint {
  opacity: 0.8;
}

/* Slots for placing letters */
.answer-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  min-height: 70px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  transition: var(--transition-smooth);
}

.answer-slots.wrong-shake {
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
  border-color: var(--color-error);
  background: rgba(239, 68, 68, 0.05);
}

.answer-slots.correct-glow {
  border-color: var(--color-success);
  background: rgba(16, 185, 129, 0.05);
  box-shadow: inset 0 0 15px rgba(16, 185, 129, 0.15);
}

@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Pool of scrambled letters */
.letter-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 100%;
  min-height: 60px;
}

/* The actual letter tiles */
.letter-tile {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 4px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1.5rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: var(--transition-spring);
  animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  touch-action: manipulation;
}

.letter-tile:hover {
  background: var(--gradient-primary);
  border-color: transparent;
  border-bottom-color: rgba(0, 0, 0, 0.2);
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3), 0 0 10px rgba(168, 85, 247, 0.3);
}

.letter-tile.placed {
  opacity: 0.15;
  background: rgba(255, 255, 255, 0.01) !important;
  border: 1.5px dashed rgba(255, 255, 255, 0.1) !important;
  border-bottom: 1.5px dashed rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.1) !important;
  transform: scale(0.85);
  pointer-events: none;
  box-shadow: none !important;
}

.letter-tile.in-slot {
  background: var(--gradient-secondary);
  border-color: transparent;
  border-bottom-color: rgba(0, 0, 0, 0.2);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  animation: pop-in-slot 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.letter-tile.in-slot:hover {
  background: var(--gradient-secondary);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

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

@keyframes pop-in-slot {
  0% { transform: scale(0.8); }
  100% { transform: scale(1); }
}

/* Controls layout */
.controls-row {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
  margin-bottom: 20px;
}

.controls-row .action-btn {
  flex-grow: 2;
  max-width: 250px;
}

.keyboard-tip {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* SCREEN 3: GAME OVER */
.game-over-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  padding: 40px 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-over-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: trophy-bounce 2s ease-in-out infinite alternate;
}

@keyframes trophy-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-10px) scale(1.05); }
}

.game-over-card h2 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-over-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.game-over-stats-summary {
  font-weight: 600;
  color: var(--color-secondary);
  margin-top: -12px;
  margin-bottom: 24px;
  font-size: 1.05rem;
}

.results-stats {
  display: flex;
  gap: 16px;
  width: 100%;
  margin-bottom: 32px;
}

.results-stat-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.game-over-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.game-over-actions button {
  width: 100%;
}

/* ADSENSE PLACEHOLDERS */
.adsense-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(22, 30, 49, 0.4);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 10px;
  margin: 16px 0;
  text-align: center;
  min-height: 100px;
  width: 100%;
}

.top-ad {
  max-width: 728px;
  margin-left: auto;
  margin-right: auto;
}

.bottom-ad {
  max-width: 728px;
  margin-left: auto;
  margin-right: auto;
}

.ad-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.2);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.ad-mockup {
  color: rgba(255, 255, 255, 0.15);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px dashed rgba(255, 255, 255, 0.05);
  padding: 12px 30px;
  border-radius: var(--radius-sm);
}

/* FOOTER */
.app-footer {
  text-align: center;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* UTILITY CLASSES */
.hidden {
  display: none !important;
}

/* LIGHT THEME (OPPORTUNISTIC OVERRIDES IN CASE THE USER TOGGLES IT) */
body.light-mode {
  --bg-dark: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.8);
  --bg-card-border: rgba(0, 0, 0, 0.08);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
  --shadow-neon-glow: 0 0 20px rgba(168, 85, 247, 0.15);
}

body.light-mode .bg-glow {
  opacity: 0.08;
}

body.light-mode button.secondary-btn {
  background: rgba(0, 0, 0, 0.03);
}

body.light-mode .letter-tile {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.1);
  border-bottom-color: rgba(0, 0, 0, 0.2);
  color: #0f172a;
}

body.light-mode .puzzle-container {
  background: rgba(255, 255, 255, 0.9);
}

body.light-mode .answer-slots {
  background: rgba(0, 0, 0, 0.01);
  border-color: rgba(0, 0, 0, 0.15);
}

body.light-mode .adsense-placeholder {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.08);
}
body.light-mode .ad-mockup {
  color: rgba(0, 0, 0, 0.3);
}
body.light-mode .ad-label {
  color: rgba(0, 0, 0, 0.3);
}

/* Floating -1 Animation */
.floating-minus-one {
  position: absolute;
  color: var(--color-error);
  font-weight: 800;
  font-size: 1.3rem;
  pointer-events: none;
  animation: float-up-fade 0.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  z-index: 10;
}

@keyframes float-up-fade {
  0% {
    transform: translate(-50%, -50%) translateY(0) scale(0.7);
    opacity: 0;
  }
  20% {
    transform: translate(-50%, -50%) translateY(-6px) scale(1.15);
    opacity: 1;
  }
  75% {
    transform: translate(-50%, -50%) translateY(-25px) scale(1.0);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) translateY(-40px) scale(0.85);
    opacity: 0;
  }
}
