/* Shared design tokens + components (v1 public page and v2 research app).
   No web fonts, no third-party requests: system font stack only. */
:root {
  color-scheme: light dark;
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --ink: #1b2226;
  --muted: #5a656d;
  --line: #e1dcd4;
  --accent: #0d6468;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ef;
  --warn: #8a5200;
  --warn-bg: #fff3dc;
  --danger: #9e2a22;
  --danger-bg: #fcebe8;
  --ok: #1e6a3b;
  --ok-bg: #e5f3ea;
  --focus: #1f7ae0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(20 30 35 / 6%), 0 6px 24px rgb(20 30 35 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111618; --surface: #182024; --surface-2: #1f292e; --ink: #e6ecee; --muted: #9fb0b7;
    --line: #2b373d; --accent: #4fb3b5; --accent-ink: #06201f; --accent-soft: #173336;
    --warn: #f0b566; --warn-bg: #33270f; --danger: #f08b82; --danger-bg: #3a1a17;
    --ok: #7fd09d; --ok-bg: #16301f; --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  /* no double-tap zoom / 300 ms delay anywhere; pinch zoom stays (accessibility) */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* no accidental pull-to-refresh mid-flow (Android Chrome) */
  overscroll-behavior-y: none;
}
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--font);
  -webkit-font-smoothing: antialiased; overflow-wrap: break-word;
}
button, .btn, label, summary, .shutter { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html:has(dialog[open]) { overflow: hidden; }
img, video, canvas, svg { max-width: 100%; display: block; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 650; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 .9em; }
small, .small { font-size: .88rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* layout */
.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.topbar { padding-top: env(safe-area-inset-top); }
.topbar .container { display: flex; align-items: center; gap: 12px; height: 56px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.brand { font-weight: 650; color: var(--ink); text-decoration: none; font-size: .98rem; display: inline-flex; align-items: center; gap: .3em; min-height: 44px; }
.brand span { color: var(--muted); font-weight: 500; }
.lang { margin-left: auto; display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button { border: 0; background: transparent; color: var(--muted); font: 600 .85rem var(--font); padding: 0 12px; cursor: pointer; min-height: 44px; min-width: 46px; }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* cards + notices */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.notice { border-radius: var(--radius-sm); padding: 14px 16px; border: 1px solid transparent; }
.notice > :last-child { margin-bottom: 0; }
.notice.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.notice.warn { background: var(--warn-bg); color: var(--ink); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice.danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.notice.ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.notice strong.label { display: block; margin-bottom: 4px; }
.notice.danger strong.label { color: var(--danger); }
.notice.warn strong.label { color: var(--warn); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 600 1rem var(--font); cursor: pointer; text-decoration: none; touch-action: manipulation; }
.btn:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 44px; padding: 0 16px; font-size: .92rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 20px; height: 20px; }

/* forms */
label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 1rem var(--font); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg label { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 0 16px; min-height: 44px; cursor: pointer; font-size: .95rem; background: var(--surface); }
.seg input { accent-color: var(--accent); margin: 0; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* dialog */
dialog.modal { border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
dialog.modal::backdrop { background: rgb(10 16 18 / 55%); }
dialog.modal .inner { padding: 22px; overflow: auto; max-height: calc(100dvh - 24px); }
dialog.modal ul { padding-left: 1.2em; margin: 0 0 1em; }
dialog.modal .actions { position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end; padding: 12px 0 0; background: var(--surface); }
/* bottom sheet on phones */
@media (max-width: 600px) {
  dialog.modal.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; }
  dialog.modal.sheet .inner { max-height: 92dvh; padding: 20px 16px max(16px, env(safe-area-inset-bottom)); }
  dialog.modal.sheet .actions .btn { flex: 1; }
}
dialog.modal li { margin: .35em 0; }

/* steps */
ol.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
ol.steps li { counter-increment: s; position: relative; padding: 0 0 14px 44px; }
ol.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: .9rem; }

/* camera */
.cam { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.cam .guide { position: absolute; inset: 0; pointer-events: none; }
.cam .hint { position: absolute; left: 12px; right: 12px; bottom: 12px; background: rgb(0 0 0 / 62%); color: #fff;
  border-radius: 12px; padding: 10px 12px; font-weight: 600; text-align: center; font-size: .98rem; }
.cam .hint.good { background: rgb(18 104 60 / 85%); }
.cam .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.cam .flash.on { opacity: .85; transition: none; }
.cam-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 12px; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--accent); background: var(--surface);
  box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 40px var(--accent); cursor: pointer; }
.shutter:active { transform: scale(.96); }
.shutter[disabled] { opacity: .45; }

/* result figures */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair figure, .strip { margin: 0; }
.pair canvas, .strip canvas { width: 100%; height: auto; border-radius: var(--radius-sm); background: #000; }
figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; text-align: center; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ref-grid figure { margin: 0; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; }
.ref-grid figcaption { text-align: left; color: var(--ink); }
.ref-grid figcaption b { display: block; font-size: .9rem; }
.ref-grid figcaption span { color: var(--muted); font-size: .82rem; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

footer.site { margin: 40px 0 0; padding: 24px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; }
footer.site p { margin: 0 0 .5em; }
footer.site a { display: inline-block; padding: 14px 2px; margin: -14px 0; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--danger-bg); color: var(--danger); }
.mono { font-family: var(--mono); font-size: .9em; }
@media (max-width: 420px) { .brand span { display: none; } }
main section, #resBox, #camBox { scroll-margin-top: 72px; }
