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

body {
  background-color: #0C0D14;
  color: #fff;
  font-family: 'Courier New', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  -webkit-user-select: none;
  user-select: none;
}

.game-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Header */
.game-header {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.game-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #00ff88;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Stats */
.stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.65rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#themeLabel {
  color: #ffcc00;
  font-size: 0.9rem;
}

/* Buttons */
.new-game-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 8px;
  background: #00ff88;
  color: #0C0D14;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

.new-game-btn:hover {
  background: #33ffaa;
  box-shadow: 0 0 16px rgba(0, 255, 136, 0.4);
}

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

/* Game Body */
.game-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Grid Wrapper */
.grid-wrapper {
  position: relative;
  width: 100%;
  max-width: 420px;
}

/* Letter Grid */
.letter-grid {
  display: grid;
  gap: 2px;
  width: 100%;
  position: relative;
  z-index: 2;
}

.letter-grid[data-size="10"] {
  grid-template-columns: repeat(10, 1fr);
}

.letter-grid[data-size="12"] {
  grid-template-columns: repeat(12, 1fr);
}

/* Canvas overlay for selection lines */
#lineCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

/* Letter Cell */
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ccc;
  background: #1A1B26;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  position: relative;
  z-index: 2;
}

.cell:hover {
  background: #2A2B36;
  color: #fff;
}

.cell.selecting {
  background: rgba(0, 255, 136, 0.2);
  color: #00ff88;
  transform: scale(1.05);
}

.cell.found {
  background: rgba(0, 255, 136, 0.15);
  color: #00ff88;
}

.cell.found-flash {
  animation: cellFlash 0.5s ease;
}

@keyframes cellFlash {
  0% { background: #00ff88; color: #0C0D14; transform: scale(1.15); }
  100% { background: rgba(0, 255, 136, 0.15); color: #00ff88; transform: scale(1); }
}

/* Word List */
.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  width: 100%;
  padding: 12px 8px;
  background: #12131C;
  border-radius: 10px;
  border: 1px solid #1e1f2e;
}

.word-item {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888;
  padding: 4px 10px;
  border-radius: 4px;
  background: #1A1B26;
  transition: all 0.3s ease;
  position: relative;
}

.word-item.found {
  color: #00ff88;
  background: rgba(0, 255, 136, 0.1);
  text-decoration: line-through;
  text-decoration-color: #00ff88;
  text-decoration-thickness: 2px;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 13, 20, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-modal {
  background: #1A1B26;
  border: 2px solid #00ff88;
  border-radius: 16px;
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 255, 136, 0.2);
  transform: scale(0.9);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 90vw;
}

.overlay.visible .overlay-modal {
  transform: scale(1);
}

.overlay-modal h2 {
  font-size: 1.8rem;
  color: #00ff88;
  margin-bottom: 12px;
  letter-spacing: 0.05em;
}

.overlay-modal p {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 20px;
}

.win-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 20px;
}

.win-stats p {
  font-size: 0.95rem;
  color: #aaa;
  margin-bottom: 0;
}

.win-stats span {
  color: #ffcc00;
  font-weight: 700;
}

/* Found lines (persistent SVG-like lines drawn on canvas) */

/* Responsive */
@media (max-width: 420px) {
  body {
    padding: 8px;
  }

  .game-container {
    gap: 12px;
  }

  .game-header h1 {
    font-size: 1.4rem;
  }

  .cell {
    font-size: 0.85rem;
    border-radius: 3px;
  }

  .stats {
    gap: 14px;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .overlay-modal {
    padding: 24px 28px;
  }

  .word-item {
    font-size: 0.75rem;
    padding: 3px 7px;
  }
}

@media (max-width: 340px) {
  .cell {
    font-size: 0.7rem;
  }

  .letter-grid {
    gap: 1px;
  }
}
