:root {
  --bg: #fffaf4;
  --panel: #ffffff;
  --text: #293241;
  --muted: #62707d;
  --line: #e7e3db;
  --primary: #ff8a5b;
  --primary-2: #ffd17a;
  --accent: #7dd3c7;
  --ok: #2a9d8f;
  --err: #d62828;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, #ffe8d6 0, transparent 25%),
    radial-gradient(circle at 90% 0%, #e0fbfc 0, transparent 22%),
    var(--bg);
}

.container { width: min(1120px, 92vw); margin: 0 auto; }
.page-main { padding: 22px 0 46px; }
.stack, .stack-lg { display: grid; gap: 12px; }
.stack-lg { gap: 18px; }
.grid { display: grid; gap: 14px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 62px; }
.brand { text-decoration: none; color: var(--text); font-weight: 700; letter-spacing: .3px; }
.nav-links { display: flex; gap: 12px; }
.nav-links a { text-decoration: none; color: var(--muted); font-size: 14px; }
.nav-links a:hover { color: var(--text); }

.hero {
  margin: 10px 0 16px;
  background: linear-gradient(120deg, #ffd6a5, #caffbf 45%, #9bf6ff);
  border-radius: calc(var(--radius) + 8px);
  padding: clamp(20px, 4vw, 38px);
}
.hero h1 { margin: 0 0 8px; font-size: clamp(1.4rem, 3.6vw, 2.2rem); }
.hero p { margin: 0; color: #324b54; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 18px rgba(28, 39, 54, 0.05);
}

.narrow { max-width: 420px; margin: 0 auto; }

.tests-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.test-card { display: grid; gap: 8px; align-content: start; }
.test-actions { margin-top: 6px; }

.search-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
input, textarea, select {
  width: 100%;
  border: 1px solid #d7d2c6;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  border-radius: 11px;
  padding: 10px 15px;
  font: inherit;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #1f2b2c;
  text-decoration: none;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.03); transform: translateY(-1px); }
.btn-small { padding: 7px 12px; font-size: 13px; }
.btn-lg { width: 100%; min-height: 48px; }
.btn-secondary {
  background: #eef3f8;
  color: #25364a;
  border: 1px solid #d8e1ec;
}

.muted { color: var(--muted); font-size: 14px; }
.preline { white-space: pre-line; }

.progress { height: 10px; background: #f0eee8; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #7dd3c7, #82b1ff); transition: width .22s ease; }
.progress-text { margin-top: 8px; color: var(--muted); }
.sticky-head { position: sticky; top: 74px; z-index: 10; }

.option-list { display: grid; gap: 8px; }
.option-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 10px;
  border: 1px solid #ece7de;
  border-radius: 10px;
  padding: 9px 10px;
}
.option-item input { width: 18px; height: 18px; margin-top: 2px; }
.question-stem { line-height: 1.55; }
.q-step { display: none; }
.q-step.active {
  display: block;
  animation: fadeInStep .18s ease;
}

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

.flash-list { margin-bottom: 12px; display: grid; gap: 8px; }
.flash { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.flash-success { background: #ddf6ef; color: #145f4c; }
.flash-error { background: #fde2e4; color: #8f2525; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { border-bottom: 1px solid #eee7df; text-align: left; padding: 10px 8px; vertical-align: top; }
.table th { color: #44515f; background: #fcfaf6; }

.stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat p { margin: 2px 0 0; font-size: 28px; font-weight: 700; color: #355070; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

.question-admin { border-top: 1px dashed #ddd5ca; padding-top: 12px; margin-top: 12px; }
.inline-form { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin: 6px 0; }
.options-admin { margin-top: 8px; }

.answer-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.answer-item { background: #f6f9fc; border: 1px solid #e5edf3; border-radius: 10px; padding: 8px 10px; }
.codebox {
  background: #1f2430;
  color: #c7d2fe;
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
}

.footer { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding: 14px 0 24px; }

@media (max-width: 768px) {
  .topbar-inner { min-height: 56px; }
  .nav-links { font-size: 13px; gap: 8px; }
  .card { padding: 13px; }
  .inline-form { grid-template-columns: 1fr; }
  .sticky-head { top: 62px; }
}

/* Image questions and choices retain their original proportions. */
.question-image { display: block; max-width: 100%; height: auto; object-fit: contain; }
.mbti-plot { margin: 1rem 0; }
.mbti-axis-labels { display: flex; justify-content: space-between; gap: .5rem; }
.mbti-axis { display: flex; height: 1rem; margin-top: .3rem; border: 1px solid #8a9b91; }
.mbti-half { position: relative; width: 50%; }
.mbti-half-left { border-right: 1px solid #26382e; }
.mbti-half i { display: block; height: 100%; background: #52ad72; }
.mbti-half-left i { margin-left: auto; }
.mbti-types td:first-child { min-width: 7rem; }
.mbti-selected { color: #154bb1; font-weight: 600; }
.psqi-question { min-width: 0; margin-bottom: 1rem; }
.psqi-question legend { max-width: 100%; font-weight: 600; }
.psqi-option { display: block; padding: .45rem 0; }
.psqi-option input[type=radio] { width: auto; margin-right: .4rem; }

/* Observed PF16/IQ2 result typography and tables; scoped to their result sections. */
.page-main.reference-page { width: 100%; }
.card.reference-result {
  box-sizing: content-box;
  width: 100%;
  max-width: none;
  margin: 0 0 20px;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: white;
  color: #444;
  font-family: "Microsoft Yahei";
}
.reference-result *, .reference-result .table { box-sizing: content-box; }
.reference-result .table {
  box-sizing: border-box;
  width: 98% !important;
  margin: 0 auto !important;
  border: 1px solid #add9c0;
  border-collapse: separate;
  border-spacing: 0;
  text-align: justify;
}
.reference-result .table td {
  width: 50%;
  border: 1px solid #add9c0;
  padding: 7px;
  font-size: 14px;
  line-height: 24px;
  font-weight: inherit;
  text-align: justify;
  vertical-align: middle;
  background: transparent;
  color: inherit;
}
.reference-result-pf16 .table td { word-break: break-all; }
.reference-result-iq3 .table { font-size: 16px; }
.reference-result-iq3 [data-iq3-grade-heading], .reference-result-iq3 [data-iq3-page-title] {
  text-align: center;
  margin: 0 0 15px;
  padding-top: 10px;
  font-size: 17px;
  font-weight: 700;
}
.reference-result-pf16 [data-pf16-table="0"] td { width: 33.33%; }
.reference-result-neo [data-neo-table="scores"] td { width: 33.33%; font-size: 13px; }
.reference-result-neo [data-neo-heading] { text-align: center; margin-bottom: 15px; font-size: 17px; font-weight: 700; }
.reference-result-neo hr { border: 0; border-top: 1px solid #ddd; margin: 12px 0; }
.reference-result [data-pf16-note], .reference-result [data-iq2-note], .reference-result [data-iq3-note], .reference-result [data-mmpi-footer-note] {
  padding: 7px;
  margin: 5px;
  border: 1px solid #ddd;
  font-size: 14px;
  line-height: 26px;
  white-space: normal;
  text-align: justify;
  color: #444;
}
.reference-result-mmpi { font-size: 16px; }
.reference-result-mmpi .table { font-size: 16px; }
.reference-result-mmpi .table td { word-break: break-all; }
.reference-result-mmpi [data-mmpi-section-heading], .reference-result-mmpi [data-mmpi-page-title] {
  text-align: center;
  margin-bottom: 15px;
  padding-top: 10px;
  font-size: 17px;
  font-weight: 700;
}
.reference-result-mmpi canvas { width: 98%; display: block; margin: auto; }
/* The reference document uses quirks-mode inline line boxes; matching the
   link's font on this text-free wrapper preserves its observed geometry. */
.reference-result-mmpi [data-mmpi-manual] { margin-top: 15px; text-align: center; font-size: 14px; }
.reference-result-mmpi [data-mmpi-manual] a {
  background: #1f8409;
  color: white;
  border-radius: 5px;
  padding: 7px 30px;
  font-size: 14px;
  border: none;
  cursor: pointer;
  -webkit-appearance: none;
  text-decoration: none;
}

/* PSQI's captured inline stylesheet uses full body width with an 8px inset. */
.card.reference-result-psqi {
  width: calc(100% - 16px);
  margin-left: 8px;
  font-size: 16px;
}
.reference-result-psqi [data-psqi-title] {
  text-align: center;
  margin-bottom: 15px;
  padding-top: 10px;
  font-size: 17px;
  font-weight: 700;
}
.reference-result-psqi .psqi-table {
  box-sizing: border-box;
  width: 100%;
  margin: 0 auto;
  border: 1px solid #add9c0;
  border-collapse: separate;
  border-spacing: 0;
  text-align: justify;
}
.reference-result-psqi .psqi-table tr { border-color: inherit; }
.reference-result-psqi .psqi-table td {
  width: 50%;
  border: 1px solid #add9c0;
  padding: 7px;
  font-size: 14px;
}
.reference-result-psqi [data-psqi-note] {
  padding: 7px;
  line-height: 26px;
  margin: 10px auto 0;
  border: 1px solid #ddd;
  font-size: 14px;
  text-align: justify;
}

/* CMI result rules transcribed from the captured reference stylesheet. */
.reference-result-cmi [data-cmi-title] {
  text-align: center;
  margin-bottom: 15px;
  padding-top: 10px;
  font-size: 17px;
  font-weight: 700;
}
.reference-result-cmi .iq_tab3 {
  width: 98%;
  margin: 0 auto;
  border: 1px solid #add9c0;
  border-collapse: separate;
  border-spacing: 0;
}
.reference-result-cmi .iq_tab3 td {
  width: 33.33%;
  border: 1px solid #add9c0;
  padding: 7px;
  font-size: 14px;
}
.reference-result-cmi hr {
  margin: 12px 0;
  background: #ddd;
  border: 0;
  height: 1px;
}
.reference-result-cmi [data-cmi-note] {
  padding: 7px;
  line-height: 26px;
  margin: 5px;
  border: 1px solid #ddd;
  font-size: 14px;
  text-align: justify;
}
.pcl5-cluster { margin: 12px 0; }
.pcl5-cluster p { margin: 6px 0; }
/* EPQ's 6px red dot needs its 3px border outside the content box. */
[data-epq-plot] div { box-sizing: content-box; }

/* Production additions: consent, result access, admin utilities. */
.nav-links { align-items: center; }
.nav-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
.link-button:hover { color: var(--text); }
.footer-inner { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.footer-inner a { color: var(--muted); }
.consent-item { display: flex; gap: 8px; align-items: flex-start; line-height: 1.6; }
.consent-item input[type=checkbox] { margin-top: 5px; flex: 0 0 auto; width: 18px; height: 18px; }
.access-banner { border-left: 4px solid var(--primary); }
.access-banner p { margin: 0; line-height: 1.7; }
.result-disclaimer { background: #fff8ec; }
.result-disclaimer p { margin: 6px 0; line-height: 1.7; }
.owner-panel form { margin-top: 12px; }
.share-row { display: flex; gap: 8px; align-items: center; }
.share-row input { flex: 1 1 auto; min-width: 0; }
.btn-danger { background: var(--err); color: #fff; }
.delete-form { border-top: 1px dashed var(--line); padding-top: 12px; display: grid; gap: 10px; }
.inline-check { display: inline-flex; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.prose h2 { font-size: 18px; margin-top: 22px; }
.prose p, .prose li { line-height: 1.8; }
button:disabled, .btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.progress-sticky { position: sticky; top: 70px; z-index: 10; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.progress-line { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 13px; }
.form-hint { color: var(--err); min-height: 1em; margin: 8px 0 0; }
.nav-card { padding-top: 12px; padding-bottom: 12px; }
.question-card h3:focus { outline: none; }
@media (max-width: 768px) { .progress-sticky { top: 62px; } }
@media (max-height: 600px) { .progress-sticky, .topbar { position: static; } }
.risk-notice { border: 2px solid var(--err); background: #fff1f1; }
.risk-notice h2 { color: #a4161a; margin-top: 0; }
.risk-notice p { line-height: 1.8; }
.result-caveat { margin: 0 0 4px; font-size: 13px; }
.observer-note { border-left: 4px solid var(--primary-2); background: #fffaf0; padding: 8px 12px; border-radius: 8px; line-height: 1.7; }
