/* Reset and Base Styles */
.tct-wordsearch-container *,
.tct-wordsearch-container *::before,
.tct-wordsearch-container *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

.tct-wordsearch-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  padding-bottom: 30vh;
  line-height: 1.5;
  color: #2d3748;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tct-wordsearch-header {
  text-align: center;
  margin-bottom: 2rem;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.tct-wordsearch-title {
  margin-bottom: 1rem;
  color: #2d3748;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.tct-wordsearch-description {
  color: #4a5568;
  font-size: 1.125rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.tct-wordsearch-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.tct-wordsearch-game-area {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  width: 100%;
}

.tct-wordsearch-sidebar {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.tct-wordsearch-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.tct-wordsearch-game-wrapper {
  position: relative;
  display: inline-block;
}

.tct-wordsearch-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--width), 1fr);
  gap: 2px;
  background-color: #f5f5f5;
  padding: 10px;
  border-radius: 4px;
  transition: opacity 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;
  margin: 0;
  list-style: none;
}

.tct-wordsearch-grid.blurred {
  filter: blur(4px);
  opacity: 0.4;
}

.tct-wordsearch-grid.started {
  opacity: 1;
}

.tct-wordsearch-row {
  display: flex;
}

.tct-wordsearch-cell {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  color: #2d3748;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  transition: all 0.3s ease;
  text-transform: uppercase;
  line-height: 1;
  padding: 0;
  margin: 0;
  position: relative;
  z-index: 1;
}

.tct-wordsearch-cell:hover {
  background-color: #f7fafc;
  transform: scale(1.05);
  z-index: 1;
}

.tct-wordsearch-cell.selected {
  background-color: #ebf8ff;
  color: #3182ce;
  border-color: #3182ce;
}

.tct-wordsearch-cell.found {
  background-color: #c6f6d5;
  color: #2f855a;
  border-color: #2f855a;
}

.tct-wordsearch-cell.hint {
  background-color: #4299e1;
  color: white;
  border-color: #2b6cb0;
  transform: scale(1.05);
  z-index: 1;
  transition: all 0.2s ease;
}

.tct-wordsearch-cell.highlighted {
  background-color: #fed7aa;
  color: #9a3412;
  border-color: #9a3412;
  transform: scale(1.05);
  z-index: 1;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tct-wordsearch-cell.highlighted.found {
  background-color: #fed7aa;
  color: #9a3412;
  border-color: #9a3412;
}

.tct-wordsearch-cell.highlighted.hint {
  background-color: #fed7aa;
  color: #9a3412;
  border-color: #9a3412;
}

.tct-wordsearch-words {
  max-width: 800px;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  margin: 0;
  border: 1px solid #e2e8f0;
}

.tct-wordsearch-words-title {
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 10px;
  text-align: center;
}

.tct-wordsearch-words h3 {
  text-align: center;
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: #2d3748;
  font-size: 1.25rem;
  font-weight: 600;
}

.tct-wordsearch-words-left {
  text-align: center;
  margin-bottom: 1rem;
  color: #4a5568;
  font-size: 1.1rem;
  font-weight: 500;
}

.tct-wordsearch-words ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.tct-wordsearch-word {
  padding: 0.5rem 1rem;
  color: #4a5568;
  transition: all 0.2s ease;
  font-size: 1rem;
  font-weight: 500;
  background: white;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  list-style: none;
  list-style-type: none;
  text-transform: none;
  line-height: 1.2;
  margin: 0;
  border: 1px solid #e2e8f0;
}

.tct-wordsearch-word.found {
  color: #2f855a;
  text-decoration: line-through;
  opacity: 0.7;
  cursor: pointer;
}

.tct-wordsearch-word.found:hover {
  opacity: 1;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tct-wordsearch-hint,
.tct-wordsearch-reset {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  background-color: #4299e1;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  text-decoration: none;
  display: inline-block;
  line-height: 1.2;
  margin: 0;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.tct-wordsearch-hint:hover,
.tct-wordsearch-reset:hover {
  background-color: #3182ce;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tct-wordsearch-hint:active,
.tct-wordsearch-reset:active {
  transform: translateY(0);
}

.tct-wordsearch-hint:disabled {
  background-color: #a0aec0;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.tct-wordsearch-timer {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  margin-bottom: 0.5rem;
  display: block;
  min-width: 200px;
}

.tct-wordsearch-timer-text {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 0.5rem;
}

.tct-wordsearch-hints-text {
  font-size: 1rem;
  color: #4a5568;
}

.tct-wordsearch-hints-text:not(:empty) {
  color: #e53e3e;
}

.tct-wordsearch-start-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2;
}

.tct-wordsearch-start-button {
  background-color: #4CAF50;
  color: white;
  border: none;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tct-wordsearch-start-button:hover {
  background-color: #45a049;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.tct-wordsearch-start-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tct-wordsearch-completion {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tct-wordsearch-completion.show {
  opacity: 1;
  visibility: visible;
}

.tct-wordsearch-completion-content {
  background: white;
  padding: 2.5rem;
  border-radius: 16px;
  text-align: center;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transform: translateY(0);
  transition: transform 0.3s ease;
  position: relative;
  z-index: 1001;
  margin: 0;
  border: 1px solid #e2e8f0;
}

.tct-wordsearch-completion.show .tct-wordsearch-completion-content {
  transform: translateY(0);
}

.tct-wordsearch-completion h3 {
  margin: 0 0 1.5rem;
  color: #2d3748;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.tct-wordsearch-completion p {
  margin: 0 0 1.5rem;
  color: #4a5568;
  font-size: 1.125rem;
  line-height: 1.6;
}

.tct-wordsearch-completion-stats {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 12px;
}

.tct-wordsearch-completion-stat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.tct-wordsearch-completion-stat-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4299e1;
}

.tct-wordsearch-completion-stat-label {
  font-size: 1rem;
  color: #4a5568;
  font-weight: 500;
}

.tct-wordsearch-completion-stat-value {
  font-size: 1.25rem;
  color: #2d3748;
  font-weight: 600;
}

.tct-wordsearch-completion-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  justify-content: center;
}

.tct-wordsearch-completion-close,
.tct-wordsearch-completion-new-game {
  padding: 0.75rem 1.5rem;
  border-radius: 0.375rem;
  font-weight: 500;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tct-wordsearch-completion-close {
  background-color: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

.tct-wordsearch-completion-close:hover {
  background-color: #e5e7eb;
}

.tct-wordsearch-completion-new-game {
  background-color: #f97316;
  color: white;
  border: 1px solid #ea580c;
}

.tct-wordsearch-completion-new-game:hover {
  background-color: #ea580c;
}

/* Accessibility */
.tct-wordsearch-cell:focus {
  outline: 2px solid #4299e1;
  outline-offset: -2px;
}

.tct-wordsearch-controls button:focus {
  outline: 2px solid #4299e1;
  outline-offset: 2px;
}

/* Responsive */
@media (min-width: 769px) {
  .tct-wordsearch-game-area {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
  }

  .tct-wordsearch-grid {
    flex: 0 0 auto;
  }

  .tct-wordsearch-sidebar {
    flex: 0 0 300px;
  }

  .tct-wordsearch-words {
    margin-top: 0;
  }
}

@media (max-width: 768px) {
  .tct-wordsearch-container {
    padding: 1rem;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .tct-wordsearch-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
  }

  .tct-wordsearch-grid {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    padding: 5px;
  }

  .tct-wordsearch-cell {
    width: calc((100% - 18px) / 10);
    height: calc((100% - 18px) / 10);
    min-width: 25px;
    min-height: 25px;
    font-size: 14px;
    padding: 2px;
  }

  .tct-wordsearch-words {
    margin: 20px auto 0;
    max-width: 300px;
    padding: 1rem;
  }

  .tct-wordsearch-word {
    padding: 5px 10px;
    font-size: 14px;
    margin: 2px;
  }

  .tct-wordsearch-hint {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1000;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: 4px;
  }

  .tct-wordsearch-controls {
    flex-direction: column;
    gap: 0.5rem;
  }

  .tct-wordsearch-controls button {
    font-size: 1rem;
    padding: 0.6rem 1.25rem;
  }

  .tct-wordsearch-completion-content {
    padding: 2rem;
    margin: 1rem;
  }

  .tct-wordsearch-completion h3 {
    font-size: 1.75rem;
  }

  .tct-wordsearch-completion p {
    font-size: 1rem;
  }

  .tct-wordsearch-completion-stats {
    padding: 1.25rem;
  }

  .tct-wordsearch-completion-stat-icon {
    width: 20px;
    height: 20px;
  }

  .tct-wordsearch-completion-stat-label {
    font-size: 0.9rem;
  }

  .tct-wordsearch-completion-stat-value {
    font-size: 1.1rem;
  }

  .tct-wordsearch-completion-close {
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
  }

  .tct-wordsearch-debug {
    font-size: 10px;
    padding: 8px;
  }
  
  .tct-wordsearch-debug-item {
    padding: 4px;
  }
  
  .tct-wordsearch-debug-label,
  .tct-wordsearch-debug-value {
    font-size: 10px;
  }
}

/* Ensure canvas is above the completion message */
canvas {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1002;
}

.tct-wordsearch-debug {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 10px;
  font-family: monospace;
  font-size: 12px;
  z-index: 9999;
  max-height: 30vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  pointer-events: auto;
  touch-action: none;
}

.tct-wordsearch-debug-content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 5px;
  padding: 5px;
}

.tct-wordsearch-debug-item {
  display: flex;
  flex-direction: column;
  padding: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  word-break: break-word;
}

.tct-wordsearch-debug-label {
  font-weight: bold;
  color: #4CAF50;
  margin-bottom: 2px;
  font-size: 11px;
}

.tct-wordsearch-debug-value {
  color: #fff;
  word-break: break-all;
  font-size: 11px;
}

/* Print Styles */
@media print {
  .tct-wordsearch-container {
    padding: 0;
    max-width: none;
  }

  .tct-wordsearch-grid {
    box-shadow: none;
    border: 1px solid #000;
  }

  .tct-wordsearch-cell {
    border: 1px solid #000;
    color: #000;
  }

  .tct-wordsearch-words {
    box-shadow: none;
    border: 1px solid #000;
  }

  .tct-wordsearch-word {
    border: 1px solid #000;
  }

  .tct-wordsearch-hint,
  .tct-wordsearch-reset {
    display: none;
  }
}
