:root {
  --paper: #ffffff;
  --paper-raised: #ffffff;
  --lav-50: #faf8ff;
  --lav-100: #f1ecfb;
  --lav-200: #e3d9f6;
  --ink: #241b36;
  --ink-soft: #665c78;
  --line: #e5ddf2;
  --purple: #7c5cbf;
  --purple-deep: #5b3e96;
  --purple-tint: #f1ecfb;
  --amber: #b5732a;
  --amber-tint: #f6e9d8;
  --red: #a83b32;
  --red-tint: #f5e1de;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --head: "Sora", -apple-system, BlinkMacSystemFont, sans-serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- topbar ---------- */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--purple), var(--purple-deep));
  color: white;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--head);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.engine-status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  flex-shrink: 0;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber);
  transition: background 0.3s;
  flex-shrink: 0;
}
.dot.ready { background: var(--purple); }

/* ---------- layout ---------- */
.wrap { max-width: 880px; margin: 0 auto; padding: 0 24px 80px; }

.hero { padding: 56px 0 40px; }
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--purple-deep);
  margin: 0 0 16px;
}
.hero h1 {
  font-family: var(--head);
  font-weight: 800;
  font-size: clamp(30px, 5.5vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 20px;
  max-width: 14ch;
}
.hero-sub {
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 56ch;
  margin: 0;
}
.hero-sub em { color: var(--ink); font-style: normal; border-bottom: 1.5px solid var(--purple); }

/* ---------- panel ---------- */
.panel {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 28px;
  box-shadow: 0 1px 2px rgba(91, 62, 150, 0.04);
}
.panel-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}
.panel-head-spaced { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.step-index {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--purple-deep);
  background: var(--purple-tint);
  border-radius: 6px;
  padding: 4px 8px;
  flex-shrink: 0;
  margin-top: 2px;
}
.panel-head h2 {
  font-family: var(--head);
  font-weight: 700;
  font-size: 21px;
  margin: 0 0 4px;
}
.panel-head p { margin: 0; color: var(--ink-soft); font-size: 14.5px; }
.optional { font-weight: 400; color: var(--ink-soft); font-size: 13px; }

/* ---------- chips ---------- */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 10px 15px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--lav-50);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.14s ease;
  user-select: none;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.chip:hover { border-color: var(--purple); background: var(--lav-100); }
.chip.selected {
  background: var(--purple);
  border-color: var(--purple);
  color: white;
}
.chip-grid-history .chip.selected { background: var(--amber); border-color: var(--amber); }

.run-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.run-btn {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14.5px;
  background: linear-gradient(135deg, var(--purple), var(--purple-deep));
  color: white;
  border: none;
  padding: 13px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 44px;
}
.run-btn:hover:not(:disabled) { opacity: 0.92; }
.run-btn:active:not(:disabled) { transform: scale(0.98); }
.run-btn:disabled { background: #d7d0e6; cursor: not-allowed; }
.reset-btn {
  font-family: var(--sans);
  font-size: 14px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 12px 18px;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
}
.reset-btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.selected-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---------- results ---------- */
.results-panel.hidden, .hidden { display: none !important; }

.diagnosis-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 16px;
  background: var(--lav-50);
}
.diagnosis-card:last-child { margin-bottom: 0; }

.dc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.dc-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dc-rank {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.dc-name {
  font-family: var(--head);
  font-weight: 700;
  font-size: 20px;
  margin: 0;
}
.urgency-tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  white-space: nowrap;
}
.urgency-self-care { background: var(--purple-tint); color: var(--purple-deep); }
.urgency-consult { background: var(--amber-tint); color: var(--amber); }
.urgency-urgent { background: var(--red-tint); color: var(--red); }

.confidence-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.confidence-label { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); width: 92px; flex-shrink: 0; }
.confidence-track {
  flex: 1;
  height: 7px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}
.confidence-fill { height: 100%; background: linear-gradient(90deg, var(--purple), var(--purple-deep)); border-radius: 4px; }
.confidence-value { font-family: var(--mono); font-size: 13px; font-weight: 500; width: 40px; text-align: right; flex-shrink: 0; }

.matched-symptoms {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 14px 0 16px;
}
.symptom-tag {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 5px;
  background: var(--purple-tint);
  color: var(--purple-deep);
}

.dc-section-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  text-transform: uppercase;
  margin: 16px 0 8px;
}
.med-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.med-item {
  border-left: 2px solid var(--purple);
  padding: 4px 0 4px 12px;
}
.med-name { font-weight: 600; font-size: 14px; }
.med-purpose { color: var(--ink-soft); font-size: 13.5px; }
.med-warning {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--red);
  background: var(--red-tint);
  padding: 7px 11px;
  border-radius: 7px;
}

.advice-box {
  font-size: 14px;
  color: var(--ink-soft);
  background: var(--purple-tint);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 14px;
}
.advice-box strong { color: var(--ink); }

.no-match {
  text-align: center;
  padding: 30px 20px;
  color: var(--ink-soft);
}
.no-match h3 { font-family: var(--head); color: var(--ink); margin-bottom: 8px; }

.alt-block {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}
.alt-block h4 {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 0 0 10px;
}
.alt-item {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13.5px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.alt-item:last-child { border-bottom: none; }
.alt-conf { font-family: var(--mono); color: var(--ink-soft); flex-shrink: 0; }

/* ---------- how it works ---------- */
.how-it-works { padding: 48px 0 20px; }
.how-it-works h3 {
  font-family: var(--head);
  font-weight: 700;
  font-size: 22px;
  margin: 0 0 24px;
}
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.step-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--purple);
}
.step h4 {
  font-family: var(--head);
  font-size: 16.5px;
  font-weight: 700;
  margin: 8px 0 8px;
}
.step p { font-size: 13.5px; color: var(--ink-soft); margin: 0; }
.step em { font-style: normal; color: var(--ink); }

/* ---------- footer ---------- */
.disclaimer {
  margin-top: 40px;
  padding: 18px 20px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.6;
  background: var(--lav-50);
}

/* ---------- responsive ---------- */
@media (max-width: 700px) {
  .wrap { padding: 0 16px 56px; }
  .topbar-inner { padding: 14px 16px; }
  .hero { padding: 32px 0 28px; }
  .panel { padding: 20px; border-radius: 14px; }
  .steps { grid-template-columns: 1fr; gap: 16px; }
  .run-row { flex-wrap: wrap; }
  .run-btn, .reset-btn { flex: 1 1 auto; justify-content: center; }
  .selected-count { margin-left: 0; width: 100%; order: 3; text-align: center; }
  .dc-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .confidence-label { width: 76px; font-size: 11px; }
  .brand-name { font-size: 17px; }
  .engine-status span:last-child { display: none; }
  .engine-status { gap: 0; }
}

@media (max-width: 420px) {
  .hero h1 { max-width: none; }
  .chip { font-size: 13px; padding: 9px 13px; }
}

/* focus visibility */
.chip:focus-visible, .run-btn:focus-visible, .reset-btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
