/* ------------------------------------------------------------------
   บัตรสะสมแต้ม — กระดาษครีม + หมึกกรมท่า + ตราส้ม
   พาเลตต์หลัก: #0A2A86 กรมท่า · #1F3FE0 น้ำเงิน · #4DB8F2 ฟ้า · #FAF9F5 ครีม · #FF7A45 ส้ม
   ฟ้า (#4DB8F2) และส้ม (#FF7A45) คอนทราสต์ต่ำบนครีม → ใช้เป็นพื้น/ตกแต่งเท่านั้น
   ตัวหนังสือสีส้มใช้ --orange-ink แทน · ไม่ใช้เงา ไม่ใช้ไล่สี
------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* แบรนด์ */
  --navy: #0A2A86;
  --navy-deep: #071E63;
  --blue: #1F3FE0;
  --sky: #4DB8F2;
  --cream: #FAF9F5;
  --orange: #FF7A45;

  /* ความหมาย */
  --paper: var(--cream);    /* พื้นหลัง */
  --card: #FFFFFF;          /* พื้นบัตร */
  --ink: var(--navy);       /* ตัวหนังสือหลัก (12:1) */
  --ink-2: #44507E;         /* ตัวหนังสือรอง (7.6:1) */
  --ink-3: #6A7294;         /* ข้อความประกอบ (4.8:1) */
  --line: #D8DAE6;          /* เส้นขอบ / เส้นประ */
  --sky-wash: #E7F5FD;      /* พื้นฟ้าอ่อน */
  --orange-ink: #B4461A;    /* ส้มสำหรับตัวหนังสือ (5:1) */
  --orange-wash: #FFEEE6;   /* พื้นส้มอ่อน */
  --red: #C42B2B;
  --red-wash: #FCEAEA;

  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r-sm: 8px;
  --r: 12px;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px 20px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- หัวข้อ ---------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  margin: 8px 0 10px;
}
.eyebrow::before {
  content: ""; width: 18px; height: 3px; border-radius: 2px; background: var(--orange);
}
.title {
  font-size: 28px; font-weight: 800; line-height: 1.25;
  letter-spacing: -0.01em; margin: 0 0 6px;
}
.subtitle { font-size: 16px; color: var(--ink-2); margin: 0 0 24px; }

/* ---------- ปุ่มสแกน ---------- */
.scan-btn {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
  width: 100%; min-height: 80px; padding: 14px 16px;
  border: 0; border-radius: 14px;
  background: var(--navy); color: #fff;
  font: inherit; text-align: left; cursor: pointer;
  transition: background-color .15s ease, transform .08s ease;
}
.scan-btn:hover { background: var(--navy-deep); }
.scan-btn:active { transform: translateY(1px); background: var(--navy-deep); }
.scan-btn__icon {
  width: 50px; height: 50px; border-radius: 10px;
  background: var(--orange); color: var(--navy);
  display: grid; place-items: center;
}
.scan-btn__icon svg { width: 28px; height: 28px; stroke-width: 2.3; }
.scan-btn__text { display: grid; line-height: 1.35; }
.scan-btn__text strong { font-size: 19px; font-weight: 700; }
.scan-btn__text small { font-size: 14px; color: #D5DCF5; }
.scan-btn__arrow { width: 22px; height: 22px; color: var(--sky); }

.icon, .scan-btn svg, .notice svg, .stamp svg, .slot svg {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon { width: 22px; height: 22px; }

.hint {
  font-size: 14px; color: var(--ink-2); margin: 0;
  padding: 12px 14px; border: 1.5px dashed var(--line); border-radius: var(--r);
}

/* ---------- เส้นปรุ (แทน "หรือ") ---------- */
.tear {
  display: flex; align-items: center; gap: 12px;
  margin: 28px 0 14px;
  font-size: 15px; font-weight: 500; color: var(--ink);
}
.tear::after { content: ""; flex: 1; border-top: 1.5px dashed var(--line); }

/* ---------- ช่องโค้ด 4 ตัว ---------- */
.code-field { position: relative; }
.code-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; outline: none;
  background: transparent; color: transparent; caret-color: transparent;
  font-size: 16px; /* กัน iOS ซูม */
  z-index: 1; cursor: text;
}
.code-input::selection { background: transparent; }
.code-cells { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cell {
  position: relative;
  height: 68px; display: grid; place-items: center;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r);
  font-family: var(--mono); font-size: 30px; font-weight: 600; color: var(--ink);
  transition: border-color .12s ease, background-color .12s ease;
}
.cell.is-filled { border-color: var(--navy); background: var(--sky-wash); }
.code-field:focus-within .cell.is-active { border: 2px solid var(--blue); background: var(--card); }
.code-field:focus-within .cell.is-active:empty::after {
  content: ""; width: 2px; height: 30px; background: var(--blue);
  animation: blink 1s steps(1) infinite;
}
.code-field.invalid .cell { border-color: var(--red); background: var(--red-wash); }
@keyframes blink { 50% { opacity: 0; } }

.field-help { font-size: 14px; color: var(--ink-3); margin: 8px 0 0; }
.error { color: var(--red); font-size: 14px; font-weight: 500; margin: 8px 0 0; }

/* ---------- ปุ่มทั่วไป ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 12px 16px;
  border: 1.5px solid transparent; border-radius: var(--r);
  font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: background-color .15s ease, transform .08s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-deep); }
.btn-secondary { background: transparent; color: var(--ink); border-color: var(--navy); }
.btn-secondary:hover { background: var(--sky-wash); }
.btn-sm { min-height: 44px; padding: 8px 10px; font-size: 14px; font-weight: 500; border-color: var(--line); }
.code-form .btn { margin-top: 14px; }

.btn:focus-visible, .scan-btn:focus-visible, .chip:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 2px;
}

/* ---------- หน้าผลลัพธ์ ---------- */
.result-mark { margin: 12px 0 18px; display: flex; align-items: center; }

/* ตราปั๊ม */
.stamp {
  --c: var(--blue);
  width: 128px; height: 128px; border-radius: 50%;
  border: 3px solid var(--c); color: var(--c);
  outline: 1.5px solid var(--c); outline-offset: -10px;
  background: var(--sky-wash);
  display: grid; place-content: center; justify-items: center; gap: 0;
  text-align: center; line-height: 1.1;
  transform: rotate(var(--tilt, -6deg));
  animation: stamp-in .32s cubic-bezier(.2,.9,.3,1.2) both;
}
.stamp__top, .stamp__bottom { font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.stamp__top { font-family: var(--mono); }
.stamp__big { font-size: 38px; font-weight: 800; margin: 2px 0; font-family: var(--mono); }
.stamp__big.th { font-family: inherit; font-size: 30px; }
.stamp__big svg { width: 34px; height: 34px; stroke-width: 2.4; display: block; }
.stamp--gold { --c: var(--orange-ink); background: var(--orange-wash); }
.stamp--faded { --c: var(--ink-3); background: transparent; border-style: dashed; outline-style: dashed; animation: none; }

@keyframes stamp-in {
  0%   { opacity: 0; transform: scale(1.35) rotate(var(--tilt, -6deg)); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: scale(1) rotate(var(--tilt, -6deg)); }
}

/* กล่องแจ้งเตือน (กรณีไม่ได้แต้ม) */
.notice {
  width: 56px; height: 56px; border-radius: var(--r);
  display: grid; place-items: center; border: 2px solid currentColor;
}
.notice svg { width: 28px; height: 28px; }
.notice--warn { color: var(--orange-ink); background: var(--orange-wash); }
.notice--err { color: var(--red); background: var(--red-wash); }

/* บัตรแต้ม */
.card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px 14px 16px; margin: 0 0 24px;
}
.card__head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font-size: 14px; color: var(--ink-2); margin-bottom: 12px;
}
.card__head b { color: var(--ink); font-weight: 700; }
.round { display: inline-flex; align-items: center; gap: 8px; }
.ticks { display: inline-flex; gap: 3px; }
.ticks i { width: 10px; height: 4px; border-radius: 2px; background: var(--line); }
.ticks i.on { background: var(--sky); }

.slots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.slot {
  position: relative; aspect-ratio: 1;
  border: 1.5px dashed var(--line); border-radius: 10px;
  display: grid; place-items: center;
}
.slot__n { position: absolute; top: 3px; left: 6px; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.slot__tag {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 700; line-height: 1; padding: 3px 6px; border-radius: 4px;
  background: var(--orange); color: var(--navy); white-space: nowrap;
}
.slot--main { border-color: var(--orange); }
.slot__mark {
  width: 74%; aspect-ratio: 1; border-radius: 50%;
  border: 2.5px solid var(--blue); color: var(--blue);
  display: grid; place-items: center;
  transform: rotate(var(--tilt, 0deg));
}
.slot__mark svg { width: 55%; height: 55%; stroke-width: 2.6; }
.slot--main .slot__mark { border-color: var(--orange-ink); color: var(--orange-ink); }
.slot.is-filled .slot__n { visibility: hidden; }
.slot.is-filled { border-style: solid; border-color: transparent; background: var(--sky-wash); }
.slot--main.is-filled { background: var(--orange-wash); }
.slot.is-new .slot__mark { animation: slot-in .34s cubic-bezier(.2,.9,.3,1.2) .15s both; }
@keyframes slot-in {
  0% { opacity: 0; transform: scale(1.5) rotate(var(--tilt, 0deg)); }
  100% { opacity: 1; transform: scale(1) rotate(var(--tilt, 0deg)); }
}

.progress-text { font-size: 15px; color: var(--ink-2); margin: 18px 0 0; }
.progress-text strong { color: var(--ink); font-weight: 700; }

.actions { display: grid; gap: 10px; }

/* บัตรแต้ม: ยอดรวม + สถานะบูธหลัก */
.card__head .total { font-size: 14px; color: var(--ink-2); }
.card__head .total .num { font-family: var(--mono); font-size: 18px; font-weight: 600; color: var(--ink); }
.mainline {
  display: flex; align-items: center; gap: 8px;
  margin: 16px 0 0; font-size: 14px; color: var(--orange-ink);
}
.mainline__ico {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; border: 1.5px solid currentColor;
}
.mainline__ico svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.mainline.ok { color: var(--ink-2); }
.mainline.ok .mainline__ico { color: var(--blue); background: var(--sky-wash); border-color: var(--blue); }
.mainline + .progress-text { margin-top: 8px; }
.card__link {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  margin: 14px 0 0; padding: 12px 0 0; min-height: 44px;
  background: none; border: 0; border-top: 1.5px dashed var(--line);
  font: inherit; font-size: 15px; font-weight: 700; color: var(--blue); cursor: pointer; text-align: left;
}
.card__link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- แถบ "แต้มของฉัน" บนหน้าแรก ---------- */
.mypoints {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label chev" "value chev" "sub chev";
  align-items: center; width: 100%; margin: 0 0 16px; padding: 12px 14px 12px 16px;
  background: var(--card); color: var(--ink); text-align: left; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: var(--r);
  font: inherit; transition: border-color .15s ease;
}
.mypoints:hover { border-color: var(--navy); }
.mypoints.has-right { border-color: var(--orange); background: var(--orange-wash); }
.mypoints__label { grid-area: label; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.mypoints__value { grid-area: value; font-size: 15px; font-weight: 700; line-height: 1.3; }
.mypoints__value .num { font-family: var(--mono); font-size: 24px; font-weight: 600; }
.mypoints__sub { grid-area: sub; font-size: 14px; color: var(--ink-2); }
.mypoints.has-right .mypoints__sub { color: var(--orange-ink); font-weight: 700; }
.mypoints__chev { grid-area: chev; width: 22px; height: 22px; fill: none; stroke: var(--ink-2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.mypoints:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------- หน้าแต้มของฉัน ---------- */
.topnav { display: flex; align-items: center; gap: 12px; margin: 0 0 8px; }
.topnav__title { margin: 0; font-size: 20px; font-weight: 800; }
.icon-btn {
  flex: none; width: 44px; height: 44px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; color: var(--ink);
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.pts-state { margin: 24px 0; font-size: 15px; color: var(--ink-2); }
.pts-state--err { padding: 14px; border: 1.5px dashed var(--red); border-radius: var(--r); background: var(--red-wash); }
.pts-state--err p { margin: 0 0 10px; color: var(--red); }

.pts-hero { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 12px 0 16px; }
.pts-hero__num { font-family: var(--mono); font-size: 64px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.pts-hero__unit { font-size: 20px; font-weight: 700; }
.pts-hero__sub { flex-basis: 100%; margin: 4px 0 0; font-size: 15px; color: var(--ink-2); }

.sec { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; margin: 8px 0 12px; }
.sec::after { content: ""; flex: 1; border-top: 1.5px dashed var(--line); }
.sec__n { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink-2); }

.rights { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.right {
  display: grid; gap: 2px; padding: 10px 8px; min-height: 64px; align-content: center; text-align: center;
  border: 1.5px dashed var(--line); border-radius: 10px; background: transparent;
}
.right__n { font-size: 13px; font-weight: 700; }
.right__s { font-size: 12px; color: var(--ink-3); line-height: 1.35; }
.right--ready { border: 2px solid var(--orange); background: var(--orange-wash); }
.right--ready .right__s { color: var(--orange-ink); font-weight: 700; }
.right--next { border-style: solid; border-color: var(--blue); }
.right--next .right__s { color: var(--blue); font-weight: 500; }
.right--used { border-style: solid; background: var(--line); }
.right--used .right__n, .right--used .right__s { color: var(--ink-3); }
.right--used .right__s { text-decoration: line-through; }
.rights-note { margin: 10px 0 24px; font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.rights-note strong { color: var(--orange-ink); }

.log { list-style: none; margin: 0 0 24px; padding: 0; }
.log li {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px;
}
.log__code { font-family: var(--mono); font-weight: 600; }
.log__name { min-width: 0; }
.log__tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  background: var(--orange); color: var(--navy); vertical-align: 1px; margin-left: 4px;
}
.log__time { font-family: var(--mono); font-size: 13px; color: var(--ink-3); }

.actions--sticky {
  position: sticky; bottom: 0; margin: 0 -20px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1.5px solid var(--line);
}
#page-points { padding-bottom: 0; }

/* ---------- โหมดทดลอง ---------- */
.demo-banner {
  display: flex; gap: 10px; align-items: baseline;
  font-size: 14px; color: var(--ink); line-height: 1.5;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--orange-wash); border: 1.5px dashed var(--orange); border-radius: var(--r-sm);
}
.demo-banner strong {
  flex: none; font-size: 12px; font-weight: 700;
  padding: 1px 6px; border-radius: 4px; background: var(--orange); color: var(--navy);
}
.demo-panel { margin-top: 36px; padding-top: 18px; border-top: 1.5px dashed var(--line); }
.demo-panel .label { font-size: 14px; font-weight: 500; color: var(--ink-2); margin: 0 0 10px; }
.demo-codes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  font: inherit; font-family: var(--mono); font-size: 14px; font-weight: 500;
  min-height: 40px; padding: 6px 12px; border-radius: var(--r-sm); cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
}
.chip:hover { border-color: var(--navy); }
.chip.main { border-color: var(--orange); background: var(--orange-wash); color: var(--orange-ink); }
.chip.test { border-style: dashed; color: var(--ink-2); font-family: inherit; }
.chip.done { color: var(--ink-3); text-decoration: line-through; border-style: dotted; }
.demo-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- โหลด / แจ้งเตือน ---------- */
.loading {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(250,249,245,.82);
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--blue);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; z-index: 30;
  left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 448px; margin: 0 auto;
  background: var(--navy); color: #fff;
  font-size: 15px; line-height: 1.5; padding: 12px 16px; border-radius: var(--r);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .spinner { animation: spin 1.4s linear infinite !important; }
}

/* แต้มปกติที่เก็บเกิน 4 ก่อนได้บูธหลัก */
.extra-line {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 0; padding: 8px 10px; border-radius: var(--r-sm);
  background: var(--sky-wash); font-size: 14px; color: var(--ink-2);
}
.extra-line .num { font-family: var(--mono); font-weight: 600; color: var(--blue); }
.extra-line + .progress-text { margin-top: 10px; }

/* แต้มของฉันบนหน้าแรก (ใต้ปุ่มยืนยันโค้ด) */
.home-points { margin-top: 32px; }

/* ---------- บัตรสะสมแบบเลื่อนดู ---------- */
.carousel { margin: 0 0 24px; }
.carousel__top {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin: 0 0 10px; font-size: 15px; font-weight: 700;
}
.carousel__top .num { font-family: var(--mono); font-size: 22px; font-weight: 600; }
.carousel__sum { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.carousel__sum strong { color: var(--orange-ink); }
.cards-track {
  display: flex; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scroll-padding: 0 20px; scrollbar-width: none;
  margin: 0 -20px; padding: 2px 20px 4px;
}
.cards-track::-webkit-scrollbar { display: none; }
.cards-track:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.card--slide { flex: 0 0 86%; margin: 0; scroll-snap-align: start; }
.card--slide .slots { margin-bottom: 4px; }
.card--slide .progress-text { margin-top: 18px; }
.card--used { opacity: .7; }
.card--ready { border-color: var(--orange); }
.st { font-size: 12px; font-weight: 700; line-height: 1; padding: 5px 8px; border-radius: 6px; white-space: nowrap; }
.st--ready { background: var(--orange); color: var(--navy); }
.st--used { background: var(--line); color: var(--ink-2); }
.st--wait { background: var(--orange-wash); color: var(--orange-ink); border: 1px dashed var(--orange); }
.st--progress { background: var(--sky-wash); color: var(--blue); }
.st--locked { background: transparent; color: var(--ink-3); border: 1px dashed var(--line); }
.dots { display: flex; justify-content: center; gap: 2px; margin-top: 6px; }
.dot {
  width: 28px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center;
}
.dot::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--line); transition: width .2s ease, background-color .2s ease; }
.dot.on::before { width: 20px; background: var(--navy); }
.dot:focus-visible { outline: 2px solid var(--blue); outline-offset: -4px; border-radius: 6px; }
