:root {
  --ink: #3d4740;
  --muted: #7e837c;
  --paper: #fbf8f2;
  --card: #fffdf9;
  --sage: #75836f;
  --sage-dark: #596653;
  --sage-soft: #eef1e8;
  --terra: #aa6047;
  --terra-soft: #fcf0e9;
  --line: #dfd5c7;
  --line-soft: #ece5da;
  --shadow: 0 18px 50px rgba(82, 67, 46, 0.08);
  --serif: Georgia, "Noto Serif SC", "Songti SC", serif;
  --sans: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); font-size: 16px; line-height: 1.65; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: var(--serif); font-weight: 500; letter-spacing: -.02em; }
h1 { font-size: clamp(1.8rem, 2.6vw, 2.8rem); line-height: 1.18; margin-bottom: 10px; }
h2 { font-size: clamp(1.3rem, 1.8vw, 1.7rem); line-height: 1.25; margin-bottom: 10px; }
h3 { font-size: 1.03rem; margin-bottom: 6px; }

.topbar {
  height: 64px; padding: 0 clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(251, 248, 242, .94);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--sage); font-family: var(--serif); font-size: 19px; }
.brand strong, .brand small { display: block; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.top-right { display: flex; align-items: center; gap: 10px; }
.pill { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 12px; }

.progress-bar { max-width: 780px; margin: 0 auto; padding: 22px clamp(18px, 4vw, 48px) 14px; }
.progress-track { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--sage); transition: width .3s ease; }
.progress-label { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); }

.page-wrap { max-width: 780px; margin: 0 auto; padding: 0 clamp(18px, 4vw, 48px) 48px; }
.page {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.page-head {
  padding: 28px 32px;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 22px 22px 0 0;
  background: linear-gradient(100deg, rgba(238,241,232,.8), rgba(255,253,249,.5));
}
.page-head p { max-width: 660px; color: var(--muted); margin-bottom: 0; }
.eyebrow { display: block; color: var(--terra); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 6px; }

.page-body { padding: 28px 32px; }
.page-footer {
  border-top: 1px solid var(--line-soft);
  padding: 18px 28px;
  border-radius: 0 0 22px 22px;
  display: flex; justify-content: space-between; align-items: center;
  background: #fffaf4;
}

.button { border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; background: white; font-weight: 700; }
.button.primary { color: white; border-color: var(--sage); background: var(--sage); }
.button.primary:hover { background: var(--sage-dark); }
.button.ghost { background: transparent; }
.button.small { padding: 6px 10px; font-size: 13px; }

/* ── Welcome ── */
.welcome-hero { text-align: center; padding: 50px 28px 30px; }
.welcome-hero h1 { font-size: clamp(2rem, 3.5vw, 3.2rem); }
.welcome-hero p { font-size: 17px; color: var(--muted); max-width: 520px; margin: 0 auto 28px; }
.welcome-meta { display: flex; justify-content: center; gap: 8px; margin-bottom: 32px; }
.welcome-meta .pill { font-size: 13px; }
.consent-document { max-width: 620px; margin: 0 auto 22px; }
.consent-document section { padding: 16px 0; border-top: 1px solid var(--line-soft); }
.consent-document section:first-child { border-top: 0; padding-top: 0; }
.consent-document h3 { color: var(--sage-dark); margin-bottom: 5px; }
.consent-document p { color: var(--muted); font-size: 14px; margin-bottom: 7px; }
.consent-box { max-width: 480px; margin: 0 auto; padding: 22px; border: 1px solid #ccd8c6; border-radius: 16px; background: var(--sage-soft); }
.consent-item { display: flex; gap: 10px; margin-top: 12px; }
.consent-item:first-child { margin-top: 0; }
.consent-item input { margin-top: 5px; flex: 0 0 auto; }
.field-row { display: flex; gap: 14px; margin-bottom: 14px; }
.field-row label { flex: 1; }
.field-row label span { display: block; font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.field-row input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fffdfa; }

/* ── Intro ── */
.intro-section { margin-bottom: 28px; }
.intro-section h3 { color: var(--sage-dark); }
.intro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.intro-node { text-align: center; padding: 16px 12px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.intro-node .node-circle { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; margin: 0 auto 8px; font-weight: 800; font-size: 16px; }
.intro-node .node-circle.ari { background: var(--sage); color: white; }
.intro-node .node-circle.user { background: var(--sage-dark); color: white; }
.intro-node .node-circle.ta { background: transparent; border: 2px solid var(--line); color: var(--muted); }
.intro-node h4 { margin: 0 0 4px; font-size: 14px; }
.intro-node p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.scene-box { padding: 18px; border: 1px solid #ccd8c6; border-radius: 14px; background: var(--sage-soft); margin: 14px 0; }
.scene-box p { margin: 4px 0; }

/* ── Tutorial ── */
.tutorial-scenario { padding: 18px; border-radius: 14px; background: var(--sage-soft); border: 1px solid #ccd8c6; margin-bottom: 22px; }
.tutorial-scenario p { margin: 4px 0; }
.rule-demo { margin: 18px 0; }
.rule-demo-item { display: grid; grid-template-columns: 80px 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: white; margin-bottom: 8px; }
.rule-demo-item .rule-tag { font-weight: 800; font-size: 12px; color: var(--sage-dark); padding-top: 2px; }
.rule-demo-item .rule-example { font-size: 14px; color: var(--muted); }
.rule-demo-item .rule-example strong { color: var(--ink); font-weight: 600; }
.comprehension { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line-soft); }
.comprehension h3 { color: var(--terra); }
.quiz-item { margin-bottom: 18px; }
.quiz-item p { font-weight: 600; margin-bottom: 8px; }
.quiz-options { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-btn {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; background: white; font-size: 14px;
}
.quiz-btn.selected { border-color: var(--sage); background: var(--sage-soft); font-weight: 700; }
.quiz-btn.correct { border-color: #4a8; background: #e8f5e9; }
.quiz-btn.wrong { border-color: #c44; background: #ffeaea; }
.quiz-feedback { margin-top: 8px; font-size: 13px; padding: 8px 12px; border-radius: 8px; }
.quiz-feedback.pass { color: #2a6a3a; background: #e8f5e9; }
.quiz-feedback.fail { color: #8b3030; background: #ffeaea; }

/* ── Card / Vignette ── */
.card-progress { text-align: center; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.vignette {
  padding: 20px; border-radius: 16px;
  background: linear-gradient(135deg, #f7f4ee, #faf8f3);
  border: 1px solid var(--line);
  margin-bottom: 24px;
}
.vignette .context-line { font-size: 14px; color: var(--muted); margin: 0 0 6px; }
.vignette .event-line { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.factor-list { display: grid; gap: 6px; }
.factor-item {
  display: grid; grid-template-columns: 8px 1fr; gap: 10px; align-items: baseline;
  padding: 8px 12px; border-radius: 10px; background: white;
  font-size: 14px; line-height: 1.55;
}
.factor-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.factor-dot.ent { background: #b07d5a; }
.factor-dot.util { background: #6a8a6e; }
.factor-dot.uptake { background: #8a7a5a; }

.rule-question { margin-bottom: 24px; }
.rule-question > h2 { font-size: 1.15rem; margin-bottom: 14px; }
.rule-options { display: grid; gap: 8px; }
.rule-option {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: white; cursor: pointer; text-align: left;
  transition: border-color .15s, background .15s;
}
.rule-option:hover { border-color: #b8c4b0; background: #fdfcf8; }
.rule-option.selected { border-color: var(--sage); background: var(--sage-soft); }
.rule-option .check-mark {
  width: 22px; height: 22px; border: 2px solid var(--line);
  border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; color: transparent;
}
.rule-option.selected .check-mark { border-color: var(--sage); background: var(--sage); color: white; }
.rule-label { font-size: 14px; line-height: 1.5; }
.rule-label strong { display: block; margin-bottom: 2px; }
.rule-label small { color: var(--muted); font-size: 12px; }

.rule-diagram {
  display: flex; align-items: center; gap: 5px;
  margin-top: 6px;
}
.dia-node {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 800; line-height: 1;
}
.dia-node.ari { background: var(--sage); color: white; }
.dia-node.user { background: var(--sage-dark); color: white; }
.dia-node.ta { background: transparent; border: 1.5px solid var(--line); color: var(--muted); }
.dia-node.ta-active { background: var(--terra-soft); border: 1.5px solid var(--terra); color: var(--terra); }
.dia-node.ta-excluded { opacity: .35; text-decoration: line-through; }
.dia-node.ta-bystander { opacity: .55; }
.dia-arrow { color: var(--sage); font-size: 14px; font-weight: 700; }
.dia-arrow.dim { opacity: .45; }
.dia-pause { color: var(--muted); font-size: 16px; }
.dia-gate { font-size: 11px; color: var(--terra); font-weight: 700; }

/* ── Ratings ── */
.card-ratings { margin-bottom: 20px; }
.rating { border: 0; padding: 0; margin: 0 0 16px; }
.rating legend { font-weight: 600; font-size: 14px; margin-bottom: 8px; display: block; }
.rating-row { display: flex; gap: 4px; }
.rating-row label {
  flex: 1; text-align: center; padding: 8px 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: white; cursor: pointer; font-size: 14px;
  transition: background .12s, border-color .12s;
}
.rating-row label:hover { background: #f5f2ec; }
.rating-row label.selected { border-color: var(--sage); background: var(--sage-soft); font-weight: 700; }
.rating-row label input { display: none; }
.rating-ends { display: flex; justify-content: space-between; margin-top: 4px; }
.rating-ends small { font-size: 11px; color: var(--muted); }

/* ── Reason ── */
.reason-section { margin-bottom: 20px; }
.reason-section label { display: block; }
.reason-section label > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.reason-section label > small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.reason-section textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; background: #fffdfa; resize: vertical;
  font: inherit; min-height: 64px;
}
.reason-section textarea:focus { outline: 2px solid rgba(117,131,111,.24); border-color: var(--sage); }
.reason-required { color: var(--terra); font-weight: 700; }

/* ── Exit ── */
.completion-card { text-align: center; padding: 26px; border: 1px solid var(--line); border-radius: 18px; background: #fffaf4; }
.completion-card.success { border-color: #b7d0b8; background: #f2f7ef; }
.completion-card > p { max-width: 540px; margin: 0 auto 20px; color: var(--muted); font-size: 14px; }
.completion-icon { width: 48px; height: 48px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; background: var(--sage); color: white; font-size: 25px; font-weight: 800; }
.participant-id-card { display: flex; flex-direction: column; align-items: center; gap: 7px; margin: 20px auto; padding: 20px; max-width: 360px; border: 1px dashed var(--sage); border-radius: 14px; background: white; }
.participant-id-card span { color: var(--muted); font-size: 12px; }
.participant-id-card strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: clamp(1.8rem, 6vw, 2.7rem); letter-spacing: .1em; color: var(--sage-dark); line-height: 1.2; }
.wechat-field { display: block; max-width: 420px; margin: 18px auto; text-align: left; }
.wechat-field > span { display: block; font-weight: 700; font-size: 14px; margin-bottom: 5px; }
.wechat-field input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.wechat-field small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.submit-button { min-width: 200px; }
.submit-error { display: grid; gap: 3px; max-width: 480px; margin: 16px auto 0; padding: 12px 14px; text-align: left; border: 1px solid #e9b4ac; border-radius: 10px; background: #fff0ed; color: #923f36; font-size: 13px; }
.completion-note { margin-bottom: 0 !important; }
.answer-summary { margin-top: 20px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.answer-summary summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.exit-summary { margin-bottom: 24px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.summary-cell { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: white; font-size: 13px; }
.summary-cell .cell-id { font-weight: 800; color: var(--sage-dark); font-size: 11px; }
.summary-cell .cell-rule { font-weight: 600; margin-top: 2px; }
.export-area { margin-top: 20px; }
.export-area textarea {
  width: 100%; height: 120px; font-family: monospace; font-size: 11px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  background: #f8f6f0; resize: vertical;
}
.export-buttons { display: flex; gap: 8px; margin-top: 10px; }

/* ── Inline message ── */
.inline-msg {
  margin-top: 10px; padding: 8px 14px; border-radius: 10px;
  font-size: 13px; min-height: 0;
  transition: opacity .2s;
}
.inline-msg:empty { display: none; }
.inline-msg.error { color: #923f36; background: #fff0ed; border: 1px solid #e9b4ac; }
.inline-msg.success { color: #2a6a3a; background: #e8f5e9; border: 1px solid #a8d5b0; }

.debug-badge {
  position: fixed; bottom: 10px; right: 10px;
  padding: 4px 8px; border-radius: 6px;
  background: var(--terra); color: white;
  font-size: 10px; font-weight: 800; z-index: 50;
}

@media (max-width: 640px) {
  .page-wrap { padding: 0 10px 36px; }
  .page { border-radius: 14px; }
  .page-head, .page-body { padding: 20px; }
  .intro-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .rule-option { grid-template-columns: auto 1fr; }
  .field-row { flex-direction: column; }
  .welcome-hero { padding: 30px 18px 20px; }
  .participant-id-card strong { letter-spacing: .06em; }
}
