/* Soi. Material: a lit glass table, a paper sheet, carbon-blue ink, lamp light.
   Three voices: Proclaim (Bricolage Grotesque) is the product; UI (Be Vietnam Pro) is the
   interface and the worker's own questions; Ledger (Xanh Mono) is every text from outside:
   the contract, a rule's own words, a host name, a number. */
:root {
  --table: #e6edea;
  --table-2: #f3f7f5;
  --sheet: #fdfefc;
  --ink: #16223b;
  --muted: #4a566f;
  --line: #cbd5d0;
  --line-strong: #6b7890;
  --lamp: #ffd23f;
  --lamp-soft: #fff1b8;
  --raise: #a3261b;
  --amber: #7a4e00;
  --clear: #0b6b58;
  --differs: #5a3e99;

  --proclaim: "Bricolage Grotesque", "Be Vietnam Pro", system-ui, sans-serif;
  --ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ledger: "Xanh Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;

  --quick: 160ms;
  --base: 240ms;
  --story: 900ms;
  --out: cubic-bezier(0.16, 1, 0.3, 1);

  --frame: 76rem;
  --gutter: 1rem;
}
@media (min-width: 40rem) { :root { --gutter: 1.5rem; } }

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--table); color: var(--ink); font-family: var(--ui); font-size: 100%; line-height: 1.6; -webkit-text-size-adjust: 100%; scroll-padding-top: 1rem; }
body { margin: 0; overflow-x: clip; }
h1, h2, h3, p, ul, ol, dl, blockquote { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1, h2, h3 { text-wrap: balance; }
p, li { text-wrap: pretty; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
.ledger { font-family: var(--ledger); font-variant-ligatures: none; font-variant-numeric: tabular-nums; }
bdi { unicode-bidi: isolate; }
[hidden] { display: none !important; }

/* --- proof line and header --------------------------------------------------------- */
.proof { display: flex; flex-wrap: wrap; gap: 0 1rem; align-items: center; min-height: 1.75rem; padding: 0.125rem var(--gutter); font-size: 0.75rem; line-height: 1.5; color: var(--muted); border-bottom: 1px solid var(--line); }
.proof-narrow { display: none; }
@media (max-width: 47.99rem) { .proof-wide { display: none; } .proof-narrow { display: inline; } }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; max-width: var(--frame); margin: 0 auto; padding: 0.75rem var(--gutter) 0; }
.brand { display: inline-flex; align-items: baseline; gap: 0.625rem; text-decoration: none; }
.brand-mark { font-family: var(--proclaim); font-weight: 700; font-size: 1.75rem; line-height: 1; letter-spacing: -0.02em; display: inline-flex; align-items: center; }
/* The "o" of Soi is the lamp: a lit ring. */
.brand-o { display: inline-block; width: 0.62em; height: 0.62em; margin: 0.12em 0.04em 0; border-radius: 50%; background: var(--lamp); border: 0.11em solid var(--ink); }
.brand-sub { font-size: 0.875rem; color: var(--muted); }
.top-tools { display: flex; align-items: center; gap: 1rem; }
.lang { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px; background: var(--table-2); }
.lang button { border: 0; background: none; padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.875rem; cursor: pointer; min-height: 2rem; }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }
.linklike { border: 0; background: none; padding: 0; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; cursor: pointer; font-size: 0.875rem; }

/* --- hero ---------------------------------------------------------------------------- */
main { max-width: var(--frame); margin: 0 auto; padding: 0 var(--gutter) 4rem; }
.hero { padding: clamp(1.25rem, 0.5rem + 3vw, 3rem) 0 clamp(1.5rem, 1rem + 2vw, 2.5rem); max-width: 54rem; }
#question { font-family: var(--proclaim); font-weight: 680; font-size: clamp(2.5rem, 1.35rem + 5.6vw, 5.5rem); line-height: 0.98; letter-spacing: -0.025em; }
:lang(vi) #question { line-height: 1.12; letter-spacing: -0.02em; }
.lead { margin-top: 1rem; font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem); line-height: 1.5; max-width: 62ch; color: var(--ink); }
.choose { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.5rem; }
.chip { border: 1px solid var(--line-strong); background: var(--table-2); border-radius: 999px; padding: 0.4rem 0.9rem; min-height: 2.5rem; cursor: pointer; font-size: 0.9375rem; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.chip:disabled { opacity: 0.55; cursor: default; }

/* The lamp: the one action with a ritual. Hold it and the light fills from the left. */
.lamp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; margin-top: 1.25rem; }
.lamp { position: relative; display: inline-flex; align-items: center; gap: 0.875rem; width: 100%; max-width: 24rem; min-height: 4rem; padding: 0.5rem 1.5rem 0.5rem 0.625rem; border: 2px solid var(--ink); border-radius: 2rem; background: var(--sheet); cursor: pointer; overflow: hidden; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.lamp-fill { position: absolute; inset: 0; background: var(--lamp); transform: scaleX(0); transform-origin: left center; }
.lamp[data-holding] .lamp-fill { transform: scaleX(1); transition: transform 600ms linear; }
.lamp[data-phase="running"] .lamp-fill { transform: scaleX(1); opacity: 0.45; }
.lamp-ring { position: relative; flex: none; width: 2.75rem; height: 2.75rem; border-radius: 50%; background: var(--lamp); border: 2px solid var(--ink); }
.lamp-ring::after { content: ""; position: absolute; inset: 30%; border-radius: 50%; background: var(--ink); }
.lamp-label { position: relative; font-family: var(--proclaim); font-weight: 650; font-size: 1.375rem; letter-spacing: -0.01em; line-height: 1.2; }
.lamp[aria-disabled="true"] { cursor: default; }
.lamp[aria-disabled="true"]:not([data-phase="running"]) { opacity: 0.6; }
.lamp-status { flex: 1 1 16rem; font-size: 0.9375rem; color: var(--muted); min-height: 3em; }
.reader-line { margin-top: 0.75rem; font-size: 0.875rem; color: var(--muted); max-width: 62ch; }
@media (prefers-reduced-motion: no-preference) {
  .lamp:active { transform: scale(0.985); }
  .lamp-nudge { animation: nudge 280ms var(--out); }
  .lamp[data-phase="running"] .lamp-ring { animation: breathe 1.4s ease-in-out infinite; }
}
@keyframes nudge { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-5px); } 65% { transform: translateX(4px); } }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* --- the table: who was asked, and the sheet ----------------------------------------- */
.table { display: grid; gap: 1.5rem; align-items: start; }
@media (min-width: 68rem) { .table { grid-template-columns: 19rem minmax(0, 1fr); gap: 2rem; } .asked-wrap { position: sticky; top: 1rem; } }
.asked-heading { font-family: var(--ui); font-size: 0.875rem; font-weight: 600; color: var(--muted); margin-bottom: 0.75rem; }
.asked { display: grid; gap: 0; }
@media (min-width: 40rem) and (max-width: 67.99rem) { .asked { grid-template-columns: 1fr 1fr; column-gap: 1.5rem; } }
.asked-item { position: relative; display: grid; grid-template-columns: 1.75rem minmax(0, 1fr); gap: 0.75rem; padding: 0 0 1.25rem; }
/* The thread between lamps. */
.asked-item::before { content: ""; position: absolute; left: calc(0.875rem - 0.5px); top: 1.75rem; bottom: 0; width: 1px; background: var(--line-strong); }
.asked-item:last-child::before { display: none; }
@media (min-width: 40rem) and (max-width: 67.99rem) { .asked-item::before { display: none; } }
.asked-name { font-weight: 600; line-height: 1.35; }
.asked-host { font-size: 0.8125rem; color: var(--muted); overflow-wrap: anywhere; }
.asked-state { font-size: 0.9375rem; margin-top: 0.125rem; }
.asked-item[data-lamp="unlit"] .asked-state { color: var(--muted); }
.asked-warn { font-size: 0.875rem; color: var(--amber); margin-top: 0.25rem; }
.asked-sent, .asked-says { font-size: 0.875rem; margin-top: 0.375rem; overflow-wrap: anywhere; }
.asked-tag { font-weight: 600; }
.asked-says summary { cursor: pointer; width: fit-content; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; min-height: 1.75rem; }
.asked-says .says-text { color: var(--muted); }

/* Seals: one shape per party, drawn in ink. Lit means that party really answered. */
.seal { position: relative; display: inline-block; flex: none; width: 1.75rem; height: 1.75rem; background: var(--ink); }
.seal::before { content: ""; position: absolute; inset: 2px; background: var(--table); }
.seal-ring, .seal-ring::before, .seal-circle, .seal-circle::before { border-radius: 50%; }
.seal-square, .seal-square::before { border-radius: 3px; }
.seal-triangle, .seal-triangle::before { clip-path: polygon(50% 6%, 97% 94%, 3% 94%); }
.seal-triangle::before { inset: 3px 4px 2px; }
.seal-ring::after { content: ""; position: absolute; inset: 34%; border-radius: 50%; background: var(--ink); }
[data-lamp="lit"] > .seal::before { background: var(--lamp); }
[data-lamp="waiting"] > .seal::before { background: var(--lamp-soft); }
[data-lamp="off"] > .seal { background: var(--line-strong); }
[data-lamp="off"] > .seal::after { content: ""; position: absolute; left: -10%; right: -10%; top: calc(50% - 1px); height: 2px; background: var(--ink); transform: rotate(-45deg); border-radius: 0; inset-block: auto; }
@media (prefers-reduced-motion: no-preference) { [data-lamp="working"] > .seal::before { animation: breathe 1.1s ease-in-out infinite; background: var(--lamp); } }
@media (prefers-reduced-motion: reduce) { [data-lamp="working"] > .seal::before { background: var(--lamp-soft); } }
.note .seal, .slip .seal { width: 1.125rem; height: 1.125rem; }
.note .seal::before { background: var(--table-2); }

/* The consent card: the exact request, before any contact. */
.ask-card { margin-top: 0.75rem; padding: 1rem; background: var(--sheet); border: 2px solid var(--ink); border-radius: 0.75rem; display: grid; gap: 0.5rem; }
.ask-card h3 { font-family: var(--proclaim); font-weight: 650; font-size: 1.25rem; line-height: 1.2; }
.ask-card p { font-size: 0.9375rem; }
.ask-request { padding: 0.625rem 0.75rem; background: var(--lamp-soft); border-radius: 0.375rem; font-size: 0.9375rem; line-height: 1.55; overflow-wrap: anywhere; }
.ask-keeps { color: var(--muted); }
.ask-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; margin-top: 0.25rem; }

.btn { border: 1.5px solid var(--ink); background: var(--sheet); border-radius: 999px; padding: 0.5rem 1.125rem; min-height: 2.75rem; cursor: pointer; font-weight: 500; }
.btn-primary { background: var(--ink); color: var(--sheet); }
.btn-small { min-height: 2.25rem; padding: 0.25rem 0.875rem; font-size: 0.875rem; margin-top: 0.5rem; width: fit-content; }
.btn-danger { background: var(--raise); border-color: var(--raise); color: #fff; }
.btn-danger-quiet { border-color: var(--raise); color: var(--raise); }
@media (prefers-reduced-motion: no-preference) { .btn:active, .chip:active { transform: scale(0.98); } }

/* The sheet. Each clause is one row: paper on the left, what was found on the right. */
.sheet-wrap { position: relative; }
.beam { position: absolute; left: 0; right: 0; top: 0; height: 22%; background: var(--lamp); mix-blend-mode: multiply; opacity: 0; pointer-events: none; z-index: 2; transform: translateY(-110%); }
@media (prefers-reduced-motion: no-preference) { .beam-run { animation: beam var(--story) ease-in-out; } }
@keyframes beam { 0% { transform: translateY(-110%); opacity: 0.55; } 100% { transform: translateY(470%); opacity: 0.55; } }

.sheet { min-height: 24rem; }
.sheet-head { background: var(--sheet); padding: 1.5rem 1.5rem 1rem; border-radius: 0.5rem 0.5rem 0 0; border-bottom: 1px solid var(--line); display: grid; gap: 0.375rem; }
.sheet-title { font-family: var(--ledger); font-weight: 400; font-size: 1.125rem; line-height: 1.4; }
.sheet-fiction, .sheet-redaction { font-size: 0.8125rem; color: var(--muted); }
.toggle { font-size: 0.875rem; display: inline-flex; align-items: center; gap: 0.5rem; min-height: 2rem; width: fit-content; cursor: pointer; }
.toggle input { width: 1.125rem; height: 1.125rem; accent-color: var(--ink); }
@media (min-width: 52rem) { .sheet-head { max-width: calc(100% - var(--notes)); } }

.sheet { --notes: 0rem; }
@media (min-width: 52rem) { .sheet { --notes: min(22rem, 40%); } }
.clause { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 52rem) { .clause { grid-template-columns: minmax(0, 1fr) var(--notes); } }
.clause-text { position: relative; background: var(--sheet); padding: 0.875rem 1.5rem 0.875rem 3.25rem; font-size: 1rem; line-height: 1.75; overflow-wrap: anywhere; }
.clause:last-child .clause-text { border-radius: 0 0 0.5rem 0.5rem; padding-bottom: 1.75rem; }
.clause-id { position: absolute; left: 1rem; top: 0.95rem; font-size: 0.8125rem; color: var(--muted); }
.clause[data-state="raise"] .clause-text { box-shadow: inset 4px 0 0 var(--raise); }
.clause[data-state="clear"] .clause-text { box-shadow: inset 4px 0 0 var(--clear); }
mark { background: var(--lamp); color: inherit; padding: 0.05em 0.2em; border-radius: 0.2em; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.clause-notes { display: grid; gap: 0.5rem; align-content: start; padding: 0.5rem 0 0.75rem; }
@media (min-width: 52rem) { .clause-notes { padding: 0.5rem 0 0.5rem 1rem; } }
.clause-notes:empty { padding: 0; }

.note { background: var(--table-2); border-left: 4px solid var(--line-strong); border-radius: 0 0.5rem 0.5rem 0; padding: 0.75rem 0.875rem; display: grid; gap: 0.375rem; font-size: 0.9375rem; }
.note[data-verdict="over"], .note[data-verdict="under"], .note[data-verdict="prohibited"] { border-left-color: var(--raise); }
.note[data-verdict="unclear"] { border-left-color: var(--amber); border-left-style: dashed; }
.note[data-verdict="within"] { border-left-color: var(--clear); }
.note[data-verdict="differs"] { border-left-color: var(--differs); }
.note-verdict { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; line-height: 1.35; }
.note[data-verdict="over"] .note-verdict, .note[data-verdict="under"] .note-verdict, .note[data-verdict="prohibited"] .note-verdict { color: var(--raise); }
.note[data-verdict="unclear"] .note-verdict { color: var(--amber); }
.note[data-verdict="within"] .note-verdict { color: var(--clear); }
.note[data-verdict="differs"] .note-verdict { color: var(--differs); }
.note-numbers { font-size: 0.9375rem; line-height: 1.55; }
.note-fx, .note-translation, .note-source { font-size: 0.8125rem; color: var(--muted); }
.note-rule + .note-rule { border-top: 1px solid var(--line); padding-top: 0.375rem; }
.note details { margin-top: 0.25rem; }
.note summary { cursor: pointer; font-size: 0.875rem; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; width: fit-content; min-height: 1.75rem; }
.note blockquote { margin: 0.375rem 0; padding-left: 0.75rem; border-left: 2px solid var(--line-strong); font-size: 0.875rem; line-height: 1.65; overflow-wrap: anywhere; }

.empty { background: var(--sheet); border: 2px dashed var(--line-strong); border-radius: 0.75rem; padding: 2.5rem 1.5rem; display: grid; gap: 0.75rem; justify-items: start; }
.empty h2 { font-family: var(--proclaim); font-weight: 650; font-size: 1.5rem; }

/* --- the slip: written for the person who signs -------------------------------------- */
.slip { margin: 3rem 0 0; max-width: 46rem; background: var(--sheet); border-top: 2px dashed var(--ink); border-radius: 0 0 0.75rem 0.75rem; padding: clamp(1.25rem, 1rem + 2vw, 2.5rem); display: grid; gap: 1rem; }
@media (min-width: 68rem) { .slip { margin-left: 21rem; } }
.slip h2 { font-family: var(--proclaim); font-weight: 680; font-size: clamp(2rem, 1.5rem + 2.4vw, 3.25rem); line-height: 1.04; letter-spacing: -0.02em; }
:lang(vi) .slip h2 { line-height: 1.18; }
.slip-open { font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.3125rem); line-height: 1.45; }
.slip-partial { color: var(--amber); font-weight: 500; }
.slip-part h3 { font-size: 0.875rem; font-weight: 600; color: var(--muted); margin-bottom: 0.5rem; }
.slip-questions { counter-reset: q; display: grid; gap: 1rem; }
.slip-questions > li { counter-increment: q; display: grid; grid-template-columns: 2rem minmax(0, 1fr); column-gap: 0.25rem; }
.slip-questions > li::before { content: counter(q); font-family: var(--proclaim); font-weight: 650; font-size: 1.25rem; line-height: 1.5; grid-row: span 2; }
.slip-q { font-style: italic; font-size: 1.0625rem; line-height: 1.55; }
.slip-ref, .slip-source, .slip-note { font-size: 0.8125rem; color: var(--muted); }
.slip-part ul { display: grid; gap: 0.5rem; padding-left: 1.125rem; list-style: disc; font-size: 0.9375rem; }
.slip-agency { font-size: 0.9375rem; }
.slip-proof { font-size: 0.8125rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 0.75rem; }
.slip-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; }

/* --- limits, console, footer --------------------------------------------------------- */
.limits { margin-top: 4rem; display: grid; gap: 2rem; border-top: 1px solid var(--line-strong); padding-top: 2rem; }
@media (min-width: 52rem) { .limits { grid-template-columns: 1fr 1fr; gap: 3rem; } }
.limits h2 { font-family: var(--proclaim); font-weight: 650; font-size: 1.5rem; line-height: 1.2; margin-bottom: 0.75rem; }
.limits ul { display: grid; gap: 0.75rem; padding-left: 1.125rem; list-style: disc; max-width: 62ch; }

.console { margin-top: 3rem; border: 1px solid var(--line-strong); border-radius: 0.75rem; background: var(--table-2); }
.console > summary { cursor: pointer; padding: 1rem 1.25rem; font-weight: 600; min-height: 3rem; }
.console-note, .console-status { padding: 0 1.25rem 0.75rem; font-size: 0.9375rem; color: var(--muted); max-width: 70ch; }
.console-status { font-size: 0.8125rem; }
.console #agent-app { padding: 0 1.25rem 1.25rem; }

.foot { max-width: var(--frame); margin: 0 auto; padding: 1.5rem var(--gutter) 3rem; font-size: 0.875rem; color: var(--muted); border-top: 1px solid var(--line); }

/* --- dialogs ------------------------------------------------------------------------- */
dialog.confirm { border: 2px solid var(--ink); border-radius: 0.875rem; padding: 1.5rem; max-width: min(34rem, calc(100vw - 2rem)); width: 100%; background: var(--sheet); color: var(--ink); }
dialog.confirm::backdrop { background: rgba(22, 34, 59, 0.55); }
dialog.confirm h2 { font-family: var(--proclaim); font-weight: 650; font-size: 1.5rem; line-height: 1.2; margin-bottom: 0.5rem; }
dialog.confirm dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 1rem 0; }
dialog.confirm dt { color: var(--muted); }
dialog.confirm dd { margin: 0; font-weight: 600; }
dialog.confirm pre { font-family: var(--ledger); font-size: 0.8125rem; white-space: pre-wrap; overflow-wrap: anywhere; }
dialog.confirm details { margin-bottom: 1rem; font-size: 0.875rem; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; margin-top: 1rem; }
.paste form { display: grid; gap: 0.5rem; }
.paste label { font-size: 0.9375rem; font-weight: 500; margin-top: 0.5rem; }
.paste textarea, .paste input { font: inherit; font-family: var(--ledger); width: 100%; border: 1.5px solid var(--line-strong); border-radius: 0.5rem; padding: 0.625rem 0.75rem; background: #fff; color: var(--ink); }
.paste-note { font-size: 0.875rem; color: var(--muted); }
.field-error { color: var(--raise); font-size: 0.9375rem; }

/* --- print: the slip alone, on one page ---------------------------------------------- */
@media print {
  html { background: #fff; }
  .proof, .top, .hero, .table, .limits, .console, .foot, .slip-actions { display: none !important; }
  main { padding: 0; }
  .slip { margin: 0; border: 0; padding: 0; max-width: none; }
  a { text-decoration: none; }
  .slip-source::after, .slip-ref a[href^="http"]::after { content: " <" attr(href) ">"; font-family: var(--ledger); font-size: 0.6875rem; overflow-wrap: anywhere; }
}
