:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #c8102e;           /* lottery red, used for the special prize only */
  --accent-soft: #fdecee;
  --series-1: #2a78d6;         /* blue: frequency */
  --series-2: #eb6834;         /* orange: gan */
  --seq-lo: #eef4fc;
  --seq-hi: #0d366b;
  --seq2-lo: #fdf0ea;
  --seq2-hi: #8a3210;
  --good: #0ca30c;
  --grid: #e8e6e1;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border: #2e2e2c;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #ff5a6e;
    --accent-soft: #3a1a1f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --seq-lo: #1f2630;
    --seq-hi: #86b6ef;
    --seq2-lo: #2a211d;
    --seq2-hi: #f2a27f;
    --grid: #2a2a28;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --border: #2e2e2c;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #ff5a6e;
  --accent-soft: #3a1a1f;
  --series-1: #3987e5;
  --series-2: #d95926;
  --seq-lo: #1f2630;
  --seq-hi: #86b6ef;
  --seq2-lo: #2a211d;
  --seq2-hi: #f2a27f;
  --grid: #2a2a28;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; letter-spacing: -.01em; }
h2 { font-size: 15px; }
p { margin: 0; }
a { color: var(--series-1); }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand p { font-size: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-weight: 500;
  padding: 6px 14px; border-radius: 7px; cursor: pointer;
}
.seg button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg.small button { padding: 4px 10px; font-size: 12px; }

select, .lookup-form input, .lookup-form button, .icon-btn {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
.icon-btn { cursor: pointer; width: 36px; padding: 6px 0; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.pill.live { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.pill.live .dot { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.backfill { display: flex; align-items: center; gap: 12px; padding: 6px 24px; font-size: 12px; }
.backfill-track { flex: 0 0 200px; height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.backfill-fill { height: 100%; width: 0; background: var(--series-1); transition: width .4s; }

/* ---------- layout ---------- */
.grid {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px;
  max-width: 1360px; margin: 0 auto; padding: 20px 24px 8px;
}
.kpis { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.card, .kpi {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); min-width: 0;
}
.card { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { font-size: 12px; margin-top: 2px; }
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- KPIs ---------- */
.kpi { padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--text-secondary); }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.hero { background: var(--accent-soft); border-color: transparent; }
.kpi.hero .kpi-value { color: var(--accent); }

/* ---------- results table ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.results th, .results td { border-bottom: 1px solid var(--grid); padding: 7px 8px; text-align: center; }
.results th { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--surface-2); }
.results td.prize { text-align: left; color: var(--text-secondary); font-size: 12px; white-space: nowrap; width: 86px; }
.results .nums { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; }
.results .num { font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.results .num .dim { color: var(--text-muted); font-weight: 400; }
.results .num.pending { color: var(--text-muted); font-weight: 400; }
.results tr.special .num { color: var(--accent); font-size: 22px; font-weight: 700; }
.results tr.g-last .num { color: var(--accent); }
.num.fresh { animation: fresh 2.4s ease-out; border-radius: 4px; }
@keyframes fresh { 0% { background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-soft); } 100% { background: transparent; box-shadow: none; } }
.codes { margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.codes b { color: var(--text-primary); }

/* ---------- summary ---------- */
.summary { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.summary li { padding-left: 14px; position: relative; color: var(--text-primary); }
.summary li::before { content: ""; position: absolute; left: 0; top: .65em; width: 5px; height: 5px; border-radius: 50%; background: var(--series-1); }
.summary li:first-child { font-weight: 600; }
.disclaimer { margin-top: 16px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 12px; color: var(--text-secondary); }

/* ---------- loto table ---------- */
.loto th, .loto td { padding: 5px 8px; border-bottom: 1px solid var(--grid); text-align: left; font-size: 13px; }
.loto th { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.loto td.d { width: 36px; text-align: center; font-weight: 700; color: var(--text-secondary); background: var(--surface-2); }
.loto .sp { color: var(--accent); font-weight: 700; }

/* ---------- heatmap ---------- */
.heat { display: grid; grid-template-columns: 24px repeat(10, minmax(0, 1fr)); gap: 3px; }
.heat .axis { font-size: 11px; color: var(--text-muted); display: grid; place-items: center; }
.heat .cell {
  aspect-ratio: 1.35; border-radius: 5px; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-primary); transition: transform .1s;
}
.heat .cell.ink-light { color: #fff; }
.heat .cell.ink-dark { color: #0b0b0b; }
.heat .cell:hover, .heat .cell:focus-visible { transform: scale(1.08); outline: 2px solid var(--text-primary); outline-offset: 1px; }
.heat .cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.legend-ramp { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 11px; color: var(--text-muted); }
.ramp { flex: 0 1 220px; height: 8px; border-radius: 4px; }
.legend-ramp .key-today { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.legend-ramp .key-today i { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- bar lists ---------- */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 30px 1fr 34px; align-items: center; gap: 8px; cursor: pointer; }
.bar-row .lbl { font-weight: 700; }
.bar-row .val { text-align: right; color: var(--text-secondary); font-size: 12px; }
.bar-track { position: relative; height: 14px; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.gan .bar-fill { background: var(--series-2); }
.bar-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-primary); opacity: .55; border-radius: 1px; }
.bar-row:hover .bar-fill { filter: brightness(1.1); }

.mini-title { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin: 4px 0 6px; }
.cols { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; align-items: end; height: 92px; margin-bottom: 10px; }
.col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; cursor: default; }
.col .c-bar { width: 100%; max-width: 22px; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 2px; }
.col .c-val { font-size: 10px; color: var(--text-muted); }
.col .c-lbl { font-size: 11px; font-weight: 600; color: var(--text-secondary); }

/* ---------- special prize chart ---------- */
.chart { position: relative; height: 260px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--text-muted); font-size: 10px; }
.chart .dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .dot.hl { fill: var(--accent); }
.chart .xhair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }

/* ---------- lookup ---------- */
.lookup-form { display: flex; gap: 8px; margin-bottom: 12px; }
.lookup-form input { width: 90px; font-size: 16px; font-weight: 600; text-align: center; }
.lookup-form button { cursor: pointer; background: var(--text-primary); color: var(--surface-1); border-color: transparent; font-weight: 600; }
.lookup-result { font-size: 13px; max-height: 260px; overflow: auto; }
.lookup-result .big { font-size: 30px; font-weight: 700; color: var(--text-primary); }
.lookup-result table td { padding: 4px 6px; border-bottom: 1px solid var(--grid); font-size: 12px; color: var(--text-primary); }
.lookup-stats { display: flex; gap: 18px; margin-bottom: 10px; }
.lookup-stats div span { display: block; font-size: 11px; color: var(--text-muted); }
.lookup-stats div b { font-size: 18px; color: var(--text-primary); }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 240px;
  background: var(--text-primary); color: var(--surface-1); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; line-height: 1.45; box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}
.tooltip b { font-size: 13px; }

.foot { max-width: 1360px; margin: 0 auto; padding: 8px 24px 28px; font-size: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-4, .span-5, .span-7, .span-8 { grid-column: span 6; }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .topbar-right { width: 100%; }
  .topbar-right .pill { margin-right: auto; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right .pill .dot { flex: none; }
  .seg#regionTabs { width: 100%; }
  .seg#regionTabs button { flex: 1; padding: 6px 4px; }
  .grid { padding: 14px 16px 8px; gap: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpis .kpi.hero { grid-column: 1 / -1; }
  .span-4, .span-5, .span-7, .span-8 { grid-column: 1 / -1; }
  .card { padding: 14px; }
  .results .num { font-size: 15px; }
  .results tr.special .num { font-size: 19px; }
  .heat .cell { font-size: 10px; }
  .backfill { padding: 6px 16px; }
  .foot { padding: 8px 16px 24px; }
}
