/**
 * style.css — Synononym game styles
 *
 * Design principles:
 * - Modern, clean aesthetic with subtle gradients and glassmorphism
 * - Mobile-first responsive design
 * - Dark theme by default with warm accent colors
 * - Smooth transitions and micro-animations
 * - Accessible: high contrast, focus indicators, reduced motion support
 */

/* ===== CSS Custom Properties (Design Tokens) ===== */
:root {
  /* Colors — dark theme palette */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1a1a2e;
  --bg-overlay: rgba(0, 0, 0, 0.7);

  /* Accent colors */
  --accent-primary: #e94560;
  --accent-secondary: #533483;
  --accent-success: #00d2a0;
  --accent-warning: #ffc107;
  --accent-danger: #ff4444;
  --accent-info: #0984e3;

  /* Text */
  --text-primary: #f1f1f1;
  --text-secondary: #a0a0b0;
  --text-muted: #8a8a9e;  /* Updated for WCAG AA contrast (5.2:1 on bg-primary) */
  --text-accent: #e94560;

  /* Chain step colors */
  --step-bg: #1a1a2e;
  --step-border: #533483;
  --step-start-bg: #533483;
  --step-start-text: #f1f1f1;
  --step-target-bg: #00d2a0;
  --step-target-text: #0f0f1a;

  /* Typography */
  --font-primary: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-full: 50rem;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(233, 69, 96, 0.3);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size:16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Subtle animated gradient background */
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, #0d1b2a 100%);
  background-attachment: fixed;
  /* Smooth scrolling for better mobile experience */
  scroll-behavior: smooth;
}

/* ===== Screen Reader Only ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-lg);
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(83, 52, 131, 0.3);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header__title {
  font-size: 2.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--accent-primary), #ff6b81);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  /* Subtle glow effect behind the text */
  filter: drop-shadow(0 0 8px rgba(233, 69, 96, 0.4));
  animation: titleGlow 3s ease-in-out infinite;
  cursor: default;
}

.header__help-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  background: transparent;
  border: 1px solid var(--text-muted);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  /* Position button in top-right corner, aligned with title */
  position: absolute;
  right: var(--space-lg);
  top: 50%;
  transform: translateY(-50%);
}

.header__help-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.header__help-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.header__help-btn span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: var(--accent-secondary);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.75rem;
}

/* ===== MAIN GAME AREA ===== */
.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-xl) var(--space-md);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  gap: var(--space-lg);
}

/* ---- Word Display ---- */
.game__words {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  width: 100%;
  justify-content: center;
}

.game__word {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.game__word-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

.game__word-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  transition: all var(--transition-normal);
}

.game__word--start .game__word-value {
  background: linear-gradient(135deg, var(--accent-secondary), #6c44b8);
  color: white;
  box-shadow: 0 4px 20px rgba(83, 52, 131, 0.4);
}

.game__word--target .game__word-value {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 2px dashed var(--text-muted);
}

.game__word--target .game__word-value--revealed {
  background: linear-gradient(135deg, var(--accent-success), #00e6b0);
  color: var(--bg-primary);
  border: none;
  box-shadow: 0 4px 20px rgba(0, 210, 160, 0.4);
  animation: revealPop 0.4s ease-out;
}

.game__word-arrow {
  font-size: 1.6rem;
  color: var(--text-muted);
  animation: pulseArrow 2s ease-in-out infinite;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Chain Display ---- */
.game__chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: rgba(22, 33, 62, 0.5);
  border: 1px solid rgba(83, 52, 131, 0.2);
  border-radius: var(--radius-lg);
  min-height: 3.5rem;
  width: 100%;
  justify-content: center;
  overflow-x: auto;
}

.chain__step {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--step-bg);
  border: 1px solid var(--step-border);
  color: var(--text-primary);
  transition: all var(--transition-normal);
  white-space: nowrap;
}

.chain__step--start {
  background: var(--step-start-bg);
  color: var(--step-start-text);
  border-color: var(--step-start-bg);
}

.chain__step--target {
  background: var(--accent-success);
  color: var(--step-target-text);
  border-color: var(--accent-success);
  box-shadow: 0 0 12px rgba(0, 210, 160, 0.4);
}

.chain__step--new {
  animation: stepSlideIn 0.35s ease-out;
}

.chain__arrow {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---- Status Bar ---- */
.game__status {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 var(--space-sm);
}

.game__steps {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.game__strikes {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
  transition: color var(--transition-fast);
}

.game__strikes--warning {
  color: var(--accent-warning);
}

.game__strikes--danger {
  color: var(--accent-danger);
  animation: pulseDanger 0.8s ease-in-out infinite;
}

/* ---- Input Area ---- */
.game__input-area {
  display: flex;
  gap: var(--space-sm);
  width: 100%;
}

.game__input {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  border: 2px solid rgba(83, 52, 131, 0.4);
  border-radius: var(--radius-full);
  background: var(--bg-input);
  color: var(--text-primary);
  /* 16px minimum on iOS to prevent auto-zoom on focus */
  font-size: max(16px, 1.05rem);
  font-family: var(--font-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.game__input::placeholder {
  color: var(--text-muted);
}

.game__input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.game__input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.game__input--valid {
  border-color: var(--accent-success) !important;
  box-shadow: 0 0 0 3px rgba(0, 210, 160, 0.2) !important;
}

.game__submit-btn {
  padding: var(--space-md) var(--space-xl);
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-primary), #ff6b81);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  /* Minimum touch target size for mobile accessibility */
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game__submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.game__submit-btn:active {
  transform: translateY(0);
}

.game__submit-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.game__submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ---- Hint Button ---- */
.game__hint-btn {
  padding: var(--space-md) var(--space-lg);
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-warning), #ffb347);
  color: #1a1a2e;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  /* Minimum touch target size for mobile accessibility */
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game__hint-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(255, 193, 7, 0.4);
}

.game__hint-btn:active:not(:disabled) {
  transform: translateY(0);
}

.game__hint-btn:focus-visible {
  outline: 2px solid var(--accent-warning);
  outline-offset: 2px;
}

.game__hint-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  background: linear-gradient(135deg, #999, #777);
  color: #ddd;
}

/* ---- Feedback Message ---- */
.game__feedback {
  min-height: 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  transition: all var(--transition-fast);
}

.game__feedback--valid {
  color: var(--accent-success);
}

.game__feedback--invalid {
  color: var(--accent-danger);
}

.game__feedback--info {
  color: var(--accent-info);
}

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  padding: var(--space-md);
  overflow-y: auto;
  /* Smooth momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.overlay--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay__card {
  background: var(--bg-secondary);
  border: 1px solid rgba(83, 52, 131, 0.3);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl) var(--space-xl);
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: overlaySlideUp 0.3s ease-out;
  /* Allow content to scroll if it overflows */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay__title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: var(--space-md);
}

.overlay__message {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.overlay__optimal {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.overlay__chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: rgba(15, 15, 26, 0.4);
  border-radius: var(--radius-md);
}

.overlay__chain-word {
  font-weight: 600;
  font-size: 0.95rem;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.overlay__chain-word--start {
  background: var(--accent-secondary);
  color: white;
}

.overlay__chain-word--target {
  background: var(--accent-success);
  color: var(--bg-primary);
}

.overlay__chain-arrow {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.overlay__next {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.overlay__btn {
  padding: var(--space-md) var(--space-2xl);
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-primary), #ff6b81);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  /* Minimum touch target size for mobile accessibility */
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Center button horizontally on the page */
  margin: 0 auto;
}

.overlay__btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.overlay__btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ---- Lose overlay variant ---- */
.overlay__card--lose .overlay__title {
  color: var(--accent-danger);
}

.overlay__solution-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: var(--space-lg) 0 var(--space-md) 0;
  text-align: center;
}

/* ---- Help overlay variant ---- */
.overlay__card--help {
  text-align: left;
  max-width: 520px;
}

.overlay__card--help .overlay__title {
  text-align: center;
}

.help__steps {
  margin: var(--space-md) 0;
  padding-left: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.help__steps li {
  color: var(--text-secondary);
  line-height: 1.5;
  font-size: 0.95rem;
}

.help__steps li strong {
  color: var(--text-primary);
}

.help__example {
  background: rgba(15, 15, 26, 0.5);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
}

.help__example p {
  margin-bottom: var(--space-sm);
  color: var(--text-secondary);
}

.help__chain-example {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.help__tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--accent-secondary);
  color: white;
  vertical-align: middle;
}

.help__tag--target {
  background: var(--accent-success);
  color: var(--bg-primary);
}

.overlay__card--help .overlay__btn {
  display: block;
  margin: 0 auto;
}

/* ===== FOOTER ===== */
.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-lg) var(--space-md);
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid rgba(83, 52, 131, 0.2);
  background: rgba(26, 26, 46, 0.6);
  margin-top: auto;
  /* Full-width footer; text is centered via justify-content */
  width: 100%;
}

.footer p {
  margin: 0;
  text-align: center;
}

/* ===== ANIMATIONS ===== */

/* Shake animation for invalid guesses */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Slide-in for new chain steps */
@keyframes stepSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Overlay slide-up entrance */
@keyframes overlaySlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Target word reveal pop */
@keyframes revealPop {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* Arrow pulse */
@keyframes pulseArrow {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Danger pulse for strikes */
@keyframes pulseDanger {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Title glow effect — subtle breathing glow */
@keyframes titleGlow {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(233, 69, 96, 0.4)); }
  50% { filter: drop-shadow(0 0 16px rgba(233, 69, 96, 0.6)); }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== RESPONSIVE ===== */

/* Very small phones (320px - 380px) */
@media (max-width: 380px) {
  .header__title {
    font-size: 1.5rem;
  }
  .header__help-btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
  }
  .game {
    padding: var(--space-lg) var(--space-sm);
    gap: var(--space-md);
  }
  .game__word-value {
    font-size: 1.4rem;
    padding: var(--space-xs) var(--space-md);
  }
  .game__input {
    padding: var(--space-sm) var(--space-md);
    /* Keep at 16px for iOS to prevent auto-zoom */
    font-size: 16px;
  }
  .game__submit-btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9rem;
    min-height: 44px;
  }
  .overlay__card {
    padding: var(--space-lg) var(--space-md);
    max-height: 85vh;
  }
  .overlay__title {
    font-size: 1.4rem;
  }
  .overlay__btn {
    min-height: 44px;
    font-size: 0.95rem;
  }
}

/* Tablets and up */
@media (min-width: 768px) {
  .game {
    padding: var(--space-2xl) var(--space-lg);
    gap: var(--space-xl);
  }
  .game__word-value {
    font-size: 2.2rem;
  }
  .game__word-arrow {
    font-size: 2rem;
  }
  .game__input {
    font-size: 1.15rem;
  }
}

/* Desktop — constrain width */
@media (min-width: 1024px) {
  .game {
    max-width: 640px;
  }
}
