/* ==========================================================
   BioVillage — style.css
   Dark theme biomarker intelligence platform
   ========================================================== */

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

:root {
  /* Palette */
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1a1a1a;
  --border: #1f1f1f;
  --border-hover: #2a2a2a;
  --accent: #22c55e;
  --accent-dim: rgba(34, 197, 94, 0.15);
  --accent-glow: rgba(34, 197, 94, 0.08);
  --accent-hover: #16a34a;
  --text: #e5e5e5;
  --text-muted: #a3a3a3;
  --text-faint: #525252;
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;
  --yellow-dim: rgba(234, 179, 8, 0.15);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.15);

  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.5rem + 2vw, 3rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Radii */
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.25rem;

  /* Transitions */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --transition: 200ms var(--ease);

  /* Font */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }

::selection {
  background: rgba(34, 197, 94, 0.3);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 10, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-link {
  text-decoration: none;
  color: var(--text-muted);
  transition: color var(--transition);
}
.logo-link:hover { color: var(--text); }

.wordmark {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.2em;
  color: inherit;
}

.header-tag {
  font-size: var(--text-xs);
  color: var(--accent);
  background: var(--accent-dim);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* --- Container --- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 var(--space-6);
  width: 100%;
}

/* --- Sections --- */
.section {
  padding: clamp(var(--space-8), 5vw, var(--space-16)) 0;
}

.section--input {
  padding-top: clamp(var(--space-12), 6vw, var(--space-20));
}

.main { flex: 1; }

/* --- Hero --- */
.hero {
  text-align: center;
  margin-bottom: var(--space-10);
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-6);
}
.hero-badge svg { flex-shrink: 0; }

.hero-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: #fff;
  margin-bottom: var(--space-4);
}

.accent { color: var(--accent); }

.hero-sub {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.65;
}

/* --- Input Card --- */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 640px;
  margin: 0 auto;
}

.input-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.input-label svg { color: var(--accent); flex-shrink: 0; }

.textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text);
  line-height: 1.6;
  resize: vertical;
  min-height: 180px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea::placeholder { color: var(--text-faint); }
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Optional fields */
.optional-fields {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

.optional-note {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-3);
  font-style: italic;
}

.optional-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder { color: var(--text-faint); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn svg { flex-shrink: 0; }

.btn-primary {
  width: 100%;
  margin-top: var(--space-5);
  background: var(--accent);
  color: #0a0a0a;
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(34, 197, 94, 0.3);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-3) var(--space-5);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--border-hover);
}

.btn-ghost {
  color: var(--text-muted);
  padding: var(--space-3) var(--space-5);
}
.btn-ghost:hover { color: var(--accent); }

.btn-link {
  color: var(--text-faint);
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: color var(--transition);
}
.btn-link:hover { color: var(--accent); }

/* --- Error --- */
.error-msg {
  font-size: var(--text-sm);
  color: var(--red);
  text-align: center;
  margin-top: var(--space-3);
}

/* --- Sample Prompt --- */
.sample-prompt {
  text-align: center;
  margin-top: var(--space-5);
}

/* --- Results Section --- */
.section--results {
  animation: fadeInUp 0.6s var(--ease) both;
}

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

.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: #fff;
  margin-bottom: var(--space-6);
  letter-spacing: -0.01em;
}

/* --- Score + Radar Top Row --- */
.results-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-10);
}

.score-card,
.radar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-label,
.radar-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-5);
}

/* Score Ring */
.score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin-bottom: var(--space-4);
}

.score-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.score-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 1.2s var(--ease), stroke 0.4s;
  filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.4));
}

.score-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: var(--text-xl);
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.score-summary {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
}

/* Radar */
.radar-card canvas {
  max-width: 340px;
  max-height: 340px;
  width: 100%;
  height: auto;
}

/* --- Insights --- */
.insights-section {
  margin-bottom: var(--space-10);
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  animation: fadeInUp 0.5s var(--ease) both;
}
.insight-card:nth-child(2) { animation-delay: 0.1s; }
.insight-card:nth-child(3) { animation-delay: 0.2s; }

.insight-priority {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
}
.insight-priority--high { color: var(--red); background: var(--red-dim); }
.insight-priority--medium { color: var(--yellow); background: var(--yellow-dim); }
.insight-priority--low { color: var(--green); background: var(--green-dim); }

.insight-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: #fff;
  margin-bottom: var(--space-2);
}

.insight-body {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.6;
}

/* --- Biomarker Cards --- */
.biomarkers-section {
  margin-bottom: var(--space-10);
}

.biomarker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.biomarker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition);
  animation: fadeInUp 0.5s var(--ease) both;
}
.biomarker-card:hover { border-color: var(--border-hover); }

.biomarker-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-1);
}

.biomarker-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.biomarker-value {
  font-size: var(--text-lg);
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.biomarker-unit {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-3);
}

/* Range Bar */
.range-bar {
  position: relative;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.range-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s var(--ease);
}
.range-fill--green  { background: var(--green); }
.range-fill--yellow { background: var(--yellow); }
.range-fill--red    { background: var(--red); }

.range-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
  transition: left 0.8s var(--ease);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.6875rem;
  color: var(--text-faint);
}

.biomarker-status {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  margin-top: var(--space-2);
}
.biomarker-status--optimal { color: var(--green); background: var(--green-dim); }
.biomarker-status--borderline { color: var(--yellow); background: var(--yellow-dim); }
.biomarker-status--concern { color: var(--red); background: var(--red-dim); }

/* --- Share --- */
.share-section {
  text-align: center;
  margin-bottom: var(--space-8);
}
.share-section .section-title { margin-bottom: var(--space-4); }

.share-buttons {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
}

/* Copied state */
.btn--copied {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}

/* --- Restart --- */
.restart-section {
  text-align: center;
  padding-bottom: var(--space-8);
}

/* --- Footer --- */
.footer {
  border-top: 1px solid var(--border);
  padding: var(--space-5) var(--space-6);
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.footer-link {
  color: var(--text-faint);
  text-decoration: none;
  transition: color var(--transition);
}
.footer-link:hover { color: var(--text-muted); }
.footer-sep { opacity: 0.4; }

/* --- Responsive --- */
@media (max-width: 640px) {
  .container { padding: 0 var(--space-4); }

  .results-top {
    grid-template-columns: 1fr;
  }

  .biomarker-grid {
    grid-template-columns: 1fr;
  }

  .insights-grid {
    grid-template-columns: 1fr;
  }

  .input-card {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }

  .hero-title { font-size: clamp(1.75rem, 1.2rem + 2.5vw, 2.5rem); }
}

/* --- Animations for stagger --- */
.biomarker-card:nth-child(1)  { animation-delay: 0.05s; }
.biomarker-card:nth-child(2)  { animation-delay: 0.10s; }
.biomarker-card:nth-child(3)  { animation-delay: 0.15s; }
.biomarker-card:nth-child(4)  { animation-delay: 0.20s; }
.biomarker-card:nth-child(5)  { animation-delay: 0.25s; }
.biomarker-card:nth-child(6)  { animation-delay: 0.30s; }
.biomarker-card:nth-child(7)  { animation-delay: 0.35s; }
.biomarker-card:nth-child(8)  { animation-delay: 0.40s; }
.biomarker-card:nth-child(9)  { animation-delay: 0.45s; }
.biomarker-card:nth-child(10) { animation-delay: 0.50s; }
.biomarker-card:nth-child(11) { animation-delay: 0.55s; }
.biomarker-card:nth-child(12) { animation-delay: 0.60s; }

/* --- Utility: Toast --- */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--text-sm);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease);
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
