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

:root {
  --cell-size: 48px;

  /* Light theme color palette */
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f7;

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #98989d;

  --accent-primary: #0071e3;
  --accent-hover: #0077ed;
  --accent-light: #e8f4fd;

  --cell-bg: #ffffff;
  --cell-border: #e5e5e7;
  --cell-selected-bg: #1d1d1f;
  --cell-hover-bg: #f5f5f7;

  --success: #34c759;
  --success-light: #d4f5dd;
  --error: #ff3b30;
  --error-light: #ffe5e3;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  min-height: 100vh;
  padding: 12px;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

.game-container {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--cell-border);
}

h1 {
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.word-info {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
}

.game-info {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.attempts {
  color: var(--error);
  font-weight: 600;
}

.score {
  color: var(--success);
  font-weight: 600;
}

.timer {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1.125rem;
  background: var(--bg-tertiary);
  padding: 8px 20px;
  border-radius: var(--radius-full);
  min-width: 80px;
  text-align: center;
  border: 1px solid var(--cell-border);
}

.grid-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-size));
  gap: 4px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  width: fit-content;
  margin: 0 auto;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  min-width: var(--cell-size);
  min-height: var(--cell-size);
  border: 1px solid var(--cell-border);
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.cell:hover {
  background: var(--cell-hover-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.cell:active {
  transform: translateY(0);
}

.cell.word-cell {
  background: var(--cell-bg);
}

.cell.target-word {
  /* Reserved for future use */
}

.cell.selected {
  background: var(--cell-selected-bg);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(29, 29, 31, 0.3);
  border-color: var(--cell-selected-bg);
}

.cell.selected:hover {
  background: var(--cell-selected-bg);
}

.cell.revealed {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
  animation: reveal 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell.revealed.target-word {
  background: #4ade80;
  border-color: #4ade80;
}

.cell.correct-swap {
  background: var(--success-light);
  color: var(--success);
  border-color: var(--success);
  animation: correctSwap 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell.incorrect-swap {
  background: var(--error-light);
  color: var(--error);
  border-color: var(--error);
  animation: incorrectSwap 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes reveal {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes correctSwap {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes incorrectSwap {
  0% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.05) rotate(-3deg);
  }
  50% {
    transform: scale(1.05) rotate(3deg);
  }
  75% {
    transform: scale(1.05) rotate(-3deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}

.swap-btn,
.reset-btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 140px;
  letter-spacing: 0.3px;
}

.swap-btn {
  background: var(--cell-selected-bg);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(29, 29, 31, 0.2);
}

.swap-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(29, 29, 31, 0.25);
}

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

.swap-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  border: 1px solid var(--cell-border);
}

.reset-btn {
  background: var(--error);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(255, 59, 48, 0.2);
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.25);
}

.help-btn {
  padding: 0;
  border: 1px solid var(--cell-border);
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.message {
  text-align: center;
  min-height: 28px;
  font-weight: 600;
  font-size: 1rem;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.message.success {
  color: var(--success);
  background: var(--success-light);
}

.message.error {
  color: var(--error);
  background: var(--error-light);
}

/* Mobile responsive */
@media (max-width: 600px) {
  :root {
    --cell-size: 38px;
  }

  body {
    padding: 8px;
  }

  .game-container {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  .cell {
    width: var(--cell-size);
    height: var(--cell-size);
    min-width: var(--cell-size);
    min-height: var(--cell-size);
    font-size: 0.875rem;
    border-radius: 6px;
  }

  .grid {
    grid-template-columns: repeat(8, var(--cell-size));
    gap: 3px;
    padding: 10px;
  }

  h1 {
    font-size: 1.25rem;
  }

  .word-info {
    font-size: 0.8125rem;
    margin-bottom: 16px;
  }

  .timer {
    font-size: 1rem;
    padding: 6px 16px;
  }

  .swap-btn,
  .reset-btn {
    padding: 12px 24px;
    font-size: 0.875rem;
    min-width: 120px;
  }

  .help-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9375rem;
  }

  .controls {
    gap: 10px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  :root {
    --cell-size: 34px;
  }

  .grid {
    gap: 2px;
    padding: 8px;
  }

  .cell {
    font-size: 0.8125rem;
  }
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease;
}

.modal-content {
  background-color: var(--bg-secondary);
  margin: 10% auto;
  padding: 0;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--cell-border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--cell-border);
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 600;
}

.close {
  color: var(--text-muted);
  font-size: 24px;
  font-weight: 400;
  cursor: pointer;
  transition: color 0.2s ease;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.close:hover {
  color: var(--text-primary);
  background: var(--bg-primary);
}

.modal-body {
  padding: 24px;
}

.modal-body h3 {
  color: var(--text-primary);
  margin: 20px 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
  font-size: 0.9375rem;
}

.modal-body ul {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 20px;
  padding-left: 20px;
  font-size: 0.9375rem;
}

.modal-body li {
  margin-bottom: 10px;
}

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

@keyframes slideIn {
  from {
    transform: translateY(-30px) scale(0.97);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Timer countdown state */
.timer.countdown {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  animation: timerPulse 1s ease-in-out infinite;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  min-width: auto;
}

.countdown-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

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