/* === Reset & Variables === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #1a1a25;
  --border: #2a2a3a;
  --text: #e4e4ef;
  --text-muted: #8888a0;
  --primary: #6c5ce7;
  --primary-glow: rgba(108, 92, 231, 0.3);
  --green: #00d68f;
  --orange: #f0a030;
  --red: #ff6b6b;
  --green-bg: rgba(0, 214, 143, 0.1);
  --orange-bg: rgba(240, 160, 48, 0.1);
  --red-bg: rgba(255, 107, 107, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

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

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* === Layout === */
.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 0 24px;
}

.logo {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.logo span {
  color: var(--primary);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.settings-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}
.settings-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

/* === Settings Panel === */
.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.settings-content h3 {
  margin-bottom: 4px;
}

.settings-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 16px;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.required {
  color: var(--red);
  font-weight: 400;
  font-size: 0.75rem;
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.setting-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.setting-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.setting-group small {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.setting-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* === Buttons === */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--text-muted);
}

.btn-analyze {
  background: var(--primary);
  color: white;
  padding: 12px 28px;
  font-size: 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: nowrap;
}
.btn-analyze:hover {
  filter: brightness(1.15);
}
.btn-analyze:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* === Main === */
.main {
  flex: 1;
}

/* === URL Input === */
.input-section {
  margin-bottom: 24px;
}

.url-input-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.url-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

#url-input {
  flex: 1;
  min-width: 200px;
  padding: 14px 18px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1rem;
}
#url-input:focus {
  outline: none;
}
#url-input::placeholder {
  color: var(--text-muted);
}

.strategy-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
}

.strategy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.strategy-btn:hover {
  color: var(--text);
}
.strategy-btn.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

/* === Progress === */
.progress-section {
  margin-bottom: 24px;
}

.progress-steps {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.step {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: color 0.3s;
}
.step.active {
  color: var(--primary);
}
.step.done {
  color: var(--green);
}

.step-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}
.step.active .step-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  animation: pulse 1.5s infinite;
}
.step.done .step-icon {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

/* === Error === */
.error-section {
  margin-bottom: 24px;
}

.error-card {
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.error-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 8px;
}

#error-message {
  margin-bottom: 12px;
  color: var(--red);
}

/* === Results === */
.results-section {
  animation: fadeIn 0.4s ease-out;
}

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

/* Score Cards */
.scores-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: border-color 0.2s;
}
.score-card:hover {
  border-color: var(--text-muted);
}

.score-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  position: relative;
}
.score-circle::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 3px solid currentColor;
  opacity: 0.3;
}

.score-green { color: var(--green); background: var(--green-bg); }
.score-orange { color: var(--orange); background: var(--orange-bg); }
.score-red { color: var(--red); background: var(--red-bg); }

.score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* AI Analysis */
.ai-analysis {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.ai-header {
  padding: 20px 24px 0;
}

.ai-badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.ai-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.ai-content {
  padding: 16px 24px 24px;
  font-size: 0.92rem;
  line-height: 1.7;
}

.ai-content h1, .ai-content h2, .ai-content h3, .ai-content h4 {
  margin-top: 20px;
  margin-bottom: 8px;
  font-weight: 700;
}
.ai-content h1 { font-size: 1.2rem; }
.ai-content h2 { font-size: 1.1rem; }
.ai-content h3 { font-size: 1rem; color: var(--primary); }

.ai-content p {
  margin-bottom: 10px;
}

.ai-content ul, .ai-content ol {
  margin-bottom: 10px;
  padding-left: 20px;
}
.ai-content li {
  margin-bottom: 4px;
}

.ai-content strong {
  color: var(--text);
}

.ai-content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.ai-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 10px 0;
}

.ai-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.ai-content .priority-high {
  border-left: 3px solid var(--red);
  padding-left: 12px;
  margin: 8px 0;
}
.ai-content .priority-medium {
  border-left: 3px solid var(--orange);
  padding-left: 12px;
  margin: 8px 0;
}
.ai-content .priority-low {
  border-left: 3px solid var(--green);
  padding-left: 12px;
  margin: 8px 0;
}

/* Streaming cursor */
.ai-content .cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Raw Metrics */
.raw-metrics {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 32px;
}

.raw-metrics summary {
  padding: 16px 20px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.raw-metrics summary:hover {
  color: var(--text);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  padding: 0 20px 20px;
}

.metric-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 1.1rem;
  font-weight: 700;
}

/* === Footer === */
.footer {
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* === Utilities === */
.hidden {
  display: none !important;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

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

/* === Responsive === */
@media (max-width: 640px) {
  .header {
    padding: 20px 0 16px;
  }
  .logo {
    font-size: 1.3rem;
  }
  .progress-steps {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    padding-left: 12px;
  }
  .scores-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .url-input-wrapper {
    flex-direction: column;
  }
  .btn-analyze {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    width: 100%;
  }
  .strategy-toggle {
    justify-content: center;
    border-top: 1px solid var(--border);
  }
  .ai-content {
    padding: 12px 16px 20px;
  }
}
