:root {
  --primary: #6B4EAB;
  --primary-dark: #5038A0;
  --primary-light: #EDE8F8;
  --accent: #9C7ED6;
  --text: #1A1A2E;
  --text-secondary: #555572;
  --border: #DDD8EE;
  --bg: #F7F5FF;
  --card-bg: #FFFFFF;
  --danger: #D94040;
  --warn: #D97A00;
  --success: #2E8B57;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(107, 78, 171, 0.10);
}

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

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 640px;
  padding: 0 16px 120px;
}

/* ── Header ── */
.header {
  background: var(--primary);
  color: #fff;
  text-align: center;
  padding: 20px 16px 16px;
  width: 100%;
}
.header h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.05em; }
.header p { font-size: 0.8rem; opacity: 0.8; margin-top: 4px; }

/* ── Card ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 16px;
}
.card-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

/* ── Input area ── */
.input-group { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
textarea, input[type="text"] {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: #FAFAFA;
  resize: vertical;
  transition: border-color 0.2s;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
textarea.chart-input { min-height: 140px; font-size: 0.82rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, opacity 0.18s, transform 0.1s;
  padding: 11px 20px;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; margin-top: 4px; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.feedback-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.btn-feedback {
  flex: 1;
  min-width: 80px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid var(--border);
  padding: 9px 10px;
  font-size: 0.85rem;
}
.btn-feedback:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-feedback.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-feedback:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-submit-feedback {
  background: var(--primary);
  color: #fff;
  margin-top: 10px;
  padding: 10px 20px;
  font-size: 0.88rem;
}
.btn-submit-feedback:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Loading ── */
#loading { display: none; flex-direction: column; align-items: center; padding: 32px 0; }
.spinner {
  width: 36px; height: 36px;
  border: 3.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { margin-top: 12px; color: var(--text-secondary); font-size: 0.9rem; }

/* ── Results ── */
#results { display: none; }
.result-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 4px;
}
.result-value {
  font-size: 0.95rem;
  line-height: 1.65;
  white-space: pre-wrap;
}
.narrative-text { font-size: 1rem; line-height: 1.75; color: var(--text); }

.evidence-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.evidence-item {
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  background: var(--primary-light);
  border-radius: 6px;
  font-size: 0.85rem;
}
.evidence-item .ev-title { font-weight: 700; color: var(--primary-dark); }
.evidence-item .ev-reason { color: var(--text-secondary); font-size: 0.8rem; margin-top: 2px; }

.risk-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
}
.risk-low { background: #D1FADF; color: #1B6B3A; }
.risk-moderate { background: #FFF0C2; color: #7A5000; }
.risk-elevated { background: #FFE5CC; color: #8B4000; }
.risk-high { background: #FFD0D0; color: #8B0000; }
.risk-acute { background: #FF4444; color: #fff; }

/* ── Feedback area ── */
#feedback-section { display: none; }
.sub-options { display: none; margin-top: 12px; }
.sub-options.visible { display: block; }
.sub-options .sub-btn-row { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.btn-sub {
  text-align: left;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn-sub:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sub.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

.error-input { margin-top: 10px; display: none; }
.error-input.visible { display: block; }
.error-input textarea { min-height: 70px; font-size: 0.85rem; }

.feedback-done {
  text-align: center;
  padding: 16px 0;
  color: var(--success);
  font-weight: 700;
  font-size: 0.95rem;
}

/* ── Footer ── */
.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(6px);
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-align: center;
  z-index: 100;
}

/* ── Disclaimer modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 26px 22px 22px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
}
.modal h2 {
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 14px;
  text-align: center;
}
.modal p {
  font-size: 0.87rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 12px;
}
.modal .btn-primary { margin-top: 6px; }

/* ── Error message ── */
.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 10px;
  display: none;
}
.error-msg.visible { display: block; }
