/* "Lưu bút mực tím": the test reads like a page of a school autograph book — ruled paper,
   a red margin line, questions handwritten in purple ink. UI chrome stays in a plain sans. */
:root {
  --desk: #e9ebf5;
  --paper: #fcfcff;
  --rule: #d6dbf1;
  --margin: #eba3ae;
  --ink: #4e35b1;
  --ink-soft: #ebe6fb;
  --text: #24223a;
  --muted: #6c6a86;
  --line: #dcdfee;
  --phuong: #d4384a;
  --disagree: #7e8aa8;
  --anxiety: #c2534f;
  --avoidance: #3c7fa6;
  --secure: #3e8d6a;
  --danger: #b3261e;
  --hand: 'Patrick Hand', 'Segoe Print', cursive;
  --ui: 'Be Vietnam Pro', system-ui, sans-serif;
  --rule-gap: 34px;
  --margin-x: 30px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #121226;
    --paper: #1b1b33;
    --rule: #2d2d50;
    --margin: #74374b;
    --ink: #b9a8ff;
    --ink-soft: #2c2650;
    --text: #eceaf8;
    --muted: #9d9bba;
    --line: #31314f;
    --phuong: #ff7a86;
    --disagree: #8e97b5;
    --anxiety: #f08a84;
    --avoidance: #7fb8db;
    --secure: #7ccba2;
    --danger: #ffb4ab;
    color-scheme: dark;
  }
}
@media (min-width: 560px) {
  :root { --margin-x: 44px; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--text);
  font: 16px/1.6 var(--ui);
}
.page { max-width: 600px; margin: 0 auto; padding: 28px 12px 40px; }
.page.wide { max-width: 1160px; padding-inline: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 0.86rem; }
.error { color: var(--danger); font-size: 0.92rem; }
.hand { font-family: var(--hand); font-weight: 400; }
.footer { margin-top: 18px; text-align: center; color: var(--muted); font-size: 0.78rem; }

/* Notebook sheet: paper with the red margin line; content starts right of the margin. */
.sheet {
  position: relative;
  padding: 30px 20px 28px calc(var(--margin-x) + 18px);
  background: var(--paper);
  border-radius: 4px 4px 10px 10px;
  box-shadow: 0 1px 0 var(--line), 0 22px 44px -30px rgb(40 30 100 / 0.45);
}
.sheet::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 var(--margin-x);
  width: 1.5px;
  background: var(--margin);
}
.sheet.plain { padding: 0; }
.sheet.plain::before { content: none; }

/* Ruled lines aligned under handwritten text (baseline sits just above each rule). */
.ruled {
  line-height: var(--rule-gap);
  background-image: linear-gradient(to bottom, transparent calc(var(--rule-gap) - 1px), var(--rule) calc(var(--rule-gap) - 1px));
  background-size: 100% var(--rule-gap);
  background-position: 0 -7px;
}

.title { margin: 0 0 10px; font-size: clamp(2.3rem, 9vw, 3rem); line-height: 1.1; color: var(--ink); }
.lede { font-size: 1.02rem; }
.doodle { display: block; width: 46px; height: 40px; margin-bottom: 6px; color: var(--phuong); }

/* Intro contents list: the three parts really are a sequence, so they are numbered. */
.toc { list-style: none; counter-reset: part; padding: 0; margin: 22px 0 26px; display: grid; gap: 14px; }
.toc li {
  counter-increment: part;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  column-gap: 8px;
  align-items: baseline;
}
.toc li::before { content: counter(part); font: 1.7rem/1 var(--hand); color: var(--ink); }
.toc-title { font-weight: 600; }
.toc-count { color: var(--muted); font-size: 0.86rem; white-space: nowrap; }
.toc-desc { grid-column: 2 / -1; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }

/* Forms & buttons */
.form { display: grid; gap: 6px; }
label { font-weight: 600; font-size: 0.92rem; }
input.name-input {
  width: 100%;
  padding: 2px 0 4px;
  font: 1.7rem/1.3 var(--hand);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--rule);
  border-radius: 0;
}
input.name-input:focus { outline: none; border-bottom-color: var(--ink); }
input.name-input::placeholder { color: var(--muted); opacity: 0.55; }
input[type='search'], input[type='password'], select {
  padding: 10px 14px;
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.actions.center { justify-content: center; }
.btn {
  padding: 12px 22px;
  font: 600 1rem var(--ui);
  color: var(--paper);
  background: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
}
.btn.ghost { color: var(--ink); background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: currentColor; }
.link { padding: 6px 0; font: inherit; color: var(--ink); background: none; border: 0; cursor: pointer; }
.link:disabled { visibility: hidden; }

/* Question screen */
.q-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 0.9rem; }
.q-part { font-weight: 600; color: var(--ink); }
.q-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-parts { display: flex; gap: 5px; margin: 8px 0 22px; }
.progress-parts .seg { height: 5px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-parts .fill { height: 100%; width: 0; background: var(--ink); transition: width 0.25s ease; }
.q-text { min-height: calc(var(--rule-gap) * 4); margin: 0; font: 1.45rem/var(--rule-gap) var(--hand); color: var(--ink); }
.q-text.prompt { min-height: 0; }
.q-text.writing { animation: write 0.45s ease-out; }
@keyframes write {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

/* Agreement scale: dots grow toward both ends; agree side in ink, disagree side in slate. */
.scale { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin: 26px 0 8px; }
.dot {
  flex: none;
  width: var(--size);
  height: var(--size);
  padding: 0;
  background: transparent;
  border: 2px solid var(--disagree);
  border-radius: 50%;
  cursor: pointer;
}
.dot.neutral { border-color: var(--muted); }
.dot.agree { border-color: var(--ink); }
.dot:hover { background: color-mix(in srgb, var(--disagree) 16%, transparent); }
.dot.agree:hover { background: var(--ink-soft); }
.dot.selected { background: var(--disagree); animation: ink-drop 0.22s ease-out; }
.dot.neutral.selected { background: var(--muted); }
.dot.agree.selected { background: var(--ink); }
@keyframes ink-drop {
  from { transform: scale(0.8); }
  to { transform: scale(1); }
}
.scale-ends { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; font-size: 0.8rem; line-height: 1.3; color: var(--muted); }
.scale-ends span:last-child { text-align: right; }
.scale-picked { min-width: 7em; text-align: center; font-weight: 600; color: var(--ink); }

/* A/B situations as two note slips */
.choices { display: grid; gap: 12px; margin-top: 22px; }
.slip {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  text-align: left;
  font: 1.32rem/1.3 var(--hand);
  color: var(--text);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.slip:hover { border-color: var(--ink); }
.slip-key {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font: 600 0.9rem var(--ui);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 50%;
}
.slip.selected { border-color: var(--ink); background: var(--ink-soft); }
.slip.selected .slip-key { color: var(--paper); background: var(--ink); }
.q-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; font-size: 0.86rem; }

/* Part divider */
.part-number { margin: 0; font-size: 1.5rem; color: var(--muted); }
.status { font-size: 1.05rem; }

/* Result */
.result-section { padding: 26px 0 8px; border-top: 1.5px dashed var(--rule); }
.result-section:first-child { border-top: 0; padding-top: 6px; }
.section-label { margin: 0; font-size: 0.86rem; font-weight: 600; color: var(--muted); }
.result-section h2 { margin: 0 0 8px; font: 2.1rem/1.15 var(--hand); color: var(--ink); }
.result-section h3 { margin: 18px 0 6px; font-size: 0.95rem; }
.tips { padding-left: 20px; margin: 0 0 14px; }
.tips li { margin-bottom: 6px; }
.bars { display: grid; gap: 12px; margin: 16px 0 18px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 0.92rem; line-height: 1.35; }
.bar-row .meter { grid-column: 1 / -1; }
.bar-row b { grid-row: 1; grid-column: 2; text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter > div { height: 100%; border-radius: 99px; background: color-mix(in srgb, var(--ink) 35%, var(--line)); }
.bar-row.top span { font-weight: 600; }
.bar-row.top .meter > div { background: var(--ink); }
.bar-row.anxiety .meter > div { background: var(--anxiety); }
.bar-row.avoidance .meter > div { background: var(--avoidance); }
.chart svg { display: block; width: 100%; max-width: 330px; margin: 4px auto 8px; }
.q-bg { fill: none; stroke: var(--rule); stroke-width: 1.5; }
.q-mid { stroke: var(--margin); stroke-width: 1.5; stroke-dasharray: 5 5; }
.q-label { fill: var(--muted); font: 15px var(--hand); }
.q-axis { fill: var(--text); font: 600 12px var(--ui); }
.q-tick { fill: var(--muted); font: 11px var(--ui); }
.q-dot { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.q-dot-halo { fill: var(--ink); opacity: 0.16; }
.history { margin-top: 26px; padding-top: 16px; border-top: 1.5px dashed var(--rule); }
.history h2 { margin: 0 0 8px; font-size: 0.92rem; }
.history ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.history-item { padding: 4px 0; font: inherit; font-size: 0.92rem; text-align: left; color: var(--ink); background: none; border: 0; cursor: pointer; }

/* Admin */
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.admin-head .title { margin: 0; font-size: 2.4rem; }
.admin-head .actions { margin: 0; }
.login-card { max-width: 420px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 32px; margin-bottom: 18px; }
.stat b { display: block; font: 2.2rem/1 var(--hand); }
.stat span { color: var(--muted); font-size: 0.86rem; }
.stat.done b { color: var(--secure); }
.stat.partial b { color: var(--anxiety); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar input { flex: 1 1 220px; max-width: 320px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.name { font-weight: 600; }
td.style-tag { white-space: nowrap; }
td.done { color: var(--secure); font-weight: 600; }
td.partial { color: var(--anxiety); font-weight: 600; }
#rows tr { cursor: pointer; }
#rows tr:hover { background: var(--ink-soft); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.detail {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 24px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.detail::backdrop { background: rgb(18 18 38 / 0.5); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-head h2 { margin: 0; font: 2rem/1.2 var(--hand); color: var(--ink); }
.detail-head .link { font-size: 1.3rem; }
.detail h3 { margin: 26px 0 8px; font-size: 0.95rem; }
.answers td.anxiety { color: var(--anxiety); white-space: nowrap; }
.answers td.avoidance { color: var(--avoidance); white-space: nowrap; }
.answers td.picked { font-weight: 600; color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .q-text.writing, .dot.selected { animation: none; }
  .progress-parts .fill { transition: none; }
}
