/* Layout: một cột rộng cỡ điện thoại ở giữa màn hình, thanh tên app dính phía trên, thanh tab cố định phía dưới */
:root {
  --bg: #F2F3F5;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --chip: #E6E8EC;
  --ink: #16181D;
  --muted: #5B606B;
  --line: #E3E5EA;
  --line-soft: #EEF0F3;
  --red: #C4122F;          /* nền đỏ, chữ trắng */
  --red-ink: #C4122F;      /* chữ đỏ trên nền sáng */
  --red-strong: #9B0E26;
  --red-tint: #FCE9EC;
  --on-red: #FFFFFF;
  --amber: #D97706;
  --amber-tint: #FEF3E2;
  --amber-ink: #92400E;
  --hero: #16181D;
  --hero-ink: #FFFFFF;
  --hero-muted: #C9CDD4;
  --hero-red: #FF6B81;
  --heat: 165, 14, 39;
  --shadow: 0 1px 2px rgba(22, 24, 29, .14);
  --focus: #2563EB;
  --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --col: 560px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1114; --surface: #181B20; --surface-2: #1F232A; --chip: #252A31;
    --ink: #ECEEF1; --muted: #A3A9B4; --line: #2B3038; --line-soft: #23272E;
    --red: #D62845; --red-ink: #FF6B81; --red-strong: #FF8597; --red-tint: #3A1A21; --on-red: #FFFFFF;
    --amber: #F59E0B; --amber-tint: #33260F; --amber-ink: #FBBF24;
    --hero: #252A31; --hero-ink: #ECEEF1; --hero-muted: #A3A9B4; --hero-red: #FF8597;
    --heat: 226, 46, 76; --shadow: 0 1px 2px rgba(0, 0, 0, .5); --focus: #60A5FA;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1114; --surface: #181B20; --surface-2: #1F232A; --chip: #252A31;
  --ink: #ECEEF1; --muted: #A3A9B4; --line: #2B3038; --line-soft: #23272E;
  --red: #D62845; --red-ink: #FF6B81; --red-strong: #FF8597; --red-tint: #3A1A21; --on-red: #FFFFFF;
  --amber: #F59E0B; --amber-tint: #33260F; --amber-ink: #FBBF24;
  --hero: #252A31; --hero-ink: #ECEEF1; --hero-muted: #A3A9B4; --hero-red: #FF8597;
  --heat: 226, 46, 76; --shadow: 0 1px 2px rgba(0, 0, 0, .5); --focus: #60A5FA;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--surface);
}
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Khung */
.inner {
  max-width: var(--col); margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .inner { display: flex; align-items: center; gap: 10px; padding-block: 10px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: var(--red); color: var(--on-red);
  display: grid; place-items: center; font: 700 14px/1 var(--font-num);
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
main.inner {
  display: flex; flex-direction: column; gap: 16px;
  padding-block: 16px calc(100px + env(safe-area-inset-bottom, 0px));
}
main:focus { outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar .inner { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding-block: 6px 8px; }
.tab {
  min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; border-radius: 10px;
}
.tab[aria-current="page"] { color: var(--red-ink); font-weight: 700; }
.tab svg { width: 22px; height: 22px; }

/* Thành phần chung */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.pad { padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.h2 { font-size: 15px; font-weight: 700; }
.small { font-size: 12px; color: var(--muted); }
.page-title { display: flex; flex-direction: column; gap: 2px; }
.page-title h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
  background: var(--chip); padding: 4px; border-radius: 12px;
}
.seg button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0 6px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer;
}
.pill[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.controls { display: flex; flex-direction: column; gap: 10px; }
.ctl-label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }

.daypick { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.daypick button {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer; padding: 0;
}
.daypick button[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: var(--on-red); }

.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--ink); flex: none;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; }

.hero { background: var(--hero); color: var(--hero-ink); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.hero .big { font-size: 18px; font-weight: 700; }
.hero .sub { font-size: 13px; color: var(--hero-muted); }
.hero .red { color: var(--hero-red); }

.note { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 10px; align-items: start; }
.note svg { width: 20px; height: 20px; color: var(--muted); }
.note p { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.note strong { color: var(--ink); font-size: 13px; display: block; margin-bottom: 2px; }

/* Kết quả */
.datebar { display: flex; align-items: center; justify-content: space-between; padding: 6px; }
.datebar .mid { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; min-width: 0; }
.datebar .mid b { font-size: 15px; }
.jump { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; }
.jump label { font-size: 13px; color: var(--muted); }
.jump input {
  font: 600 14px var(--font-ui); color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; min-height: 40px; padding: 0 10px;
}
.results { overflow: hidden; }
.prize { display: grid; grid-template-columns: 52px minmax(0, 1fr); border-bottom: 1px solid var(--line-soft); }
.prize:last-child { border-bottom: 0; }
.prize:nth-child(even) { background: var(--surface-2); }
.prize.db { background: var(--red-tint); }
.prize .lab { display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--muted); border-right: 1px solid var(--line-soft); }
.prize.db .lab, .prize.g7 .lab { color: var(--red-ink); }
.prize .vals { display: grid; row-gap: 8px; padding: 12px 6px; }
.prize .vals span { text-align: center; font: 600 19px/1.2 var(--font-num); letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.prize.db .vals span { font-size: 32px; font-weight: 700; color: var(--red-ink); }
.prize.g7 .vals span { font-size: 22px; font-weight: 700; color: var(--red-ink); }
.loto { overflow: hidden; }
.loto-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr) 44px; align-items: stretch; border-top: 1px solid var(--line-soft); min-height: 34px; }
.loto-row.head { border-top: 0; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted); }
.loto-row > span { display: flex; align-items: center; }
.loto-row .k { justify-content: center; font: 700 14px var(--font-num); color: var(--red-ink); }
.loto-row .a { padding-left: 8px; font: 500 14px var(--font-num); }
.loto-row .b { padding-right: 8px; justify-content: flex-end; font: 500 14px var(--font-num); border-left: 1px solid var(--line-soft); }
.loto-row.head .k, .loto-row.head .a, .loto-row.head .b { font: 600 12px var(--font-ui); color: var(--muted); }
.empty-val { color: var(--muted); }

/* Tần suất */
.heat { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; }
.heat button {
  min-height: 44px; padding: 0; border: 0; border-radius: 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.heat button b { font-size: 13px; }
.heat button i { font-style: normal; font-size: 10px; }
.heat button[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.legend span.sw { width: 14px; height: 14px; border-radius: 3px; }

.toplist { display: flex; flex-direction: column; }
.toprow { display: grid; grid-template-columns: 26px 40px minmax(0, 1fr) 54px; gap: 10px; align-items: center; min-height: 50px; }
.toprow .rk { font-size: 12px; color: var(--muted); text-align: right; }
.badge {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--red-tint); color: var(--red-ink); font: 700 17px var(--font-num);
}
.bar { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--red); }
.bar.amber > i { background: var(--amber); }
.toprow .cnt { font-size: 13px; font-weight: 600; }
.toprow .diff { font-size: 13px; font-weight: 700; color: var(--red-strong); text-align: right; }
.toprow .diff.neg { color: var(--muted); }
.mini { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.mini > div { background: var(--surface-2); border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mini b { font: 700 17px var(--font-num); }
.mini span { font-size: 11px; color: var(--muted); }
.wk { overflow: hidden; }
.wk button {
  width: 100%; min-height: 48px; border: 0; border-top: 1px solid var(--line-soft); background: var(--surface);
  display: grid; grid-template-columns: 78px repeat(3, minmax(0, 1fr)); gap: 6px; align-items: center;
  padding: 6px 14px; text-align: left; cursor: pointer; color: var(--ink);
}
.wk button[aria-pressed="true"] { background: var(--red-tint); }
.wk .lb { font-size: 13px; font-weight: 700; }
.wk .it { font-size: 12px; color: var(--muted); }
.wk .it b { font: 700 15px var(--font-num); color: var(--red-ink); }

/* Lô gan */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile span { font-size: 11px; color: var(--muted); }
.tile b { font-size: 20px; font-weight: 700; }
.tile small { font-size: 12px; font-weight: 500; color: var(--muted); }
.ganrow { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line-soft); }
.ganrow:first-child { border-top: 0; }
.ganbadge { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--amber-tint); color: var(--amber-ink); font: 700 20px var(--font-num); }
.ganrow .t { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.ganrow .t b { font-size: 15px; }
.tag { font-size: 11px; font-weight: 700; color: var(--amber-ink); background: var(--amber-tint); border-radius: 999px; padding: 4px 8px; white-space: nowrap; }

/* Giải ĐB */
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head span { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.cal > * {
  min-height: 56px; border-radius: 8px; padding: 4px 2px; border: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  background: var(--surface-2); color: var(--muted);
}
.cal > .blank { background: transparent; }
.cal button { cursor: pointer; }
.cal .dd { align-self: flex-start; padding-left: 3px; font-size: 10px; font-weight: 600; }
.cal .v { font: 12px var(--font-num); letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.cal .v b { color: var(--red-ink); }
.cal button[aria-pressed="true"] { background: var(--hero); color: var(--hero-muted); }
.cal button[aria-pressed="true"] .v b { color: var(--hero-red); }
.cal .today { box-shadow: inset 0 0 0 1.5px var(--red); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.facts > div { background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.facts span { font-size: 11px; color: var(--hero-muted); }
.facts b { font: 700 18px var(--font-num); }
.bars { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; align-items: end; height: 104px; }
.bars > div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.bars i { display: block; width: 100%; border-radius: 4px 4px 0 0; background: var(--red-tint); }
.bars i.top { background: var(--red); }
.bars span { font-size: 11px; color: var(--muted); }
.bars b { font: 700 12px var(--font-num); }

/* Hôm nay */
.sync b { font-size: 14px; }
.sync .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--amber); }
.sync.ok .dot { background: #16A34A; }
.sync.ok .row { justify-content: flex-start; gap: 12px; }
.sync .pill:disabled { opacity: .6; cursor: default; }
.link-light { color: var(--hero-muted); text-decoration: underline; text-underline-offset: 2px; }
.link-light:hover { color: var(--hero-ink); }
.kv { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.kv:first-of-type { border-top: 0; padding-top: 0; }
.kv > span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px; min-height: 36px; padding: 6px 10px;
  border-radius: 10px; background: var(--red-tint); color: var(--red-ink);
}
.chip b { font-size: 17px; font-weight: 700; }
.chip i { font-style: normal; font-size: 12px; color: var(--muted); }
.digits { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.digits > div { background: var(--surface-2); border-radius: 8px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.digits b { font: 700 14px var(--font-num); color: var(--red-ink); }
.digits i { font-style: normal; font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; }
.digits > .mute b { color: var(--muted); }
.digits > .mute i { color: var(--muted); }

.loading { padding: 48px 0; text-align: center; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
