:root {
  --paper: #f5f2ea;
  --surface: #fffdf8;
  --ink: #16213a;
  --ink-soft: #4a556d;
  --line: #ddd6c6;
  --navy: #16213a;
  --brass: #8a5a14;
  --brass-soft: #f3e7d1;
  --ok: #1d6b47;
  --ok-soft: #e0f0e7;
  --warn: #8a5a14;
  --bad: #a3271f;
  --bad-soft: #f8e3e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 33, 58, 0.06), 0 8px 24px rgba(22, 33, 58, 0.06);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10141d;
    --surface: #181e2b;
    --ink: #ece7db;
    --ink-soft: #a6adbd;
    --line: #2c3547;
    --navy: #e3c78e;
    --brass: #e3c78e;
    --brass-soft: #2e2818;
    --ok: #6fcf9b;
    --ok-soft: #173024;
    --bad: #f08b83;
    --bad-soft: #3a1b19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 0.9em; }
a { color: var(--brass); }
small, .muted { color: var(--ink-soft); }
.mono { font-family: var(--mono); font-size: 0.82em; word-break: break-all; }
.hidden { display: none !important; }

/* ---- layout ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand svg { width: 28px; height: 28px; color: var(--brass); }
.topbar nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.topbar nav a, .linkish { color: var(--ink-soft); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 0.93rem; background: none; border: 0; cursor: pointer; font-family: inherit; }
.topbar nav a:hover, .linkish:hover { background: var(--paper); color: var(--ink); }
main { max-width: 920px; margin: 0 auto; padding: 28px 16px 80px; }
main.narrow { max-width: 620px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.card > :last-child { margin-bottom: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } h1 { font-size: 1.55rem; } .card { padding: 18px; } }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: 0.92rem; margin-bottom: 5px; }
label .hint { display: block; font-weight: 400; color: var(--ink-soft); font-size: 0.86rem; margin-top: 2px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 11px 12px; font: inherit; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--brass); outline-offset: 2px;
}
.code-input { font-family: var(--mono); font-size: 1.7rem !important; letter-spacing: 0.35em; text-align: center; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-weight: 400; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--ok); }
.check.locked { opacity: 0.55; cursor: not-allowed; }
.secret-field { border-left: 4px solid var(--brass); padding-left: 14px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; min-height: 48px; padding: 10px 18px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--ink-soft); }
button.primary, .btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.seal { background: var(--ok); color: #fff; border-color: var(--ok); font-size: 1.05rem; min-height: 56px; width: 100%; }
@media (prefers-color-scheme: dark) { button.seal { color: #0c1a13; } }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.block { width: 100%; }

/* ---- feedback ---- */
.notice { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--brass-soft); font-size: 0.94rem; }
.notice.ok { background: var(--ok-soft); border-color: transparent; }
.notice.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.error { color: var(--bad); font-weight: 600; min-height: 1.3em; margin: 8px 0 0; font-size: 0.93rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; background: var(--brass-soft); color: var(--brass); }
.badge.signed { background: var(--ok-soft); color: var(--ok); }
.badge.revoked, .badge.expired { background: var(--bad-soft); color: var(--bad); }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.item { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 14px 4px; color: inherit; text-decoration: none; }
.list a.item:hover { background: var(--paper); }
.empty { text-align: center; padding: 34px 10px; color: var(--ink-soft); }
dl.facts { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 6px 16px; margin: 0; font-size: 0.94rem; }
dl.facts dt { color: var(--ink-soft); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) { dl.facts { grid-template-columns: 1fr; gap: 0; } dl.facts dd { margin-bottom: 8px; } }

/* ---- the agreement ---- */
.agreement { font-family: var(--serif); font-size: 1.02rem; line-height: 1.65; }
.agreement h2 { text-align: center; font-size: 1.2rem; margin-bottom: 2px; }
.agreement .subtitle { text-align: center; font-style: italic; color: var(--ink-soft); margin-bottom: 1.2em; }
.agreement h3 { font-family: var(--serif); font-size: 0.98rem; text-transform: uppercase; letter-spacing: 0.04em; margin: 1.5em 0 0.5em; }
.agreement .clause { margin: 0 0 0.8em; }
.agreement .clause b { font-family: var(--sans); font-size: 0.84em; color: var(--ink-soft); margin-right: 6px; }
.agreement .schedule { border-top: 2px solid var(--line); margin-top: 1.6em; padding-top: 1em; }
.scrollbox { max-height: 62vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 20px; background: var(--paper); overscroll-behavior: contain; }
.progress-read { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress-read span { display: block; height: 100%; width: 0; background: var(--ok); }

/* ---- signing wizard ---- */
.steps { display: flex; gap: 6px; margin: 0 0 22px; padding: 0; list-style: none; }
.steps li { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps li.done { background: var(--ok); }
.steps li.now { background: var(--brass); }
.step-label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brass); margin-bottom: 4px; }
.stage { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.stage video, .stage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage video.mirror { transform: scaleX(-1); }
.stage .rec { position: absolute; top: 12px; left: 12px; background: #b3261e; color: #fff; font-weight: 700; font-size: 0.85rem; padding: 4px 10px; border-radius: 999px; font-family: var(--mono); }
.statement { font-family: var(--serif); font-size: 1.15rem; line-height: 1.6; border-left: 4px solid var(--brass); padding: 4px 0 4px 16px; margin: 0; }
.sigpad { width: 100%; height: 200px; background: #fff; border: 1px dashed #8a8a8a; border-radius: 8px; touch-action: none; display: block; cursor: crosshair; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 7px 0 7px 30px; position: relative; border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.checklist li::before { content: "○"; position: absolute; left: 4px; color: var(--ink-soft); }
.checklist li.ok::before { content: "✓"; color: var(--ok); font-weight: 700; }
.checklist li.fail::before { content: "✕"; color: var(--bad); font-weight: 700; }
.checklist li small { display: block; }
.sealmark { display: flex; gap: 16px; align-items: center; }
.sealmark svg { width: 64px; height: 64px; color: var(--ok); flex: none; }

/* ---- confidential viewer ---- */
.vault { position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.vault .content { white-space: pre-wrap; font-family: var(--serif); font-size: 1.05rem; position: relative; z-index: 1; }
.vault .marks { position: absolute; inset: -40%; display: flex; flex-wrap: wrap; gap: 46px 30px; transform: rotate(-24deg); pointer-events: none; z-index: 2; opacity: 0.13; font-size: 0.78rem; font-family: var(--mono); align-content: flex-start; }
@media print { .vault { display: none !important; } }

/* ---- timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 16px 14px; font-size: 0.93rem; }
.timeline li::before { content: ""; position: absolute; left: -24px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brass); border: 2px solid var(--surface); }
.timeline li.key::before { background: var(--ok); }
.timeline .when { color: var(--ink-soft); font-size: 0.84rem; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.media-grid figure { margin: 0; }
.media-grid img, .media-grid video { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: block; }
.media-grid figcaption { font-size: 0.84rem; color: var(--ink-soft); margin-top: 4px; }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 220px; height: 220px; display: block; }
.codes { columns: 2; font-family: var(--mono); font-size: 1rem; list-style: none; padding: 14px; margin: 0; background: var(--paper); border-radius: 8px; border: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: -6px 0 18px; }
.tabs button { border: 0; background: none; border-bottom: 3px solid transparent; border-radius: 0; color: var(--ink-soft); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brass); }
pre.mail { white-space: pre-wrap; font-family: var(--mono); font-size: 0.84rem; background: var(--paper); padding: 12px; border-radius: 8px; margin: 8px 0 0; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: no-preference) { .steps li, .progress-read span { transition: background 0.2s, width 0.15s; } }

/* ---- saved work, search, reuse ---- */
.saved { color: var(--ok); font-weight: 600; min-height: 1.3em; margin: 8px 0 0; font-size: 0.93rem; }
input[type="search"] { width: 100%; padding: 12px 14px; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { min-height: 38px; padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 0.88rem; white-space: nowrap; background: var(--paper); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.list .kind { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7rem; font-weight: 700; color: var(--brass); }
.list .note { color: var(--brass); }
.list .right { text-align: right; flex: none; }
.badge.draft { background: var(--paper); color: var(--ink-soft); border: 1px dashed var(--ink-soft); }
.badge.ready { background: var(--brass-soft); color: var(--brass); }
.step-head { margin-bottom: 4px; }
.step-head .step-label { margin: 0; }
.save-later { min-height: 38px; padding: 6px 12px; font-size: 0.86rem; background: var(--paper); }
.qr-box { text-align: center; border: 2px solid var(--brass); border-radius: var(--radius); padding: 16px; }
.qr.big { width: min(320px, 80vw); height: auto; aspect-ratio: 1; margin: 0 auto 8px; }
.split > * { min-width: 0; }

/* Phone: keep the main actions within thumb reach while a long form scrolls. */
@media (max-width: 699px) {
  .sticky-actions { position: sticky; bottom: 0; z-index: 5; background: var(--paper); padding: 10px 0 max(10px, env(safe-area-inset-bottom)); margin: 0 -2px; }
  .sticky-actions > * { flex: 1 1 auto; }
}

/* ---- Galaxy Z Fold: unfolded inner screen (nearly square, ~840 CSS px wide) ---- */
@media (min-width: 700px) {
  main { max-width: 1180px; }
  main.narrow { max-width: 680px; }
  .split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
  .split > .card, .split > form.card { position: sticky; top: 12px; max-height: calc(100dvh - 24px); overflow-y: auto; }
  .scrollbox { max-height: 68vh; }
}

/* ---- Fold half-open ("Flex mode" / tabletop): camera on the top half, controls below the hinge ---- */
@media (vertical-viewport-segments: 2) {
  body.capture main {
    padding-top: 8px;
  }
  body.capture .stage {
    aspect-ratio: auto;
    height: calc(env(viewport-segment-bottom 0 0, 50vh) - 80px);
  }
  body.capture .stage ~ * { scroll-margin-top: env(viewport-segment-top 0 1, 50vh); }
}
.steps-list { margin: 0; padding-left: 22px; } .steps-list li { margin: 0 0 8px; }

/* ---- legal pages ---- */
main.legal { max-width: 760px; }
main.legal h2 { margin-top: 1.6em; }
main.legal h3 { margin-top: 1.1em; font-family: var(--sans); font-size: 1rem; }
main.legal ul { padding-left: 22px; }
main.legal li { margin-bottom: 6px; }
main.legal .notice { margin: 1em 0; }
.legal-footer { text-align: center; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); color: var(--ink-soft); font-size: 0.9rem; border-top: 1px solid var(--line); }
.cta-box { border: 2px solid var(--brass); border-radius: var(--radius); background: var(--surface); padding: 20px; margin: 1.2em 0; }
.cta-box .cta-main { font-size: 1.25rem; font-family: var(--serif); margin-bottom: 0.6em; }
.cta-box .cta-fine { font-size: 0.92rem; color: var(--ink-soft); margin: 0; }
.sample { display: block; margin-top: 6px; padding: 8px 12px; background: var(--paper); border-left: 3px solid var(--brass); border-radius: 4px; font-size: 0.93rem; }
.cta-box .cta-consent { font-size: 1rem; margin: 0 0 0.6em; }
