:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --card: #1c2128;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #8b949e;
  --red: #e5484d;
  --red-soft: #7d1f24;
  --blue: #3b82f6;
  --blue-soft: #1e3a5f;
  --gold: #d29922;
  --green: #3fb950;
  --purple: #a371f7;
}
body.light {
  --bg: #f6f8fa;
  --bg2: #eef1f4;
  --card: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --red-soft: #ffebe9;
  --blue-soft: #ddf4ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--card); position: sticky; top: 0; z-index: 100;
}
.brand h1 { font-size: 18px; letter-spacing: 1px; }
.badge { font-size: 12px; color: var(--muted); margin-left: 10px; }
.topbar-actions { display: flex; gap: 8px; }
.topbar-actions button { font-size: 12px; padding: 4px 10px; }

/* 布局 */
.layout { display: flex; flex: 1; }

/* 侧边导航 */
.sidebar {
  width: 160px; min-width: 160px; border-right: 1px solid var(--border);
  padding: 12px 8px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
}
.nav-btn {
  background: transparent; color: var(--muted); border: none;
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  text-align: left; transition: all .15s;
}
.nav-btn:hover { background: var(--bg2); color: var(--text); }
.nav-btn.active { background: var(--blue-soft); color: var(--blue); border-color: var(--blue); }

/* 主内容 */
.content { flex: 1; padding: 16px 20px; overflow-x: hidden; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 卡片 */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin-bottom: 12px; color: #fff; display:flex; align-items:center; gap:8px; }
body.light .card h2 { color: var(--text); }
.card h2 .tag { font-size: 11px; color: var(--muted); font-weight: 400; }

/* 工具栏 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
button {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: all .15s;
}
button:hover { border-color: var(--blue); color: #fff; }
button.primary { background: var(--blue-soft); border-color: var(--blue); }
button:disabled { opacity: .5; cursor: wait; }
.spin { display:inline-block; animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* 预测配置 */
.pred-config { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pred-config label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.pred-config select { background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; }

/* 网格 */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* 球 */
.balls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ball {
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 14px; color: #fff;
}
.ball.red { background: linear-gradient(145deg, #f0565b, var(--red)); box-shadow: 0 2px 6px rgba(229,72,77,.35); }
.ball.blue { background: linear-gradient(145deg, #5c9cff, var(--blue)); box-shadow: 0 2px 6px rgba(59,130,246,.35); }
.ball.sm { width: 22px; height: 22px; font-size: 11px; cursor: pointer; transition: transform .1s; }
.ball.sm:hover { transform: scale(1.2); }

/* 预测票卡 */
.ticket {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--bg2); position: relative;
}
.ticket.small { padding: 6px 10px; }
.ticket .row1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ticket .meta { color: var(--muted); font-size: 12px; }
.ticket .conf { flex: 1; min-width: 120px; }
.conf .bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.conf .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--purple)); }
.conf num { font-size: 12px; color: var(--gold); font-weight: 600; }
.badge { font-size: 10.5px; padding: 2px 7px; border-radius: 10px; border: 1px solid var(--border); color: var(--muted); }
.badge.badge-ver { color: var(--gold); border-color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge.llm { color: var(--purple); border-color: var(--purple); }
.badge.gradeA { color: var(--green); border-color: var(--green); }
.badge.gradeB { color: var(--gold); border-color: var(--gold); }
.badge.gradeC { color: var(--muted); }
.ticket .reasoning { margin-top: 6px; font-size: 12px; color: var(--muted); }
.ticket .detail { margin-top: 4px; }
.copy-btn, .fav-btn { font-size: 14px; padding: 2px 6px; background: transparent; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.copy-btn:hover, .fav-btn:hover { border-color: var(--blue); }

/* 热力图 */
.heat { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; }
.heat .cell {
  aspect-ratio: 1; border-radius: 5px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: rgba(255,255,255,.92); font-weight: 600; cursor: pointer;
  transition: transform .1s;
}
.heat .cell:hover { transform: scale(1.1); }
.heat .cell.b { background: var(--blue-soft); color: var(--blue); }
.legend { display: flex; gap: 12px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; vertical-align: middle; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.scroll { overflow-x: auto; }

/* 评估指标 */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.metric { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.metric .k { color: var(--muted); font-size: 12px; }
.metric .v { font-size: 18px; font-weight: 700; margin-top: 2px; }
.metric .v.pos { color: var(--green); } .metric .v.neg { color: var(--red); }
.metric .sub { font-size: 10px; color: var(--muted); font-weight: 400; display: block; margin-top: 2px; }

/* 标签页 */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { padding: 5px 14px; border: 1px solid var(--border); border-radius: 16px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.tab.on { background: var(--blue-soft); border-color: var(--blue); color: #fff; }

/* 图表 */
.chart { width: 100%; height: 260px; }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.hidden { display: none !important; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #24292f; border: 1px solid var(--border); padding: 10px 18px;
  border-radius: 10px; font-size: 13px; z-index: 99; display: none;
}

/* 弹窗 */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  align-items: center; justify-content: center; z-index: 200;
}
.modal-content {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; max-width: 420px; width: 90%; position: relative;
}
.close-btn {
  position: absolute; top: 10px; right: 10px; background: transparent;
  border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px;
}
.close-btn:hover { color: var(--text); }

/* 诊断 */
.diagnose-input { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.diagnose-input input {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.diagnose-input input:first-child { flex: 1; min-width: 200px; }
.diagnose-card h4 { margin: 12px 0 6px; font-size: 13px; color: var(--gold); }

/* 规律筛选 */
.pat-filters { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: wrap; }
.pat-filters select { background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 12px; }

/* ==================== M5 交互升级 ==================== */

/* 命中球高亮（回放/对照） */
.ball.hit {
  position: relative;
  outline: 2px solid var(--gold);
  box-shadow: 0 0 0 3px rgba(210,153,34,.22), 0 2px 10px rgba(210,153,34,.45);
}
.ball.hit::after {
  content: "✓"; position: absolute; top: -7px; right: -7px;
  width: 14px; height: 14px; background: var(--gold); color: #1a1a1a;
  border-radius: 50%; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.ball.red.hit { background: linear-gradient(145deg, #ffb199, #f0565b); }
.ball.blue.hit { background: linear-gradient(145deg, #9ed0ff, #5c9cff); }

/* 回放 */
.replay-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.replay-bar select {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; font-size: 12.5px; max-width: 360px;
}
.chk { font-size: 12px; color: var(--muted); display: flex; gap: 5px; align-items: center; cursor: pointer; user-select: none; }
.hint-inline { font-size: 12px; color: var(--muted); }
.replay-actual {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--bg2); border: 1px solid var(--gold); border-radius: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.replay-actual .label { color: var(--gold); font-size: 13px; font-weight: 600; white-space: nowrap; }
.replay-ticket .rk { color: var(--muted); font-size: 12px; min-width: 26px; }
.replay-ticket .meta b { font-size: 14px; }
.replay-detail { margin-top: 6px; }
.replay-detail summary { cursor: pointer; font-size: 12px; color: var(--muted); user-select: none; }
.replay-detail summary:hover { color: var(--text); }
.prize-badge {
  font-size: 11px; padding: 2px 9px; border-radius: 10px; border: 1px solid var(--border);
  color: var(--muted); white-space: nowrap; font-weight: 600;
}
.prize-badge.lv1, .prize-badge.lv2 { color: #ffdf6b; border-color: #ffdf6b; background: rgba(210,153,34,.18); }
.prize-badge.lv3 { color: var(--gold); border-color: var(--gold); }
.prize-badge.lv4, .prize-badge.lv5, .prize-badge.lv6 { color: var(--green); border-color: var(--green); }
.prize-badge.none { color: var(--muted); font-weight: 400; }

/* mini 模式切换（热力图等） */
.mini-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.mini-tab {
  padding: 2px 11px; border: 1px solid var(--border); border-radius: 12px;
  font-size: 11px; color: var(--muted); cursor: pointer; user-select: none; transition: all .15s;
}
.mini-tab:hover { color: var(--text); }
.mini-tab.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); font-weight: 600; }

/* 分析区块 */
.ana-block { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.ana-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.ana-head b { font-size: 12.5px; }
.ana-sec { margin: 14px 0 6px; font-size: 13px; color: var(--gold); }
.heat-blue { grid-template-columns: repeat(8, 1fr); }
.heat .cell.last { outline: 1.5px dashed var(--gold); outline-offset: 1px; }
.range-sel {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; margin-left: 8px;
}

/* 评估子页 */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 12px; }
.subtab {
  padding: 5px 14px; border: 1px solid var(--border); border-radius: 16px;
  cursor: pointer; color: var(--muted); font-size: 12.5px; user-select: none; transition: all .15s;
}
.subtab:hover { color: var(--text); }
.subtab.on { background: var(--blue-soft); border-color: var(--blue); color: #fff; }
.sub-panel.hidden { display: none; }
.callout {
  border-left: 3px solid var(--gold); background: var(--bg2);
  padding: 8px 12px; border-radius: 0 8px 8px 0; margin-top: 10px;
}
.ci { font-size: 10.5px; color: var(--muted); }
td .badge { white-space: nowrap; }

/* 数据管理 */
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.eval-actions { display: flex; gap: 8px; margin-bottom: 12px; }

/* 进度条 */
.bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--purple)); }

/* 底部 */

/* ==================== 设置页 ==================== */
.settings-wrap { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }

.settings-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.settings-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  background: linear-gradient(135deg, rgba(230,57,70,.12), rgba(255,193,7,.06));
  border-bottom: 1px solid var(--border);
}
.settings-card-head h3 { margin: 0; font-size: 15px; color: var(--text); }
.settings-desc { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.llm-status-badge {
  flex: none;
  padding: 5px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--bg3); color: var(--muted);
  border: 1px solid var(--border);
}
.llm-status-badge.ok { background: rgba(46,204,113,.15); color: #2ecc71; border-color: rgba(46,204,113,.4); }
.llm-status-badge.bad { background: rgba(230,57,70,.12); color: #e63946; border-color: rgba(230,57,70,.4); }

.settings-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; }

/* 开关 */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text); cursor: pointer;
}
.switch { position: relative; width: 42px; height: 22px; display: inline-block; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--border);
  transition: .2s; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: .2s;
}
.switch input:checked + .slider { background: rgba(46,204,113,.4); border-color: #2ecc71; }
.switch input:checked + .slider::before { left: 22px; background: #2ecc71; }

/* 字段 */
.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field > label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input {
  width: 100%; padding: 9px 12px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none; transition: border-color .15s, box-shadow .15s;
  box-sizing: border-box;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,193,7,.15); }
.field input:disabled { opacity: .45; cursor: not-allowed; }
.field-hint { margin: 0; font-size: 11px; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-sm { flex: 0 0 120px; }

/* 操作区 */
.settings-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.settings-actions button { padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s; }
button.primary { background: var(--gold); color: #1a1a1a; border: none; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { border-color: var(--gold); color: var(--gold); }
button.ghost:disabled { opacity: .5; cursor: wait; }
.test-result { font-size: 12px; color: var(--muted); }
.config-status { font-size: 12px; min-height: 16px; }
.config-status .oktxt { color: #2ecc71; }
.config-status .errtxt { color: #e63946; }

/* 明色主题适配 */
[data-theme="light"] .settings-card { box-shadow: 0 1px 3px rgba(0,0,0,.08); }
[data-theme="light"] .settings-card-head { background: linear-gradient(135deg, rgba(230,57,70,.08), rgba(255,193,7,.05)); }

footer { color: var(--muted); font-size: 12px; text-align: center; margin-top: 20px; padding: 12px; }

/* 移动端 */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: unset; height: auto; position: static;
    flex-direction: row; flex-wrap: wrap; padding: 8px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .nav-btn { flex: 1; text-align: center; font-size: 12px; padding: 8px 6px; }
  .content { padding: 12px; }
  .heat { grid-template-columns: repeat(11, 1fr); }
  .heat-blue { grid-template-columns: repeat(8, 1fr); }
  .heat .cell { font-size: 9px; }
}
