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

:root {
  --cell-size: min(40px, calc((100vw - 4rem) / 12));
  --grid-padding: min(1rem, 2vw);
}

body {
  font-family: "Arial", sans-serif;
  line-height: 1.6;
  background-color: #f0f2f5;
  min-height: 100vh;
  padding: 1rem;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  flex-shrink: 0;
}

h1 {
  color: #2c3e50;
  margin-bottom: 1rem;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.theme-selector {
  margin-bottom: 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
}

select,
button {
  padding: 0.5rem 1rem;
  font-size: clamp(0.875rem, 2vw, 1rem);
  border: 2px solid #3498db;
  border-radius: 4px;
  min-width: 120px;
}

button {
  background-color: #3498db;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #2980b9;
}

.game-container {
  display: flex;
  flex-direction: row;
  gap: 2rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
}

.word-search-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 10), var(--cell-size));
  gap: 2px;
  background-color: white;
  padding: var(--grid-padding);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin: 0;
  flex-shrink: 0;
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.875rem, calc(var(--cell-size) * 0.4), 1.2rem);
  font-weight: bold;
  border: 1px solid #ddd;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.grid-cell.found-word {
  background-color: #27ae60;
  color: white;
}

.grid-cell.selected {
  background-color: #3498db;
  color: white;
}

.word-list {
  background-color: white;
  padding: 1rem;
  border-radius: 8px;
  width: 300px;
  max-width: 100%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  align-self: stretch;
}

.word-list h2 {
  color: #2c3e50;
  margin-bottom: 1rem;
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  text-align: center;
}

.word-list ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  justify-items: center;
  padding: 0 0.5rem;
}

.word-list li {
  padding: 0.5rem;
  border: 1px solid #eee;
  border-radius: 4px;
  text-align: center;
  font-size: clamp(0.875rem, 2vw, 1rem);
  width: 100%;
  background-color: #f8f9fa;
}

.word-list li.found {
  color: #27ae60;
  text-decoration: line-through;
  background-color: #e8f5e9;
  border-color: #27ae60;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.show {
  display: flex;
}

.modal-content {
  background-color: white;
  padding: clamp(1rem, 4vw, 2rem);
  border-radius: 12px;
  text-align: center;
  animation: modalPop 0.3s ease-out;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: min(90vw, 400px);
}

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

.modal h2 {
  color: #2c3e50;
  margin-bottom: 1rem;
  font-size: clamp(1.5rem, 4vw, 1.8rem);
}

.modal p {
  color: #34495e;
  margin-bottom: 1.5rem;
  font-size: clamp(1rem, 3vw, 1.2rem);
}

.modal button {
  background-color: #27ae60;
  border-color: #27ae60;
  font-size: clamp(1rem, 2.5vw, 1.1rem);
  padding: 0.7rem 1.5rem;
}

.modal button:hover {
  background-color: #219a52;
}

/* Media Queries */
@media (max-width: 768px) {
  .game-container {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
  }

  .word-list {
    width: 100%;
    align-self: center;
  }

  .word-search-grid {
    margin: 0 auto;
  }

  :root {
    --cell-size: min(40px, calc((100vw - 3rem) / 12));
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .game-container {
    gap: 1.5rem;
  }

  .word-list {
    width: 250px;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0.5rem;
  }

  .container {
    padding: 0.5rem;
  }

  .theme-selector {
    flex-direction: column;
  }

  select,
  button {
    width: 100%;
    max-width: 300px;
  }

  :root {
    --cell-size: min(35px, calc((100vw - 2rem) / 12));
  }

  .word-list {
    padding: 0.75rem;
  }

  .word-list ul {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .word-list li {
    font-size: 0.9rem;
    padding: 0.4rem;
  }
}

@media (max-width: 390px) {
  body {
    padding: 0.25rem;
  }

  .container {
    padding: 0.25rem;
  }

  :root {
    --cell-size: min(30px, calc((100vw - 1rem) / 12));
    --grid-padding: 0.5rem;
  }

  .game-container {
    gap: 0.75rem;
  }

  .word-list {
    padding: 0.75rem 0.5rem;
  }

  .word-list ul {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    padding: 0 0.25rem;
  }

  .word-list li {
    font-size: 0.85rem;
    padding: 0.35rem;
    border-radius: 3px;
  }

  .word-list h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }

  .grid-cell {
    font-size: clamp(0.75rem, calc(var(--cell-size) * 0.5), 1rem);
  }

  h1 {
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    margin-bottom: 0.75rem;
  }

  .theme-selector {
    margin-bottom: 1rem;
  }

  select,
  button {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  .grid-cell {
    min-width: 28px;
    min-height: 28px;
  }
}
