:root {
  --navy: #16385e; --ink: #1a2332; --muted: #5b6472; --page: #faf9f7; --card: #ffffff;
  --border: #d9d4cb; --teal: #4a9b8e; --teal-dark: #3a7f74; --gold: #c9a858; --gold-tint: #f6eed9;
  --error: #a4513f; --error-tint: #f7e9e5; --focus: #2156a6;
  --sans: 'Inter', 'Noto Sans Thai', Tahoma, sans-serif;
  --serif: 'Newsreader', 'Noto Sans Thai', Georgia, serif;
  --r-sm: 8px; --r-md: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 20px; }
h2, h3 { margin: 0; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar { background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top, 0px); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: 24px; letter-spacing: 0.04em; }
.lang { background: transparent; border: 1px solid rgba(255,255,255,.45); color: #fff; border-radius: var(--r-sm); padding: 6px 14px; font-size: 15px; cursor: pointer; }

/* The one bold element: the navy band that carries the step title and progress. */
.step-head { background: var(--navy); color: #fff; margin: 0 -20px; padding: 8px 20px 44px; }
.stage { font-size: 15px; color: #c3d0de; }
.step-head h2 { font-family: var(--serif); font-weight: 600; font-size: 32px; line-height: 1.15; margin: 4px 0 18px; outline: none; }
.progress { height: 6px; background: rgba(255,255,255,.18); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--teal); border-radius: 3px; transition: width .3s ease; }
.step-count { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: #c3d0de; margin-top: 8px; }
#save-state[data-state="failed"] { color: #f2c9bf; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); padding: 24px 20px 28px; margin-top: -28px; position: relative; }
.intro { color: var(--muted); margin-bottom: 20px; }
.for-whom { border-left: 4px solid var(--gold); background: var(--gold-tint); border-radius: 0 var(--r-sm) var(--r-sm) 0; padding: 12px 16px; margin-bottom: 20px; }
.for-label { font-size: 14px; color: var(--muted); }
.for-name { font-family: var(--serif); font-size: 24px; font-weight: 600; line-height: 1.25; }

.fields { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label, legend { font-weight: 500; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; }
.opt { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 8px; }
.help { font-size: 15px; color: var(--muted); }
.subhead { font-family: var(--serif); font-size: 22px; font-weight: 600; padding-top: 14px; border-top: 1px solid var(--border); margin-top: 6px; }

input[type=text], input[type=email], input[type=tel], input[type=date], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-sm); background: #fff; }
textarea { resize: vertical; }
input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--error); }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: flex-start; gap: 12px; min-height: 48px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-sm); background: #fff; cursor: pointer; }
.choice input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--teal-dark); flex: none; }
.choice:has(input:checked) { border-color: var(--teal-dark); background: #eef6f4; }
.choice.check { border-style: solid; }

.masked { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: var(--r-sm); background: var(--page); }
.link { background: none; border: 0; padding: 4px 2px; color: var(--focus); text-decoration: underline; cursor: pointer; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.file-btn { display: flex; align-items: center; justify-content: center; min-height: 56px; padding: 12px; border: 1px dashed var(--muted); border-radius: var(--r-sm); background: var(--page); cursor: pointer; text-align: center; }
input[type=file]:focus-visible + .file-btn { outline: 3px solid var(--focus); outline-offset: 2px; }
.file-state { padding: 10px 14px; border-radius: var(--r-sm); font-size: 15px; word-break: break-all; }
.file-state.done { background: #eef6f4; border: 1px solid var(--teal); }
.file-state.uploading { --p: 0%; border: 1px solid var(--border); background: linear-gradient(90deg, var(--gold-tint) var(--p), #fff var(--p)); }

.repeat { border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px; display: flex; flex-direction: column; gap: 20px; }
.repeat > legend { font-family: var(--serif); font-size: 20px; font-weight: 600; padding: 0 6px; }

.error { color: var(--error); font-size: 15px; }
.warn { background: var(--gold-tint); border-left: 4px solid var(--gold); padding: 10px 12px; font-size: 15px; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.alert { background: var(--error-tint); color: var(--error); padding: 12px 14px; border-radius: var(--r-sm); margin-bottom: 18px; }

.nav { display: flex; gap: 12px; margin: 20px 0 8px; }
.btn { min-height: 52px; padding: 12px 22px; border-radius: var(--r-sm); border: 1px solid transparent; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--teal-dark); color: #fff; flex: 1; }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: #fff; border-color: var(--border); }
.expiry { font-size: 14px; color: var(--muted); text-align: center; margin: 8px 0 40px; }

.review { display: flex; flex-direction: column; gap: 18px; }
.review-block { border-top: 1px solid var(--border); padding-top: 14px; }
.review-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.review-head h3 { font-family: var(--serif); font-size: 20px; font-weight: 600; }
dl { margin: 0; display: grid; grid-template-columns: 1fr; gap: 2px 16px; }
dt { font-size: 14px; color: var(--muted); margin-top: 8px; }
dd { margin: 0; word-break: break-word; }
dd.empty { color: var(--muted); font-style: italic; }
@media (min-width: 560px) { dl { grid-template-columns: 44% 1fr; } dt { margin-top: 6px; } dd { margin-top: 6px; } }

.message { padding: 56px 4px; }
.message h2 { font-family: var(--serif); font-size: 30px; font-weight: 600; line-height: 1.2; margin-bottom: 12px; outline: none; }
.message p { color: var(--muted); margin-bottom: 24px; }
.message.done h2 { color: var(--teal-dark); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.has-error .choice, .has-error .file-btn { border-color: var(--error); }
