:root {
  color-scheme: light;
  --page: #f6f7f4; --surface: #fcfcfb; --surface-2: #eef0ec; --ink: #131514; --ink-2: #52514e; --muted: #7d7b75;
  --line: #dfded7; --accent: #0b6f5b; --accent-ink: #fff; --accent-soft: #e2f1ec; --bad: #b3261e; --bad-soft: #fbe9e7;
  --warn-soft: #fdf3dc; --warn-ink: #7a5300; --good-soft: #e3f3e3; --good-ink: #1d6b1d;
  --radius: 14px; --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Sukhumvit Set", "Thonburi", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e; --surface: #1a1a19; --surface-2: #242422; --ink: #f4f4f1; --ink-2: #c3c2b7; --muted: #92908a;
    --line: #2f2f2c; --accent: #3fbf9c; --accent-ink: #06231c; --accent-soft: #15302a; --bad: #f2877e; --bad-soft: #3a1a17;
    --warn-soft: #33290f; --warn-ink: #f2c865; --good-soft: #15301a; --good-ink: #8fd88f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.55 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 6px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand .mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; flex: none; }
.brand b { display: block; font-size: 16px; line-height: 1.25; }
.brand small { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.top-r { display: flex; align-items: center; gap: 8px; flex: none; }
.net { font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.net.on { background: var(--good-soft); color: var(--good-ink); }
.net.off { background: var(--warn-soft); color: var(--warn-ink); }
@media (max-width: 560px) { .brand small { display: none; } .net.on { display: none; } }

.wrap { max-width: 880px; margin: 0 auto; padding: 20px 16px 48px; }
.wrap.narrow { max-width: 560px; }
h1 { font-size: 21px; line-height: 1.35; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; font-size: 17px; flex: 1 1 240px; }
.btn.tiny { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.notice { background: var(--warn-soft); color: var(--warn-ink); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 15px; }
.notice a { color: inherit; font-weight: 600; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.good { background: var(--good-soft); color: var(--good-ink); }
.hero { display: flex; flex-wrap: wrap; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { color: var(--ink-2); font-size: 13px; }
.list { display: grid; gap: 8px; }
.rec { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.rec-main { flex: 1; min-width: 0; color: var(--ink); text-decoration: none; }
.rec-main b { display: block; }
.rec-main small { display: block; color: var(--ink-2); font-size: 13px; }
.rec-main .err { color: var(--bad); }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--line); }
.chip.ready { background: var(--warn-soft); color: var(--warn-ink); border-color: transparent; }
.chip.sent { background: var(--good-soft); color: var(--good-ink); border-color: transparent; }
.empty { color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.fine { color: var(--muted); font-size: 13px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; color: var(--ink-2); font-size: 14px; }

/* form layout: section list on the side (tablet/desktop), a scrolling strip on phones */
.form-layout { display: grid; grid-template-columns: 250px 1fr; max-width: 1180px; margin: 0 auto; gap: 24px; padding: 16px; }
.secnav { position: sticky; top: 76px; align-self: start; display: grid; gap: 2px; max-height: calc(100vh - 96px); overflow: auto; }
.sec { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.sec:hover { background: var(--surface-2); }
.sec .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: var(--surface-2); color: var(--ink-2); }
.sec .c { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sec.full .n { background: var(--accent-soft); color: var(--accent); }
.sec.cur { background: var(--accent); color: var(--accent-ink); }
.sec.cur .n { background: color-mix(in srgb, var(--accent-ink) 25%, transparent); color: var(--accent-ink); }
.sec.cur .c { color: inherit; opacity: .8; }
.form-main { min-width: 0; max-width: 820px; }
.rec-info { color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
@media (max-width: 900px) {
  .form-layout { grid-template-columns: 1fr; padding: 0 0 16px; gap: 0; }
  .secnav { position: sticky; top: 58px; z-index: 20; display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; background: var(--page); border-bottom: 1px solid var(--line); max-height: none; scrollbar-width: none; }
  .secnav::-webkit-scrollbar { display: none; }
  .sec { grid-template-columns: auto auto; flex: none; padding: 6px 12px; background: var(--surface); border: 1px solid var(--line); }
  .sec .c { display: none; }
  .form-main { padding: 12px 16px; }
}

/* questions */
.snote { color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.q.done { border-left: 4px solid var(--accent); }
.qhead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-bottom: 10px; }
.qno { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.qt { font-weight: 600; flex: 1 1 260px; }
.req { color: var(--bad); font-weight: 700; }
.tag { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 1px 9px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 8px; }
.opts { display: grid; gap: 8px; }
@media (min-width: 640px) { .opts.many { grid-template-columns: 1fr 1fr; } }
.opt { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-height: 48px; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.opt:hover { border-color: var(--muted); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .code { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--surface-2); color: var(--ink-2); flex: none; }
.opt .lbl { flex: 1; min-width: 0; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt.on .code { background: var(--accent); color: var(--accent-ink); }
.opt.excl .lbl { font-style: italic; }
.opt:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.opt input.other, .opt .other { position: static; opacity: 1; pointer-events: auto; flex: 1 1 100%; }
input[type="text"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
  width: 100%; min-height: 46px; padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px; }
input.warn, .computed.warn { border-color: #d98e00; background: var(--warn-soft); }
.num { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.num input { max-width: 180px; }
.unit { color: var(--ink-2); font-size: 14px; }
.row3 { display: grid; grid-template-columns: 90px 1fr 130px; gap: 8px; margin-bottom: 10px; }
.computed { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); border: 1.5px solid transparent; }
.fixed { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.clear { margin-top: 2px; justify-self: start; background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; padding: 4px 2px; }
.grid, .animals { display: grid; gap: 10px; }
.grow, .arow { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.grow:first-child, .arow:first-child { border-top: 0; }
.glabel { min-width: 0; }
.glabel .qno { margin-right: 6px; font-size: 13px; }
.gopts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt.small { min-height: 42px; padding: 6px 12px; }
.afields { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }
.afields label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; }
.afields input { width: 100px; }
.gopts .opt.small { flex: 0 1 auto; }
@media (max-width: 700px) { .gopts .opt.small { flex: 1 1 auto; } }
.pager { display: flex; justify-content: space-between; gap: 10px; margin: 20px 0; flex-wrap: wrap; }
.review .rv { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.review .rv a { font-weight: 600; display: block; }
.review .rv small { color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 40px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 12px; max-width: min(92vw, 520px); transition: .2s; z-index: 50; font-size: 15px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }
#selftest { white-space: pre-wrap; font: 12px ui-monospace, monospace; padding: 16px; }
