:root {
  --bg: #edf1f7;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #475569;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --accent: #1d4ed8;
  --accent-dark: #1e40af;
  --accent-soft: #e8efff;
  --red: #dc2626;
  --blue: #1d4ed8;
  --green: #15803d;
  --gold: #b45309;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .05);
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 400px at 10% -120px, #dbe7ff 0%, rgba(219, 231, 255, 0) 70%),
    var(--bg);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3, p { margin: 0; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px) 14px;
  max-width: 1400px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-mark {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #1e40af, #2563eb 60%, #3b82f6);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .28);
}

.brand-text { min-width: 0; }

.brand h1 {
  font-size: clamp(19px, 2.4vw, 24px);
  line-height: 1.2;
  letter-spacing: -.02em;
}

.brand p {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.top-account {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 5px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
}

.top-account[hidden] { display: none; }

.top-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #2563eb, #1e3a8a);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.top-user {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.top-user b {
  max-width: 110px;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-user span {
  font-size: 10.5px;
  color: var(--muted);
}

.top-logout {
  flex: 0 0 auto;
  padding: 5px 10px;
  border: 0;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-2);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.top-logout:hover {
  background: #fee2e2;
  color: #b91c1c;
}

/* ---------- header live draw ---------- */

.live-draw {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  min-width: 0;
  margin-left: auto;
  text-align: right;
}

.live-top,
.live-main {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.live-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #0f766e;
  letter-spacing: .02em;
  white-space: nowrap;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .15);
}

.live-draw.is-loading .live-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .16);
  animation: livePulse 1.2s ease-in-out infinite;
}

.live-draw.is-error .live-dot {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .14);
}

@keyframes livePulse {
  50% { opacity: .35; }
}

.live-meta {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live-meta strong {
  color: var(--text);
  font-weight: 600;
}

.live-new {
  padding: 1px 7px;
  border: 1px solid #fde68a;
  border-radius: 999px;
  background: #fef3c7;
  color: #b45309;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.live-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.live-btn {
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
  cursor: pointer;
}

.live-btn:hover {
  border-color: #94a3b8;
  color: var(--text);
}

.live-balls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.live-balls .ball.sm {
  width: 23px;
  height: 23px;
  font-size: 10.5px;
}

.live-balls .special-sep {
  height: 18px;
  margin: 0 1px;
}

.live-source {
  max-width: 100%;
  overflow: hidden;
  font-size: 11.5px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-edit {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  margin-top: 2px;
}

.live-edit[hidden] {
  display: none;
}

.live-edit input {
  flex: 1 1 280px;
  min-width: 0;
  max-width: 560px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-size: 12px;
}

.live-edit .btn {
  padding: 4px 10px;
  font-size: 12px;
}

.live-msg {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: right;
}

.live-msg.err {
  color: var(--red);
}

@media (min-width: 1181px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }
  .brand { justify-self: start; }
  .live-draw {
    justify-self: center;
    margin-left: 0;
    align-items: center;
    text-align: center;
  }
  .live-top,
  .live-main { justify-content: center; }
  .live-edit { justify-content: center; }
  .live-msg { text-align: center; }
  .top-account { justify-self: end; }
}

main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px clamp(12px, 3vw, 28px) 40px;
}

/* ---------- sticky page top ---------- */

.top-sticky {
  position: sticky;
  top: 0;
  z-index: 60;
  padding-bottom: 2px;
  background:
    radial-gradient(1200px 400px at 10% -120px, #dbe7ff 0%, rgba(219, 231, 255, 0) 70%),
    var(--bg);
}

.top-sticky.stuck { box-shadow: 0 10px 24px rgba(15, 23, 42, .08); }

.top-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px clamp(12px, 3vw, 28px) 12px;
}

.top-inner .tabs { margin-bottom: 0; }

/* ---------- overview ---------- */

.overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stat-card .label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
}

.stat-card .value {
  margin-top: 6px;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -.02em;
}

.stat-card .value.small { font-size: 21px; }

.stat-card .hint {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card .balls { margin-top: 10px; display: flex; gap: 5px; flex-wrap: wrap; }

.stat-card.accent { border-left: 4px solid var(--accent); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 16px;
  background: #e2e8f0;
  border-radius: 13px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  padding: 9px 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}

.tab:hover { background: rgba(255, 255, 255, .65); color: var(--text); }

.tab.active {
  background: var(--card);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

.page-top {
  position: fixed;
  right: clamp(14px, 3vw, 30px);
  bottom: clamp(18px, 4vh, 36px);
  z-index: 80;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 9px 15px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, .9);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .25);
}

.page-top.show { display: inline-flex; }
.page-top:hover { background: var(--accent-dark); }

.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* ---------- cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: -.01em;
}

.card-head .sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.card-head .sub.err { color: #b91c1c; font-weight: 600; }

.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-2 > .card { margin-bottom: 16px; }

/* ---------- buttons & controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}

.btn:hover { background: #f8fafc; border-color: #94a3b8; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn.ghost { background: #fff; }

.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; border-color: #f87171; }

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .35);
  outline-offset: 1px;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #eef2f7;
  border-radius: 10px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.segmented button:hover { background: rgba(255, 255, 255, .7); }

.segmented button.active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .14);
}

.order-toggle { flex: 0 0 auto; }
.order-toggle button { padding: 5px 10px; font-size: 12.5px; }

.order-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 10px;
}

.order-picker-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
}

.order-picker-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.order-picker .segmented { padding: 3px; background: #e8eef6; }
.order-picker .segmented button { padding: 4px 10px; font-size: 12.5px; }

.ordered-ball {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  margin-right: 3px;
}

.ordered-ball > i {
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  min-width: 8px;
  padding-bottom: 3px;
  text-align: center;
}

.order-missing {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.order-mode-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11.5px;
  font-weight: 700;
  vertical-align: 1px;
}

.range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.range-title { font-size: 14px; font-weight: 700; color: var(--text); }

.range-presets { padding: 3px; }

.range-presets button { padding: 5px 11px; font-size: 13px; }

.range-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.range-custom input {
  width: 92px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  text-align: center;
}

.range-hint { margin-left: auto; font-size: 12.5px; color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr)) minmax(160px, 1.3fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

select, input[type="search"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  min-height: 38px;
}

select:hover, input:hover, textarea:hover { border-color: #94a3b8; }

.reset-btn { min-height: 38px; }

/* ---------- tables ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  scrollbar-width: thin;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 680px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 12px;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table tbody tr:hover td { background: #f8fbff; }

.data-table tbody tr.clickable { cursor: pointer; }

.data-table .num { font-variant-numeric: tabular-nums; }

.sortable th[data-sort] { cursor: pointer; user-select: none; }
.sortable th[data-sort]:hover { color: var(--accent-dark); }
.sortable th .arrow { color: var(--accent); margin-left: 3px; font-size: 11px; }

.ball-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

.ball {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #475569;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  line-height: 1;
}

.ball.red { background: var(--red); }
.ball.blue { background: var(--blue); }
.ball.green { background: var(--green); }

.ball.is-special {
  box-shadow: 0 0 0 3px #fbbf24, 0 0 0 4px rgba(251, 191, 36, .25);
}

.ball.lg {
  width: 52px;
  height: 52px;
  font-size: 21px;
}

.ball.xl {
  width: 64px;
  height: 64px;
  font-size: 27px;
}

.ball.sm {
  width: 25px;
  height: 25px;
  font-size: 11.5px;
}

.special-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 3px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tag.red { color: #991b1b; background: #fee2e2; }
.tag.blue { color: #1e40af; background: #dbeafe; }
.tag.green { color: #166534; background: #dcfce7; }
.tag.neutral { color: var(--text-2); background: #f1f5f9; }
.tag.gold { color: #92400e; background: #fef3c7; }
.tag.folder { color: #3730a3; background: #e0e7ff; }

.tag-row { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------- pager ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pager .page-info { font-size: 13px; color: var(--muted); }
.pager .pager-nav { display: inline-flex; align-items: center; gap: 10px; }

.pager button {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pager button:hover:not(:disabled) { border-color: #94a3b8; background: #f8fafc; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

.pager select { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }

/* ---------- KPIs ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.kpi .label { font-size: 12px; font-weight: 600; color: var(--muted); }

.kpi .main {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.01em;
}

.kpi .main .unit { font-size: 13px; font-weight: 600; color: var(--muted); }

.kpi .hint { margin-top: 5px; font-size: 12.5px; color: var(--muted); }

/* ---------- special number grid ---------- */

.number-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.num-tile {
  position: relative;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 8px 6px 7px;
  background: #fff;
  cursor: pointer;
  text-align: center;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  min-width: 0;
}

.num-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .1);
  border-color: #94a3b8;
}

.num-tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .3);
}

.num-tile .n {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.num-tile .n.red { background: var(--red); }
.num-tile .n.blue { background: var(--blue); }
.num-tile .n.green { background: var(--green); }

.num-tile .cnt {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.num-tile .miss {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.detail-card { position: relative; }

.detail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.detail-head .detail-title { min-width: 0; }
.detail-head h2 { font-size: 18px; }
.detail-head .sub { margin-top: 3px; font-size: 13px; color: var(--muted); }

.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.detail-stat {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 9px;
  padding: 9px 11px;
}

.detail-stat .k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.detail-stat .v { margin-top: 2px; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }

.recent-list { display: flex; flex-direction: column; gap: 6px; }

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}

.recent-item .date { color: var(--text-2); font-variant-numeric: tabular-nums; }
.recent-item .no { color: var(--muted); font-size: 12px; }

/* ---------- charts ---------- */

.chart-scroll {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.chart-svg { display: block; width: 100%; height: auto; min-width: 860px; }

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }

.chart-hint { display: none; margin-left: auto; }

.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.red { background: var(--red); }
.swatch.blue { background: var(--blue); }
.swatch.green { background: var(--green); }
.swatch.avg { background: #b45309; height: 2px; border-radius: 0; width: 16px; }

/* ---------- rank list ---------- */

.rank-list { display: flex; flex-direction: column; gap: 8px; }

.rank-item {
  display: grid;
  grid-template-columns: 26px 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 9px;
  background: #fff;
}

.rank-item .idx {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.rank-item .bar-track {
  height: 8px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.rank-item .bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #93c5fd, var(--accent));
}

.rank-item .val {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- trend ---------- */

.legend {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: -2px 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-note { margin-left: auto; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid var(--accent);
  background: #fff;
}

.dot.special { border-color: var(--red); background: var(--red); }

.trend-wrap {
  width: 100%;
  overflow: auto;
  max-height: 620px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  scrollbar-width: thin;
}

.trend-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  min-width: 1200px;
}

.trend-table th, .trend-table td {
  padding: 0;
  text-align: center;
  border-bottom: 1px solid #eef2f7;
}

.trend-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 34px;
  min-width: 22px;
  font-size: 10.5px;
  font-weight: 700;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.trend-table thead th.c-red { color: var(--red); }
.trend-table thead th.c-blue { color: var(--blue); }
.trend-table thead th.c-green { color: var(--green); }

.trend-table th.row-head, .trend-table td.row-head {
  position: sticky;
  left: 0;
  z-index: 4;
  min-width: 104px;
  width: 104px;
  text-align: left;
  padding: 5px 10px;
  background: #fff;
  border-right: 1px solid var(--border-light);
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
}

.trend-table thead th.row-head { z-index: 6; background: #f8fafc; }

.trend-table tbody tr:nth-child(even) td { background: #fbfcfe; }
.trend-table tbody tr:nth-child(even) td.row-head { background: #fbfcfe; }
.trend-table tbody tr:hover td { background: #eef5ff; }
.trend-table tbody tr:hover td.row-head { background: #eef5ff; }

.trend-table td .cell {
  width: 22px;
  height: 24px;
  display: grid;
  place-items: center;
  margin: 0 auto;
}

.trend-table td .td-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
}

.trend-table td .td-dot.special {
  background: var(--red);
  border-color: var(--red);
  width: 10px;
  height: 10px;
}

.recent-balls { display: flex; flex-wrap: wrap; gap: 14px; }

.recent-ball {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 7px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: #fff;
}

.recent-ball .meta { display: flex; flex-direction: column; gap: 1px; }
.recent-ball .meta .d { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.recent-ball .meta .a { font-size: 11px; color: var(--muted); }

/* ---------- attributes ---------- */

.intro-card { padding-bottom: 16px; }
.intro-card .card-head { margin-bottom: 0; }

.attr-grid {
  column-count: 3;
  column-gap: 16px;
}

.attr-card {
  break-inside: avoid;
  margin-bottom: 16px;
}

.attr-card h3 {
  font-size: 15px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.attr-card h3 .total { font-size: 11.5px; color: var(--muted); font-weight: 600; }

.attr-rows { display: flex; flex-direction: column; gap: 8px; }

.attr-row {
  display: grid;
  grid-template-columns: 54px 1fr 72px;
  align-items: center;
  gap: 3px 9px;
  font-size: 12.5px;
}

.attr-row .attr-meta {
  grid-column: 2 / -1;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.attr-row .attr-meta b { font-weight: 700; color: var(--text-2); }

.attr-row .attr-meta .m { white-space: nowrap; }

.attr-row .attr-meta .m + .m { margin-left: 4px; }

.attr-row .k { font-weight: 700; color: var(--text-2); white-space: nowrap; }

.attr-row .bar-track {
  height: 9px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.attr-row .bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  min-width: 0;
}

.attr-row .v {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.attr-row .v small { color: var(--muted); font-size: 11px; }

/* ---------- data panel ---------- */

.import-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.import-text {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.55;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fcfdff;
}

.format-help {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.format-help strong { color: var(--text-2); }

.import-preview { margin-top: 12px; }
.import-preview:empty { display: none; }

.import-result {
  border: 1px solid var(--border-light);
  border-radius: 9px;
  padding: 10px 12px;
  background: #f8fafc;
  font-size: 13px;
}

.import-result strong { color: var(--text); }
.import-result .err { color: #b91c1c; }
.import-result ul { margin: 6px 0 0; padding-left: 18px; max-height: 120px; overflow: auto; }

.manual-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.manual-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.manual-form .wide { grid-column: 1 / -1; }
.manual-form button { margin-top: 4px; }

.note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

.note.warn { color: #b45309; }

footer {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px) 30px;
  font-size: 12.5px;
  color: #52627a;
  line-height: 1.7;
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 30px 70px rgba(15, 23, 42, .35);
  animation: pop .16s ease;
}

@keyframes pop {
  from { opacity: 0; transform: scale(.97); }
  to { opacity: 1; transform: none; }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--text-2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { background: #e2e8f0; }

.modal-head {
  text-align: center;
  padding-right: 24px;
}

.modal-head .d { font-size: 14px; color: var(--muted); }
.modal-head h2 { margin-top: 3px; font-size: 21px; }

.modal-balls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin: 18px 0 20px;
}

.modal-attrs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.modal-attr {
  border: 1px solid var(--border-light);
  border-radius: 9px;
  padding: 8px 10px;
  background: #f8fafc;
}

.modal-attr .k { font-size: 11.5px; color: var(--muted); }
.modal-attr .v { margin-top: 2px; font-weight: 700; font-size: 14px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 200;
  padding: 10px 18px;
  border-radius: 999px;
  background: #0f172a;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .3);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.hidden { display: none; }
.toast.error { background: #b91c1c; }
.toast.ok { background: #166534; }

/* ---------- empty state ---------- */

.empty {
  padding: 28px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 自定义规则分析 ---------- */

.rule-def {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
  margin-bottom: 14px;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: #f8fafc;
}

.rule-tag {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.rule-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.rule-text {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2);
}

.rules-filters { align-items: flex-end; }

.rules-picker { align-items: flex-end; }

.rules-picker label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.rules-picker select { min-width: 220px; }

.rules2-lookback { align-items: flex-end; }

.rules2-lookback label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.lookback-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lookback-field input[type="number"] {
  width: 88px;
  min-height: 38px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lookback-field > span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

@media (min-width: 1181px) {
  #rules2-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  #rules3-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #rules4-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 701px) and (max-width: 1180px) {
  #rules4-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.rules-stats-wrap {
  max-height: 560px;
  overflow-y: auto;
}

.rule-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rule-label.plus { background: var(--accent-soft); color: var(--accent-dark); }
.rule-label.minus { background: #fef3c7; color: #b45309; }
.rule-label.zero { background: #e2e8f0; color: var(--text-2); }

.neighbor-balls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 3px 5px;
}

.ordered-ball.special > i { color: #b45309; }

.neighbor-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--border-light);
}

.neighbor-line:last-child { border-bottom: 0; }

.neighbor-line-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
}

.neighbor-arrow {
  color: var(--muted);
  font-weight: 700;
}

.neighbor-labels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
}

.neighbor-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  margin: 2px 4px 2px 0;
  padding: 3px 9px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.neighbor-label.right {
  background: #fef3c7;
  color: #b45309;
}

.neighbor-label.empty {
  background: #eef2f7;
  color: #64748b;
}

.rules-stats-table tbody tr.current td { background: #eef4ff; }
.rules-stats-table tbody tr.current:hover td { background: #e4edff; }
.rules-stats-table tbody tr.empty-row td { border-top: 1px solid var(--border); }

.back-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 300px;
}

.back-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 2px 8px;
  border: 1px solid #d5e4fb;
  border-radius: 999px;
  background: #f2f7ff;
  color: var(--accent-dark);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
}

.back-chip:hover { background: #e4edff; }

.back-chip.special {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.back-chip.special:hover { background: var(--accent-dark); }

.miss-count {
  font-size: 12.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ball-link {
  display: inline-flex;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.ball-link:hover .ball { filter: brightness(1.08); }

.overlap-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 240px;
}

.num-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.special-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.special-hit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.rules3-union {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
}

.rules3-union .union-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rules3-union .union-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  max-width: 420px;
}

.rules3-union .union-chips .muted { font-size: 12.5px; }

.miss-none {
  font-size: 12.5px;
  color: var(--accent-dark);
  font-weight: 600;
  white-space: nowrap;
}

.hit-yes {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-dark);
  white-space: nowrap;
}

.hit-no {
  font-size: 12.5px;
  font-weight: 600;
  color: #b45309;
  white-space: nowrap;
}

.rules-recent-table .muted {
  color: var(--text-2);
  font-size: 13px;
}

/* ---------- library ---------- */

.drop-zone {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 26px 16px;
  border: 1.5px dashed #94a3b8;
  border-radius: 12px;
  background: #f8fafc;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.drop-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 22px;
  font-weight: 700;
}

.drop-title { margin-top: 4px; font-size: 15px; font-weight: 700; }

.drop-sub { max-width: 640px; font-size: 12.5px; color: var(--muted); }

.lib-help { margin-top: 10px; }

.lib-folder-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.lib-folder-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.lib-folder-row select { min-width: 190px; }
.lib-folder-row .btn { padding: 8px 12px; font-size: 13px; }

.lib-import-status { color: var(--accent-dark); font-weight: 600; }
.lib-import-status.err { color: #b91c1c; }
.lib-import-status:empty { display: none; }

.lib-toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1.5fr) minmax(120px, .5fr) minmax(120px, .5fr) minmax(120px, .5fr);
  gap: 10px;
  align-items: end;
}

.lib-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.lib-result-info { margin: 12px 0 4px; font-size: 12.5px; color: var(--muted); }

.lib-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.lib-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
  border-radius: 11px;
  background: #fff;
}

.lib-item:hover {
  border-color: #bfdbfe;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .06);
}

.lib-main { flex: 1 1 auto; min-width: 0; }

.lib-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.lib-title-row h3 { font-size: 15.5px; line-height: 1.35; overflow-wrap: anywhere; }

.lib-meta { margin-top: 4px; font-size: 12px; color: var(--muted); }

.lib-snippet {
  margin-top: 7px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.lib-snippet mark, .lib-doc-text mark {
  padding: 0 1px;
  border-radius: 2px;
  background: #fef08a;
  color: inherit;
}

.lib-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }

.lib-actions .btn { padding: 6px 10px; font-size: 12.5px; }

.lib-empty { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 14px; }

.lib-doc-text {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: #f8fafc;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.75;
}

.modal-card.wide { width: min(880px, 100%); }

/* ---------- cloud sync ---------- */

.cloud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
  padding: 4px 10px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.cloud-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

.cloud-chip.on { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.cloud-chip.on::before { background: #16a34a; }
.cloud-chip.pending { border-color: #fde68a; background: #fffbeb; color: #b45309; }
.cloud-chip.pending::before { background: #d97706; }
.cloud-chip.err { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.cloud-chip.err::before { background: #dc2626; }

html.gate-boot body { background: var(--bg); }

html.gate-boot body > .top-sticky,
html.gate-boot body > main,
html.gate-boot body > footer,
html.gate-boot body > .page-top,
body.gate-only > .top-sticky,
body.gate-only > main,
body.gate-only > footer,
body.gate-only > .page-top { display: none; }

.cloud-gate {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
}

.cloud-gate.hidden { display: none; }

.cloud-gate-card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--border-light);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15, 23, 42, .12);
  animation: pop .16s ease;
}

.cloud-gate-card h2 { font-size: 20px; }

.cloud-gate-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}

.cloud-gate-label input { min-height: 40px; }

.cloud-gate-error {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #b91c1c;
}

.cloud-gate-error:empty { display: none; }

.cloud-gate-actions { display: flex; gap: 8px; margin-top: 16px; }
.cloud-gate-actions .btn { flex: 1 1 0; }

@media (max-width: 700px) {
  .cloud-gate { padding: 16px; }
  .cloud-gate-card { padding: 22px 20px; }
}

/* ---------- 资料对奖 ---------- */

.bet-note {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
}

.bet-season-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.bet-season-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.bet-season-bar select {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}

.bet-season-hint { color: var(--muted); }
.bet-season-bar .btn { padding: 4px 10px; font-size: 12.5px; }

.bet-main-label {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
}

.bet-kpis {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.bet-kpi {
  padding: 10px 10px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: #f8fafc;
}

.bet-kpi b {
  display: block;
  font-size: 19px;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.bet-kpi span { font-size: 12.5px; color: var(--muted); }
.bet-kpi.ok b { color: #15803d; }
.bet-kpi.bad b { color: #dc2626; }

.bet-tiers { margin-bottom: 14px; }
.bet-tiers .data-table { min-width: 780px; }
.bet-tiers .data-table th,
.bet-tiers .data-table td { text-align: right; }
.bet-tiers .data-table th:first-child,
.bet-tiers .data-table td:first-child { text-align: left; }
.bet-main-row td { background: #f0fdf4; font-weight: 700; }

.bet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.bet-legend { font-size: 12.5px; color: var(--muted); }
.bet-text { margin-top: 12px; font-size: 13.5px; line-height: 1.8; }
.bet-mark { display: inline-block; width: 1.1em; font-weight: 700; text-align: center; }
.bet-mark.ok { color: #15803d; }
.bet-mark.bad { color: #dc2626; }
.bet-mark.pending { color: #94a3b8; }
.bet-actual { margin-left: 6px; font-size: 12.5px; color: var(--muted); }

.to-top {
  position: sticky;
  bottom: 2px;
  z-index: 6;
  display: none;
  align-items: center;
  gap: 4px;
  width: max-content;
  margin: 16px 0 0 auto;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, .92);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .3);
}

.to-top.show { display: flex; }
.to-top:hover { background: #0f172a; }

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .top-sticky { position: static; background: none; }
  .top-sticky.stuck { box-shadow: none; }
  .brand { order: 1; }
  .top-account { order: 2; margin-left: auto; }
  .live-draw { order: 3; width: 100%; align-items: flex-start; text-align: left; }
  .live-top, .live-main { justify-content: flex-start; }
  .live-msg { text-align: left; }
  .overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
  .filters .search-field { grid-column: span 2; }
  .attr-grid { column-count: 2; }
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .special-top { grid-template-columns: 1fr; }
  .hide-md { display: none; }
  .card { padding: 16px; }
  .attr-grid { column-count: 1; }
  .modal-attrs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-hint { display: inline-flex; }
  .lib-toolbar { grid-template-columns: 1fr 1fr; }
  .lib-search { grid-column: 1 / -1; }
  .bet-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .rules3-union .union-chips { max-width: 300px; }
}

@media (max-width: 700px) {
  body { font-size: 15px; }
  .topbar { padding: 14px 16px 10px; }
  .brand { flex: 1 1 0; }
  .brand-mark { width: 42px; height: 42px; font-size: 21px; border-radius: 12px; }
  .brand h1 { font-size: 18px; }
  .brand p { font-size: 12px; }
  .top-account { flex: 0 0 auto; gap: 6px; padding: 4px 4px 4px 5px; }
  .top-avatar { width: 24px; height: 24px; font-size: 11px; }
  .top-user { display: none; }
  .top-logout { padding: 4px 8px; font-size: 11px; }
  .live-draw { gap: 4px; }
  .live-meta { font-size: 12px; }
  .live-balls { gap: 3px; }
  .live-balls .ball.sm { width: 22px; height: 22px; font-size: 10px; }
  .live-source { font-size: 11px; }
  .live-edit { justify-content: flex-start; }
  .live-edit input { flex-basis: 100%; }
  main { padding: 14px 12px 30px; }
  .overview { gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .value { font-size: 24px; }
  .stat-card .value.small { font-size: 18px; }
  .tabs { margin-bottom: 12px; }
  .tab { padding: 8px 12px; font-size: 13.5px; }
  .card { padding: 14px; border-radius: 12px; }
  .card-head { flex-direction: column; gap: 10px; }
  .card-head .card-actions { width: 100%; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .filters .search-field { grid-column: 1 / -1; }
  .reset-btn { grid-column: 1 / -1; }
  .hide-sm { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .main { font-size: 19px; }
  .number-grid { gap: 5px; }
  .num-tile { padding: 6px 3px; border-radius: 8px; }
  .num-tile .n { width: 27px; height: 27px; font-size: 12px; }
  .num-tile .cnt { font-size: 11px; margin-top: 3px; }
  .num-tile .miss { font-size: 10px; }
  .ball { width: 28px; height: 28px; font-size: 12px; }
  .ball.lg { width: 46px; height: 46px; font-size: 19px; }
  .ball.xl { width: 54px; height: 54px; font-size: 23px; }
  .data-table { min-width: 620px; }
  .pager { justify-content: center; }
  .recent-balls { gap: 8px; }
  .legend-note { margin-left: 0; width: 100%; }
  .modal-card { padding: 20px; }
  .modal-attrs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .manual-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .manual-form .wide { grid-column: 1 / -1; }
  .attr-row { grid-template-columns: 48px 1fr 66px; }
  .drop-zone { padding: 20px 12px; }
  .lib-item { flex-direction: column; gap: 10px; }
  .lib-actions { width: 100%; }
  .lib-actions .btn { flex: 1 1 0; }
  .range-bar { padding: 10px 12px; gap: 8px 10px; }
  .range-title { order: 1; }
  .range-custom { order: 2; margin-left: auto; }
  .range-custom input { width: 72px; }
  .range-presets { order: 3; width: 100%; }
  .range-presets button { flex: 1 1 0; padding: 6px 4px; font-size: 12.5px; }
  .range-hint { order: 4; flex-basis: 100%; margin-left: 0; }
  .bet-note { text-align: left; }
  .bet-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bet-kpi:last-child { grid-column: span 2; }
  .bet-toolbar .btn { flex: 1 1 0; }
  .to-top { padding: 7px 12px; font-size: 12.5px; }
  .page-top { right: 12px; bottom: 14px; padding: 8px 12px; font-size: 12.5px; }
}

@media (max-width: 420px) {
  .overview { grid-template-columns: 1fr; }
  .ball-row { gap: 3px; }
  .ball { width: 26px; height: 26px; font-size: 11.5px; }
  .brand h1 { font-size: 16.5px; }
  .brand-mark { width: 38px; height: 38px; font-size: 18px; }
}

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

/* ---------- small additions ---------- */

.date-cell {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.date-cell .weekday {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.data-table td .ball-row { flex-wrap: nowrap; }

@media (max-width: 700px) {
  .date-cell { flex-direction: column; gap: 0; }
  .data-table td .ball-row { flex-wrap: wrap; }
}

@media (max-width: 600px) {
  .tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }
  .tab {
    width: 100%;
    padding: 9px 4px;
    font-size: 13px;
  }
  .records-table { min-width: 0; }
  .records-table th, .records-table td { padding: 10px 8px; }
  .records-table th:nth-child(2), .records-table td:nth-child(2) { display: none; }
  .records-table td .ball { margin: 1px 0; }
}

/* ---------- 账号与用户管理 ---------- */

.account-card { padding: 20px 22px; }

.account-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.account-avatar {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #2563eb, #1e3a8a);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
}

.account-info { flex: 1 1 220px; min-width: 0; }
.account-info h2 { font-size: 19px; }
.account-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.account-username { font-size: 12.5px; color: var(--muted); }

.account-role {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.account-role.admin { border-color: #bfdbfe; background: var(--accent-soft); color: var(--accent-dark); }

.password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
}

.password-form label,
.user-create-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}

.password-form input,
.user-create-form input,
.user-create-form select { min-height: 40px; }
.password-form .btn { min-height: 40px; }

.user-create-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.user-create-form .btn { min-height: 40px; }

.btn-mini {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 12px;
}

.users-table td { vertical-align: middle; }

.user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }

.user-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e2e8f0;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 700;
}

.user-cell > div { display: flex; flex-direction: column; min-width: 0; }
.user-cell strong { font-size: 13.5px; }
.user-username { font-size: 12px; color: var(--muted); }
.user-off { opacity: .6; }
.user-state { font-size: 12px; font-weight: 600; color: var(--muted); }
.user-state.on { color: var(--green); }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-self { font-size: 12px; color: var(--muted); }
.note.err { color: #b91c1c; }

@media (max-width: 900px) {
  .password-form { grid-template-columns: 1fr 1fr; }
  .password-form .btn { grid-column: 1 / -1; }
  .user-create-form { grid-template-columns: 1fr 1fr; }
  .user-create-form .btn { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .password-form,
  .user-create-form { grid-template-columns: 1fr; }
  .account-head .card-actions { width: 100%; }
  .account-head .card-actions .btn { width: 100%; }
  .users-table,
  .users-table tbody { display: block; width: 100%; }
  .users-table { min-width: 0; }
  .users-table thead { display: none; }
  .users-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "user role state"
      "actions actions actions";
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--border-light);
  }
  .users-table tbody tr:last-child { border-bottom: 0; }
  .users-table tbody tr:hover td { background: transparent; }
  .users-table tbody td { display: block; padding: 0; border: 0; }
  .users-table tbody td:nth-child(1) { grid-area: user; }
  .users-table tbody td:nth-child(2) { grid-area: role; }
  .users-table tbody td:nth-child(3) { grid-area: state; }
  .users-table tbody td:nth-child(4) { display: none; }
  .users-table tbody td:nth-child(5) { grid-area: actions; }
  .users-table tbody td[colspan] { grid-column: 1 / -1; }
  .user-actions { gap: 6px; }
  .user-actions .btn-mini { flex: 1 1 auto; }
}

/* ---------- 自定义规则分析：窄屏 ---------- */

@media (max-width: 700px) {
  .rule-def { flex-wrap: wrap; gap: 8px; }
  .rules-filters { align-items: stretch; }
  .rules-filters label { flex: 1 1 0; }
  .rules-filters select { width: 100%; }
  .rules-picker { align-items: stretch; }
  .rules-picker label { flex: 1 1 100%; }
  .rules-picker select { width: 100%; min-width: 0; }
  .rules-picker .btn { width: 100%; }
  #rules2-intro .card-head,
  #rules3-intro .card-head,
  #rules4-intro .card-head { flex-direction: column; }
  .rules2-lookback { width: 100%; align-items: stretch; }
  .rules2-lookback label { width: 100%; }
  .lookback-field { width: 100%; }
  .lookback-field input[type="number"] { flex: 1 1 auto; width: auto; }
  .rules-recent-table,
  .rules-stats-table { min-width: 0; }
  .rules-recent-table th,
  .rules-recent-table td,
  .rules-stats-table th,
  .rules-stats-table td { padding: 9px 8px; }
  .rules2-recent-table th,
  .rules2-recent-table td { padding: 9px 6px; }
  .rules2-recent-table .back-chips { max-width: 132px; gap: 3px; }
  .rules2-recent-table .back-chip { min-width: 38px; padding: 2px 6px; font-size: 11.5px; }
  .rules2-recent-table .rule-label { min-width: 46px; padding: 3px 8px; }
  .rules4-recent-table .neighbor-balls { max-width: 218px; }
  .rules4-recent-table .ordered-ball > i { display: none; }
  .rules4-recent-table .neighbor-label { min-width: 40px; padding: 2px 7px; font-size: 11.5px; }
  .overlap-chips { max-width: 142px; gap: 3px; }
  .num-chip { min-width: 27px; padding: 2px 5px; font-size: 11.5px; }
  .rules3-union { align-items: flex-start; }
  .rules3-union .union-chips { justify-content: flex-start; max-width: none; }
  .rules-stats-wrap { max-height: 460px; }
}
