:root {
  --red: #e60012;
  --red-dark: #b0000e;
  --bg: #0b0b0f;
  --panel: #16161d;
  --line: rgba(255,255,255,.14);
  --text: #ffffff;
  --muted: rgba(255,255,255,.62);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Kanit', system-ui, sans-serif; overflow: hidden; }
button { font-family: inherit; }
#app { position: fixed; inset: 0; max-width: 560px; margin: 0 auto; overflow: hidden; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; opacity: 0; pointer-events: none; transition: opacity .3s ease; }
.screen.active { opacity: 1; pointer-events: auto; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 999px; height: 56px; padding: 0 28px; font-size: 18px; font-weight: 600; letter-spacing: .06em; color: #fff; cursor: pointer; transition: transform .1s, opacity .2s, background .2s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; }
.btn-primary { background: var(--red); box-shadow: 0 8px 24px rgba(230,0,18,.35); }
.btn-primary:active { background: var(--red-dark); }
.btn-ghost { background: transparent; border: 1.5px solid rgba(255,255,255,.5); }
.btn-xl { width: 100%; height: 62px; font-size: 22px; font-weight: 800; letter-spacing: .14em; }

.bottom-bar { margin-top: auto; padding: 16px 20px calc(20px + var(--safe-b)); }
.bottom-bar.two { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }

.top { display: flex; align-items: center; gap: 12px; padding: calc(14px + var(--safe-t)) 16px 12px; }
.top h2 { margin: 0; font-size: 22px; font-weight: 600; }
.step { margin: 0; font-size: 12px; letter-spacing: .18em; color: var(--red); font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0,0,0,.35); color: #fff; font-size: 28px; line-height: 1; padding-bottom: 4px; cursor: pointer; flex: none; }

/* ---------- start ---------- */
#screen-start { justify-content: flex-end; }
/* v19: หน้าแรกใช้ assets/cover.png ฟิตซ้าย-ขวาเต็มความกว้าง (รถไม่ขาด) ชิดบน แล้วไล่สีลงพื้นดำด้านล่าง */
.start-bg { position: absolute; inset: 0; background: var(--bg); overflow: hidden; }
.cover-wrap { position: relative; width: 100%; }
.cover-wrap img { display: block; width: 100%; height: auto; }
.cover-wrap::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,11,15,.35) 0%, rgba(11,11,15,0) 22%, rgba(11,11,15,0) 72%, var(--bg) 100%); }
.start-logo { position: absolute; z-index: 2; top: var(--safe-t); left: 0; width: clamp(72px, 22vw, 112px); height: auto; }
.start-content { position: absolute; top: calc(clamp(72px, 22vw, 112px) * .78 + 8px + var(--safe-t)); left: 20px; right: 20px; }
/* head_title.png มีขอบใสรอบ ๆ — ขยายรูปแล้วใช้ margin ติดลบ ให้ตัวกราฟิกจริงกว้างประมาณ 92% ของจอ */
.head-title { margin: 0; line-height: 0; }
.head-title img { display: block; width: 110%; height: auto; margin: -23.7% 0 -25.5% -8.3%; pointer-events: none; }
.eyebrow { margin: 0; font-weight: 800; font-size: 22px; letter-spacing: .04em; }
.title { margin: 0; font-weight: 800; font-size: clamp(46px, 14vw, 76px); line-height: .92; letter-spacing: -.01em; }
.tag-row { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.tag { background: var(--red); padding: 2px 14px; font-weight: 800; font-size: 28px; }
.script { font-style: italic; font-weight: 800; font-size: 24px; }
.sub { margin-top: 18px; color: rgba(255,255,255,.85); font-size: 16px; line-height: 1.5; }
#screen-start .bottom-bar { position: relative; }
/* v19: title_low.png ใต้ head_title ชิดขอบซ้ายจอ (ตามภาพ cover_composition_ref) */
.title-low { position: relative; z-index: 1; display: block; width: 72%; height: auto; margin: 0 0 auto; pointer-events: none; }
.start-stack { position: absolute; top: calc(clamp(72px, 22vw, 112px) * .78 + 8px + var(--safe-t)); left: 0; right: 0; }
.start-stack .start-content { position: static; padding: 0 20px; }

/* ---------- bg select ---------- */
.bg-list { flex: 1; overflow-y: auto; padding: 4px 16px 8px; display: grid; gap: 12px; }
.bg-card { position: relative; display: block; width: 100%; height: 26vh; min-height: 140px; border-radius: 18px; overflow: hidden; border: 2px solid transparent; background: var(--panel); padding: 0; text-align: left; color: #fff; cursor: pointer; transition: border-color .2s, transform .15s; }
.bg-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.bg-card::after { content: ''; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(0,0,0,.8), transparent 60%); }
.bg-name, .bg-desc { position: absolute; left: 16px; z-index: 1; }
.bg-name { bottom: 34px; font-weight: 800; font-size: 22px; letter-spacing: .04em; }
.bg-desc { bottom: 12px; font-size: 14px; color: rgba(255,255,255,.8); }
.bg-card.selected { border-color: var(--red); transform: scale(.985); }
.bg-card.selected::before { content: '✓'; position: absolute; top: 12px; right: 12px; z-index: 2; width: 32px; height: 32px; border-radius: 50%; background: var(--red); display: grid; place-items: center; font-weight: 800; }

/* ---------- camera ---------- */
#screen-camera { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cam-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; }
.top-cam { background: linear-gradient(180deg, rgba(0,0,0,.65), transparent); }
.guide-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 10px; }
/* ไกด์ไลน์: assets/car-guide.png (2752×1536) — mix-blend-mode: screen ทำให้ส่วนสีดำโปร่งใส เหลือแต่เส้นขาวทับภาพกล้อง */
.guide { width: 100%; max-width: 560px; aspect-ratio: 2752 / 1536; object-fit: contain; opacity: .85; pointer-events: none; }
.guide-hint { margin: 10px 0 0; font-size: 14px; background: rgba(0,0,0,.5); padding: 6px 14px; border-radius: 999px; }
.cam-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 20px 4px; background: linear-gradient(0deg, rgba(0,0,0,.7), transparent); }
.cam-bar .small-btn:first-child { justify-self: start; }
.cam-bar .small-btn:last-child { justify-self: end; }
.small-btn { border: 1px solid var(--line); background: rgba(0,0,0,.45); color: #fff; border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.shutter { width: 80px; height: 80px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--red); transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.cam-label { text-align: center; margin: 4px 0 calc(14px + var(--safe-b)); font-weight: 600; letter-spacing: .2em; font-size: 13px; }
.flash { position: absolute; inset: 0; background: #fff; animation: flash .35s ease-out forwards; pointer-events: none; }
@keyframes flash { from { opacity: .9 } to { opacity: 0 } }

/* ---------- preview / result ---------- */
.preview-wrap, .result-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 16px; }
.preview-wrap img, .result-wrap img { max-width: 100%; max-height: 100%; border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.6); }
.result-wrap { padding-top: calc(16px + var(--safe-t)); }
.result-wrap img { animation: pop .5s cubic-bezier(.2,.9,.3,1.2); -webkit-touch-callout: default; }
@keyframes pop { from { transform: scale(.92); opacity: 0 } to { transform: none; opacity: 1 } }
.save-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 20px 0; }

/* ---------- loading ---------- */
#screen-loading { justify-content: center; align-items: center; background: radial-gradient(circle at 50% 40%, #2a0a0e, var(--bg) 70%); }
.loader { text-align: center; padding: 24px; width: 100%; }
.tire-spin { width: 150px; height: 150px; margin: 0 auto 24px; border-radius: 50%; overflow: hidden; animation: spin 1.4s linear infinite; box-shadow: 0 0 40px rgba(230,0,18,.45); background: #fff; }
.tire-spin img { width: 100%; height: 100%; object-fit: cover; }
@keyframes spin { to { transform: rotate(360deg) } }
.load-title { font-size: 24px; font-weight: 800; margin: 0; }
.load-msg { color: var(--muted); margin: 6px 0 18px; min-height: 1.5em; }
.progress { width: 80%; max-width: 320px; height: 6px; margin: 0 auto; background: rgba(255,255,255,.12); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--red); border-radius: 99px; transition: width .6s ease; }
.load-note { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ---------- modal ---------- */
.inapp-gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: rgba(5,5,8,.94); backdrop-filter: blur(6px); }
.gate-card { width: 100%; max-width: 360px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 26px 22px 22px; animation: pop .3s ease; }
.gate-logo { width: 72px; height: auto; margin: 0 auto 14px; display: block; }
.gate-card h3 { margin: 0 0 8px; font-size: 22px; }
.gate-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; font-size: 15px; }
.gate-card p b { color: #fff; }
.gate-card .btn { width: 100%; }
.gate-help { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.gate-help[hidden] { display: none; }
.gate-help p { font-size: 14px; margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 60; transform: translate(-50%, 20px);
  width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: rgba(20,20,26,.96); border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0,0,0,.5); color: #fff; font-size: 14px; line-height: 1.45; text-align: center; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { color: #ff3b47; }
.modal { position: absolute; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 10; padding: 24px; backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 28px 22px 22px; text-align: center; width: 100%; max-width: 340px; animation: pop .3s ease; }
.modal-icon { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%; background: var(--red); display: grid; place-items: center; font-size: 30px; font-weight: 800; }
.modal-card h3 { margin: 0 0 6px; font-size: 22px; }
.modal-card p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
.modal-card .btn { width: 100%; }

/* ---------- preparing overlay (after capture) ---------- */
.preparing { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(5,5,7,.82); backdrop-filter: blur(6px); }
.preparing[hidden] { display: none; }
.prep-ring { width: 54px; height: 54px; border-radius: 50%; border: 4px solid rgba(255,255,255,.18); border-top-color: var(--red); animation: spin .8s linear infinite; }
.prep-title { margin: 0; font-size: 18px; font-weight: 600; }
.prep-bar { width: 180px; height: 4px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
.prep-bar span { display: block; height: 100%; width: 40%; background: var(--red); border-radius: 99px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%) } to { transform: translateX(250%) } }

/* ---------- quota ---------- */
.quota { margin: 10px 0 0; text-align: center; font-size: 13px; color: var(--muted); letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.quota:empty { display: none; }
.quota.empty { color: #ff6b75; }
.save-hint:empty { display: none; }

/* ---------- in-app browser hint ---------- */
.inapp-banner { position: absolute; left: 16px; right: 16px; top: calc(14px + var(--safe-t)); z-index: 4; background: rgba(230,0,18,.92); color: #fff; font-size: 14px; line-height: 1.45; padding: 10px 14px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

/* ---------- start: gallery button ---------- */
.btn-gallery { width: 100%; margin-top: 10px; height: 50px; font-size: 16px; }

/* ---------- PDPA ---------- */
.pdpa-body { flex: 1; min-height: 0; overflow-y: auto; margin: 0 16px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; font-size: 14px; line-height: 1.6; color: rgba(255,255,255,.86); -webkit-overflow-scrolling: touch; }
.pdpa-body h3 { margin: 0 0 4px; font-size: 18px; color: #fff; }
.pdpa-body h4 { margin: 16px 0 4px; font-size: 15px; color: #fff; }
.pdpa-body ul { margin: 4px 0; padding-left: 20px; }
.pdpa-body p { margin: 4px 0; }
.pdpa-body a { color: #ff5a66; text-decoration: underline; word-break: break-all; }
.pd-sub { color: var(--muted); font-size: 13px; }
.pd-consent { margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,.06); border: 1px solid var(--line); font-weight: 600; }
.pdpa-consent { padding: 12px 18px 0; display: grid; gap: 10px; }
.chk { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.45; cursor: pointer; }
.chk input { flex: none; width: 22px; height: 22px; margin-top: 1px; accent-color: var(--red); }
.chk .req { color: #ff6b75; font-weight: 600; }

/* ---------- GALLERY ---------- */
.gallery-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 8px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-content: start; }
.g-item { position: relative; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--panel); aspect-ratio: 2 / 3; cursor: pointer; }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.g-item span { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; font-size: 11px; color: #fff; text-align: left; background: linear-gradient(0deg, rgba(0,0,0,.75), transparent); }
.gallery-empty { flex: 1; text-align: center; color: var(--muted); line-height: 1.7; padding-top: 18vh; margin: 0; }
.gallery-note { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 16px calc(16px + var(--safe-b)); }
.viewer { padding: 16px; }
.viewer-card { width: 100%; max-width: 420px; display: grid; gap: 12px; }
.viewer-card img { width: 100%; max-height: 72vh; object-fit: contain; border-radius: 12px; }
.viewer-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------- v19: buttons / register / result ---------- */
.btn-light { background: #fff; color: #0b0b0f; box-shadow: 0 8px 24px rgba(255,255,255,.18); }
.btn-light:active { background: #ddd; }
.reg-form { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 20px; display: grid; gap: 14px; align-content: start; }
.reg-note { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; color: rgba(255,255,255,.85); }
.field input { height: 54px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--panel); color: #fff; padding: 0 16px; font: inherit; font-size: 17px; outline: none; }
.field input:focus { border-color: var(--red); }
.field input.bad { border-color: #ff6b75; }
.reg-err { margin: 0; min-height: 1.4em; color: #ff6b75; font-size: 14px; }
#screen-result .result-wrap { padding-top: calc(12px + var(--safe-t)); }
.result-wrap img { user-select: none; -webkit-user-select: auto; }
.fb-contest { text-align: center; margin: 8px 16px 0; font-size: 14px; line-height: 1.45; font-weight: 600; color: #fff; }
.fb-contest b { color: #ff3b47; letter-spacing: .01em; overflow-wrap: anywhere; }
.press-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 16px 0; }
.result-cta { display: flex; align-items: center; gap: 12px; margin: 10px 20px 0; padding: 12px 12px 12px 16px; border-radius: 16px; background: linear-gradient(90deg, rgba(230,0,18,.22), rgba(230,0,18,.06)); border: 1px solid rgba(230,0,18,.45); }
.cta-text { flex: 1; margin: 0; font-size: 14px; line-height: 1.4; }
.cta-text b { font-size: 15px; font-style: italic; letter-spacing: .01em; }
.btn-reg { flex: none; height: 46px; padding: 0 20px; font-size: 16px; display: inline-flex; align-items: center; text-decoration: none; }
.result-bar { padding-top: 12px; padding-bottom: 6px; display: grid; grid-template-columns: 1fr; }
.result-bar .btn { width: 100%; }
.share-cta .cta-text b { font-style: normal; }
.btn-copy { display: block; width: calc(100% - 40px); margin: 10px 20px 0; height: 46px; font-size: 16px; background: #fff; color: #0b0b0f; border: 0; box-shadow: 0 6px 18px rgba(255,255,255,.12); }
.btn-copy:active { background: #ddd; }
.btn-copy.done { background: #e9ffe9; color: #0b0b0f; }
.viewer-card .btn-copy { width: 100%; margin: 0; }
.share-cta .hashtag { color: #ff3b47; font-weight: 600; overflow-wrap: anywhere; }
.share-cta .btn-reg { padding: 0 26px; }
/* v19r: หน้าผลลัพธ์ — รูปใหญ่เกือบเต็มจอ เลื่อนลงดูปุ่ม/กล่องข้อความ */
#screen-result { display: block; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#screen-result .result-wrap { display: flex; justify-content: center; align-items: flex-start; padding: calc(10px + var(--safe-t)) 10px 0; min-height: 0; }
#screen-result .result-wrap img { width: 100%; height: auto; max-width: 100%; max-height: calc(100vh - 110px - var(--safe-t)); max-height: calc(100svh - 110px - var(--safe-t)); object-fit: contain; }
#screen-result .result-cta { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px 16px; }
#screen-result .cta-text { text-align: center; font-size: 15px; line-height: 1.5; }
#screen-result .cta-text b { font-size: 17px; }
#screen-result .result-cta .btn-reg { width: 100%; justify-content: center; height: 50px; font-size: 18px; }
#screen-result .bottom-bar { margin-top: 0; }
/* v19t: คิว */
.queue-box { margin-top: 18px; padding: 16px 18px; border-radius: 16px; background: rgba(255,255,255,.06); border: 1px solid var(--line); text-align: center; width: min(340px, 100%); }
.queue-box[hidden] { display: none; }
.queue-title { margin: 0 0 4px; font-weight: 600; }
.queue-line { margin: 0; font-size: 18px; }
.queue-line b { font-size: 34px; color: var(--red); margin-left: 6px; vertical-align: -3px; }
.queue-eta { margin: 2px 0 8px; color: var(--muted); font-size: 14px; }
.queue-note { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.queue-box .btn { height: 42px; font-size: 15px; padding: 0 22px; }
.loader.queued .load-title, .loader.queued .load-msg, .loader.queued .progress, .loader.queued .load-note { display: none; }
/* v19s: ปุ่ม COPY HASHTAG อยู่ในกล่องแชร์ (เหนือปุ่มแชร์) */
#screen-result .share-cta .btn-copy { width: 100%; margin: 0; height: 50px; font-size: 17px; font-weight: 700; letter-spacing: .04em; border: 1.5px solid rgba(0,0,0,.08); }
#screen-result .share-cta #btn-share { background: var(--red); color: #fff; box-shadow: 0 8px 24px rgba(230,0,18,.35); }
#screen-result .share-cta #btn-share:active { background: var(--red-dark); }
.result-quota { margin: 0 0 calc(12px + var(--safe-b)); }
.viewer-card .press-hint { margin: 0; }
.toast { position: absolute; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 20; background: rgba(20,20,26,.95); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86%; text-align: center; animation: pop .25s ease; }
