/* หน้าฟอร์ม: มือถือเต็มจอ, จอกว้างเป็นการ์ดกลางจอกว้าง 560px */
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
@media (min-width: 640px) {
  body { padding: 32px 16px; }
  .app { min-height: 0; border-radius: 20px; box-shadow: var(--shadow); overflow: clip; }
}

/* หัว: ปุ่มย้อนกลับ + ขั้นที่ + แถบความคืบหน้า */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(14px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) 10px max(20px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.back {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: var(--soft); color: var(--blue); display: grid; place-items: center; cursor: pointer;
}
.back:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.top-text { min-width: 0; }
.brand { font-weight: 700; font-size: 15px; line-height: 1.3; }
.stepno { color: var(--muted); font-size: 13.5px; font-weight: 500; }
.prog { height: 6px; border-radius: 99px; background: var(--soft); overflow: hidden; margin-top: 10px; }
.prog i { display: block; height: 100%; width: 25%; background: var(--blue); border-radius: 99px; transition: width .3s ease; }
.steps {
  list-style: none; margin: 7px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  font-size: 12.5px; color: var(--muted); text-align: center;
}
.steps li.done { color: var(--ok); font-weight: 700; }
.steps li.now { color: var(--blue); font-weight: 700; }
.app.is-done .top-row .stepno, .app.is-done .prog, .app.is-done .steps { display: none; }

/* เนื้อหาแต่ละขั้น */
.main { flex: 1; display: flex; flex-direction: column; }
.step, .done {
  flex: 1;
  display: grid; align-content: start; gap: 18px;
  padding-block: 22px 24px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}
.step h1, .done h1 { font-size: 24px; font-weight: 700; outline: none; }
.lead { margin: -10px 0 0; color: var(--muted); font-size: 15px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ชั้น: แตะเลือก */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip span {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 64px; padding: 0 16px;
  border: 1.5px solid var(--line); border-radius: 99px; background: var(--field);
  font-weight: 600; font-size: 15.5px; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip input:checked + span { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.chip input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.field.bad .chip span { border-color: var(--err); }

/* กรอบรูปใบขับขี่ สัดส่วนเท่าบัตรจริง 85.6 x 54 มม. */
.lic {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 85.6 / 54; max-width: 100%;
  border: 2px dashed var(--blue); border-radius: 14px; background: var(--soft);
  color: var(--blue); text-align: center; overflow: hidden; cursor: pointer;
}
.lic.has { border-style: solid; border-color: var(--line); background: var(--field); }
.lic.bad { border-color: var(--err); }
.lic img { width: 100%; height: 100%; object-fit: contain; }
.lic-empty { display: grid; justify-items: center; gap: 2px; padding: 12px; }
.lic-empty b { font-size: 16px; }
.lic-empty small { color: var(--muted); font-size: 13.5px; }
.lic-busy {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--soft); font-weight: 600;
}
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14.5px; }
.tips li { display: flex; gap: 8px; }
.tips li::before { content: "✓"; color: var(--ok); font-weight: 700; }

/* คนซ้อน: การ์ดใหญ่ 2 ใบ */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-box {
  display: grid; justify-items: center; gap: 4px; padding: 18px 10px;
  border: 2px solid var(--line); border-radius: 16px; background: var(--field);
  text-align: center; cursor: pointer; color: var(--muted);
  transition: border-color .15s, background-color .15s, color .15s;
}
.choice-box b { color: var(--ink); font-size: 16.5px; }
.choice-box small { font-size: 13.5px; }
.choice input:checked + .choice-box { border-color: var(--blue); background: var(--soft); color: var(--blue); }
.choice input:focus-visible + .choice-box { outline: 3px solid var(--blue); outline-offset: 2px; }
.choices.bad .choice-box { border-color: var(--err); }

/* ตรวจทาน */
.review { display: grid; gap: 10px; }
.rv { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 4px; min-width: 0; }
.rv-h { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; }
.rv-h b { font-weight: 600; }
.link {
  border: 0; background: var(--soft); color: var(--blue); font-weight: 700; font-size: 14px;
  border-radius: 8px; padding: 4px 14px; min-height: 32px; cursor: pointer;
}
.link:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.rv-name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.rv-sub { color: var(--muted); }
.rv-photo { display: block; width: 100%; max-height: 200px; object-fit: contain; border-radius: 8px; background: var(--soft); margin-top: 4px; }

.helmet { background: var(--warn-bg); border: 1.5px solid var(--warn-line); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.helmet.bad { border-color: var(--err); }
.helmet-note { margin: 0; color: var(--warn-ink); font-weight: 700; }
.check { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; font-weight: 500; }
.check .box {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 7px;
  border: 2px solid var(--warn-line); background: var(--field); color: transparent;
  display: grid; place-items: center; transition: background-color .15s, border-color .15s;
}
.check input:checked + .box { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.check input:focus-visible + .box { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ปุ่มล่าง ติดขอบจอตลอด */
.foot {
  position: sticky; bottom: 0; z-index: 4;
  background: var(--bg); border-top: 1px solid var(--line);
  padding-top: 12px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: grid; gap: 8px;
}
.send-err { background: var(--err-soft); border-radius: 10px; padding: 10px 12px; }

/* ส่งเสร็จ: บัตรนำรถ */
.done { justify-items: stretch; text-align: center; }
.tick { width: 72px; height: 72px; border-radius: 50%; background: var(--ok); color: var(--bg); display: grid; place-items: center; margin: 6px auto 0; }
.done .lead { margin: -12px 0 0; }
.pass { border: 1.5px solid var(--line); border-radius: 16px; overflow: hidden; text-align: left; background: var(--field); }
.pass-top { background: var(--blue); color: var(--blue-ink); padding: 9px 14px; font-weight: 600; font-size: 14px; }
.pass-body { padding: 14px; display: grid; gap: 10px; }
.pass-body small { display: block; color: var(--muted); font-size: 12.5px; }
.pass-body b { font-size: 16px; overflow-wrap: anywhere; }
.pass-name { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.pass-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pass-helmet { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 10px; padding: 8px 10px; font-weight: 600; font-size: 14px; }
.pass-time { border-top: 2px dashed var(--line); padding: 9px 14px 11px; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.app.is-done .foot, .app.is-done .back { display: none; }

/* กำลังส่ง */
.sending {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(10, 18, 32, 0.55);
  display: grid; place-items: center; padding: 24px;
}
.sbox { background: var(--bg); border-radius: 18px; padding: 22px; width: min(320px, 100%); display: grid; justify-items: center; gap: 10px; text-align: center; box-shadow: var(--shadow); }
.sbox b { font-size: 17px; }
.sbox small { color: var(--muted); }
.sbar { width: 100%; height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.sbar i { display: block; height: 100%; width: 0; background: var(--blue); border-radius: 99px; transition: width .2s; }
.spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--soft); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .row2, .pick, .choices { grid-template-columns: 1fr; }
  .step h1, .done h1 { font-size: 22px; }
}
