:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel-2: #222b35;
  --border: #2c3742;
  --text: #e6edf3;
  --muted: #8b97a3;
  --accent: #4cc9f0;
  --good: #3fb950;
  --warn: #e3b341;
  --bad: #f85149;
  --chip: #2d3a47;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; }
.subtitle { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.status { margin-left: auto; font-size: 12px; color: var(--muted); text-align: right; line-height: 1.4; }
.src-live { color: #3fb950; }   /* live：绿色 */
.src-mock { color: #d29922; }   /* mock：黄色 */
.src-down { color: #f85149; }   /* 断开/未就绪：红色 */
.btn {
  background: var(--accent);
  color: #06222e;
  border: none;
  padding: 7px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 自动刷新控件 */
.auto-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.ar-toggle { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.auto-refresh input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.ar-opts { display: flex; gap: 4px; }
.ar-opt {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.ar-opt:hover { color: var(--text); border-color: var(--accent); }
.ar-opt.active { background: var(--accent); color: #06222e; border-color: var(--accent); font-weight: 600; }
.auto-countdown {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  display: inline-block;
  width: 64px;            /* 固定宽，倒计时变化不挤动旁边元素 */
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
}

/* ---------- 布局 ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 340px 1fr; overflow: hidden; }
.list-pane { border-right: 1px solid var(--border); overflow-y: auto; background: var(--panel); }
.detail-pane { overflow-y: auto; padding: 20px 28px; }

.pane-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel);
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.pane-head-row { display: flex; align-items: baseline; gap: 8px; }
.pane-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); }

/* 球队筛选框 */
.filter-box { position: relative; display: flex; }
.filter-input {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 28px 7px 10px; font-size: 13px; outline: none;
}
.filter-input:focus { border-color: var(--accent); }
.filter-input::placeholder { color: var(--muted); }
.filter-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px 6px; border-radius: 4px;
}
.filter-clear:hover { color: var(--text); background: var(--border); }

/* ---------- 赛事列表 ---------- */
.match-list { list-style: none; }

/* 日期分组头（可折叠） */
.day-header {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  cursor: pointer;
  position: sticky; top: 78px; z-index: 1;
  user-select: none;
}
.day-header:hover { filter: brightness(1.15); }
.dh-arrow { color: var(--accent); font-size: 11px; width: 12px; }
.dh-date { font-weight: 700; font-size: 13px; }
.dh-meta { margin-left: auto; font-size: 11px; color: var(--muted); }
.day-header.collapsed { opacity: .85; }
.match-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.match-item:hover { background: var(--panel-2); }
.match-item.active { background: var(--panel-2); border-left: 3px solid var(--accent); padding-left: 13px; }
.mi-teams { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.mi-meta { margin-top: 5px; font-size: 11px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mi-probs { margin-top: 7px; display: flex; gap: 4px; font-size: 11px; }
.mi-prob { flex: 1; text-align: center; background: var(--panel-2); border-radius: 4px; padding: 3px 0; }
.mi-prob b { display: block; font-size: 12px; }

/* 徽章 */
.badge { font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.badge.sig { background: rgba(63,185,80,.18); color: var(--good); }
.badge.inj { background: rgba(227,179,65,.18); color: var(--warn); }
.badge.noodds { background: rgba(139,151,163,.15); color: var(--muted); }
.badge.live { background: rgba(248,81,73,.2); color: var(--bad); animation: livepulse 1.6s ease-in-out infinite; }
.badge.final { background: rgba(76,201,240,.16); color: var(--accent); }
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* 列表里的比分 */
.mi-score { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mi-score.live { color: var(--bad); }
.mi-score.final { color: var(--text); }
.match-item.is-live { border-left: 3px solid var(--bad); padding-left: 13px; }
.dh-live { color: var(--bad); font-weight: 700; }

/* ---------- 详情 ---------- */
.empty { color: var(--muted); margin-top: 80px; text-align: center; font-size: 14px; }
.detail h1 { font-size: 22px; margin-bottom: 4px; }
.detail .d-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* 详情比分牌 */
.scoreboard {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.scoreboard.live { border-color: var(--bad); }
.scoreboard.final { border-color: var(--accent); }
.sb-tag { font-size: 12px; font-weight: 700; }
.sb-tag.live { color: var(--bad); }
.sb-tag.final { color: var(--accent); }
.sb-row { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.sb-team { flex: 1; font-size: 16px; font-weight: 700; }
.sb-team:first-of-type { text-align: right; }
.sb-team:last-of-type { text-align: left; }
.sb-team.win { color: var(--good); }
.sb-team.win::after { content: " ✓"; font-size: 12px; }
.sb-score { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-dash { color: var(--muted); margin: 0 10px; }
.sb-extra { font-size: 12px; color: var(--muted); margin-top: 2px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); margin-bottom: 12px; }

/* 概率条 */
.probrow { display: flex; gap: 10px; margin-bottom: 14px; }
.probcell { flex: 1; text-align: center; background: var(--panel-2); border-radius: 8px; padding: 10px 0; }
.probcell .v { font-size: 20px; font-weight: 700; }
.probcell .k { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kv { display: flex; flex-wrap: wrap; gap: 10px 24px; font-size: 13px; }
.kv div b { color: var(--muted); font-weight: 400; margin-right: 6px; }

/* 两队对比表 */
.team-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px 16px; align-items: center; font-size: 13px; }
.team-grid .tg-label { text-align: center; color: var(--muted); font-size: 11px; }
.team-grid .tg-home { text-align: right; }
.team-grid .tg-away { text-align: left; }
.team-grid .tg-name { font-weight: 700; font-size: 15px; }

/* 队员/伤停 */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.players h4 { font-size: 13px; margin-bottom: 8px; }
.player { padding: 7px 10px; background: var(--panel-2); border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.player .pp-pos { color: var(--muted); font-size: 11px; }
.player .pp-st { float: right; font-weight: 600; font-size: 11px; }
.player.key { border-left: 3px solid var(--warn); }
.st-OUT { color: var(--bad); }
.st-DOUBTFUL, .st-GTD { color: var(--warn); }
.none { color: var(--muted); font-size: 12px; font-style: italic; }

/* 信号 / 盘口表 */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; }
.edge-pos { color: var(--good); font-weight: 700; }
.sig-note { color: var(--good); }

.flags-note { font-size: 12px; color: var(--warn); margin-top: 8px; line-height: 1.5; }
.caveat { font-size: 11px; color: var(--muted); margin-top: 18px; line-height: 1.5; padding: 10px 12px; background: var(--panel); border-radius: 8px; border: 1px dashed var(--border); }

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

/* ===================== 视图切换（日期 / Bracket） ===================== */
.view-toggle { display: flex; gap: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 2px; }
.vt { background: transparent; color: var(--muted); border: none; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; border-radius: 5px; white-space: nowrap; }
.vt:hover { color: var(--text); }
.vt.active { background: var(--accent); color: #06222e; }

/* ===================== Bracket 对阵树 ===================== */
.bracket-pane { display: none; overflow: hidden; height: 100%; }
body.bracket-mode .layout { display: block; }      /* 整宽，别再被 340px 栅格挤住 */
body.bracket-mode .list-pane,
body.bracket-mode .detail-pane { display: none; }
body.bracket-mode .bracket-pane { display: block; }
/* bracket 模式下点开比赛 → 详情作为右侧抽屉浮出 */
body.bracket-mode.show-detail .detail-pane {
  display: block; position: fixed; top: 57px; right: 0; bottom: 0;
  width: var(--drawer-w, min(560px, 94vw)); background: var(--bg); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 18px 22px 18px 26px; z-index: 50; box-shadow: -10px 0 30px rgba(0,0,0,.45);
}
body.bracket-mode.show-detail .mobile-back { display: block; }

/* 抽屉左缘拖拽手柄 */
.drawer-resize { display: none; }
body.bracket-mode.show-detail .drawer-resize {
  display: flex; align-items: center; justify-content: center;
  position: absolute; left: -6px; top: 0; bottom: 0; width: 14px;
  cursor: ew-resize; z-index: 52;
}
body.bracket-mode.show-detail .drawer-resize::before {
  content: ""; width: 3px; height: 40px; border-radius: 3px; background: var(--border);
}
body.bracket-mode.show-detail .drawer-resize:hover::before { background: var(--accent); height: 100%; border-radius: 0; }
body.resizing { cursor: ew-resize !important; user-select: none; }
body.resizing .detail-pane { transition: none; }

.bracket-scroll { width: 100%; height: 100%; overflow: auto; padding: 20px; }
.bracket { position: relative; display: flex; align-items: stretch; gap: 40px; width: max-content; }
.bk-svg { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; overflow: visible; }
.bk-line { fill: none; stroke: #4a5a6b; stroke-width: 2; }

.bk-round { display: flex; flex-direction: column; min-width: 190px; position: relative; z-index: 1; }
.bk-round-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; text-align: center; padding-bottom: 10px; position: sticky; top: 0; }
.bk-round-head span { display: inline-block; margin-left: 4px; opacity: .6; font-weight: 400; }
.bk-round-body { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }

.bk-match { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; cursor: pointer; transition: border-color .12s, background .12s; }
.bk-match:hover { border-color: var(--accent); background: var(--panel-2); }
.bk-match.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bk-match.live { border-color: var(--bad); }
.bk-head { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.bk-tag.live { color: var(--bad); font-weight: 700; }
.bk-tag.final { color: var(--accent); }
.bk-side { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 0; font-size: 13px; }
.bk-side.win { font-weight: 800; }
.bk-side.win .bk-sc { color: var(--good); }
.bk-side.tbd .bk-tm { color: var(--muted); font-style: italic; }
.bk-tm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-sc { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 14px; text-align: right; }
.bk-third { justify-content: flex-end; }
.bk-third .bk-round-body { flex: 0 0 auto; }

/* 移动端返回按钮（默认隐藏，仅手机详情视图显示） */
.mobile-back {
  display: none;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 14px;
}

/* ====================== iPhone / 窄屏自适应 ====================== */
@media (max-width: 720px) {
  /* 整页可滚动，不再锁死 100vh 的内部双栏滚动 */
  body { height: auto; min-height: 100vh; }

  /* 顶栏：允许换行，控件挨个流到下一行 */
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .brand { font-size: 16px; width: 100%; }
  .subtitle { display: block; margin-left: 0; margin-top: 2px; }
  .status { margin-left: 0; text-align: left; width: 100%; order: 5; }
  .auto-refresh { flex-wrap: wrap; white-space: normal; gap: 8px; }
  .ar-opts { flex-wrap: wrap; }
  .ar-opt { padding: 5px 10px; font-size: 13px; }      /* 触控目标加大 */
  .auto-countdown { width: auto; min-width: 56px; }
  .btn { padding: 8px 14px; font-size: 14px; }

  /* 布局：单列，主从切换（列表 ↔ 详情） */
  .layout { display: block; overflow: visible; }
  .list-pane {
    border-right: none;
    height: auto;
    overflow: visible;
    max-height: none;
  }
  .detail-pane { display: none; padding: 16px 14px; }
  body.show-detail .list-pane { display: none; }
  body.show-detail .detail-pane { display: block; }
  .mobile-back { display: block; }
  .empty { display: none; }                            /* 手机上不需要"点左侧"提示 */

  /* 日期分组头吸顶位置：随单列布局调整 */
  .day-header { top: 0; }
  .pane-head { position: static; }

  /* 详情排版收紧 */
  .detail h1 { font-size: 19px; }
  .card { padding: 14px; }
  .players { grid-template-columns: 1fr; gap: 10px; }  /* 伤停两队改上下叠 */
  .kv { gap: 8px 16px; font-size: 12px; }
  .probcell .v { font-size: 18px; }

  /* 表格收紧，5 列也能塞进 375px */
  table { font-size: 12px; }
  th, td { padding: 6px 5px; }
  th { font-size: 10px; }
}
