/* CourseOS · Compose Tool (Phase 7)
   Guided response builder with AI comprehension questions,
   multiple-choice answers, TTS playback, and final assembly.
   Categories: School, Work, Life, Family. Saves to localStorage. */

/* Overlay container — full screen like reading view */
.compose-overlay {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  bottom: 0;
  background: var(--bg-secondary);
  z-index: 1100;
  display: none;
  flex-direction: column;
}

.compose-overlay.open {
  display: flex;
}

/* Top bar */
.compose-top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px var(--space-md);
  background: var(--bg-primary);
  border-bottom: var(--border-width) solid var(--border-color);
  flex-shrink: 0;
}

.compose-back-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gray-100);
  border: none;
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-top-title {
  flex: 1;
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text-primary);
}

.compose-step-badge {
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--color-red);
  background: #FEF0F0;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

/* Scrollable body */
.compose-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-md);
}

/* ── Category bar ── */
.compose-category-bar {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.compose-cat-tab {
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.compose-cat-tab.active {
  background: var(--bg-primary);
  border-width: 2px;
}

/* ── Title input ── */
.compose-title-input {
  width: 100%;
  padding: 10px 12px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 600;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-secondary);
  outline: none;
}

.compose-title-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.compose-title-input:focus {
  border-color: var(--color-red);
}

/* ── Phase 1: Paste text ── */
.compose-paste-section {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--border-color);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.compose-paste-label {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.compose-paste-hint {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
}

.compose-textarea {
  width: 100%;
  max-width: 100%;
  min-height: 140px;
  padding: 12px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-secondary);
  resize: vertical;
  line-height: 1.6;
  outline: none;
  margin-top: var(--space-sm);
}

.compose-textarea:focus {
  border-color: var(--color-red);
}

.compose-analyze-btn {
  width: 100%;
  padding: 14px;
  background: var(--color-red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
  margin-top: var(--space-sm);
}

.compose-analyze-btn:active {
  opacity: 0.8;
}

.compose-analyze-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Saved compositions ── */
.compose-saved-section {
  margin-top: var(--space-md);
}

.compose-saved-filters {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-sm);
  overflow-x: auto;
}

.compose-saved-filter {
  padding: 6px 12px;
  background: var(--bg-primary);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.compose-saved-filter.active {
  background: var(--color-red);
  color: #fff;
  border-color: var(--color-red);
}

.compose-saved-card {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--border-color);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

.compose-saved-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: 6px;
}

.compose-saved-cat-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.compose-saved-card-info {
  flex: 1;
  min-width: 0;
}

.compose-saved-card-title {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compose-saved-card-date {
  font-size: 10px;
  color: var(--text-muted);
}

.compose-saved-card-preview {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: var(--space-sm);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.compose-saved-card-actions {
  display: flex;
  gap: var(--space-sm);
}

.compose-saved-open {
  flex: 1;
  padding: 8px;
  background: var(--color-red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-weight: 700;
  cursor: pointer;
}

.compose-saved-open:active {
  opacity: 0.8;
}

.compose-saved-delete {
  padding: 8px 12px;
  background: var(--gray-100);
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-weight: 600;
  cursor: pointer;
}

.compose-saved-delete:active {
  background: var(--gray-200);
}

/* ── Loading state ── */
.compose-loading {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
}

.compose-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--color-red);
  border-radius: 50%;
  animation: compose-spin 0.8s linear infinite;
  margin: 0 auto var(--space-sm);
}

@keyframes compose-spin {
  to { transform: rotate(360deg); }
}

.compose-loading-text {
  font-size: var(--font-sm);
  color: var(--text-muted);
  font-style: italic;
}

/* ── Phase 2: Summary ── */
.compose-summary-section {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--border-color);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.compose-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.compose-section-title {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--text-primary);
}

.compose-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--color-teal-light);
  color: var(--color-teal-text);
  border: none;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.compose-play-btn:active {
  background: var(--color-safe);
}

.compose-summary-text {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ── Phase 3: Questions ── */
.compose-question-card {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--border-color);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

.compose-question-card.answered {
  border-color: var(--color-safe);
}

.compose-q-number {
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--color-red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.compose-q-text {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: var(--space-sm);
}

.compose-q-play {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--color-teal-light);
  color: var(--color-teal-text);
  border: none;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: var(--space-sm);
}

/* Answer choices */
.compose-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-sm);
}

.compose-choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.compose-choice:active {
  transform: scale(0.98);
}

.compose-choice.selected {
  background: #FEF8F0;
  border-color: var(--color-red);
}

.compose-choice-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.compose-choice.selected .compose-choice-radio {
  border-color: var(--color-red);
  background: var(--color-red);
}

.compose-choice.selected .compose-choice-radio::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.compose-choice-text {
  font-size: var(--font-sm);
  color: var(--text-primary);
  line-height: 1.4;
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}

.compose-choice-play {
  padding: 2px 8px;
  background: transparent;
  border: var(--border-width) solid var(--gray-200);
  border-radius: var(--radius-full);
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.compose-choice-play:active {
  background: var(--gray-100);
}

/* Custom input field below choices */
.compose-custom-input {
  width: 100%;
  padding: 8px 12px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary);
  outline: none;
  margin-top: 4px;
}

.compose-custom-input::placeholder {
  color: var(--text-muted);
}

.compose-custom-input:focus {
  border-color: var(--color-red);
}

/* ── Phase 4: Build Response ── */
.compose-build-btn {
  width: 100%;
  padding: 14px;
  background: var(--color-red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
  margin: var(--space-md) 0;
}

.compose-build-btn:active {
  opacity: 0.8;
}

.compose-build-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Phase 5: Final response ── */
.compose-response-title {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.compose-response-section {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-safe);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.compose-response-text {
  font-size: var(--font-sm);
  color: var(--text-primary);
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
  margin-bottom: var(--space-md);
}

.compose-response-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.compose-copy-btn {
  flex: 1;
  padding: 12px;
  background: var(--color-safe);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
}

.compose-copy-btn:active {
  opacity: 0.8;
}

.compose-response-play-btn {
  padding: 12px 16px;
  background: var(--color-teal-light);
  color: var(--color-teal-text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
}

.compose-save-btn {
  padding: 12px 16px;
  background: var(--color-purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
}

.compose-save-btn:active {
  opacity: 0.8;
}

.compose-save-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Character counter */
.compose-char-count {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  margin-top: var(--space-xs);
}

.compose-char-count.in-range {
  color: var(--color-safe);
}

.compose-char-count.out-range {
  color: var(--color-danger-text);
}

/* ── Tag system ── */
.compose-tags-section {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--border-color);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
}

.compose-tags-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: 6px;
}

.compose-tags-label {
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.compose-tags-hint {
  font-size: 10px;
  color: var(--text-muted);
}

.compose-tags-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.compose-tag-chip {
  padding: 5px 12px;
  background: var(--gray-100);
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.compose-tag-chip.active {
  background: var(--color-purple);
  color: #fff;
  border-color: var(--color-purple);
}

.compose-tag-chip:active {
  transform: scale(0.95);
}

.compose-tag-add {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gray-100);
  border: 2px dashed var(--gray-300);
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-tag-add:active {
  background: var(--gray-200);
}

.compose-tag-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.compose-tag-input-field {
  flex: 1;
  padding: 6px 10px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-secondary);
  outline: none;
}

.compose-tag-input-field:focus {
  border-color: var(--color-purple);
}

.compose-tag-input-add {
  padding: 6px 14px;
  background: var(--color-purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-weight: 700;
  cursor: pointer;
}

/* Tag pills — used on response and saved cards */
.compose-tag-pill {
  display: inline-block;
  padding: 3px 10px;
  background: #F3EEFF;
  color: var(--color-purple);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
  margin-bottom: 4px;
}

.compose-tag-pill.small {
  font-size: 10px;
  padding: 2px 8px;
}

.compose-response-tags {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: var(--space-sm);
}

.compose-saved-card-tags {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

/* Tag filters row */
.compose-saved-tag-filters {
  margin-top: 4px;
}
