/* Game Styles - ChainWhich */

/* ========================================
   GLOBAL
   ======================================== */

body {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-loose);
  color: var(--color-gray-900);
  background-color: var(--color-white);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================================
   HEADER
   ======================================== */

.header {
  background-color: var(--color-white);
  border-bottom: 1px solid var(--color-gray-200);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Fix for iPad landscape: Make header non-sticky when viewport height is constrained */
@media (max-height: 800px) and (min-width: 768px) {
  .header {
    position: relative;  /* Change from sticky to relative */
  }
}

.header__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding: 0 var(--container-padding);
}

.header__logo {
  display: flex;
  gap: 0.25rem;
  font-size: var(--font-size-display);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-tight);
}

.logo__word {
  padding: 0.25rem 0.5rem;
  border: 2px solid var(--color-primary);
  border-radius: var(--border-radius-sm);
  background: var(--color-white);
  color: var(--color-gray-900);
}

.header__menu {
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-gray-700);
  font-size: 1.5rem;
  transition: color var(--duration-fast) var(--ease-out);
}

.header__menu:hover {
  color: var(--color-primary);
}

.header__menu:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}

.header__info {
  display: flex;
  justify-content: center;
  align-items: center;
  height: var(--header-info-height);
  padding: 0 var(--container-padding);
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-snug);
  color: var(--color-gray-900);
}

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

/* Tutorial header (replaces puzzle info during tutorial mode) */
.tutorial-header {
  text-align: center;
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-snug);
  color: var(--color-gray-900);
}

.tutorial-header[hidden] {
  display: none !important;
}

.tutorial-header h2 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

/* Daily header wrapper (same styling as header__info) */
.daily-header {
  display: flex;
  justify-content: center;
  align-items: baseline; /* Align text baselines for proper typography */
  gap: 1.5rem; /* 24px spacing between date and streak */
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem; /* Prevent overlap with puzzle border */
  background: var(--color-gray-50);
  border-radius: var(--border-radius-sm);
}

.daily-header[hidden] {
  display: none !important;
}

.puzzle-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.puzzle-date {
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-900);
  line-height: 1.5; /* Consistent line height for baseline alignment */
}

.streak--inline {
  display: inline-flex;
  align-items: baseline; /* Align emoji and text */
  gap: 0.25rem;
  font-size: var(--font-size-body);
  line-height: 1.5; /* Match puzzle-date line height */
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-900);
  white-space: nowrap;
}

.streak__label {
  font-size: var(--font-size-subhead);
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-700);
  margin-right: var(--space-xs);
}

/* ========================================
   MENU
   ======================================== */

.menu {
  position: absolute;
  top: var(--header-height);
  right: 0;
  background-color: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-xs);
  margin: var(--space-xs) var(--container-padding);
  min-width: 200px;
  z-index: var(--z-menu);
}

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-body);
  text-align: left;
  color: var(--color-gray-900);
  border-radius: var(--border-radius-sm);
  transition: background-color var(--duration-fast) var(--ease-out);
  min-height: var(--touch-target-min);
}

.menu__item:hover {
  background-color: var(--color-gray-50);
}

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

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

.menu__icon {
  font-size: 1.25rem;
}

/* ========================================
   MAIN GAME AREA
   ======================================== */

.game {
  flex: 1;
  min-height: 0;  /* Allow shrinking in nested flex column (Safari overflow fix) */
  display: flex;
  flex-direction: column;
  padding: var(--space-xs) var(--space-md);  /* 8px top, 16px left/right on mobile */
  /* Reserve space at bottom for fixed submit button */
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  gap: var(--space-sm);  /* 12px on mobile - tighter for viewport fit */
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ========================================
   TUTORIAL CAPTION
   ======================================== */

/* Progressive tutorial prompt (Rec B1) */
.tutorial-prompt {
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-caption);
  line-height: var(--line-height-relaxed);
  color: var(--color-gray-700);
  background-color: var(--color-teal-50);
  border: 1px solid var(--color-primary);
  border-radius: var(--border-radius-sm);
  margin-bottom: var(--space-xs);
}

.tutorial-prompt[hidden] {
  display: none !important;
}

.tutorial-prompt__text {
  margin: 0;
  transition: opacity 0.2s ease;
}

/* Error state: warm amber accent (Rec B5) */
.tutorial-prompt--error .tutorial-prompt__text {
  color: var(--color-warning);
  font-weight: var(--font-weight-medium);
}

/* Shake animation for incorrect chain word (Rec B5) */
@keyframes tutorialShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.slot--tutorial-shake {
  animation: tutorialShake 0.4s ease-out;
}

/* ========================================
   CHAIN AREA
   ======================================== */

.chain {
  flex-shrink: 0;
}

.chain__slots {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);  /* 8px on mobile - tighter for viewport fit */
}

.slot {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--slot-height);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-white);
  border: var(--border-width) dashed var(--color-gray-300);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-word-slot);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
  color: var(--color-gray-900);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  position: relative;
}

.slot__number {
  display: none; /* Hidden per ux-steve Issue #19 - numbers don't add value */
}

.slot__content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);  /* Space between word and icon */
  min-height: 32px;
}

/* Slot States */
.slot--empty {
  border-style: dashed;
}

/* Tutorial-only: Show "Place word here" in empty slots */
.tutorial .slot--empty .slot__content {
  position: relative;
}

.tutorial .slot--empty .slot__content::before {
  content: 'Place word here';
  font-size: var(--font-size-xs);
  color: var(--color-gray-400);
  font-weight: var(--font-weight-normal);
  text-transform: none;
  letter-spacing: normal;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

/* Hide timer during tutorial (Rec B4) — visibility preserves layout */
.tutorial .status-bar__timer {
  visibility: hidden;
}

/* Hide placeholder when slot has content */
.tutorial .slot--filled .slot__content::before,
.tutorial .slot--correct .slot__content::before,
.tutorial .slot--wrong .slot__content::before {
  display: none;
}

.slot--filled {
  border: var(--border-width) solid var(--color-primary);
  border-style: solid;
}

.slot--prefilled {
  background-color: var(--color-gray-50);
  border: var(--border-width) solid var(--color-gray-400);
  color: var(--color-gray-500);
  cursor: default;
}

/* Lock icon centering: invisible spacer on left to balance lock icon on right */
.slot--prefilled .slot__content::before {
  content: '';
  width: calc(0.875rem + var(--space-xs));
  flex-shrink: 0;
}

.slot--prefilled .slot__content::after {
  content: '🔒';
  margin-left: var(--space-xs);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.slot--highlight {
  border: var(--border-width) solid var(--color-primary);
  box-shadow: var(--glow-primary);
  animation: pulse 2s var(--ease-in-out) infinite;
}

/* Enhanced pulsing when word is selected (both tutorial and game) */
.slot--empty.slot--highlight {
  border: 2px solid var(--color-primary);
  box-shadow:
    var(--glow-primary-soft),
    var(--glow-primary);
  animation: pulse-enhanced 1.2s ease-in-out infinite;
}

/* Filled slot highlighting when word is selected (replace-in-place feature) */
.slot--filled.slot--highlight {
  border: 2px solid var(--color-primary);
  box-shadow: 0 0 8px rgba(var(--color-primary-rgb), 0.3);
  cursor: pointer;
  animation: pulse-subtle 2s ease-in-out infinite;
}

@keyframes pulse-subtle {
  0%, 100% {
    box-shadow: 0 0 4px rgba(var(--color-primary-rgb), 0.2);
  }
  50% {
    box-shadow: 0 0 12px rgba(var(--color-primary-rgb), 0.4);
  }
}

@keyframes pulse-enhanced {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      var(--glow-primary-soft),
      0 0 12px rgba(var(--color-primary-rgb), 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow:
      var(--glow-primary-medium),
      0 0 20px rgba(var(--color-primary-rgb), 0.5);
  }
}

.slot--correct {
  background-color: var(--color-success-bg);
  border: var(--border-width) solid var(--color-success);
}

.slot--wrong {
  background-color: var(--color-error-bg);
  border: var(--border-width) solid var(--color-error);
  /* Shake animation removed per ux-steve spec - color + icon is sufficient feedback */
  transition: all var(--duration-normal) var(--ease-out);
}

.slot--decoy {
  background-color: var(--color-gray-100);
  border: var(--border-width) solid var(--color-gray-500);
  color: var(--color-gray-400);
  text-decoration: line-through;
  opacity: 0.6;
}

/* Locked slot (revealed by second hint) */
.slot--locked {
  background-color: var(--color-info-bg);
  border: var(--border-width) solid var(--color-info);
  cursor: not-allowed;
  pointer-events: none;
  position: relative;
}

/* Lock icon centering: invisible spacer on left to balance lock icon on right */
.slot--locked .slot__content::before {
  content: '';
  width: calc(1rem + var(--space-xs));
  flex-shrink: 0;
}

.slot--locked .slot__content::after {
  content: '🔒';
  margin-left: var(--space-xs);
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.8;
}

/* Icon styling - visible to all users for WCAG 2.1 AA compliance */
.slot--correct .slot__icon,
.slot--wrong .slot__icon {
  font-size: 1.125rem;
  font-weight: var(--font-weight-bold);
  animation: scaleIn var(--duration-medium) var(--ease-bounce);
}

.slot--correct .slot__icon {
  color: var(--color-success);
}

.slot--wrong .slot__icon {
  color: var(--color-error);
}

/* Focus Styles */
.slot:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ========================================
   STATUS BAR
   ======================================== */

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--status-bar-height);
  font-size: var(--font-size-subhead);
  font-weight: var(--font-weight-regular);
  color: var(--color-gray-500);
}

.status-bar__attempts {
  display: flex;
  align-items: center;
  gap: 0.5rem; /* Spacing for label */
}

.attempts-label {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-600);
  margin-right: 0.25rem; /* Space before circles */
}

.attempts-circles {
  display: flex;
  gap: var(--space-xs);
}

.circle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--color-gray-300);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.circle.filled {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

.status-bar__hint {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-regular);
  color: var(--color-gray-500);
  background: transparent;
  border: none;
  padding: var(--space-xs);
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.status-bar__hint:hover {
  color: var(--color-primary);
}

.status-bar__hint:active {
  transform: scale(0.96);
}

.status-bar__hint:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}

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

.status-bar__hint[hidden] {
  display: none;
}

.status-bar__timer {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-variant-numeric: tabular-nums;
}

/* ========================================
   WORD BANK
   ======================================== */

/* Word bank ready state: pulsing glow on each word before first interaction */
.word--ready {
  animation: word-ready-pulse 2s ease-in-out infinite;
}

@keyframes word-ready-pulse {
  0%, 100% {
    border-color: var(--color-gray-200);
    box-shadow: var(--shadow-sm);
  }
  50% {
    border-color: var(--color-primary);
    box-shadow: var(--glow-primary);
  }
}

/* Slot click reminder (tutorial only) */
.slot-click-reminder {
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-gray-700);
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning);
  border-radius: var(--border-radius-md);
  animation: fadeInBounce 0.6s ease-out;
}

@keyframes fadeInBounce {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.word-bank {
  flex: 1;
  min-height: 0;  /* Allow shrinking in flex column (Safari fix for tutorial overlap) */
  overflow-y: auto;
  /* Ensure clearance above fixed submit button (Safari ignores parent padding-bottom) */
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

.word-bank__container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: var(--space-sm);
  padding: var(--space-xs); /* Overflow room for selected state scale effect */
}

.word {
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-white);
  border: var(--border-width) solid var(--color-gray-200);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-word-bank);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-gray-900);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--duration-fast) var(--ease-out);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.word:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.word--selected {
  background-color: var(--color-teal-50);
  border-color: var(--color-primary);
  box-shadow: var(--glow-primary);
  transform: scale(1.05);
}

.word--used {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-200);
  color: var(--color-gray-400);
  opacity: 0.5;
  pointer-events: none;
}

/* Eliminated word (removed by first hint) */
.word--eliminated {
  /* Text styling */
  text-decoration: line-through;
  text-decoration-thickness: 3px; /* Thicker for visibility */
  text-decoration-color: var(--color-error); /* Red instead of gray */

  /* Opacity */
  opacity: 0.6; /* Increased from 0.4 for better visibility */

  /* Interaction */
  pointer-events: none;
  cursor: not-allowed;

  /* Background */
  background-color: var(--color-error-bg); /* Light red tint */
  border-color: var(--color-error-border); /* Red border */
  color: var(--color-gray-600); /* Slightly darken text for contrast */

  /* Transition */
  transition: all 0.3s ease; /* Smooth transition when applied */
}

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

/* Loading and Error States */
.loading-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  min-height: 200px;
}

.error-state {
  background-color: var(--color-gray-50);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-gray-200);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: var(--space-md);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-message {
  font-size: var(--font-size-body);
  color: var(--color-gray-600);
  font-weight: var(--font-weight-medium);
}

.error-icon {
  font-size: 3rem;
  margin-bottom: var(--space-sm);
}

.error-message {
  font-size: var(--font-size-body);
  color: var(--color-gray-700);
  margin-bottom: var(--space-md);
  font-weight: var(--font-weight-medium);
}

.error-fallback {
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
  font-style: italic;
}

/* ========================================
   SUBMIT BUTTON
   ======================================== */

.submit-button {
  position: fixed;
  bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
  left: var(--space-md);
  right: var(--space-md);
  width: auto;
  max-width: calc(600px - var(--space-md) * 2);  /* Match .game max-width minus padding */
  margin: 0 auto;
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-primary);
  color: var(--color-white);
  font-size: var(--font-size-button);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-wide);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-md);
  transition: all var(--duration-fast) var(--ease-out);
  cursor: pointer;
  z-index: 10;
}

.submit-button:not(:disabled):hover {
  background-color: var(--color-primary-hover);
}

.submit-button:not(:disabled):active {
  transform: scale(0.96);
}

.submit-button:disabled,
.submit-button--disabled {
  background-color: var(--color-gray-400);
  color: var(--color-gray-100);
  border: 1px solid var(--color-gray-300);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.5;
}

.submit-button:not(:disabled) {
  animation: pulse 2s var(--ease-in-out) infinite;
}

.submit-button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.submit-button--loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.submit-button--loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-left: -10px;
  margin-top: -10px;
  border: 3px solid var(--color-white);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 800ms linear infinite;
}

/* ========================================
   MODALS
   ======================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

/* Respect the hidden attribute - prevent CSS display override */
.modal[hidden] {
  display: none !important;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: var(--z-modal-backdrop);
}

.modal__content {
  position: relative;
  z-index: var(--z-modal);
  background-color: var(--color-white);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn var(--duration-medium) var(--ease-out);
}

.modal__header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal__title {
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.modal__close {
  width: var(--touch-target-min);  /* 48px - WCAG 2.1 AA compliant */
  height: var(--touch-target-min); /* 48px */
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-gray-500);
  font-size: 1.5rem;
  border: none; /* No border - consistent plain gray styling per ux-steve Issue #9 */
  background: transparent; /* No background */
  border-radius: var(--border-radius-sm);
  transition: all var(--duration-fast) var(--ease-out);
}

.modal__close:hover {
  background-color: var(--color-gray-100); /* Subtle hover */
  color: var(--color-gray-700);
}

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

.modal__body {
  padding: var(--space-md); /* Reduced from lg for tighter mobile fit per ux-steve Issue #2 */
  font-size: var(--font-size-body);
  color: var(--color-gray-700);
  line-height: var(--line-height-loose);
}

.modal__body ul {
  list-style: disc;
  padding-left: var(--space-lg);
  margin-top: var(--space-sm);
}

.modal__body li {
  margin-top: var(--space-xs);
}

/* Partial feedback styles */
.feedback-partial {
  text-align: left;
}

.feedback-success {
  color: var(--color-success);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-sm);
}

.feedback-guidance {
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-900);
  margin-bottom: var(--space-xs);
}

.feedback-partial ul {
  margin: var(--space-sm) 0;
  padding-left: var(--space-md);
  list-style: none;
}

.feedback-partial li {
  margin-bottom: var(--space-xs);
  color: var(--color-gray-700);
}

.feedback-partial li::before {
  content: '• ';
  color: var(--color-error);
  font-weight: bold;
  margin-right: var(--space-xs);
}

.feedback-hint {
  font-size: var(--font-size-caption);
  color: var(--color-gray-500);
  margin-top: var(--space-sm);
}

.feedback-attempts {
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-gray-200);
}

.modal__icon {
  font-size: 1.5rem;
  margin-right: var(--space-xs);
}

.modal__subtitle {
  font-size: 1.125rem;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
}

/* Welcome screen styles (for returning users) */
.welcome-container {
  text-align: center;
  padding: var(--space-md) 0;
}

.welcome-header h3 {
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  margin-bottom: var(--space-xs);
}

.welcome-date {
  font-size: var(--font-size-body);
  color: var(--color-gray-500);
  margin: 0;
}

.welcome-streak {
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  margin: var(--space-lg) 0;
  padding: var(--space-md);
  background: var(--color-gray-50);
  border-radius: var(--border-radius-md);
}

.welcome-divider {
  border: none;
  border-top: 1px solid var(--color-gray-200);
  margin: var(--space-lg) 0;
}

.how-to-play-disclosure {
  text-align: left;
  margin-top: var(--space-md);
}

.how-to-play-disclosure summary {
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
  cursor: pointer;
  padding: var(--space-sm);
  list-style: none; /* Remove default triangle */
}

.how-to-play-disclosure summary::before {
  content: '▸ ';
  display: inline-block;
  transition: transform 150ms ease-out;
}

.how-to-play-disclosure[open] summary::before {
  transform: rotate(90deg);
}

.how-to-play-disclosure summary:hover {
  text-decoration: underline;
}

.how-to-play-content {
  padding: var(--space-md) var(--space-sm);
}

/* Welcome Results screen (for returning users who completed today's puzzle) */
.welcome-container--results {
  padding-top: 0;
}

.welcome-title {
  font-size: var(--font-size-headline);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  margin: var(--space-md) 0;
}

.welcome-actions {
  margin: var(--space-lg) 0 var(--space-md);
}

.welcome-actions .button {
  min-width: 200px;
}

/* Static achievement ribbon (no animation, no border-bottom) */
.achievement-ribbon--static {
  border-bottom: none;
  margin-bottom: var(--space-sm);
  border-radius: var(--border-radius-md);
}

.achievement-ribbon--static .achievement-badge {
  opacity: 1;
  transform: scale(1);
  transition: none;
}

/* Compact solution display for welcome modal */
.solution-display--compact {
  padding: 0.375rem;
  margin: 0.375rem auto;
  max-width: 300px;
}

.solution-display--compact .solution-slot {
  padding: 0.375rem 0.5rem;
}

.solution-display--compact .solution-slot__word {
  font-size: 14px;
}

/* Solution Display (Failure Modal) - Condensed per ux-steve Issue #2 */
.solution-display {
  background: var(--color-gray-50);
  border-radius: 12px;
  padding: 0.5rem; /* Tightened for modal height */
  margin: 0.5rem 0; /* Tightened for modal height */
  border: 2px solid var(--color-gray-200);
}

.solution-chain {
  display: flex;
  flex-direction: column;
  gap: 0.25rem; /* Further reduced to save space */
  align-items: center;
}

.solution-slot {
  background: var(--color-white);
  border: 2px solid var(--color-success);
  border-radius: 8px;
  padding: 0.5rem 0.75rem; /* Reduced from 0.75rem 1rem */
  width: 100%;
  max-width: 280px;
  text-align: center;
}

.solution-slot__word {
  font-size: 16px; /* Reduced from 18px */
  font-weight: 600;
  color: var(--color-gray-900);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.solution-connector {
  font-size: 16px; /* Reduced from 20px */
  color: var(--color-gray-400);
  font-weight: 600;
  margin: 0;
  padding: 0;
}

/* Mobile optimization - tighter spacing for iPhone SE */
@media (max-width: 380px) {
  .solution-display {
    padding: 0.5rem;
    margin: 0.5rem 0;
  }

  .solution-chain {
    gap: 0.125rem; /* Very tight spacing on mobile */
  }

  .solution-slot {
    padding: 0.375rem 0.5rem;
    max-width: 240px;
  }

  .solution-slot__word {
    font-size: 14px; /* Further reduced for small screens */
  }

  .solution-connector {
    font-size: 14px;
  }
}

.chain-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin: var(--space-md) 0;
  padding: var(--space-md);
  background-color: var(--color-gray-50);
  border-radius: var(--border-radius-md);
}

.chain-preview__word {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: var(--border-radius-sm);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-subhead);
  color: var(--color-gray-900);
}

.chain-preview__connector {
  color: var(--color-primary);
  font-size: 1.5rem;
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* First-time user animated chain preview (pa-audry curiosity-gap)
   Timeline compressed to complete within 1.5s (Rec A4) */
.chain-preview--animated .chain-preview__word--reveal {
  display: grid;
  place-items: center;
  border-style: dashed;
  border-color: var(--color-gray-300);
  animation: revealBorder 0.01s ease-out 1.0s forwards;
}

.chain-preview__blank {
  grid-area: 1 / 1;
  color: var(--color-gray-400);
  font-weight: var(--font-weight-regular);
  animation: fadeOut 0.2s ease-out 0.9s forwards;
}

.chain-preview__answer {
  grid-area: 1 / 1;
  opacity: 0;
  animation: revealAnswer var(--duration-slow) var(--ease-bounce) 1.0s forwards;
}

.chain-preview__explanation {
  font-size: var(--font-size-caption);
  color: var(--color-gray-500);
  text-align: center;
  margin-top: var(--space-sm);
}

.chain-preview__explanation--animated {
  opacity: 0;
  animation: fadeIn var(--duration-slow) var(--ease-out) 0.8s forwards;
}

.modal__rules--animated {
  opacity: 0;
  animation: fadeIn var(--duration-slow) var(--ease-out) 1.1s forwards;
}

@keyframes fadeOut {
  to { opacity: 0; }
}

@keyframes revealBorder {
  to {
    border-style: solid;
    border-color: var(--color-primary);
  }
}

@keyframes revealAnswer {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ========================================
   RULES MODAL (hamburger "How to Play")
   ======================================== */

.rules-section {
  margin-bottom: var(--space-lg);
}

.rules-section:last-of-type {
  margin-bottom: 0;
}

.rules-section__title {
  font-size: var(--font-size-subhead);
  font-weight: var(--font-weight-bold);
  color: var(--color-gray-900);
  margin-bottom: var(--space-xs);
}

.rules-section__text {
  color: var(--color-gray-700);
  margin-bottom: var(--space-sm);
}

.rules-section__caption {
  font-size: var(--font-size-caption);
  color: var(--color-gray-600);
  text-align: center;
  font-style: italic;
}

/* Mini solved-puzzle visualization */
.rules-demo {
  margin: var(--space-md) 0;
  padding: var(--space-md);
  background-color: var(--color-gray-50);
  border-radius: var(--border-radius-md);
}

.rules-demo__chain {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.rules-demo__slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-sm);
  border: 2px solid transparent;
}

.rules-demo__slot--locked {
  background-color: var(--color-gray-100);
  border-color: var(--color-gray-300);
}

.rules-demo__slot--correct {
  background-color: var(--color-success-bg);
  border-color: var(--color-success);
}

.rules-demo__word {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-caption);
  color: var(--color-gray-900);
  letter-spacing: 0.05em;
}

.rules-demo__lock,
.rules-demo__check {
  font-size: 0.75rem;
}

.rules-demo__check {
  color: var(--color-success);
  font-weight: var(--font-weight-bold);
}

/* Mini word bank */
.rules-demo__bank {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-xs);
}

.rules-demo__bank-word {
  text-align: center;
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  padding: var(--space-xs);
  border-radius: var(--border-radius-sm);
  border: 1px solid transparent;
}

.rules-demo__bank-word--used {
  background-color: var(--color-success-bg);
  border-color: var(--color-success);
  color: var(--color-success);
}

.rules-demo__bank-word--decoy {
  background-color: var(--color-error-bg);
  border-color: var(--color-error-border);
  color: var(--color-error);
  text-decoration: line-through;
}

/* Quick rules list */
.rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.rules-list li {
  padding: var(--space-xs) 0;
  color: var(--color-gray-700);
  border-bottom: 1px solid var(--color-gray-100);
}

.rules-list li:last-child {
  border-bottom: none;
}

.rules-list li strong {
  color: var(--color-gray-900);
}

/* Staggered entrance animation */
.htp-fade-in {
  opacity: 0;
  transform: translateY(8px);
  animation: htpFadeIn 0.4s ease-out forwards;
}

@keyframes htpFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reduced motion: show all content immediately */
@media (prefers-reduced-motion: reduce) {
  .chain-preview--animated .chain-preview__word--reveal {
    border-style: solid;
    border-color: var(--color-primary);
    animation: none;
  }
  .chain-preview__blank { display: none; }
  .chain-preview__answer {
    opacity: 1;
    animation: none;
  }
  .chain-preview__explanation--animated,
  .modal__rules--animated {
    opacity: 1;
    animation: none;
  }
  .htp-fade-in {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

/* Success modal stats — immediate when splash handles the reveal choreography,
   delayed only on uncurated days where there's no splash to provide pacing */
.success-stats {
  opacity: 0;
  animation: fadeInStats 300ms ease-out forwards;
}

/* Uncurated days: keep a shorter delay for pacing (800ms matches share button delay) */
.modal--success:not(.modal--splash-done) .success-stats {
  animation-delay: 0.8s;
}

/* After splash transition completes, stats appear immediately (no stagger) */
.modal--splash-done .success-stats {
  animation-delay: 0s;
}

/* Failure modal stats - shorter delay to not prolong negative experience */
.failure-stats {
  opacity: 0;
  animation: fadeInStats 300ms ease-out 0.75s forwards;
}

@keyframes fadeInStats {
  to { opacity: 1; }
}

/* ========================================
   SUCCESS MODAL ENHANCEMENTS (UX Improvement Plan)
   ======================================== */

/* Title scale-in animation for success modal */
.modal--success .modal__title {
  animation: titleScaleIn 400ms var(--ease-bounce) forwards;
}

@keyframes titleScaleIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .modal--success .modal__title {
    animation: none;
  }

  .word--ready {
    animation: none;
    border-color: var(--color-primary);
    box-shadow: var(--glow-primary);
  }
}

/* Horizontal stats layout */
.success-stats__puzzle {
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-align: center;
}

.success-stats__row {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.success-stats__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.success-stats__icon {
  font-size: 1.25rem;
}

.success-stats__value {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-gray-900);
}

.success-stats__label {
  font-size: 0.75rem;
  color: var(--color-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.success-stats__streak {
  text-align: center;
  margin-top: 0.5rem;
  color: var(--color-gray-700);
}

/* Narrow viewport: wrap stats to 2+1 layout */
@media (max-width: 319px) {
  .success-stats__row {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .success-stats__item {
    min-width: 45%;
  }

  /* Center the third item when it wraps */
  .success-stats__item:last-child {
    flex-basis: 100%;
  }
}

.modal__footer-note {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-gray-200);
  text-align: center;
  color: var(--color-gray-500);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums; /* Stable width for countdown */
}

/* Phase 1: Restyled countdown per ux-steve theme-improvements spec */
.countdown-container {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);        /* Teal #0F766E */
  text-align: center;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-variant-numeric: tabular-nums; /* Stable width for countdown */
}

.modal__actions {
  padding: var(--space-lg);
  border-top: 1px solid var(--color-gray-200);
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  align-items: center;
}

/* ========================================
   GIFT-SHARE SECTION (pa-audry spec)
   ======================================== */

.gift-share-section {
  padding: var(--space-md) var(--space-lg) var(--space-lg);
  text-align: center;
}

.gift-share-section__separator {
  border: none;
  border-top: 1px solid var(--color-gray-200);
  margin: 0 0 var(--space-md) 0;
}

.gift-share-section__prompt {
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
  margin-bottom: var(--space-sm);
}

/* ========================================
   SPLASH REVEAL (Giftshare "Aha" Moment)
   ======================================== */

/* During splash phase: hide header, body, actions, ribbon — show only the splash text */
.modal--splash .modal__header,
.modal--splash .modal__body,
.modal--splash .modal__actions,
.modal--splash .achievement-ribbon {
  opacity: 0;
  pointer-events: none;
}

/* Teal title card — splash modal content gets a branded gradient background.
   Transitions back to white when Act 2 reveals the full modal content. */
.modal--splash .modal__content {
  min-height: 180px;
  overflow: hidden; /* No scrollbar during splash */
  background: linear-gradient(135deg, #094D47 0%, #062F2B 100%);
  transition: background 500ms cubic-bezier(0.4, 0, 0.2, 1);
  perspective: 800px; /* 3D context for card-tuck transition */
}

/* Film-grain texture overlay — adds cinematic depth to the teal gradient */
.modal--splash .modal__content::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 128px 128px;
  opacity: 0.07;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
  border-radius: inherit;
}

/* Restore white background during Act 2 transition */
.modal--splash-entering .modal__content {
  background: var(--color-white);
}

/* The splash text element — centered, white on teal, prominent */
.gift-share-section__prompt--splash {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 3rem);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 2.1rem;
  font-weight: 500;
  font-style: italic;
  color: var(--color-white);
  line-height: 1.4;
  text-align: center;
  margin: 0;
  z-index: 2; /* Above grain overlay */
  animation: splashEntrance 300ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Decorative curly quotes — frames the text as a message, not a slide title */
.gift-share-section__prompt--splash::before,
.gift-share-section__prompt--splash::after {
  position: absolute;
  font-size: 5rem;
  font-style: normal;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.12);
  line-height: 1;
  pointer-events: none;
}

.gift-share-section__prompt--splash::before {
  content: '\201C';
  top: -0.35em;
  left: -0.1em;
}

.gift-share-section__prompt--splash::after {
  content: '\201D';
  bottom: -0.65em;
  right: -0.1em;
}


@keyframes splashEntrance {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* During FLIP transition: the prompt animates from splash to final position.
   Card-tuck effect: partial Y-rotation + blur recede to flat resting state. */
.gift-share-section__prompt--flipping {
  transition: transform 500ms cubic-bezier(0.4, 0, 0.2, 1),
              font-size 500ms cubic-bezier(0.4, 0, 0.2, 1),
              color 500ms cubic-bezier(0.4, 0, 0.2, 1),
              filter 500ms cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  will-change: transform, filter;
}

/* Modal content entering (Act 2 fade+slide, synced with card-tuck duration) */
.modal--splash-entering .modal__header,
.modal--splash-entering .modal__body,
.modal--splash-entering .modal__actions,
.modal--splash-entering .achievement-ribbon {
  animation: modalContentEnter 500ms cubic-bezier(0.4, 0, 0.2, 1) both;
  pointer-events: auto;
}

@keyframes modalContentEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Achievement ribbon animated insertion (for async honors arrival) */
.achievement-ribbon--animated {
  max-height: 0;
  overflow: hidden;
  padding-top: 0;
  padding-bottom: 0;
  transition: max-height 400ms cubic-bezier(0.4, 0, 0.2, 1),
              padding 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.achievement-ribbon--animated.achievement-ribbon--expanded {
  max-height: 120px; /* Enough for 2 badges */
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

/* ── SPLASH HONORS EXPERIMENT ──────────────────────────────────────────
   Teaser mode: small honor confirmation on the splash card.
   Pulse mode: attention-drawing glow on the ribbon after Act 2 reveals.
   Controlled by Config.SPLASH_HONORS_MODE in config.js.
   ── */

/* Teaser: anchored to bottom of splash card, fades in after a beat */
.splash-honor-teaser {
  position: absolute;
  bottom: 1.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.45);
  z-index: 2;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 400ms ease, transform 400ms ease;
}

.splash-honor-teaser--visible {
  opacity: 1;
  transform: translateY(0);
}

/* Pulse: draws eye to ribbon after card-tuck completes.
   Two pulses with background flash so it's unmissable. */
.achievement-ribbon--pulse {
  animation: ribbonPulse 800ms cubic-bezier(0.4, 0, 0.2, 1) 2;
}

@keyframes ribbonPulse {
  0%   { background-color: var(--color-gray-50);
         box-shadow: 0 0 0 0 rgba(234, 179, 8, 0.5); }
  40%  { background-color: rgba(234, 179, 8, 0.12);
         box-shadow: 0 0 8px 4px rgba(234, 179, 8, 0.25); }
  100% { background-color: var(--color-gray-50);
         box-shadow: 0 0 0 0 rgba(234, 179, 8, 0); }
}

/* ── END SPLASH HONORS EXPERIMENT ───────────────────────────────────── */

/* Respect prefers-reduced-motion for splash */
@media (prefers-reduced-motion: reduce) {
  .modal--splash .modal__content {
    transition: none;
  }

  .gift-share-section__prompt--splash {
    animation: none;
    opacity: 1;
  }

  .gift-share-section__prompt--flipping {
    transition: none;
    filter: none !important;
  }

  .modal--splash-entering .modal__header,
  .modal--splash-entering .modal__body,
  .modal--splash-entering .modal__actions,
  .modal--splash-entering .achievement-ribbon {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .achievement-ribbon--animated {
    transition: none;
    max-height: none;
    overflow: visible;
  }

  .splash-honor-teaser {
    transition: none;
    opacity: 1;
    transform: none;
  }

  .achievement-ribbon--pulse {
    animation: none;
  }
}

/* ========================================
   ACHIEVEMENT RIBBON (Daily Honors)
   ======================================== */

.achievement-ribbon {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--color-gray-200);
}

.achievement-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s ease, transform 0.3s var(--ease-bounce);
}

.achievement-badge--visible {
  opacity: 1;
  transform: scale(1);
}

.achievement-badge__icon {
  font-size: 1.25rem;
}

.achievement-badge__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.achievement-badge__label {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-900);
  line-height: 1.2;
}

.achievement-badge__subtitle {
  font-size: 0.75rem;
  font-weight: var(--font-weight-normal);
  color: var(--color-gray-500);
  line-height: 1.2;
}

/* Respect prefers-reduced-motion for badge animations */
@media (prefers-reduced-motion: reduce) {
  .achievement-badge {
    opacity: 1;
    transform: scale(1);
    transition: none;
  }
}

/* ========================================
   STATS
   ======================================== */

/* Stats-modal-specific header: compact padding + subtle gradient (#1, #3) */
#stats-modal .modal__header {
  padding: var(--space-md);
  background: linear-gradient(to bottom, rgba(var(--color-primary-rgb), 0.03), transparent);
}

/* Chart labels for sub-sections within Today's Puzzle */
.stats-chart-label {
  font-size: 0.65rem;
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-gray-400);
  margin-bottom: 4px;
}

/* Section titles (#2: increased from 0.65rem) */
.stats-section__title {
  font-size: 0.7rem;
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-gray-500);
  margin-bottom: var(--space-xs);
}

/* Attempt distribution chart (#1: compacted) */
.stats-distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.stats-distribution__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 4px;
  border-left: 3px solid transparent;
}

/* User's row highlight (#5) */
.stats-distribution__row--you {
  background-color: rgba(var(--color-primary-rgb), 0.06);
  border-left-color: var(--color-primary);
}

.stats-distribution__label {
  width: 1rem;
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-600);
  text-align: right;
  flex-shrink: 0;
}

.stats-distribution__track {
  flex: 1;
  height: 1rem;
  background-color: var(--color-gray-100);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
}

.stats-distribution__bar {
  height: 100%;
  width: 0;
  background-color: var(--color-gray-300);
  border-radius: var(--border-radius-sm);
  transition: width 600ms ease-out;
  transition-delay: calc(var(--row-index, 0) * 100ms);
  min-width: 0;
}

.stats-distribution__row--you .stats-distribution__bar {
  background-color: var(--color-primary);
}

.stats-distribution__pct {
  width: 2.5rem;
  font-size: var(--font-size-caption);
  color: var(--color-gray-500);
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.stats-distribution__you {
  font-size: 0.6rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  background-color: rgba(var(--color-primary-rgb), 0.1);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Time to Solve spectrum bar */
.stats-time-spectrum {
  margin-bottom: var(--space-sm);
  padding: 0 4px;
}

.stats-time-spectrum[hidden] {
  display: none;
}

.stats-time-spectrum__track {
  position: relative;
  height: 6px;
  background-color: var(--color-gray-100);
  border-radius: 3px;
  margin: 10px 0 6px;
}

.stats-time-spectrum__fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  background-color: var(--color-primary);
  border-radius: 3px;
  transition: width 600ms ease-out;
}

.stats-time-spectrum__tick {
  position: absolute;
  top: 50%;
  width: 1px;
  height: 14px;
  background-color: var(--color-gray-300);
  transform: translate(-50%, -50%);
}

.stats-time-spectrum__marker {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background-color: var(--color-primary);
  border: 2px solid var(--color-white);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 200ms ease-out 600ms;
}

.stats-time-spectrum__marker--visible {
  opacity: 1;
}

.stats-time-spectrum__labels {
  position: relative;
  height: 2rem;
  font-size: var(--font-size-caption);
  color: var(--color-gray-400);
}

.stats-time-spectrum__label {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  line-height: 1;
}

.stats-time-spectrum__label--you {
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-800);
}

.stats-time-spectrum__label--sub {
  top: 1rem;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-time-spectrum__summary {
  text-align: center;
  font-size: var(--font-size-small);
  margin-top: 2px;
}

.stats-time-spectrum__percentile {
  color: var(--color-primary);
  font-weight: var(--font-weight-bold);
}

/* All-Time rows (#3: tabular nums for alignment) */
.stats-alltime__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--color-gray-100);
  font-size: var(--font-size-small);
}

.stats-alltime__row:last-child {
  border-bottom: none;
}

.stats-alltime__row span:last-child {
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-800);
  font-variant-numeric: tabular-nums;
}

/* Stats sections spacing (#1: compacted) */
.stats-section {
  margin-top: var(--space-md);
}

/* Loading spinner */
.stats-loading {
  display: flex;
  justify-content: center;
  padding: var(--space-sm);
}

.stats-loading[hidden] {
  display: none;
}

.stats-loading__spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: stats-spin 0.6s linear infinite;
}

@keyframes stats-spin {
  to { transform: rotate(360deg); }
}

/* Early data message */
.stats-early-data {
  text-align: center;
  font-size: var(--font-size-small);
  color: var(--color-gray-500);
  font-style: italic;
  padding: var(--space-xs) 0;
}

/* Stats honors */
.stats-honors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-xs);
}

/* Stats actions (#1, #7: compacted + sticky footer safety net) */
#stats-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  position: sticky;
  bottom: 0;
  background-color: var(--color-white);
  padding: var(--space-sm) 0;
  box-shadow: 0 -4px 8px -4px rgba(0, 0, 0, 0.06);
}

/* Override display:flex so hidden attribute works (specificity fix) */
#stats-actions[hidden] {
  display: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .stats-distribution__bar {
    transition: none;
  }
  .stats-time-spectrum__fill {
    transition: none;
  }
  .stats-time-spectrum__marker {
    transition: none;
  }
  .stats-loading__spinner {
    animation: none;
    border-top-color: var(--color-primary);
    opacity: 0.5;
  }
}

/* ========================================
   SETTINGS
   ======================================== */

.settings-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  background-color: var(--color-gray-50);
  border-radius: var(--border-radius-md);
}

.setting-item label {
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-900);
}

.toggle {
  width: 48px;
  height: 24px;
  appearance: none;
  background-color: var(--color-gray-300);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.toggle::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--color-white);
  top: 2px;
  left: 2px;
  transition: transform var(--duration-fast) var(--ease-out);
}

.toggle:checked {
  background-color: var(--color-primary);
}

.toggle:checked::before {
  transform: translateX(24px);
}

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

/* ========================================
   BUTTONS
   ======================================== */

.button {
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-button);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.button--primary {
  background-color: var(--color-primary);
  color: var(--color-white);
}

.button--primary:hover {
  background-color: var(--color-primary-hover);
}

.button--primary:active {
  transform: scale(0.96);
}

.button--secondary {
  background-color: transparent;
  color: var(--color-primary);
  border: var(--border-width) solid var(--color-primary);
}

.button--secondary:hover {
  background-color: var(--color-teal-50);
}

.button--secondary:active {
  transform: scale(0.96);
}

.button--tertiary {
  background: transparent;
  color: var(--color-gray-600);
  border: none;
  text-decoration: underline;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
}

.button--tertiary:hover {
  color: var(--color-gray-800);
}

.button--tertiary:active {
  transform: scale(0.98);
}

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

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

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

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}

@keyframes scaleIn {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes modalSlideIn {
  0% {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

@media (min-width: 768px) {
  .game {
    padding: var(--space-md);  /* 16px all sides on tablet+ */
    /* Reserve space at bottom for fixed submit button */
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    gap: var(--space-lg);  /* 24px on tablet+ */
  }

  .chain__slots {
    gap: var(--space-sm);  /* 12px on tablet+ */
  }

  /* Wider grid columns on tablet/desktop to match mobile's 2-row layout.
     At 80px min, all 6 words pack into one row with only ~82px per column,
     too narrow for long words like "WASHINGTON". At 150px min, the grid
     creates 3 columns (2 rows of 3) with ~176px per column. */
  .word-bank__container {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .submit-button {
    left: var(--space-lg);
    right: var(--space-lg);
    bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
  }
}

/* ========================================
   UTILITIES
   ======================================== */

.hidden {
  display: none !important;
}

/* Skip Tutorial Button */
.skip-tutorial[hidden] {
  display: none !important;
}

.skip-tutorial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  margin-top: var(--space-xs);
  padding: 0.5rem 1rem;
  min-height: 36px;
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
  background: transparent;
  border: 1px solid var(--color-primary);
  border-radius: var(--border-radius-sm);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.skip-tutorial:hover {
  background: var(--color-teal-50);
  color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.skip-tutorial:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.skip-tutorial:active {
  transform: scale(0.98);
}

/* ========================================
   TUTORIAL FLOW IMPROVEMENTS (ux-steve recs)
   ======================================== */

/* Hide X close button on tutorial success modal only */
.modal--tutorial-success .modal__close {
  display: none;
}

/* Skip to game link in landing modal for new users */
.skip-to-game-link {
  display: block;
  margin-top: var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
  text-decoration: underline;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out);
}

.skip-to-game-link:hover {
  color: var(--color-gray-700);
}

.skip-to-game-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}

/* Tutorial indicator banner */
.tutorial-indicator {
  background: #E3F2FD;
  color: #1565C0;
  text-align: center;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: none; /* Hidden by default */
}

/* Tutorial indicator disabled — Tutorial header is sufficient */

/* ========================================
   DRAG-AND-DROP (progressive enhancement)
   ======================================== */

/* Prevent browser scroll/zoom during drag on touch devices */
.word:not(.word--used):not(.word--eliminated) {
  touch-action: none;
}

.slot:not(.slot--prefilled):not(.slot--locked) {
  touch-action: none;
}

/* Grab cursor on desktop for draggable elements */
@media (pointer: fine) {
  .word:not(.word--used):not(.word--eliminated) {
    cursor: grab;
  }

  .slot--filled:not(.slot--prefilled):not(.slot--locked) {
    cursor: grab;
  }
}

/* Source element fades while being dragged */
.word--dragging {
  opacity: 0.4;
  transform: scale(0.95);
  user-select: none;
}

.slot--dragging {
  user-select: none;
}

.slot--dragging .slot__content {
  opacity: 0.3;
}

/* Floating ghost that follows the pointer */
.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  transform: translate(-50%, -50%);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: var(--border-radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: var(--font-size-word-bank);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-gray-900);
  white-space: nowrap;
}

/* Valid drop target highlight */
.slot--drop-target {
  border: var(--border-width) solid var(--color-primary);
  box-shadow: var(--glow-primary);
}

/* Reduced motion: disable scale/opacity transitions on drag */
@media (prefers-reduced-motion: reduce) {
  .word--dragging {
    transform: none;
  }

  .drag-ghost {
    transition: none;
  }
}
