:root {
  color-scheme: dark;
  --bg: #0b0f0e;
  --bg-2: #101614;
  --surface: #141c19;
  --surface-2: #1a2420;
  --line: #24312c;
  --line-2: #2f3f39;
  --text: #e8efec;
  --text-2: #a7b5af;
  --muted: #6f807a;
  --accent: #2fbf8f;
  --accent-ink: #04140e;
  --accent-soft: rgba(47, 191, 143, 0.12);
  --ok: #3ccf91;
  --warn: #e6b450;
  --bad: #f06a6a;
  --info: #6aa8f0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Bengali", "Kohinoor Bangla", "Bangla Sangam MN", "Hind Siliguri", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f6f5;
    --bg-2: #eaf0ee;
    --surface: #ffffff;
    --surface-2: #f6f9f8;
    --line: #dde5e2;
    --line-2: #cbd6d2;
    --text: #0f1a16;
    --text-2: #42524c;
    --muted: #788a83;
    --accent: #13936b;
    --accent-ink: #ffffff;
    --accent-soft: rgba(19, 147, 107, 0.1);
    --ok: #128a5c;
    --warn: #a86f00;
    --bad: #c93c3c;
    --info: #2a6fc2;
    --shadow: 0 10px 30px rgba(15, 26, 22, 0.08);
  }
}

/* trong khung nạp/rút của web game (embed.js): luôn sáng cho hợp trang game, cùng bộ màu với chế độ sáng ở trên */
html.embedded {
  color-scheme: light;
  --bg: #f3f6f5;
  --bg-2: #eaf0ee;
  --surface: #ffffff;
  --surface-2: #f6f9f8;
  --line: #dde5e2;
  --line-2: #cbd6d2;
  --text: #0f1a16;
  --text-2: #42524c;
  --muted: #788a83;
  --accent: #13936b;
  --accent-ink: #ffffff;
  --accent-soft: rgba(19, 147, 107, 0.1);
  --ok: #128a5c;
  --warn: #a86f00;
  --bad: #c93c3c;
  --info: #2a6fc2;
  --shadow: 0 10px 30px rgba(15, 26, 22, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: 0.92em; word-break: break-all; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.money.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* ---- Nút & form ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  font: 600 14px var(--font); cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: rgba(240, 106, 106, 0.1); border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--text) transparent var(--text) transparent;
  animation: spin 0.8s linear infinite;
}
.btn-primary.loading::after { border-color: var(--accent-ink) transparent var(--accent-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); color: var(--text); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field small { font-size: 12px; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text);
  font: 15px var(--font); outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-row { display: flex; gap: 8px; }
.input-row > input { flex: 1; min-width: 0; }
.form-error { color: var(--bad); font-size: 14px; margin: 0 0 12px; }

/* ---- Tabs & segmented ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  padding: 10px 14px; border: 0; background: none; color: var(--text-2);
  font: 600 14px var(--font); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px;
  background: var(--warn); color: #1b1300; font-size: 12px; line-height: 20px; text-align: center;
}

.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--bg-2); border: 1px solid var(--line); gap: 2px; }
.seg button {
  padding: 7px 14px; border: 0; border-radius: 8px; background: none; color: var(--text-2);
  font: 600 13px var(--font); cursor: pointer; white-space: nowrap;
}
.seg button.active { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 var(--line-2) inset, 0 1px 3px rgba(0,0,0,.2); }

/* ---- Thẻ & bảng ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge-bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge-info { color: var(--info); background: color-mix(in srgb, var(--info) 13%, transparent); }
.badge-muted { color: var(--muted); border-color: var(--line-2); }
.net { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--text-2); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .r { text-align: right; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .actions .btn + .btn { margin-left: 6px; }
.cell-stack { display: grid; gap: 2px; }
.cell-row { display: inline-flex; align-items: center; gap: 4px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 14px; }

@media (max-width: 720px) {
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { padding: 12px 4px; border-bottom: 1px solid var(--line); }
  table.data tr:last-child { border-bottom: 0; }
  table.data td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  table.data td.actions { justify-content: flex-end; padding-top: 8px; }
  table.data td.actions::before { content: none; }
  table.data .r { text-align: right; }
}

/* ---- Hộp thoại & thông báo ---- */
.dialog {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
.dialog-body { padding: 22px; }
.dialog-body h3 { font-size: 18px; margin-bottom: 10px; }
.dialog-body > p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

#toast-root { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  padding: 11px 16px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line-2);
  box-shadow: var(--shadow); font-size: 14px; animation: toast-in 0.2s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast-ok { border-left: 3px solid var(--ok); }
.toast-error { border-left: 3px solid var(--bad); }
.toast-info { border-left: 3px solid var(--info); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- Màn hình đăng nhập ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); }
.auth-card .card { padding: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 16px;
}
.auth-card .brand { justify-content: center; margin-bottom: 22px; font-size: 20px; }
.auth-card .tabs { margin-bottom: 20px; }
.auth-card .tabs button { flex: 1; }
table.data .mono { word-break: normal; white-space: nowrap; }

/* ---- Chọn mạng ---- */
.net-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.net-picker button {
  display: grid; gap: 2px; justify-items: start; padding: 10px 12px; border-radius: 10px; cursor: pointer; text-align: left;
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text); font: 600 14px var(--font);
  transition: border-color 0.15s, background 0.15s;
}
.net-picker button small { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.net-picker button:hover { border-color: var(--muted); }
.net-picker button.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.net-picker button.active small { color: var(--accent); }

/* biểu tượng token / mạng (icons.js) */
.tk-ic, .net-ic { display: inline-block; flex: none; vertical-align: middle; }
.tk-ic svg, .net-ic svg { display: block; width: 100%; height: 100%; }
.tk-ic { width: 14px; height: 14px; }
.tk { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.net { display: inline-flex; align-items: center; gap: 5px; }
.net .net-ic { width: 14px; height: 14px; margin-left: -2px; }
.net-picker button { display: flex; flex-direction: row; align-items: center; gap: 10px; text-align: left; }
.net-picker button .net-ic { width: 30px; height: 30px; }
.net-picker .np-txt { display: grid; gap: 3px; min-width: 0; }
.net-picker .np-txt small { display: flex; gap: 8px; flex-wrap: wrap; }
.dep-tks { display: inline-flex; margin-right: 8px; vertical-align: -3px; }
.dep-tks .tk-ic { width: 18px; height: 18px; }
.dep-tks .tk-ic + .tk-ic { margin-left: -5px; box-shadow: 0 0 0 2px var(--surface); border-radius: 50%; }
.tk-pick { display: flex; gap: 8px; }
.tk-pick button { display: inline-flex; align-items: center; height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font: 600 14px var(--font); cursor: pointer; }
.tk-pick button .tk-ic { width: 20px; height: 20px; }
.tk-pick button .tk { gap: 8px; }
.tk-pick button.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
