:root {
  /* Brand palette sampled from the artwork (ตลาดใบบัว วงศ์สว่าง) */
  --green: #21532a;
  --green-deep: #1a4422;
  --green-soft: rgba(255, 255, 255, 0.10);
  --line: rgba(255, 255, 255, 0.55);
  --line-strong: #ffffff;
  --gold: #c2a35a;
  --radius: 999px;

  /* Responsive layout knobs — overridden per breakpoint below */
  --maxw: 460px;          /* content column width */
  --pad-x: clamp(18px, 5.5vw, 30px);
  --gap-welcome: clamp(44px, 9vh, 72px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--green);
  color: #fff;
  font-family: 'Kanit', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* safety net against any horizontal overflow */
}

/* Thai has no spaces between words, so long labels are one "word". Allow them to
   wrap (and let flex items shrink) so nothing overflows on narrow phones. */
.screen, .reg-form, .redeem, .field, .brand { min-width: 0; }
.group-label, .field > label, .opt, .opt span,
.redeem-note, .redeem-done-note, .thankyou-sub,
.modal__title, .modal__body, .err, .form-error {
  overflow-wrap: break-word;
  word-break: break-word;
}

.stage {
  /* dvh tracks the real viewport as mobile browser chrome shows/hides */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* honour notch / home-indicator safe areas */
  padding:
    max(28px, env(safe-area-inset-top)) max(var(--pad-x), env(safe-area-inset-right))
    max(44px, env(safe-area-inset-bottom)) max(var(--pad-x), env(safe-area-inset-left));
}

/* ---------- Screens ---------- */
.screen { display: none; width: 100%; max-width: var(--maxw); }
.screen.is-active { display: flex; flex-direction: column; align-items: center; }

/* Full-height, vertically-centred screens (welcome + thank you) */
.screen--welcome,
.screen--thankyou {
  min-height: calc(100dvh - 72px);
  justify-content: center;
}
.screen--welcome { gap: var(--gap-welcome); }
.screen--thankyou { text-align: center; }

/* ---------- Brand ---------- */
.brand { text-align: center; }
.brand__logo { display: block; margin: 0 auto; height: auto; }
.brand--lg .brand__logo { width: clamp(220px, 64vw, 360px); }
.brand--sm .brand__logo { width: clamp(170px, 50vw, 220px); }

/* ---------- Image buttons (real PNG assets) ---------- */
.btn-img {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.btn-img img { display: block; width: 100%; height: auto; }
.btn-img:active { transform: translateY(0); }
.btn-img:disabled { opacity: .6; cursor: progress; transform: none; }

/* REGISTER button (welcome) */
.btn-register { width: clamp(220px, 66vw, 300px); }

/* ---------- Form ---------- */
.screen--form { gap: 0; padding-top: clamp(20px, 5vh, 40px); padding-bottom: clamp(24px, 6vh, 48px); }
.reg-form { width: 100%; margin-top: clamp(20px, 4vh, 30px); }

.field { margin-bottom: clamp(16px, 2.6vh, 22px); }
.field > label,
.group-label {
  display: block;
  font-size: clamp(15px, 4vw, 17px);
  font-weight: 400;
  margin-bottom: 9px;
  line-height: 1.45;
  color: rgba(255, 255, 255, .95);
}

.field input[type="text"],
.field input[type="tel"] {
  width: 100%;
  height: 48px;
  padding: 0 18px;
  font-family: inherit;
  font-size: 16px; /* >=16px so iOS does not auto-zoom the page on focus */
  color: #fff;
  background: var(--green-soft);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.field input::placeholder { color: rgba(255, 255, 255, .5); }
.field input:focus { border-color: var(--line-strong); background: rgba(255, 255, 255, .16); }
.field input.invalid { border-color: #ffb0b0; }

/* checkbox / radio groups */
.options { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 4px 2px 2px; }
.options--col { flex-direction: column; gap: clamp(8px, 1.3vh, 11px); padding-left: 20px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  font-size: clamp(14px, 3.8vw, 16px); font-weight: 300;
  cursor: pointer; user-select: none;
  min-height: 24px; /* comfortable tap target */
}
/* Square boxes for BOTH radios & checkboxes, to match the artwork */
.opt input {
  appearance: none; -webkit-appearance: none;
  width: 19px; height: 19px; flex-shrink: 0; cursor: pointer; margin: 0;
  border: 1.6px solid rgba(255, 255, 255, .75);
  border-radius: 4px; background: transparent;
  position: relative; transition: background .15s ease, border-color .15s ease;
}
.opt input:checked { background: var(--gold); border-color: var(--gold); }
.opt input:checked::after {
  content: ''; position: absolute; left: 50%; top: 46%;
  width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
.opt input:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 2px; }

/* errors */
.err { display: block; min-height: 14px; margin-top: 5px; font-size: 12px; color: #ffc9c9; }
.form-error { min-height: 18px; margin: 4px 0 0; font-size: 13px; color: #ffc9c9; text-align: center; }

/* form actions */
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: clamp(20px, 3vh, 28px); }
.btn-cancel, .btn-ok { width: clamp(120px, 40vw, 160px); }

/* ---------- Thank you / Redeem ---------- */
.thankyou-title {
  font-family: 'Poppins', sans-serif; font-weight: 800;
  font-size: clamp(42px, 13vw, 72px); letter-spacing: 4px; margin: clamp(16px, 3vh, 28px) 0 4px;
  text-shadow: 0 3px 6px rgba(0, 0, 0, .35);
}
.thankyou-sub {
  margin: 2px 0 clamp(22px, 4vh, 34px); font-size: clamp(20px, 5.5vw, 30px);
  font-weight: 400; opacity: .96;
}
.redeem { width: 100%; display: flex; flex-direction: column; align-items: center; }
.redeem[hidden] { display: none; }
.redeem-note { margin: clamp(18px, 3vh, 26px) 0 0; font-size: clamp(14px, 3.9vw, 17px); line-height: 1.7; opacity: .95; }
.redeem-clock {
  margin: clamp(18px, 3vh, 26px) 0 0; font-size: clamp(14px, 3.9vw, 17px); opacity: .9;
  display: inline-flex; align-items: center; gap: 7px;
}
.redeem-clock #clockNow { font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.redeem-done-note { margin: 20px 0 0; font-size: clamp(15px, 4.2vw, 18px); font-weight: 400; opacity: .96; }

/* ---------- Pill buttons (gold / ghost / done) ---------- */
.btn-pill {
  font-family: inherit; font-size: 16px; font-weight: 500;
  border: 0; border-radius: var(--radius); cursor: pointer; color: #fff;
  padding: 13px 26px; line-height: 1.25;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.btn-pill:active { transform: translateY(0); }
.btn-pill:disabled { cursor: default; transform: none; filter: none; }
.btn-pill--lg { width: clamp(260px, 84vw, 340px); font-size: clamp(17px, 4.8vw, 20px); padding: 16px 22px; }

.btn-pill--gold {
  background: linear-gradient(180deg, #e0c884 0%, #c8a657 48%, #b1903f 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .45);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
}
.btn-pill--ghost {
  background: #fff; color: #2f6b3a; font-weight: 600;
  border: 1.5px solid #cbb27a;
}
.btn-pill--done {
  background: linear-gradient(180deg, #cdd0cd 0%, #b3b7b3 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
}

/* ---------- Confirm modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); animation: fade .2s ease both; }
.modal__card {
  position: relative; z-index: 1; width: 100%; max-width: 360px;
  background: #fff; color: #222; border-radius: 18px;
  padding: 30px 26px 24px; text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  animation: pop .22s ease both;
}
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(6px); } to { opacity: 1; transform: none; } }
.modal__close {
  position: absolute; top: 10px; right: 12px; width: 38px; height: 38px;
  border: 0; background: none; font-size: 26px; line-height: 1; color: #9aa09a;
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.modal__title { margin: 4px 0 12px; font-size: clamp(20px, 5.5vw, 23px); font-weight: 600; color: #1f4a28; }
.modal__body { margin: 0 0 6px; font-size: clamp(14px, 4vw, 15px); line-height: 1.6; color: #555; }
.modal__error { min-height: 16px; margin: 8px 0 0; font-size: 13px; color: #d33; }
.modal__actions { display: flex; gap: 14px; justify-content: center; margin-top: 22px; }
.modal__actions .btn-pill { flex: 1; max-width: 160px; font-size: 15px; padding: 13px 10px; }

/* ---------- Hover only on devices that truly hover (not touch) ---------- */
@media (hover: hover) {
  .btn-img:hover { transform: translateY(-2px); filter: brightness(1.05); }
  .btn-pill:hover { transform: translateY(-1px); filter: brightness(1.05); }
  .btn-pill--ghost:hover { filter: none; background: #faf6ec; }
  .modal__close:hover { color: #555; background: rgba(0, 0, 0, .05); }
}

/* ---------- Tablets / iPad (portrait & up): scale the whole UI up ---------- */
@media (min-width: 768px) {
  :root {
    --maxw: 600px;
    --gap-welcome: clamp(60px, 9vh, 96px);
  }
  .brand--lg .brand__logo { width: clamp(360px, 52vw, 460px); }
  .brand--sm .brand__logo { width: clamp(220px, 34vw, 280px); }
  .btn-register { width: clamp(300px, 46vw, 360px); }

  .field { margin-bottom: 24px; }
  .field > label, .group-label { font-size: 18px; }
  .field input[type="text"], .field input[type="tel"] { height: 54px; font-size: 18px; }
  .opt { font-size: 18px; min-height: 30px; gap: 14px; }
  .opt input { width: 22px; height: 22px; }
  .btn-cancel, .btn-ok { width: clamp(150px, 26vw, 190px); }

  .thankyou-title { font-size: clamp(64px, 11vw, 92px); }
  .thankyou-sub { font-size: clamp(26px, 4.5vw, 34px); }
  .btn-pill--lg { width: clamp(340px, 52vw, 420px); font-size: 22px; padding: 18px 24px; }
  .redeem-note, .redeem-clock { font-size: 18px; }
  .modal__card { max-width: 430px; padding: 36px 32px 28px; }
  .modal__actions .btn-pill { max-width: 180px; font-size: 16px; }
}

/* ---------- Large iPad / desktop: a touch more breathing room ---------- */
@media (min-width: 1024px) {
  :root { --maxw: 640px; }
}

/* ---------- Short landscape phones: tighten vertical rhythm ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  .screen--welcome, .screen--thankyou { min-height: 0; padding-top: 8px; padding-bottom: 8px; }
  :root { --gap-welcome: 28px; }
  .thankyou-title { font-size: clamp(34px, 9vh, 48px); margin-top: 6px; }
  .thankyou-sub { margin-bottom: 16px; }
}

/* ---------- transitions ---------- */
.screen.is-active { animation: fade .35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
