:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --text: #1f1c17;
  --muted: #6b645a;
  --line: #e2dccf;
  --accent: #b8860b;
  --accent-ink: #7a5800;
  --win: #c0392b;
  --ok: #1e7d4f;
  --warn: #a86400;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 14px;
  --font: "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --surface: #1f1c17;
    --surface-2: #2a261f;
    --text: #f2ede3;
    --muted: #a99f90;
    --line: #3a352c;
    --accent: #e0b44a;
    --accent-ink: #f0cd78;
    --win: #ff7a6b;
    --ok: #5fcf96;
    --warn: #f0b060;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.6; }
html.big { font-size: 20px; }
a { color: var(--accent-ink); }
img { max-width: 100%; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .wrap { display: flex; align-items: center; gap: 16px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; }
.nav a.on, .nav a:hover { background: var(--surface-2); color: var(--text); }
.size-btn { margin-left: auto; border: 1px solid var(--line); background: none; color: var(--text); border-radius: 8px; padding: 4px 10px; font: inherit; cursor: pointer; }

.wrap { max-width: 1080px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
main.wrap { padding-top: 20px; padding-bottom: 40px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 16px; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .section { margin-top: 16px; }

/* Thai government lottery result */
.hero { text-align: center; }
.hero .date { color: var(--muted); }
.first { font-family: var(--mono); font-size: clamp(2.4rem, 11vw, 4rem); letter-spacing: .08em; font-weight: 700; color: var(--win); line-height: 1.1; margin: 6px 0 2px; }
.prize-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.prize { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.prize .label { font-size: .85rem; color: var(--muted); }
.prize .num { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; letter-spacing: .05em; }
.near { color: var(--muted); font-size: .9rem; margin-top: 8px; }
.num-list { font-family: var(--mono); display: flex; flex-wrap: wrap; gap: 6px 14px; }

.countdown { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.countdown div { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; min-width: 62px; text-align: center; }
.countdown b { display: block; font-family: var(--mono); font-size: 1.5rem; }
.countdown span { font-size: .8rem; color: var(--muted); }

/* forms */
input[type=text], input[type=search], input[type=date], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; font-family: var(--mono); }
button.primary { font: inherit; font-weight: 600; background: var(--accent); color: #1f1c17; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; }
button.ghost { font: inherit; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.row > button { flex: 0 0 auto; }
label.inline { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: .9rem; }

.check-out { margin-top: 12px; display: grid; gap: 6px; }
.hit { border-left: 4px solid var(--ok); background: var(--surface-2); padding: 8px 12px; border-radius: 8px; }
.hit.win { border-color: var(--win); }
.hit b { font-family: var(--mono); }

/* other lotteries */
.lot { display: flex; flex-direction: column; gap: 6px; }
.lot .name { font-weight: 600; }
.lot .meta { color: var(--muted); font-size: .85rem; }
.lot .nums { display: flex; gap: 12px; }
.lot .nums div { text-align: center; }
.lot .nums small { display: block; color: var(--muted); font-size: .75rem; }
.lot .nums b { font-family: var(--mono); font-size: 1.35rem; }
.badge { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.official { border-color: var(--ok); color: var(--ok); }
.badge.real, .badge.derived { border-color: var(--accent); color: var(--accent-ink); }
.badge.approx, .badge.unverified, .badge.site-made { border-color: var(--warn); color: var(--warn); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 14px; cursor: pointer; }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* hot numbers & news */
.hot { display: grid; gap: 10px; }
.hot-item { display: grid; grid-template-columns: minmax(84px, 38%) 1fr; gap: 12px; align-items: start; }
.hot-item .nums { font-family: var(--mono); font-weight: 700; color: var(--win); font-size: 1.1rem; overflow-wrap: anywhere; }
.hot-item p { margin: 0; }
.hot-item small, .news small { color: var(--muted); }
.news { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.news a { text-decoration: none; color: var(--text); }
.news a:hover { text-decoration: underline; }
.chip { font-family: var(--mono); background: var(--surface-2); padding: 0 6px; border-radius: 6px; margin-left: 4px; }
.news li > small { display: block; }
.hn-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0 1px; }
.chip.hn { margin: 0; color: var(--win); font-weight: 700; background: var(--surface); border: 1px solid var(--line); font-size: 1rem; }
.hn-row .more { color: var(--muted); font-size: .85rem; align-self: center; }

/* สรุปเลขจากข่าว (home) */
.hint-sum { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.hint-sum h3 { font-size: 1.05rem; margin: 0 0 2px; }
.hint-sum .sub { margin: 0 0 6px; font-size: .85rem; }
.hint-sum .hint-note { margin: 8px 0 0; }
.hnums { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.hnums .lbl { font-size: .8rem; color: var(--muted); min-width: 2.8em; }
.hnum { font: inherit; font-family: var(--mono); font-weight: 700; font-size: 1.1rem; color: var(--win); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1px 8px; cursor: pointer; line-height: 1.5; }
.hnum small { font-size: .7rem; color: var(--muted); font-weight: 500; margin-left: 2px; }
.hnum.on { border-color: var(--win); box-shadow: inset 0 0 0 1px var(--win); }
.hint-src { background: var(--surface); border-radius: 10px; padding: 8px 12px; margin-top: 6px; font-size: .9rem; overflow-wrap: anywhere; }
.hint-src ul { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.hint-src a { color: var(--text); }

/* แหล่งใบ้หวยไหนเคยใบ้ถูก (stats) */
.acc-table { font-size: .9rem; }
.acc-table th, .acc-table td { padding: 6px 6px; }
.acc-table td.num, .acc-table th.num { text-align: right; }
.acc-table td.name { white-space: normal; min-width: 7em; }
.acc-table .hitn { font-family: var(--mono); color: var(--win); font-weight: 700; }
.acc-draw { margin-top: 10px; }
.acc-draw summary { cursor: pointer; color: var(--accent-ink); }
.acc-draw ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; font-size: .9rem; overflow-wrap: anywhere; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
tr.detail td { white-space: normal; padding: 0; }
.prize-detail { position: sticky; left: 0; box-sizing: border-box; width: min(100vw - 76px, 60rem); padding: 12px 10px; }
.prize-detail .prize { margin-bottom: 8px; }
.prize-detail .prize .num { font-size: 1.05rem; word-spacing: .5em; }
td.mono, .mono { font-family: var(--mono); }
.bar { height: 8px; border-radius: 4px; background: var(--accent); opacity: .8; }

.freq { display: grid; grid-template-columns: 48px 1fr auto; gap: 6px 10px; align-items: center; font-size: .95rem; }
.freq .n { font-family: var(--mono); font-weight: 700; }
.freq .c { color: var(--muted); text-align: right; font-size: .85rem; white-space: nowrap; }

/* dreams */
.dream-list { display: grid; gap: 10px; }
.dream { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.dream h3 { margin: 0; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dream p { margin: 4px 0; color: var(--muted); }
.dream .dnums { font-family: var(--mono); font-weight: 700; color: var(--win); font-size: 1.2rem; }
.combo { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }

.notice { font-size: .85rem; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 10px 14px; }
footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; padding: 20px 0 40px; }
footer p { margin: 4px 0; }
.empty { color: var(--muted); }
.hidden { display: none !important; }

@media (max-width: 560px) {
  .top .wrap { gap: 6px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { padding: 4px 10px; }
  .hot-item { grid-template-columns: 1fr; gap: 2px; }
  .g2 { grid-template-columns: 1fr; }
}

/* live broadcast block (js/live.js) */
.live { margin-top: 12px; }
.live-mini { margin: 0; font-size: .9rem; color: var(--muted); }
.live-box { text-align: left; background: var(--surface-2); border-radius: 12px; padding: 12px; }
.live-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--win); flex: 0 0 auto; animation: live-blink 1.4s infinite; }
@keyframes live-blink { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.live-player { position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 200px; background: #000; border-radius: 10px; overflow: hidden; }
.live-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.live-play { position: absolute; inset: 0; width: 100%; border: 0; background: #111; color: #fff; font: inherit; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px; }
.live-play .tri { width: 0; height: 0; border-style: solid; border-width: 14px 0 14px 24px; border-color: transparent transparent transparent #fff; }
.live-note { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }
.live-more summary { cursor: pointer; color: var(--accent-ink); font-size: .9rem; margin-top: 6px; }
.live-links { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; font-size: .9rem; }
.live-links small { color: var(--muted); }

/* ticket scanner (scan.html) */
.scan-video { position: relative; width: 100%; max-width: 480px; aspect-ratio: 1 / 1; background: #000; border-radius: 12px; overflow: hidden; margin: 0 auto; }
.scan-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-video .frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px; pointer-events: none; }
.scan-status { text-align: center; color: var(--muted); font-size: .9rem; min-height: 1.6em; margin: 8px 0; }
.scan-raw { font-family: var(--mono); font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
input.ticket { font-family: var(--mono); font-size: 1.3rem; letter-spacing: .1em; }
.file-btn { flex: 0 0 auto; text-align: center; cursor: pointer; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; }
.scan-actions > button { flex: 1 1 200px; max-width: 100%; }
