/* === Помощник выбора темы (toggle "Помочь с выбором темы") ===
   Стили виджета, который подключается на все лендинги textworks.
   Парный JS — /static/textworks-topic-helper.js.
   Markup на странице — два блока:
     <div id="tw-topic-row" class="mt-3 flex items-center gap-3 select-none">
       <label id="tw-topic-switch" ...>
         <input type="checkbox" id="tw-topic-toggle" ...>
         <span id="tw-topic-thumb" ...></span>
       </label>
       <label for="tw-topic-toggle">Помочь с выбором темы</label>
     </div>
     <div id="tw-topic-mount" class="hidden"></div>
   ============================================================== */

.tw-topic-panel {
  margin-top: 12px;
  padding: 16px;
  background: #faf5ff;            /* мягкий purple-50 */
  border: 1px solid #e9d5ff;      /* purple-200 */
  border-radius: 12px;
}
.tw-topic-panel textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  /* 16px важно: меньше — и iOS Safari при фокусе автоматически
     зумит страницу, что выглядит как «прыжок» интерфейса. */
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background: #fff;
  touch-action: manipulation;
}
.tw-topic-panel textarea:focus {
  outline: none;
  border-color: #a855f7;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.12);
}
.tw-topic-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.tw-topic-submit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 4px 14px rgba(168, 85, 247, 0.25);
}
.tw-topic-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(168, 85, 247, 0.35); }
.tw-topic-submit:disabled { opacity: 0.65; cursor: not-allowed; transform: none; box-shadow: none; }
.tw-topic-secondary {
  font-size: 13px;
  color: #6d28d9;
  background: transparent;
  border: 1px solid #d8b4fe;
  padding: 8px 14px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.tw-topic-secondary:hover { background: #f3e8ff; }
.tw-topic-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.tw-topic-error {
  margin-top: 10px;
  padding: 9px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 13px;
  border-radius: 8px;
}
.tw-topic-hint {
  margin-top: 10px;
  padding: 9px 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  border-radius: 8px;
}

.tw-topic-list { margin-top: 14px; display: grid; gap: 10px; }
.tw-topic-card {
  background: #fff;
  border: 1px solid #ede9fe;
  border-radius: 12px;
  padding: 14px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  cursor: pointer;
  position: relative;
}
.tw-topic-card:hover {
  border-color: #a855f7;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.12);
  transform: translateY(-1px);
}
.tw-topic-card-title {
  font-size: 15px;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.4;
  margin-bottom: 6px;
  padding-right: 70px;            /* место под бейдж сложности */
}
.tw-topic-card-desc {
  font-size: 13px;
  color: #4b5563;
  line-height: 1.5;
  margin-bottom: 6px;
}
.tw-topic-card-fit {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  line-height: 1.4;
}
.tw-topic-card-take {
  margin-top: 10px;
  font-size: 13px;
  color: #7c3aed;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tw-topic-card-take::after {
  content: '→';
  transition: transform 0.15s ease;
}
.tw-topic-card:hover .tw-topic-card-take::after { transform: translateX(3px); }
.tw-topic-difficulty {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 9999px;
}
.tw-topic-difficulty-easy   { background: #dcfce7; color: #15803d; }
.tw-topic-difficulty-medium { background: #fef3c7; color: #b45309; }
.tw-topic-difficulty-hard   { background: #fee2e2; color: #b91c1c; }

.tw-topic-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 16px;
  min-height: 140px;
  color: #6b7280;
  font-size: 14px;
}
.tw-topic-loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #ede9fe;
  border-top-color: #a855f7;
  border-radius: 50%;
  animation: tw-topic-spin 0.8s linear infinite;
}
.tw-topic-loading-text {
  font-weight: 500;
  letter-spacing: 0.01em;
}
@keyframes tw-topic-spin {
  to { transform: rotate(360deg); }
}

/* Состояние «карточка в работе»: после клика «Взять эту тему»
   выбранная карточка превращается в индикатор «Создаём работу…».
   Hover-эффекты выключаются, содержимое заменяется на спиннер +
   подпись. Параллельно навешиваем .tw-topic-list--busy /
   .tw-topic-panel--busy, чтобы юзер не мог тыкнуть в другие
   карточки или кнопки помощника, пока POST в работе. */
.tw-topic-card.tw-topic-card--loading {
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 22px 16px;
  background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
  border-color: #c084fc;
}
.tw-topic-card.tw-topic-card--loading:hover {
  transform: none;
  box-shadow: none;
  border-color: #c084fc;
}
.tw-topic-card-loading-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #ede9fe;
  border-top-color: #a855f7;
  border-radius: 50%;
  animation: tw-topic-spin 0.8s linear infinite;
  flex-shrink: 0;
}
.tw-topic-card-loading-text {
  font-size: 15px;
  font-weight: 600;
  color: #6b21a8;
  letter-spacing: 0.01em;
}
.tw-topic-list--busy .tw-topic-card:not(.tw-topic-card--loading) {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.tw-topic-panel--busy .tw-topic-textarea,
.tw-topic-panel--busy .tw-topic-submit,
.tw-topic-panel--busy .tw-topic-secondary {
  pointer-events: none;
  opacity: 0.55;
}

@media (max-width: 640px) {
  .tw-topic-panel { padding: 14px; }
  .tw-topic-card-title { padding-right: 0; }
  .tw-topic-difficulty { position: static; display: inline-block; margin-bottom: 6px; }
  /* На узком экране кнопка-CTA во всю ширину — удобнее тапать. */
  .tw-topic-actions { justify-content: stretch; }
  .tw-topic-submit { width: 100%; justify-content: center; padding: 11px 18px; }
  /* «Ещё вариантов» — тоже шире и крупнее тап-таргет. */
  .tw-topic-secondary { padding: 10px 16px; }
}
