:root {
  --ink: #1e2422;
  --sub: #59605d;
  --faint: #8a908d;
  --line: #e3dfd6;
  --line2: #cfcac0;
  --band: #f5f3ee;
  --accent: #2e6656;
  --accent-ink: #ffffff;
  --accent-tint: #e9f1ed;
  --warn: #8a5a12;
  --warn-tint: #fbf3e2;
  --f: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: #fff; color: var(--ink);
  font: 400 17px/1.6 var(--f);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { max-width: 660px; margin: 0 auto; padding: 0 20px; }

/* 頂端進度 */
.progress { position: sticky; top: 0; z-index: 5; height: 3px; background: var(--band); pointer-events: none; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.inapp { background: var(--warn-tint); color: var(--warn); font-size: 15px; padding: 12px 20px; }
.inapp a { color: inherit; font-weight: 600; }

/* 頁首 */
.top { padding: 34px 0 22px; }
.clinic { margin: 0 0 4px; font-size: 15px; color: var(--sub); font-weight: 600; }
h1 { margin: 0; font-size: 26px; line-height: 1.3; font-weight: 700; letter-spacing: .02em; }
.lede { margin: 10px 0 0; color: var(--sub); font-size: 15px; }
.restored { margin: 14px 0 0; padding: 12px 14px; background: var(--accent-tint); border-radius: 10px; font-size: 15px; }

/* 每一段 */
.sec { padding: 26px 0 24px; border-top: 1px solid var(--line); }
.sec h2 { margin: 0 0 14px; font-size: 20px; line-height: 1.35; font-weight: 700; display: flex; align-items: baseline; flex-wrap: wrap; }
.sec h2 .no { color: var(--accent); font-weight: 700; }
.sec h2 small { font-size: 13px; color: var(--faint); font-weight: 400; margin-left: 10px; }
.rl { margin: 16px 0 8px; font-size: 15px; color: var(--sub); }
.rl:first-child { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.chip { position: relative; display: inline-flex; flex-direction: column; justify-content: center; min-height: 46px; padding: 9px 16px;
  border: 1.5px solid var(--line2); border-radius: 23px; background: #fff; line-height: 1.35; user-select: none; -webkit-user-select: none; }
.chip.has-hint { border-radius: 14px; }
.chip small { font-size: 13px; color: var(--faint); margin-top: 2px; }
/* 只藏選項本身的勾選框；框裡的填空（.fill input）要看得到、點得到 */
.chip > input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip:has(> input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: rgba(255,255,255,.82); }
.chip:has(> input[type="checkbox"]:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) { .chip:hover { border-color: var(--accent); } }

/* 有填空的選項：勾選後填空出現在同一個框裡 */
.chip.has-fill { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 10px; row-gap: 2px; }
.fill { display: inline-flex; align-items: baseline; gap: 6px; font-size: 15px; cursor: text; }
.fill input { width: 3.2em; font-size: 17px; color: var(--ink); text-align: center; border: 0; border-bottom: 1.5px solid var(--line2); border-radius: 0; padding: 2px; background: transparent; outline: none; }
.fill input.w8 { width: 7.5em; text-align: left; }
.chip.on .fill input { color: #fff; border-bottom-color: rgba(255,255,255,.8); caret-color: #fff; }
.chip.on .fill input:focus { border-bottom-color: #fff; }
.fld input:focus { border-bottom-color: var(--accent); }

.fld { display: grid; grid-template-columns: 6.5em 1fr; align-items: baseline; gap: 12px; margin-top: 14px; }
.fld > span:first-child { font-size: 15px; color: var(--sub); }
.fld .in { display: flex; align-items: baseline; gap: 8px; color: var(--sub); font-size: 15px; }
.fld input { width: 100%; min-width: 0; font-size: 17px; color: var(--ink); border: 0; border-bottom: 1.5px solid var(--line2); border-radius: 0; padding: 7px 2px; background: transparent; outline: none; }
.fld input.num { width: 4.5em; text-align: center; }
.fld input[type="date"] { width: auto; min-height: 40px; }
.fld.stack { grid-template-columns: 1fr; gap: 4px; }

textarea { display: block; width: 100%; min-height: 96px; resize: vertical; font-size: 17px; line-height: 1.55; padding: 10px 12px;
  border: 1.5px solid var(--line2); border-radius: 10px; background: #fff; outline: none; }
textarea:focus { border-color: var(--accent); }

.note { margin-top: 16px; }
.note .add { border: 0; background: none; padding: 6px 0; color: var(--accent); font-size: 15px; font-weight: 600; }
.note textarea { min-height: 80px; }
.note .nl { display: block; font-size: 15px; color: var(--sub); margin: 0 0 6px; }

/* 性別 */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg .chip { border-radius: 12px; align-items: center; }

/* 舌頭照片 */
.tips { margin: 0 0 16px; padding: 0 0 0 1.2em; color: var(--sub); font-size: 15px; }
.tips li { margin: 2px 0; }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ph .drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; aspect-ratio: 3 / 4;
  border: 1.5px dashed var(--line2); border-radius: 14px; color: var(--sub); text-align: center; padding: 10px; cursor: pointer; }
.ph .drop svg { width: 30px; height: 30px; stroke: var(--accent); }
.ph .drop b { color: var(--ink); font-size: 17px; }
.ph .drop small { font-size: 13px; color: var(--faint); line-height: 1.4; }
.ph .drop input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.ph .drop:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.ph figure { margin: 0; }
.ph figure img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: var(--band); border-radius: 14px; border: 1px solid var(--line); }
.ph figcaption { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 15px; }
.ph figcaption b { flex: 1; font-weight: 600; }
.ph figcaption button { border: 0; background: none; color: var(--accent); font-size: 15px; padding: 6px 6px; font-weight: 600; }
.ph .busy { font-size: 15px; color: var(--sub); padding: 12px 0; }
.ph .err { font-size: 13px; color: var(--warn); margin: 6px 0 0; }

.foot { padding: 22px 0 140px; border-top: 1px solid var(--line); color: var(--faint); font-size: 13px; }
.foot p { margin: 0 0 10px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: #9c3d2a; }

/* 底部按鈕列 */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom)); }
.bar .wrap { padding: 0; }
.bar.hide { display: none; }
.primary { display: block; width: 100%; min-height: 54px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-size: 18px; font-weight: 700; letter-spacing: .04em; }
.primary:active { filter: brightness(.92); }
.primary:disabled { opacity: .6; }

/* 結果頁 */
.rtop { padding: 14px 0 0; }
.back { border: 0; background: none; padding: 8px 0; color: var(--accent); font-size: 17px; font-weight: 600; }
.result h1 { margin-top: 10px; }
.result .lede { margin-bottom: 18px; }
.warn { margin: 0 0 16px; padding: 12px 14px; border-radius: 10px; background: var(--warn-tint); color: var(--warn); font-size: 15px; }
.warn button { color: inherit; }
.save3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.sec-btn { min-height: 50px; border: 1.5px solid var(--line2); border-radius: 12px; background: #fff; font-size: 16px; font-weight: 600; padding: 6px 4px; }
.sec-btn:active { background: var(--band); }
.msg { min-height: 1.6em; margin: 12px 0 0; font-size: 15px; color: var(--sub); }
.pages { margin: 18px 0 0; }
.pages figure { margin: 0 0 14px; }
.pages img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px -14px rgba(30,36,34,.28); }
.pages figcaption { font-size: 13px; color: var(--faint); margin-top: 6px; text-align: right; }
.after { padding: 6px 0 60px; font-size: 15px; color: var(--sub); }
.after p { margin: 0 0 12px; }
.next { margin-top: 8px; }

@media (min-width: 720px) {
  .top { padding-top: 48px; }
  .photos { max-width: 520px; }
}

/* 列印：只印問診單頁面 */
@media print {
  @page { size: A4; margin: 0; }
  body * { visibility: hidden; }
  #pages, #pages * { visibility: visible; }
  #pages { position: absolute; left: 0; top: 0; width: 100%; margin: 0; }
  #pages figure { margin: 0; break-after: page; }
  #pages img { width: 100%; border: 0; border-radius: 0; box-shadow: none; }
  #pages figcaption { display: none; }
  .bar, .progress { display: none !important; }
}
