/* ============================================================
   Кроссворды — полностью обновлённые стили
   ============================================================ */

/* ---------- Фильтры ---------------------------------------- */
.crossword-filters {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 2rem;
  padding: 1.75rem 2rem;
  background: rgba(22, 33, 62, 0.7);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  border: 1px solid rgba(102, 126, 234, 0.2);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter-group label {
  font-size: 0.85rem;
  color: #94a3b8;
  font-weight: 600;
  white-space: nowrap;
  min-width: 60px;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-btn {
  padding: 0.4rem 1.1rem;
  background: rgba(102, 126, 234, 0.08);
  border: 1px solid rgba(102, 126, 234, 0.25);
  border-radius: 8px;
  color: #c7d2fe;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  background: rgba(102, 126, 234, 0.18);
  border-color: rgba(102, 126, 234, 0.5);
  transform: translateY(-1px);
}

.filter-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

/* ---------- Сетка карточек --------------------------------- */
.crosswords-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

/* ---------- Карточка кроссворда---------------------------- */
.crossword-card {
  background: rgba(22, 33, 62, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(102, 126, 234, 0.2);
  border-radius: 16px;
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  position: relative;
  overflow: hidden;
}

.crossword-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea, #764ba2, #f093fb);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.crossword-card:hover {
  transform: translateY(-6px);
  border-color: rgba(102, 126, 234, 0.45);
  box-shadow: 0 16px 40px rgba(102, 126, 234, 0.25);
}

.crossword-card:hover::before {
  opacity: 1;
}

.crossword-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.crossword-card h3 {
  font-size: 1.2rem;
  color: #e0e7ff;
  margin: 0;
  line-height: 1.3;
}

.crossword-badge {
  padding: 0.2rem 0.7rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-chemistry {
  background: rgba(79, 172, 254, 0.15);
  color: #4facfe;
  border: 1px solid rgba(79, 172, 254, 0.3);
}

.badge-biology {
  background: rgba(107, 196, 145, 0.15);
  color: #6bc491;
  border: 1px solid rgba(107, 196, 145, 0.3);
}

.crossword-card p {
  color: #94a3b8;
  font-size: 0.9rem;
  margin: 0 0 1rem;
  line-height: 1.5;
}

.crossword-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid rgba(102, 126, 234, 0.15);
}

.crossword-meta-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #94a3b8;
  font-size: 0.8rem;
}

.crossword-meta-item svg {
  width: 14px;
  height: 14px;
  color: #667eea;
  flex-shrink: 0;
}

.difficulty-easy {
  color: #6bc491;
}

.difficulty-medium {
  color: #f0a500;
}

.difficulty-hard {
  color: #ef4444;
}

/* ---------- Модальное окно --------------------------------- */
.crossword-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.92);
  backdrop-filter: blur(12px);
  z-index: 1000;
  overflow-y: auto;
  padding: 2rem 1rem;
  align-items: flex-start;
  justify-content: center;
}

.crossword-modal.active {
  display: flex;
}

.crossword-modal-content {
  background: rgba(18, 27, 56, 0.98);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 20px;
  padding: 2rem;
  max-width: 1200px;
  width: 100%;
  position: relative;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  margin: auto;
}

.crossword-modal-close {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: rgba(102, 126, 234, 0.1);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
  color: #e0e7ff;
  z-index: 1;
}

.crossword-modal-close:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  transform: rotate(90deg);
}

/* ---- Header ---- */
.crossword-header {
  margin-bottom: 1.5rem;
  padding-right: 3rem;
}

.crossword-header h2 {
  font-size: 1.75rem;
  color: #e0e7ff;
  margin: 0 0 0.35rem;
}

.crossword-header p {
  color: #94a3b8;
  margin: 0;
  font-size: 0.95rem;
}

/* ---- Layout ---- */
.crossword-container {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  align-items: start;
}

/* ---------- Сетка кроссворда ------------------------------- */
.crossword-grid-container {
  background: rgba(8, 12, 30, 0.6);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.crossword-grid {
  display: grid;
  gap: 0;
  /* Убираем gap — используем border-collapse */
  width: fit-content;
  border: 2px solid rgba(102, 126, 234, 0.3);
  border-radius: 6px;
  overflow: hidden;
}

/* ---------- Ячейка ----------------------------------------- */
.crossword-cell {
  position: relative;
  background: rgba(22, 33, 62, 0.9);
  border: 1px solid rgba(102, 126, 234, 0.15);
  box-sizing: border-box;
  transition: background 0.15s ease;
}

/* Скрытая (чёрная) ячейка */
.crossword-cell.black {
  background: rgba(5, 8, 20, 0.95);
  border-color: rgba(5, 8, 20, 0.3);
  pointer-events: none;
}

/* Подсветка текущего слова */
.crossword-cell.active-word {
  background: rgba(102, 126, 234, 0.18);
  border-color: rgba(102, 126, 234, 0.35);
}

/* Активная (выбранная) ячейка */
.crossword-cell.active-cell {
  background: rgba(102, 126, 234, 0.42) !important;
  border-color: #667eea !important;
  box-shadow: inset 0 0 0 2px #667eea;
  z-index: 2;
}

/* Правильный ответ */
.crossword-cell.correct {
  background: rgba(107, 196, 145, 0.22) !important;
  border-color: #6bc491 !important;
  box-shadow: inset 0 0 0 1.5px #6bc491;
}

/* Неправильный ответ */
.crossword-cell.incorrect {
  background: rgba(239, 68, 68, 0.2) !important;
  border-color: #ef4444 !important;
  box-shadow: inset 0 0 0 1.5px #ef4444;
  animation: shake 0.4s ease;
}

/* Hover для активных ячеек */
.crossword-cell:not(.black):hover {
  background: rgba(102, 126, 234, 0.12);
  cursor: pointer;
}

/* Input */
.crossword-cell input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #e0e7ff;
  font-family: 'Inter', 'Space Grotesk', sans-serif;
  font-size: clamp(0.85rem, 2vw, 1.15rem);
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  caret-color: transparent;
  padding: 0;
  /* Учитываем номер: сдвигаем текст чуть ниже */
  padding-top: 8px;
}

/* Номер вопроса в ячейке */
.crossword-cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.58rem;
  line-height: 1;
  color: #a5b4fc;
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
  user-select: none;
}

/* ---------- Подсказки -------------------------------------- */
.crossword-clues {
  background: rgba(8, 12, 30, 0.6);
  border-radius: 12px;
  padding: 1.25rem;
  overflow-y: auto;
  max-height: 560px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.clues-section h3 {
  font-size: 1rem;
  color: #a5b4fc;
  margin: 0 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid rgba(102, 126, 234, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.clue-item {
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.35rem;
  background: rgba(22, 33, 62, 0.5);
  border-radius: 8px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.clue-item:hover {
  background: rgba(102, 126, 234, 0.12);
  border-left-color: rgba(102, 126, 234, 0.5);
}

.clue-item.active {
  background: rgba(102, 126, 234, 0.2);
  border-left-color: #667eea;
}

.clue-number {
  color: #818cf8;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  min-width: 1.5rem;
}

.clue-text {
  color: #94a3b8;
  font-size: 0.875rem;
  line-height: 1.4;
}

.no-clues {
  color: #475569;
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- Кнопки действий -------------------------------- */
.crossword-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
  padding: 0.65rem 1.75rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  border: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(102, 126, 234, 0.55);
}

.btn-secondary {
  background: rgba(102, 126, 234, 0.1);
  color: #c7d2fe;
  border: 1px solid rgba(102, 126, 234, 0.3);
}

.btn-secondary:hover {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.5);
}

/* ---------- Toast уведомление ------------------------------ */
.cw-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(22, 33, 62, 0.97);
  color: #e0e7ff;
  padding: 1rem 2rem;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  border: 1px solid rgba(102, 126, 234, 0.4);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.cw-toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.cw-toast-success {
  border-color: rgba(107, 196, 145, 0.5);
}

.cw-toast-info {
  border-color: rgba(102, 126, 234, 0.5);
}

/* ---------- Анимации --------------------------------------- */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-4px);
  }

  40% {
    transform: translateX(4px);
  }

  60% {
    transform: translateX(-3px);
  }

  80% {
    transform: translateX(3px);
  }
}

/* ---------- Адаптивность ----------------------------------- */
@media (max-width: 900px) {
  .crossword-container {
    grid-template-columns: 1fr;
  }

  .crossword-clues {
    max-height: 340px;
  }
}

@media (max-width: 600px) {
  .crossword-modal {
    padding: 0.75rem;
  }

  .crossword-modal-content {
    padding: 1.25rem;
    border-radius: 14px;
  }

  .crossword-header h2 {
    font-size: 1.35rem;
  }

  .crossword-grid-container {
    padding: 0.75rem;
  }

  .crossword-cell-number {
    font-size: 0.5rem;
    top: 1px;
    left: 2px;
  }

  .crossword-actions {
    justify-content: center;
  }

  .btn-primary,
  .btn-secondary {
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
  }

  .filter-group {
    flex-direction: column;
    align-items: flex-start;
  }

  .cw-toast {
    font-size: 0.9rem;
    padding: 0.8rem 1.4rem;
    white-space: normal;
    max-width: 90vw;
    text-align: center;
  }
}