:root {
  /* สีหลัก 4 สี — แต่ละเว็บเปลี่ยนได้จากหลังบ้าน (server ใส่ค่าทับให้) */
  --bg: #4a0505;
  --topbar: #5e0000;
  --red: #e10000;
  --gold: #c8b400;
  /* สีที่คำนวณจากสีหลัก */
  --bg-deep: color-mix(in srgb, var(--bg), #000 40%);
  --red-dark: color-mix(in srgb, var(--red), #000 32%);
  --red-deep: color-mix(in srgb, var(--red), #000 45%);
  --gold-light: color-mix(in srgb, var(--gold), #fff 45%);
  --frame: color-mix(in srgb, var(--gold), #ff9800 25%);
  --card: #fff;
  --text: #444;
  --muted: #777;
  --gray-pill: #666;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Kanit', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
/* ภาพพื้นหลังแบบอยู่กับที่ (ตั้งจากหลังบ้าน) — ใช้ชั้น fixed แทน background-attachment: fixed ที่ Safari มือถือไม่รองรับ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--bg);
  background-image: var(--bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

/* ---------- แถบบน ---------- */
.topbar {
  position: relative;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -16px -16px 12px;
  padding: 10px 12px;
  background: linear-gradient(var(--topbar), color-mix(in srgb, var(--topbar), #000 38%));
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.menu-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1.5px solid #fff;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.menu-btn svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.logo { flex: 1; min-width: 0; display: flex; }
.logo img { height: 62px; max-width: 100%; object-fit: contain; object-position: left; }
.topbar-actions { flex: none; display: flex; gap: 6px; }
.btn-top {
  padding: 7px 12px;
  border-radius: 20px;
  background: #fff;
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
}
.menu {
  position: absolute;
  top: 100%;
  left: 12px;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  padding: 6px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.menu[hidden] { display: none; }
.menu a { padding: 10px 12px; border-radius: 8px; color: #444; font-size: 15px; }
.menu a:hover { background: #fbe9e9; }

@media (max-width: 400px) {
  .btn-top { padding: 6px 9px; font-size: 12.5px; }
  .logo img { height: 52px; }
}

/* ---------- ภาพสไลด์ ---------- */
.slider {
  position: relative;
  margin-bottom: 14px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--frame);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.slides {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.slides::-webkit-scrollbar { display: none; }
.slides img {
  flex: none;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  scroll-snap-align: start;
  display: block;
}
.dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.dots button {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #fff8;
  cursor: pointer;
  transition: width .2s;
}
.dots button.active { width: 20px; background: #fff; }

/* ---------- แบนเนอร์ ---------- */
.banner {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  padding: 22px 16px 18px;
  text-align: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 215, 0, .25), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(255, 215, 0, .2), transparent 40%),
    repeating-radial-gradient(circle at 50% 120%, color-mix(in srgb, var(--red), #000 20%) 0 14px, color-mix(in srgb, var(--red), #000 29%) 14px 28px);
  border: 2px solid var(--frame);
  box-shadow: 0 0 0 3px var(--red-deep) inset, 0 8px 24px rgba(0, 0, 0, .4);
}
.banner-brand {
  display: inline-block;
  padding: 2px 14px;
  border-radius: 20px;
  background: linear-gradient(#fff6c2, #e0b300);
  color: var(--red-deep);
  font-weight: 700;
  font-size: 14px;
}
.banner-title {
  margin: 8px 0 2px;
  font-size: clamp(26px, 8vw, 38px);
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  text-shadow: 0 2px 0 var(--red-deep), 0 0 12px rgba(255, 200, 0, .6);
}
.banner-sub { color: #ffe9a8; font-size: 14px; }
.banner-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.stat {
  background: linear-gradient(color-mix(in srgb, var(--red), #000 40%), color-mix(in srgb, var(--red), #000 58%));
  border: 2px solid color-mix(in srgb, var(--gold), #fff 25%);
  border-radius: 10px;
  padding: 6px 4px;
  color: var(--gold-light);
}
.stat span { display: block; font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat small { color: #fff; font-size: 12px; }

/* ---------- เมนูลัด ---------- */
.quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  background: var(--card);
  border-radius: 14px;
  font-size: 13px;
  color: #555;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.quick-item:active { transform: scale(.96); }
.qi-ico { font-size: 24px; line-height: 1; }

.site-name {
  margin-top: 24px;
  text-align: center;
  color: var(--red);
  font-size: 28px;
  font-weight: 700;
  text-shadow: 0 1px 0 #fff3;
}
.site-tag { text-align: center; color: #e8cfcf; font-size: 15px; }

/* ---------- ปุ่มหมวด ---------- */
.pills-wrap {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 18px -16px 0;
  /* โปร่งแสงเล็กน้อย ให้กลืนกับภาพพื้นหลัง (ถ้ามี) */
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 8px;
  scrollbar-width: none;
  scroll-behavior: smooth;
  cursor: grab;
}
.pills.dragging { cursor: grabbing; scroll-behavior: auto; user-select: none; }
.pills.dragging .pill { pointer-events: none; }
/* ไล่สีจางที่ขอบ + ปุ่มลูกศร บอกว่ายังเลื่อนต่อได้ */
.pills-arrow {
  position: absolute;
  top: 0;
  bottom: 4px;
  z-index: 1;
  width: 44px;
  border: 0;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.pills-arrow.prev { left: 0; padding-right: 14px; background: linear-gradient(90deg, var(--bg) 55%, transparent); }
.pills-arrow.next { right: 0; padding-left: 14px; background: linear-gradient(270deg, var(--bg) 55%, transparent); }
.pills-wrap.can-prev .prev,
.pills-wrap.can-next .next { opacity: 1; pointer-events: auto; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  padding: 4px 14px;
  border-radius: 20px;
  border: 2px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.pill.active { background: var(--gold); border-color: var(--gold); }

/* ---------- ส่วนหมวด ---------- */
.section { margin-top: 14px; scroll-margin-top: 56px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 8px;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}
.section-title small { color: #e0bcbc; font-size: 12px; font-weight: 400; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 10px 10px 14px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.card:active { transform: scale(.98); }
.card-head { display: flex; gap: 6px; align-items: flex-start; }
.card-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  color: #555;
  line-height: 1.35;
}
.flag {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #eee;
  background: #f3f3f3;
}
.card-meta { margin-top: 4px; font-size: 11.5px; color: #333; }
.card-meta b { font-weight: 600; }

.nums {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}
.num {
  text-align: center;
  background: #fbf6e3;
  border: 1px solid #efe2a8;
  border-radius: 8px;
  padding: 3px 0 2px;
}
.num small { display: block; font-size: 10.5px; color: var(--muted); }
.num strong {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--red-dark);
  letter-spacing: 1px;
  line-height: 1.2;
}
.num.empty strong { color: #bbb; }

.status {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  border-radius: 16px;
  color: #fff;
  font-size: 15px;
  background: var(--gold);
  font-variant-numeric: tabular-nums;
}
.status svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; }
.status.done { background: linear-gradient(#1faa4a, #13823a); }
.status.wait { background: var(--gray-pill); }

.more {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 5px;
  border: 0;
  border-radius: 16px;
  background: #777;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* การ์ดใหญ่ (รัฐบาล / ออมสิน) */
.card.wide { grid-column: 1 / -1; padding: 14px; }
.first-prize {
  margin: 8px 0 6px;
  text-align: center;
  background: linear-gradient(#fff8d6, #ffe98a);
  border: 1px solid #e5c64c;
  border-radius: 10px;
  padding: 6px;
}
.first-prize small { display: block; font-size: 12px; color: #7a5a00; }
.first-prize strong {
  font-size: 34px;
  font-weight: 700;
  color: var(--red-dark);
  letter-spacing: 4px;
}
.nums.four { grid-template-columns: repeat(4, 1fr); }
.nums.four .num strong { font-size: 16px; }

/* ---------- สถานะโหลด / ข้อผิดพลาด ---------- */
.loading, .error {
  padding: 40px 0;
  text-align: center;
  color: #fff;
}
.error button {
  margin-top: 8px;
  padding: 6px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--gold);
  color: #fff;
  cursor: pointer;
}
.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 10px;
  border: 3px solid #fff4;
  border-top-color: var(--gold-light);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.updated { margin-top: 20px; text-align: center; color: #d9b3b3; font-size: 12px; }

/* ---------- เมนูล่าง ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: #fff;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .2);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1;
  max-width: 174px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 6px;
  font-size: 13px;
  color: #444;
}
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.bottom-nav a.active { color: var(--red); }

/* ---------- หน้าต่าง ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.modal[hidden] { display: none; }
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px 16px 0 0;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
/* จอคอม/แท็บเล็ต: หน้าต่างลอยขึ้นมาค่อนกลางจอ (มือถือยังเลื่อนขึ้นจากด้านล่างเหมือนเดิม)
   ยึดขอบบนไว้ที่ 10vh ผลตรวจที่ยาวขึ้นจะขยายลงล่าง หน้าต่างไม่กระโดด */
@media (min-width: 600px) {
  .modal { align-items: flex-start; padding: 10vh 16px 24px; }
  .modal-box { max-height: 80vh; border-radius: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); }
  .modal-body { border-radius: 0 0 16px 16px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(var(--red), var(--red-dark));
  border-radius: 16px 16px 0 0;
  color: #fff;
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 500; }
.modal-close {
  border: 0;
  background: none;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.modal-body { overflow-y: auto; padding: 12px 16px 20px; }

.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist th {
  position: sticky;
  top: -12px;
  background: #fbe9e9;
  color: var(--red-dark);
  font-weight: 500;
  padding: 6px 4px;
}
.hist td { text-align: center; padding: 7px 4px; border-bottom: 1px solid #eee; }
.hist td.n { font-weight: 600; color: var(--red-dark); letter-spacing: 1px; font-size: 16px; }
.hist td.d { color: var(--muted); font-size: 13px; }

.prize-block { margin-bottom: 14px; }
.prize-block h4 { margin: 0 0 6px; font-size: 14px; font-weight: 500; color: var(--red-dark); }
.prize-block h4 small { color: var(--muted); font-weight: 400; }
.prize-list { display: flex; flex-wrap: wrap; gap: 6px; }
.prize-list span {
  padding: 2px 8px;
  border-radius: 6px;
  background: #f5f5f5;
  font-size: 14px;
  letter-spacing: 1px;
}
.prize-list span.hit { background: var(--gold); color: #fff; }

.check-form { display: flex; gap: 8px; margin-bottom: 12px; }
.check-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 2px solid #ddd;
  border-radius: 10px;
  font: inherit;
  font-size: 20px;
  letter-spacing: 4px;
  text-align: center;
}
.check-form input:focus { outline: none; border-color: var(--gold); }
.check-form button {
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.check-result {
  padding: 12px;
  border-radius: 10px;
  text-align: center;
  font-size: 16px;
  background: #f4f4f4;
}
.check-result.win { background: #fff5cc; color: #7a5a00; font-weight: 500; }
.check-result small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; font-weight: 400; }

/* แท็บในหน้าต่างตรวจสลาก */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 12px;
  background: #f1eeee;
}
.tabs button {
  padding: 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #666;
  font-size: 15px;
  cursor: pointer;
}
.tabs button.active { background: #fff; color: var(--red-dark); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
[data-panel][hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.field select {
  padding: 8px 10px;
  border: 2px solid #ddd;
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: #333;
}
.field select:focus { outline: none; border-color: var(--gold); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.win-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #efe2a8;
  border-radius: 10px;
  background: #fffdf3;
}
.win-row .flag { width: 30px; height: 30px; }
.win-name { flex: 1; min-width: 0; font-size: 14.5px; color: #444; }
.win-name small, .win-hit small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.win-hit { text-align: right; color: var(--red-dark); font-weight: 600; font-size: 14px; }

/* ---------- หน้าต่างเข้าสู่ระบบ ---------- */
.login {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .6);
}
.login[hidden] { display: none; }
.login-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 24px 22px 22px;
  border-radius: 16px;
  background: #fff;
  text-align: center;
  animation: pop .2s ease-out;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.login-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: #f0453a;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.login-ico {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 6px;
  border-radius: 50%;
  background: linear-gradient(#ffb23f, #f28c00);
}
.login-ico svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.login-box h2 { margin: 0; color: #b8a000; font-size: 26px; font-weight: 600; }
.login-box p { margin: 2px 0 16px; color: #555; font-size: 17px; font-weight: 500; }
.login-box input:not([type=checkbox]) {
  display: block;
  width: 100%;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #c8b400;
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
}
.login-box input:focus { outline: 2px solid #e6d24a; outline-offset: 0; }
.login-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -4px 0 14px;
  color: #a89000;
  font-size: 14px;
}
.login-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.login-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: 0;
  border-radius: 24px;
  background: #a86400;
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}
.login-btn:active { transform: scale(.98); }

@media (max-width: 360px) {
  .num strong { font-size: 17px; }
  .card-name { font-size: 14px; }
}
