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

:root {
  --accent:        #6c63ff;
  --accent-dk:     #5a52d5;
  --bg:            #f5f5f7;
  --surface:       #ffffff;
  --text:          #1a1a2e;
  --text-secondary: #4b5563;
  --muted:         #6b7280;
  --border:        #e5e7eb;
  --radius:        14px;
  --shadow:        0 4px 24px rgba(0,0,0,.08);
  --transition:    .3s cubic-bezier(.4,.0,.2,1);
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ──────────────── Dark Mode ──────────────── */
.intelliprompt-app.dark-mode {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 24px rgba(0,0,0,.3);
}

/* ──────────────── App Layout ──────────────── */
.intelliprompt-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

.app-header {
  background: var(--surface);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
}

.header-content h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
  margin-bottom: 8px;
}

.header-content .tagline {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 24px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}

.theme-toggle:hover {
  background: var(--border);
  border-color: var(--accent);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
}

.app-footer {
  background: var(--surface);
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ──────────────── Stage Containers ──────────────── */
.stage-container {
  animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stage-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: clamp(24px, 5vw, 40px);
  box-shadow: var(--shadow);
}

.stage-content > h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.stage-description {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 28px;
  line-height: 1.6;
}

/* ──────────────── Form Styles ──────────────── */
.prompt-form {
  display: flex;
  flex-direction: column;
}

.prompt-input {
  width: 100%;
  min-height: 140px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.prompt-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,.1);
}

.prompt-input::placeholder {
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* ──────────────── Buttons ──────────────── */
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  white-space: nowrap;
  user-select: none;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
  flex: 1;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dk);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(108,99,255,.3);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(108,99,255,.08);
}

/* ──────────────── Progress Indicator ──────────────── */
.progress-indicator {
  margin-bottom: 32px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dk));
  border-radius: 99px;
  transition: width 0.4s ease;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--muted);
  text-align: right;
}

/* ──────────────── Question Card ──────────────── */
.question-card {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.question-text {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 28px;
  line-height: 1.5;
  color: var(--text);
}

/* ──────────────── Options List ──────────────── */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.option-radio {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  transition: all var(--transition);
}

.option-radio:hover {
  border-color: var(--accent);
  background: rgba(108,99,255,.05);
}

.option-input {
  margin: 0;
  margin-right: 12px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--accent);
}

.option-label {
  flex: 1;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.option-radio input:checked + .option-label {
  font-weight: 600;
}

.multi-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ──────────────── Custom Answer ──────────────── */
.custom-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.custom-divider::before,
.custom-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.custom-text {
  margin: 0 0 24px;
}

.custom-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: box-shadow var(--transition);
}

.custom-input:focus {
  box-shadow: 0 0 0 3px rgba(108,99,255,.1);
}

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

/* ──────────────── Actions ──────────────── */
.question-actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.right-actions {
  display: flex;
  gap: 12px;
  flex: 1;
  justify-content: flex-end;
}

.question-actions .btn {
  min-width: 120px;
}

/* ──────────────── Examples ──────────────── */
.examples {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.examples-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.examples ul {
  list-style: none;
}

.examples li {
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.examples code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  color: var(--accent);
  font-size: 0.85rem;
}

/* ──────────────── Result Styles ──────────────── */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}

.result-header h2 {
  flex: 1;
}

.framework-badge {
  display: inline-block;
  background: rgba(108,99,255,.15);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.framework-reason {
  background: rgba(108,99,255,.05);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 28px;
}

.framework-reason p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

.framework-reason strong {
  color: var(--text);
}

/* ──────────────── Result Prompt Container ──────────────── */
.result-prompt-container {
  margin-bottom: 24px;
}

.result-prompt {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 50vh;
  color: var(--text);
}

.result-prompt::-webkit-scrollbar {
  width: 6px;
}

.result-prompt::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 3px;
}

.result-prompt::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

/* ──────────────── Result Actions ──────────────── */
.result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.result-actions .btn {
  flex: 1;
  min-width: 140px;
}

/* ──────────────── Error Message ──────────────── */
.error-message {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-left: 3px solid #ef4444;
  color: #7f1d1d;
  padding: 14px 16px;
  border-radius: 8px;
  margin-top: 20px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.intelliprompt-app.dark-mode .error-message {
  background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.3);
  border-left-color: #ef4444;
  color: #fca5a5;
}

/* ──────────────── Loading Overlay ──────────────── */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 999;
  backdrop-filter: blur(4px);
}

.spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 24px;
}

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

.loading-overlay p {
  color: #f1f5f9;
  font-size: 1.05rem;
  font-weight: 500;
  text-align: center;
  max-width: 300px;
}

/* ──────────────── Mobile Responsive ──────────────── */
@media (max-width: 640px) {
  .app-header {
    padding: 24px 16px;
  }

  .header-content h1 {
    font-size: 1.5rem;
  }

  .theme-toggle {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
    top: 16px;
    right: 16px;
  }

  .app-main {
    padding: 24px 16px;
  }

  .stage-content {
    padding: 20px 16px;
  }

  .stage-content > h2 {
    font-size: 1.25rem;
  }

  .question-text {
    font-size: 1.1rem;
  }

  .question-actions {
    flex-direction: column-reverse;
  }

  .question-actions .btn {
    width: 100%;
  }

  .right-actions {
    flex-direction: column;
  }

  .right-actions .btn {
    width: 100%;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-actions .btn {
    width: 100%;
    min-width: unset;
  }

  .result-prompt {
    max-height: 40vh;
    padding: 16px;
    font-size: 0.9rem;
  }

  .result-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .framework-badge {
    align-self: flex-start;
  }
}

@media (max-width: 380px) {
  body {
    padding: 16px;
  }

  .app-header {
    padding: 20px 12px;
  }

  .app-main {
    padding: 16px 12px;
  }

  .stage-content {
    padding: 16px 12px;
  }

  .spinner {
    width: 48px;
    height: 48px;
    border-width: 3px;
  }
}

/* ──────────────── Prompt Evolution Timeline ──────────────── */
.evolution-section {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.evolution-heading {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 24px;
}

.evolution-timeline {
  display: flex;
  flex-direction: column;
}

.evolution-step {
  display: flex;
  gap: 16px;
  padding-bottom: 8px;
}

.evolution-step:last-child {
  padding-bottom: 0;
}

.evolution-step-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 20px;
}

.evolution-step-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.evolution-step.is-original .evolution-step-dot {
  background: var(--muted);
  border-color: var(--muted);
}

.evolution-step.is-current .evolution-step-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,.18);
}

.evolution-step:not(:last-child) .evolution-step-track::after {
  content: '';
  flex: 1;
  width: 2px;
  background: var(--border);
  min-height: 20px;
  margin: 6px 0 0;
}

.evolution-step-body {
  flex: 1;
  padding-bottom: 20px;
}

.evolution-step:last-child .evolution-step-body {
  padding-bottom: 0;
}

.evolution-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.evolution-step-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.evolution-step.is-current .evolution-step-label {
  color: var(--text);
}

.evolution-framework-badge {
  background: rgba(108,99,255,.12);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.evolution-current-tag {
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.evolution-step-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  max-height: 160px;
  overflow-y: auto;
}

.evolution-step.is-current .evolution-step-content {
  border-color: rgba(108,99,255,.35);
  color: var(--text);
}

.evolution-step-content::-webkit-scrollbar {
  width: 4px;
}

.evolution-step-content::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 2px;
}

.evolution-step-content::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 2px;
}

/* ──────────────── Print Styles ──────────────── */
@media print {
  .app-header,
  .app-footer,
  .question-actions,
  .result-actions,
  .theme-toggle {
    display: none;
  }

  .result-prompt {
    max-height: none;
    border: 1px solid #ccc;
  }
}
