/* lucky — giao diện cục bộ.
   Màu theo bảng palette đã chạy validator (6 kiểm tra, cả light & dark).
   Light mode: slot aqua dưới 3:1 nên mọi đường trong biểu đồ EV đều có
   direct label — đúng quy tắc relief. */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f2ee;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);

  --series-1:        #2a78d6;
  --series-2:        #eb6834;
  --series-3:        #1baf7a;

  --good:            #0ca30c;
  --warning:         #fab219;
  --serious:         #ec835a;
  --critical:        #d03b3b;
  --good-text:       #006300;

  --seq-100:         #cde2fb;
  --seq-250:         #86b6ef;
  --seq-450:         #2a78d6;
  --seq-600:         #184f95;

  --radius:          10px;
  --shadow:          0 1px 2px rgba(11, 11, 11, 0.04),
                     0 8px 24px rgba(11, 11, 11, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-3:       #199e70;
    --good-text:      #0ca30c;
    --seq-100:        #0d366b;
    --seq-250:        #184f95;
    --seq-450:        #3987e5;
    --seq-600:        #9ec5f4;
    --shadow:         0 1px 2px rgba(0, 0, 0, 0.3),
                      0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-3:       #199e70;
  --good-text:      #0ca30c;
  --seq-100:        #0d366b;
  --seq-250:        #184f95;
  --seq-450:        #3987e5;
  --seq-600:        #9ec5f4;
  --shadow:         0 1px 2px rgba(0, 0, 0, 0.3),
                    0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.9rem; }
p { margin: 0 0 0.7em; }
a { color: var(--series-1); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px 72px; }

/* ───────────────────────── header ───────────────────────── */

header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 1120px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 9px; margin-right: auto; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--series-1); flex: none; align-self: center;
}
.brand small { color: var(--text-muted); font-size: 0.78rem; }

.seg {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 2px;
}
.seg button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 0.85rem; color: var(--text-secondary);
  padding: 5px 11px; border-radius: 6px;
}
.seg button[aria-pressed="true"] {
  background: var(--surface-1); color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(11, 11, 11, 0.07); font-weight: 600;
}
.icon-btn {
  appearance: none; cursor: pointer; font: inherit;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 8px;
  width: 34px; height: 32px; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text-primary); }

/* ───────────────────────── tabs ───────────────────────── */

nav.tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 10px 0 0;
  border-bottom: 1px solid var(--border); margin-bottom: 22px;
  scrollbar-width: thin;
}
nav.tabs button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 0.9rem; color: var(--text-secondary);
  padding: 9px 13px; border-radius: 8px 8px 0 0; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav.tabs button:hover { color: var(--text-primary); }
nav.tabs button[aria-selected="true"] {
  color: var(--text-primary); font-weight: 620;
  border-bottom-color: var(--series-1);
}

section.panel[hidden] { display: none; }

/* ───────────────────────── cards ───────────────────────── */

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card > h2, .card > h3 { margin-bottom: 4px; }
.card .sub {
  color: var(--text-secondary); font-size: 0.86rem; margin: 0 0 14px;
  max-width: 76ch;
}
.card .sub:last-child { margin-bottom: 0; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ───────────────────────── stat tiles ───────────────────────── */

.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.tile .label {
  font-size: 0.74rem; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600;
}
.tile .value {
  font-size: 1.65rem; font-weight: 660; margin: 3px 0 1px;
  letter-spacing: -0.015em;
}
.tile .note { font-size: 0.8rem; color: var(--text-secondary); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.76rem; font-weight: 620; padding: 2px 9px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-secondary);
}
.pill.good  { color: var(--good-text);  border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.warn  { color: var(--text-primary); border-color: color-mix(in srgb, var(--warning) 55%, transparent); }
.pill.bad   { color: var(--critical);  border-color: color-mix(in srgb, var(--critical) 45%, transparent); }

/* ───────────────────────── lottery balls ───────────────────────── */

.ticket {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 0; border-bottom: 1px solid var(--grid);
}
.ticket:last-child { border-bottom: 0; }
.ticket .idx {
  font-size: 0.78rem; color: var(--text-muted); width: 42px; flex: none;
  font-variant-numeric: tabular-nums;
}
.balls { display: flex; gap: 7px; flex-wrap: wrap; }
.ball {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 0.95rem; font-weight: 650; font-variant-numeric: tabular-nums;
  background: var(--seq-450); color: #fff;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.14);
}
.ball.bonus { background: var(--series-2); }
.ball.sm { width: 30px; height: 30px; font-size: 0.8rem; }
.ticket .meta {
  margin-left: auto; font-size: 0.8rem; color: var(--text-secondary);
  text-align: right; flex: none;
}
.ticket .meta b { font-variant-numeric: tabular-nums; }

/* ───────────────────────── forms ───────────────────────── */

.controls {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end;
  padding-bottom: 16px; margin-bottom: 4px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label {
  font-size: 0.76rem; font-weight: 600; color: var(--text-secondary);
}
.field .hint { font-size: 0.72rem; color: var(--text-muted); }
input[type="text"], input[type="number"], input[type="date"], select {
  font: inherit; font-size: 0.9rem; padding: 7px 10px;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--axis); border-radius: 8px; min-width: 0;
}
input[type="range"] { accent-color: var(--series-1); width: 100%; }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 620;
  font-size: 0.9rem; padding: 8px 18px; border-radius: 8px;
  background: var(--series-1); color: #fff; border: 1px solid transparent;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.ghost {
  background: var(--surface-2); color: var(--text-primary);
  border-color: var(--border);
}

/* ───────────────────────── tables ───────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
caption {
  caption-side: top; text-align: left; font-size: 0.8rem;
  color: var(--text-secondary); padding-bottom: 8px;
}
th, td {
  padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; font-variant-numeric: normal; }
thead th {
  font-size: 0.74rem; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600; border-bottom-color: var(--axis);
}
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--axis); }
td.num { font-variant-numeric: tabular-nums; }

/* ───────────────────────── charts ───────────────────────── */

figure { margin: 0; }
figure figcaption {
  font-size: 0.8rem; color: var(--text-secondary); margin-top: 10px;
  max-width: 80ch;
}
.chart-wrap { position: relative; width: 100%; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font-family: var(--font); }
.tick { fill: var(--text-muted); font-size: 11px; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.refline { stroke: var(--text-secondary); stroke-width: 1.5; stroke-dasharray: 5 4; }
.bar { fill: var(--seq-450); }
.bar.lo { fill: var(--seq-250); }
.bar:hover { fill: var(--seq-600); }
.serieslabel { font-size: 12px; font-weight: 620; }

.legend {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: center;
  font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 10px;
}
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch {
  width: 11px; height: 11px; border-radius: 3px; flex: none;
}

.tip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--axis); border-radius: 8px;
  padding: 7px 10px; font-size: 0.8rem; box-shadow: var(--shadow);
  transform: translate(-50%, -115%); white-space: nowrap; opacity: 0;
  transition: opacity 0.1s;
}
.tip[data-show="1"] { opacity: 1; }
.tip b { font-variant-numeric: tabular-nums; }

/* ───────────────────────── misc ───────────────────────── */

.notice {
  border-left: 3px solid var(--warning); background: var(--surface-2);
  padding: 13px 16px; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.86rem; color: var(--text-secondary);
}
.notice strong { color: var(--text-primary); }
.err {
  border-left: 3px solid var(--critical); background: var(--surface-2);
  padding: 11px 14px; border-radius: 0 8px 8px 0;
  font-size: 0.86rem; color: var(--text-primary);
}
.muted { color: var(--text-secondary); }
.tiny { font-size: 0.78rem; }
.spin {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid var(--axis); border-top-color: var(--series-1);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: var(--surface-2); border-radius: 6px; height: 1em;
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.5; } }

details.reasons { margin-top: 6px; }
details.reasons summary {
  cursor: pointer; font-size: 0.78rem; color: var(--text-secondary);
}
details.reasons ul {
  margin: 7px 0 0; padding-left: 18px; font-size: 0.8rem;
  color: var(--text-secondary);
}
details.reasons .pts { font-variant-numeric: tabular-nums; font-weight: 620; }
details.reasons .plus { color: var(--critical); }
details.reasons .minus { color: var(--good-text); }

@media (max-width: 860px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 16px 56px; }
  .ball { width: 33px; height: 33px; font-size: 0.85rem; }
  .ticket .meta { margin-left: 0; text-align: left; width: 100%; }
  .grid.c4 { grid-template-columns: 1fr; }
}

/* ═══════════════ Màn hình đơn giản (trang chủ) ═══════════════ */

/* Căn giữa bằng flex hàng ngang, KHÔNG dùng grid + place-items:center:
   cột lưới auto sẽ co theo max-content của đoạn chữ dài nhất và làm thẻ
   tràn ngang ở màn hình hẹp. min-width:0 cho phép thẻ co lại đúng cách. */
body.simple {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: 24px 16px;
}

.stage {
  flex: 0 1 520px;
  min-width: 0;
  width: 100%;
  max-width: 520px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 26px 24px;
  text-align: center;
}

.stage-head { margin-bottom: 24px; }

.kicker {
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 650;
}

.stage-head h1 {
  font-size: 1.55rem;
  margin: 6px 0 4px;
  letter-spacing: -0.02em;
}

.gameline { font-size: 0.87rem; color: var(--text-secondary); }

.ticketbox { display: flex; flex-direction: column; gap: 10px; }

.trow {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 12px;
}

/* số thứ tự đặt tuyệt đối để dãy bóng luôn nằm giữa đúng tâm thẻ */
.trow .tno {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.trow .balls { gap: 8px; }

.ticket-skel {
  height: 60px;
  border-radius: 12px;
  background: var(--surface-2);
  animation: pulse 1.3s ease-in-out infinite;
}

.stage-actions { margin-top: 22px; }

.btn.big {
  width: 100%;
  padding: 13px 20px;
  font-size: 0.98rem;
  border-radius: 12px;
}

.costline {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fineprint {
  margin: 22px 0 0;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: left;
  border-top: 1px solid var(--grid);
  padding-top: 14px;
}

@media (max-width: 420px) {
  .stage { padding: 24px 16px 20px; border-radius: 14px; }
  .stage-head h1 { font-size: 1.3rem; }
  .trow { gap: 8px; padding: 9px 8px; }
  .trow .balls { gap: 5px; }
  .ball { width: 34px; height: 34px; font-size: 0.85rem; }
}
