body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: #95B7D2;
  color: #1e293b;
  min-height: 100vh;
  padding: 0;
  box-sizing: border-box;
  /* Extend white background through iOS safe area */
  background: linear-gradient(to bottom, white 0, white env(safe-area-inset-top), #95B7D2 env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

#game-container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: #ffffff;
  padding: 1rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content {
  width: 100%;
  max-width: 700px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
}

.date {
  font-size: 1rem;
  color: #64748b;
  font-weight: 400;
}

.help-btn {
  background: none;
  border: none;
  font-size: 0.9rem;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.2s ease;
}

.help-icon {
  background: #64748b;
  color: white;
  border-radius: 50%;
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Main Game Area */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  gap: 1rem;
}

.progress-container {
  width: 100%;
  max-width: 700px;
  margin-bottom: 1rem;
}

#progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  overflow: hidden;
}

#progress-bar-fill {
  height: 100%;
  background: #ef4444;
  width: 20%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.level-progress-container {
  width: 100%;
  max-width: 700px;
  margin-top: -0.8rem;
  margin-bottom: 1rem;
}

#level-progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  overflow: hidden;
}

#level-progress-bar-fill {
  height: 100%;
  background: #3b82f6;
  width: 0%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.game-content {
  display: grid;
  grid-template-columns: 140px auto 140px;
  gap: 3rem;
  width: 100%;
  max-width: 1000px;
  align-items: start;
  justify-content: center;
}

/* Found Words Section - Now to the left of the board */
.found-words-section {
  display: flex;
  flex-direction: column;
  height: 22rem; /* Same height as board (5×4rem + 4×0.5rem gaps) */
}

.found-words-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #DFE9F2;
  margin: 0 0 0.75rem 0;
  letter-spacing: 0.1em;
  text-align: center;
  flex-shrink: 0;
}

#found-words-list {
  list-style: none;
  padding: 0 1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#found-words-list::-webkit-scrollbar {
  width: 4px;
}

#found-words-list::-webkit-scrollbar-track {
  background: transparent;
}

#found-words-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

#found-words-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

#found-words-list li {
  background: #4B86B6;
  color: white;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.word-points {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Remove old found words panel styles */
.found-words-panel {
  display: none;
}

/* Board Section */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#board {
  display: grid;
  grid-template-columns: repeat(5, 4rem);
  grid-template-rows: repeat(5, 4rem);
  gap: 0.5rem;
  position: relative;
}

.tile {
  background: #F9ECB0;
  color: black;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  touch-action: none;
  position: relative;
  border-radius: 0px;
  border: none;
  /* Improve touch target size */
  min-height: 44px;
  min-width: 44px;
  /* Flip animation setup */
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

/* Initial state - tiles start flipped (showing back) */
.tile.pre-flip {
  transform: rotateY(180deg);
  background: rgba(249, 236, 176, 0.4);
  color: transparent;
}

.tile.pre-flip .points {
  opacity: 0;
}

/* Flip animation */
@keyframes flipCard {
  0% {
    transform: rotateY(180deg);
    background: rgba(249, 236, 176, 0.4);
  }
  50% {
    transform: rotateY(90deg);
    background: rgba(249, 236, 176, 0.4);
  }
  100% {
    transform: rotateY(0deg);
  }
}

  .tile.flipping {
    animation: flipCard 0.6s ease-out forwards;
  }

/* Score popup animation */
.score-popup {
  position: absolute;
  font-size: 2rem;
  font-weight: bold;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 1000;
  animation: scorePopup 1s ease-out forwards;
}

@keyframes scorePopup {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-20px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1);
  }
}

/* Letter color coding based on point values */
.tile.letter-1pt {
  background: #F8EEC2;  /* 1 point */
  color: black;
}

.tile.letter-2pt {
  background: #FFD181;  /* 2 points */
  color: black;
}

.tile.letter-3pt {
  background: #FFB159;  /* 3 points */
  color: black;
}

.tile.letter-4pt {
  background: #FF8D5C;  /* 4 points */
  color: black;
}

.tile.letter-5pt {
  background: #FF8B8D;  /* 5 points */
  color: black;
}

.tile.letter-8pt {
  background: #FFAAE8;  /* 8 points */
  color: black;
}

.tile.letter-10pt {
  background: #B8EBFF;  /* 10 points */
  color: black;
}

.tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tile .points {
  position: absolute;
  bottom: 0.25rem;
  right: 0.25rem;
  font-size: 0.625rem;
  font-weight: 600;
  color: black;
  opacity: 0.7;
}

/* Darker versions for used-once tiles */
.tile.letter-1pt.used-once {
  background: #E6D99A;  /* Darker 1 point */
  color: black;
}

.tile.letter-2pt.used-once {
  background: #E6B85F;  /* Darker 2 points */
  color: black;
}

.tile.letter-3pt.used-once {
  background: #E69543;  /* Darker 3 points */
  color: black;
}

.tile.letter-4pt.used-once {
  background: #E6714A;  /* Darker 4 points */
  color: black;
}

.tile.letter-5pt.used-once {
  background: #E66F71;  /* Darker 5 points */
  color: black;
}

.tile.letter-8pt.used-once {
  background: #E68ED6;  /* Darker 8 points */
  color: black;
}

.tile.letter-10pt.used-once {
  background: #9CD6E6;  /* Darker 10 points */
  color: black;
}

/* Fallback for any tiles without specific point classes */
.tile.used-once {
  background: #D8CA8B;
  color: black;
}

.tile.used-twice {
  background: #e5e7eb;
  color: #4b5563;
  border-color: #9ca3af;
}

/* Custom highlight colors for selected tiles - overrides all other background colors */
.tile.letter-1pt.selected {
  background: #FFFAE0 !important;  /* 1 point selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-2pt.selected {
  background: #FFE7BE !important;  /* 2 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-3pt.selected {
  background: #FFD19C !important;  /* 3 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-4pt.selected {
  background: #FFBC9F !important;  /* 4 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-5pt.selected {
  background: #FFBBBC !important;  /* 5 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-8pt.selected {
  background: #FFD3F3 !important;  /* 8 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.letter-10pt.selected {
  background: #DFF6FF !important;  /* 10 points selected */
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

/* Custom highlight colors for path tiles - same colors as selected */
.tile.letter-1pt.path {
  background: #FFFAE0 !important;  /* 1 point path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-2pt.path {
  background: #FFE7BE !important;  /* 2 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-3pt.path {
  background: #FFD19C !important;  /* 3 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-4pt.path {
  background: #FFBC9F !important;  /* 4 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-5pt.path {
  background: #FFBBBC !important;  /* 5 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-8pt.path {
  background: #FFD3F3 !important;  /* 8 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.letter-10pt.path {
  background: #DFF6FF !important;  /* 10 points path */
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

/* Fallback for tiles without specific point classes */
.tile.selected {
  background: #FFF8D9;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(30, 41, 59, 0.3);
  z-index: 2;
}

.tile.path {
  background: #FFF8D9;
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(71, 85, 105, 0.3);
  z-index: 1;
}

.tile.dummy-tile {
  background: rgba(249, 236, 176, 0.3);
  color: transparent;
  cursor: default;
  opacity: 0.6;
}

.tile.dummy-tile:hover {
  transform: none;
  box-shadow: none;
}


#game-message {
  font-size: 1rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  min-height: 1.5rem;
  text-align: center;
}

/* Stats Panel */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.score-display {
  text-align: left;
}

.score-display::before {
  content: "SCORE";
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.25rem;
  letter-spacing: 0.05em;
}

.score-display .score-number {
  font-size: 3rem;
  font-weight: 600;
  color: white;
  line-height: 1;
  min-width: 5ch;
  text-align: left;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-item {
  text-align: left;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.25rem;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: white;
  min-width: 4ch;
  text-align: left;
}


/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #ffffff;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

.modal-content h2 {
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
}

#final-stats {
  margin-bottom: 0;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
}

.completion-message {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 2rem;
  margin-bottom: 2rem;
  color: white;
}



.completion-message h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.2;
  color: white;
}

.completion-message p {
  font-size: 1rem;
  opacity: 0.9;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.tomorrow-date {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
}

.play-again-btn {
  background: #1e40af;
  color: white;
  border: none;
  border-radius: 0;
  padding: 16px 32px;
  font-weight: 600 !important;
  font-family: 'Inter', sans-serif !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 24px;
  margin-bottom: 0;
  transition: all 0.3s ease;
  width: 100%;
  box-shadow: none;
  text-transform: uppercase !important;
  line-height: 1 !important;
  letter-spacing: 0.05em !important;
  height: 52px;
}

.play-again-btn:hover {
  background: #1d4ed8;
  transform: none;
  box-shadow: none;
}

.play-again-btn:active {
  transform: translateY(1px);
}

.share-btn {
  background: #60a5fa;
  color: white;
  border: none;
  border-radius: 0;
  padding: 16px 32px;
  font-weight: 600 !important;
  font-family: 'Inter', sans-serif !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 12px;
  transition: all 0.3s ease;
  width: 100%;
  box-shadow: none;
  text-transform: uppercase !important;
  line-height: 1 !important;
  letter-spacing: 0.05em !important;
  height: 52px;
}

.share-btn:hover {
  background: #3b82f6;
  transform: none;
  box-shadow: none;
}

.share-btn:active {
  transform: translateY(1px);
}

.welcome-modal-content {
  background: white;
  padding: 48px 32px;
  max-width: 500px;
  width: 90%;
  margin: 20px auto;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.welcome-header {
  margin-bottom: 32px;
}

.welcome-header h1 {
  font-size: 36px;
  font-weight: 700;
  color: #000000;
  margin: 0 0 16px 0;
  line-height: 1.2;
}

.welcome-header p {
  font-size: 18px;
  color: #000000;
  margin: 0 0 24px 0;
  font-weight: 600;
  line-height: 1.5;
}

.welcome-rules {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
  max-width: 380px;
  margin: 0 auto;
}

.welcome-rules li {
  font-size: 16px;
  margin: 0 0 12px 0;
  font-weight: 400;
  line-height: 1.5;
  color: #000000;
  position: relative;
  padding-left: 16px;
  text-align: left !important;
}

.welcome-rules li:before {
  content: "•";
  font-weight: bold;
  position: absolute;
  left: 0;
}

.start-game-btn {
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 0;
  padding: 20px 0;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 32px 10px 0 10px;
  transition: all 0.3s ease;
  box-shadow: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  height: 64px;
  width: calc(100% - 20px);
}

.start-game-btn:hover {
  background: #2563eb;
  transform: none;
  box-shadow: none;
}

.start-game-btn:active {
  transform: translateY(1px);
}

.modal-content {
  background: white;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  margin: 20px auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.game-over-header {
  text-align: center;
  margin-bottom: 24px;
}

.game-over-header h1 {
  font-size: 32px;
  font-weight: 700;
  color: #000000;
  margin: 0 0 8px 0;
  line-height: 1.2;
}

.game-over-header p {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
  font-weight: 400;
}

.game-over-score {
  text-align: center;
  margin-bottom: 32px;
}

.game-over-score .score-label {
  font-size: 14px;
  font-weight: 600;
  color: #6b7280;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.game-over-score .score-number {
  font-size: 64px;
  font-weight: 700;
  color: #CF5959;
  line-height: 1;
  margin: 0;
}

.game-over-stats {
  margin-bottom: 24px;
}

.stat-row {
  display: flex;
  margin-bottom: 24px;
}

.stat-row:last-child {
  margin-bottom: 0;
}

.stat-col {
  flex: 1;
  text-align: center;
  padding: 0 8px;
}

.game-over-stats .stat-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 45px;
}

.game-over-stats .stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.game-over-stats .stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #000000;
  line-height: 1.2;
  text-align: center;
  width: 100%;
}

/* Help Modal Styles */
.help-modal-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #e2e8f0;
}

.modal-header h2 {
  margin: 0;
  color: #1e293b;
  font-size: 1.75rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: #64748b;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.help-content {
  text-align: left;
}

.help-section {
  margin-bottom: 1.5rem;
}

.help-section h3 {
  color: #334155;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
}

.help-section p {
  color: #64748b;
  line-height: 1.5;
  margin: 0 0 0.5rem 0;
}

.help-section ul {
  margin: 0;
  padding-left: 1.5rem;
  color: #64748b;
}

.help-section li {
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.final-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  text-align: center;
}

.final-stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.final-stat-label {
  font-size: 0.75rem;
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.final-stat-value {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
}

.final-score {
  grid-column: span 2;
  padding: 1rem;
  background: #1e293b;
  color: white;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.final-score-label {
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.final-score-value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

#play-again-btn {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#play-again-btn:hover {
  background: #2563eb;
}

@media (max-width: 768px) {
  .game-main {
    padding: 1rem;
    gap: 0.5rem;
    display: grid;
    grid-template-areas: 
      "stats"
      "progress" 
      "level-progress"
      "board"
      "words";
    grid-template-rows: auto auto auto auto 1fr;
    margin: 0 auto;
  }
  
  .game-content {
    display: contents; /* Break out of container */
  }
  
  .progress-container {
    grid-area: progress;
    max-width: 100%;
    padding-top: 1rem;
  }
  
  .level-progress-container {
    grid-area: level-progress;
    max-width: 100%;
  }
  
  .stats-panel {
    grid-area: stats;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .board-section {
    grid-area: board;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  #game-message {
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .found-words-section {
    grid-area: words;
    height: 120px;
    max-width: 345px;
    width: 100%;
    margin-top: -1rem;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
  }
  
  .score-display {
    display: none; /* Hide the separate large score on mobile */
  }
  
  .stats-list {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
    grid-template-areas: 
      "score time level"
      "words bestword longest";
  }
  
  /* Mobile score stat - will be added via JavaScript */
  .mobile-score-stat {
    grid-area: score !important;
    text-align: left !important;
    display: block !important;
  }
  
  .stat-item:nth-child(2) { /* TIME (after mobile score is inserted first) */
    grid-area: time !important;
    text-align: center !important;
  }
  
  .stat-item:nth-child(2) .stat-label {
    text-align: center !important;
  }
  
  .stat-item:nth-child(2) .stat-value {
    text-align: center !important;
  }
  
  .stat-item:nth-child(3) { /* LEVEL */
    grid-area: level !important;
    text-align: right !important;
  }
  
  .stat-item:nth-child(3) .stat-label {
    text-align: right !important;
  }
  
  .stat-item:nth-child(3) .stat-value {
    text-align: right !important;
  }
  
  .stat-item:nth-child(4) { /* WORDS */
    grid-area: words !important;
    text-align: left !important;
  }
  
  .stat-item:nth-child(4) .stat-label {
    text-align: left !important;
  }
  
  .stat-item:nth-child(4) .stat-value {
    text-align: left !important;
  }
  
  .stat-item:nth-child(5) { /* BEST WORD */
    grid-area: bestword !important;
    text-align: center !important;
  }
  
  .stat-item:nth-child(5) .stat-label {
    text-align: center !important;
  }
  
  .stat-item:nth-child(5) .stat-value {
    text-align: center !important;
  }
  
  .stat-item:nth-child(6) { /* LONGEST WORD */
    grid-area: longest !important;
    text-align: right !important;
  }
  
  .stat-item:nth-child(6) .stat-label {
    text-align: right !important;
  }
  
  .stat-item:nth-child(6) .stat-value {
    text-align: right !important;
  }
  
  /* Hide avg score and avg length on mobile */
  .stat-item:nth-child(7),
  .stat-item:nth-child(8) {
    display: none !important;
  }
  
  .stat-item {
    text-align: center;
  }
  
  .stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #DFE9F2;
    margin-bottom: 0.25rem;
    letter-spacing: 0.1em;
  }
  
  #board {
    grid-template-columns: repeat(5, min(15vw, 5rem));
    grid-template-rows: repeat(5, min(15vw, 5rem));
    gap: 0.75rem;
    width: calc(100vw - 2rem);
    max-width: 26rem;
    margin: 0 auto;
  }
  
  .tile {
    font-size: clamp(1.8rem, 5vw, 2.2rem);
  }
  
  .found-words-section h3 {
    text-align: left;
    margin: 0 0 0.5rem 0;
    flex-shrink: 0;
  }
  
  #found-words-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    gap: 0.375rem;
    flex: 1;
    min-height: 0;
    align-content: flex-start;
    width: 100%;
    box-sizing: border-box;
  }
  
  #found-words-list li {
    flex-shrink: 1;
    min-width: 0;
    max-width: calc(50% - 0.1875rem); /* Account for gap */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
  }
}

@media (max-width: 480px) {
  header {
    padding: 1rem;
  }
  
  .header-left {
    flex-direction: column;
    gap: 0.25rem;
    align-items: flex-start;
  }
  
  h1 {
    font-size: 1.25rem;
  }
  
  .date {
    font-size: 0.875rem;
  }
  
  .game-main {
    padding: 0.75rem;
  }
  
  #board {
    grid-template-columns: repeat(5, min(17vw, 3.5rem));
    grid-template-rows: repeat(5, min(17vw, 3.5rem));
    gap: 0.5rem;
    width: calc(100vw - 1.5rem);
    max-width: 19rem;
    margin: 0 auto;
  }
  
  .tile {
    font-size: clamp(1.3rem, 4.5vw, 1.8rem);
  }
  
  .score-number {
    font-size: 2.5rem;
  }
  
  /* Modal Mobile Styles */
  .modal-content {
    padding: 1.5rem;
    max-width: 95%;
  }
  
  .completion-message {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
  }
  

  
  .completion-message h2 {
    font-size: 1.25rem;
  }
  
  .completion-message p {
    font-size: 0.9rem;
    margin-bottom: 1rem;
  }
  
  .tomorrow-date {
    padding: 0.5rem;
    font-size: 0.8rem;
  }
  
  .share-btn {
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
    margin-top: 0.75rem;
  }
  
  .play-again-btn {
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
    margin-top: 0.5rem;
  }

  /* Game Over Modal Mobile Styles */
  .modal-content {
    padding: 20px;
    margin: 16px auto;
    max-width: 380px;
  }

  .game-over-header h1 {
    font-size: 28px;
  }

  .game-over-score .score-number {
    font-size: 48px;
  }

  .game-over-stats .stat-value {
    font-size: 16px;
  }

  .game-over-stats .stat-label {
    font-size: 10px;
  }

  .stat-col {
    padding: 0 4px;
  }

  .play-again-btn, .share-btn {
    padding: 14px 24px;
    font-size: 14px;
  }

  .welcome-modal-content {
    padding: 32px 24px;
    margin: 16px auto;
    max-width: 380px;
  }

  .welcome-header h1 {
    font-size: 28px;
  }

  .welcome-header p {
    font-size: 16px;
  }

  .start-game-btn {
    padding: 14px 28px;
    font-size: 14px;
    min-width: 180px;
    height: 52px;
  }
  
  /* Modal Mobile Styles */
  .modal-content {
    margin: 1rem;
    width: calc(100% - 2rem);
    max-width: none;
  }
  
  /* Help Modal Mobile Styles */
  .help-modal-content {
    max-width: 95%;
    max-height: 85vh;
    padding: 1.5rem;
  }
  
  .modal-header h2 {
    font-size: 1.5rem;
  }
  
  .close-btn {
    font-size: 1.5rem;
    width: 1.5rem;
    height: 1.5rem;
  }
  
  .help-section h3 {
    font-size: 1rem;
  }
  
  .help-section p,
  .help-section li {
    font-size: 0.9rem;
  }

}

/* === Leaderboard Styles === */

.leaderboard-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background-color 0.2s;
  margin-right: 0.5rem;
}

.leaderboard-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.leaderboard-icon {
  font-size: 1.2rem;
  display: block;
}

.leaderboard-modal-content {
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.leaderboard-header h1 {
  margin: 0;
  color: #333;
  font-size: 1.8rem;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  padding: 0.25rem;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background-color: #f0f0f0;
}

.leaderboard-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 500;
  color: #666;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
}

.tab-btn:hover {
  color: #3b82f6;
  background-color: #f8fafc;
}

.leaderboard-content {
  min-height: 200px;
  position: relative;
}

.loading-spinner {
  text-align: center;
  padding: 2rem;
  color: #666;
  font-style: italic;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid #e0e0e0;
  transition: background-color 0.2s;
}

.leaderboard-item:hover {
  background-color: #f8fafc;
}

.leaderboard-item:last-child {
  border-bottom: none;
}

.leaderboard-rank {
  font-weight: bold;
  color: #666;
  width: 2rem;
  text-align: center;
  margin-right: 1rem;
}

.leaderboard-rank.rank-1 {
  color: #ffd700;
}

.leaderboard-rank.rank-2 {
  color: #c0c0c0;
}

.leaderboard-rank.rank-3 {
  color: #cd7f32;
}

.leaderboard-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-right: 1rem;
}

.leaderboard-name {
  font-weight: 600;
  color: #333;
  margin-bottom: 0.25rem;
}

.leaderboard-details {
  font-size: 0.85rem;
  color: #666;
}

.leaderboard-score {
  font-weight: bold;
  color: #3b82f6;
  font-size: 1.1rem;
}

.leaderboard-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: #666;
}

.leaderboard-empty p {
  margin: 0;
  font-style: italic;
}

.leaderboard-footer {
  margin-top: 1.5rem;
  text-align: center;
  border-top: 1px solid #e0e0e0;
  padding-top: 1rem;
}

.leaderboard-note {
  margin: 0;
  font-size: 0.85rem;
  color: #666;
  font-style: italic;
}

/* Player Name Modal */
.player-name-modal-content {
  max-width: 400px;
  width: 90%;
}

.player-name-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.player-name-header h1 {
  margin: 0 0 0.5rem 0;
  color: #333;
  font-size: 1.6rem;
}

.player-name-header p {
  margin: 0;
  color: #666;
}

.player-name-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#player-name-input {
  padding: 0.75rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  text-align: center;
  font-family: inherit;
}

#player-name-input:focus {
  outline: none;
  border-color: #3b82f6;
}

.player-name-buttons {
  display: flex;
  gap: 0.5rem;
}

.save-score-btn, .skip-save-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.save-score-btn {
  background-color: #3b82f6;
  color: white;
}

.save-score-btn:hover {
  background-color: #2563eb;
}

.save-score-btn:disabled {
  background-color: #94a3b8;
  cursor: not-allowed;
}

.skip-save-btn {
  background-color: #f1f5f9;
  color: #64748b;
}

.skip-save-btn:hover {
  background-color: #e2e8f0;
}
