/* ============ FRC PIT 智能看板 · 纯黑简洁风 ============ */
:root {
  --bg: #000;
  --panel: #111;
  --panel-2: #1a1a1a;
  --line: #2a2a2a;
  --txt: #e8e8e8;
  --txt-dim: #666;
  --red: #e83a3a;
  --red-dim: #2a1010;
  --blue: #2b7fff;
  --blue-dim: #0d1a2e;
  --green: #22c55e;
  --yellow: #eab308;
  --accent: #22c55e;
  --gold: #f59e0b;
  --mono: "Consolas", "SF Mono", "JetBrains Mono", monospace;
  --sans: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--txt); font-family: var(--sans); overflow: hidden; }

/* ══════════ 总布局：顶栏 + 主区 ══════════ */
.stage {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: 52px 1fr;
  gap: 8px; padding: 10px;
  background: var(--bg);
}
.zone {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; position: relative; overflow: hidden;
}

/* ══════════ 顶栏 ══════════ */
.topbar {
  display: flex; align-items: center; gap: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 18px 0 6px;
}
.top-nav { display: flex; align-items: stretch; gap: 2px; padding: 8px 6px; }
.nav-btn {
  display: flex; align-items: center; padding: 0 14px; height: 32px;
  font: 600 13px var(--sans); color: var(--txt-dim);
  text-decoration: none; border-radius: 7px;
  transition: color .15s, background .15s; white-space: nowrap;
}
.nav-btn:hover  { color: var(--txt); background: rgba(255,255,255,.06); }
.nav-btn.active { color: var(--txt); background: rgba(255,255,255,.09); font-weight: 700; }
.tb-divider { width: 1px; height: 22px; background: var(--line); flex-shrink: 0; margin: 0 10px; }
.tb-clock { display: flex; align-items: baseline; gap: 10px; }
.clock { font: 800 30px var(--mono); }
.clock-date { font: 400 12px var(--mono); color: var(--txt-dim); }
.tb-mid { margin-left: auto; }
.team-field { display: inline-flex; align-items: center; gap: 5px; font: 600 12px var(--mono); color: var(--txt-dim); }
.team-field input {
  width: 78px; text-align: center;
  background: #0d0d0d; border: 1px solid var(--line); border-radius: 6px;
  color: var(--gold); padding: 3px 6px; font: 800 17px var(--mono); outline: none;
  transition: border-color .15s;
}
.team-field input:focus { border-color: var(--gold); }
.team-field input::-webkit-outer-spin-button,
.team-field input::-webkit-inner-spin-button { -webkit-appearance: none; }
.tba-bar { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--txt-dim); border-left: 1px solid var(--line); padding-left: 14px; }
.tba-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--txt-dim); }
.tba-dot.ok  { background: var(--green); animation: pulse 1.8s infinite; }
.tba-dot.err { background: var(--red); }
.tba-updated { font-family: var(--mono); font-size: 11px; }
@keyframes pulse { 50% { opacity: .3; } }

/* ══════════ 主区三列 ══════════ */
.main-area {
  display: grid;
  grid-template-columns: 1fr 1.55fr 1fr;
  grid-template-rows: 1fr;
  gap: 8px; min-height: 0; height: 100%;
}
.main-area > .zone { min-height: 0; height: 100%; }

/* ── 左：Delta ── */
.delta-zone { padding: 14px; display: flex; flex-direction: column; }
.delta-panel {
  flex: 1; min-height: 0; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px 14px;
  transition: background .3s, border-color .3s;
}
.delta-top { display: flex; justify-content: space-between; align-items: center; }
.delta-label { font-size: 12px; color: var(--txt-dim); }
.delta-state { font-weight: 700; font-size: 13px; }
.delta-number {
  flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden;
  font-family: var(--mono); font-weight: 900;
  font-size: clamp(70px, 16vh, 180px); line-height: 1;
}
.delta-sub          { display: flex; justify-content: space-between; align-items: flex-end; }
.dsub-item          { display: flex; flex-direction: column; gap: 2px; }
.dsub-right         { align-items: flex-end; }
.dsub-mid           { align-items: center; }
.dsub-mid .dsub-val { color: var(--yellow); }
.dsub-label         { font-size: 11px; color: var(--txt-dim); }
.dsub-val           { font: 800 24px var(--mono); color: var(--txt); line-height: 1; }

/* Delta 三态 */
.delta-panel.safe   { border-color: #1e4d2f; background: #0d1f14; }
.delta-panel.safe   .delta-number, .delta-panel.safe   .delta-state { color: var(--green); }
.delta-panel.warn   { border-color: #4d3a00; background: #1f1800; }
.delta-panel.warn   .delta-number, .delta-panel.warn   .delta-state { color: var(--yellow); }
.delta-panel.urgent { border-color: #5a1010; animation: redflash .9s steps(1) infinite; }
.delta-panel.urgent .delta-number, .delta-panel.urgent .delta-state { color: #fff; }
@keyframes redflash { 0%,100% { background: #7a0000; } 50% { background: #2a0000; } }

/* ── 中：对阵 + 战绩 + 赛程 ── */
.mid-zone { display: flex; flex-direction: column; padding: 12px 14px; gap: 8px; }

/* 2×3 对战网格 */
.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex-shrink: 0;
}
.match-grid > .alliance.red  { grid-column: 1; grid-row: 1; }
.match-grid > .alliance.blue { grid-column: 2; grid-row: 1; }
.match-grid > .next-box      { grid-column: 1; grid-row: 2; }
.match-grid > .eta-box       { grid-column: 2; grid-row: 2; }
.match-grid > .stats-bar     { grid-column: 1 / 3; grid-row: 3; }
.zone-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--txt-dim); margin-bottom: 8px;
}
/* .match-id removed — replaced by .match-num-badge in VS center */
.alliances { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; }
.alliance { border-radius: 8px; padding: 7px 10px; display: flex; flex-direction: column; min-height: 120px; }
.alliance.red  { background: var(--red-dim);  border: 1px solid #4a1a1a; }
.alliance.blue { background: var(--blue-dim); border: 1px solid #142238; }
.alliance-tag { font: 700 11px var(--sans); text-align: center; letter-spacing: 1px; margin-bottom: 5px; }
.alliance.red  .alliance-tag { color: var(--red); }
.alliance.blue .alliance-tag { color: var(--blue); }
/* 下一场序号框（与 ETA 框同款） */
.next-box {
  background: #1a1a1a; border: 1px solid #2e2e2e; border-radius: 8px;
  padding: 10px 14px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.next-box-label { font-size: 11px; color: var(--txt-dim); font-weight: 600; }
.next-box-num   { font: 900 30px var(--mono); color: var(--txt); line-height: 1; letter-spacing: 1px; }

/* .eta-row 已被 .eta-box 替代 */
.team-list { list-style: none; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.team-list li {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255,255,255,.04); border: 1px solid transparent;
  border-radius: 5px; padding: 3px 4px; font-family: var(--mono);
}
.team-list li .tno   { font-weight: 800; font-size: clamp(14px, 2vh, 22px); line-height: 1.2; }
.team-list li .trank { font-size: 10px; color: var(--txt-dim); line-height: 1.2; }
.team-list li.is-ours { border-color: var(--gold); background: rgba(245,158,11,.1); }
.team-list li.is-ours .tno { color: var(--gold); }

/* 横向战绩条（下一场/ETA 框下方，跨两列） */
.stats-bar {
  background: #1a1a1a; border: 1px solid #2e2e2e; border-radius: 8px;
  padding: 10px 18px; display: flex; flex-direction: row;
  align-items: center; justify-content: space-around; gap: 10px;
}
.sbox-item  { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sbox-label { font-size: 10px; color: var(--txt-dim); white-space: nowrap; }
.sbox-val   { font: 800 18px var(--mono); color: var(--txt); line-height: 1.3; white-space: nowrap; }
.sbox-div   { width: 1px; height: 30px; background: rgba(255,255,255,.08); flex-shrink: 0; }

/* ETA框（蓝方下方） */
.eta-box {
  background: #1a1a1a; border: 1px solid #2e2e2e; border-radius: 8px;
  padding: 10px 14px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.eta-box-label { font-size: 11px; color: var(--txt-dim); font-weight: 600; }
.eta-box-time  { font: 900 30px var(--mono); color: var(--txt); line-height: 1; }
.eta-box-cd    { font: 600 13px var(--mono); color: var(--txt-dim); }
.eta-box-queue { font: 700 13px var(--mono); color: var(--yellow); margin-top: 2px; }
.eta-box-queue.due { color: var(--green); }
.eta-box-time.soon   { color: var(--yellow); }
.eta-box-time.urgent { color: var(--red); }

/* 秒表 / 倒计时 */
.timer-bar {
  flex-shrink: 0; display: flex; align-items: stretch; gap: 0;
  background: #1a1a1a; border: 1px solid #2e2e2e; border-radius: 8px;
  padding: 8px 14px; margin-top: 8px;
}
.timer-cell {
  flex: 1; display: flex; align-items: center; justify-content: center;
  gap: 12px;
}
.timer-head    { font-size: 11px; color: var(--txt-dim); white-space: nowrap; }
.timer-display { font: 900 26px var(--mono); color: var(--txt); line-height: 1; min-width: 116px; text-align: center; letter-spacing: 1px; }
.timer-display.run     { color: var(--green); }
.timer-display.cd-soon { color: var(--yellow); }
.timer-display.cd-done { color: var(--red); animation: pulse .8s steps(1) infinite; }
.timer-btns    { display: flex; align-items: center; gap: 6px; }
.timer-btn {
  padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt-dim);
  font: 600 12px var(--sans); transition: color .12s, border-color .12s;
}
.timer-btn:hover { color: var(--txt); border-color: #555; }
.timer-btn.active { color: var(--green); border-color: #2e5a3a; }
.timer-input {
  width: 56px; text-align: center; background: #0a0e16; border: 1px solid var(--line);
  border-radius: 6px; color: var(--txt); padding: 5px 4px; font: 700 13px var(--mono); outline: none;
}
.timer-input:focus { border-color: var(--accent); }
.timer-div { width: 1px; background: rgba(255,255,255,.08); margin: 0 10px; flex-shrink: 0; }

/* 赛程结果（贴底，flex:1 撑满剩余高度） */
.results-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.results-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.results-scroll::-webkit-scrollbar { width: 3px; }
.results-scroll::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.results-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px;
  table-layout: fixed; }
.results-table thead th {
  position: sticky; top: 0; background: var(--panel);
  font-size: 10px; font-weight: 600; color: var(--txt-dim);
  padding: 4px 4px 6px;
  border-bottom: 1px solid var(--line);
}
/* 列宽分配：场 | 红方队伍 | 红RP | 比分 | 蓝RP | 蓝方队伍 */
.col-match-h { width: 44px; text-align: left; }
.col-red-h   { text-align: center; }
.col-rp-h    { width: 28px; text-align: center; }
.col-score-h { width: 72px; text-align: center; }
.col-blue-h  { text-align: center; }
.results-table tbody tr { border-bottom: 1px solid rgba(255,255,255,.04); }
.results-table tbody tr:hover { background: rgba(255,255,255,.04); }
.results-table tbody td { padding: 4px 4px; color: var(--txt-dim); vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results-table .col-match { font-weight: 700; color: var(--txt-dim); }
.results-table .col-teams     { padding: 3px 2px; }
.results-table .team-row      { display: flex; gap: 2px; align-items: center; }
.results-table .team-row.red  { justify-content: center; } /* 居中，场次与RP之间 */
.results-table .team-row.blue { justify-content: center; } /* 居中，与红方对称 */
.results-table .ts            { display: inline-block; width: 40px; flex-shrink: 0;
                                text-align: center; overflow: hidden; text-overflow: clip;
                                font-size: 11px; font-family: var(--mono); }
.results-table .ts.ours       { color: var(--gold); font-weight: 800; }
/* 比分居中，红分靠右、蓝分靠左，体现对称 */
.results-table .col-score { text-align: center; font-weight: 700; color: var(--txt); }
.results-table .col-score .score-red  { color: #f87171; }
.results-table .col-score .score-blue { color: #60a5fa; }
.results-table .col-score .score-sep  { color: var(--txt-dim); margin: 0 2px; }
/* RP */
.results-table .col-rp       { text-align: center; font-weight: 700; }
.results-table .col-rp-red   { color: #f87171; }
.results-table .col-rp-blue  { color: #60a5fa; }
.results-table .col-rp-zero  { color: #444; }
/* 本队参与的行 */
.results-table tr.our-match { background: rgba(245,158,11,.06); }
.results-table tr.our-match .col-match { color: var(--gold); }

/* ── 右：排名表 ── */
.rankings-zone { display: flex; flex-direction: column; padding: 12px 14px; }
.rank-count { font: 600 12px var(--mono); color: var(--txt-dim); }
.rank-scroll {
  flex: 1; min-height: 0; overflow-y: auto; margin-top: 6px;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.rank-scroll::-webkit-scrollbar { width: 3px; }
.rank-scroll::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }
.rank-table { width: 100%; border-collapse: collapse; font-family: var(--mono); }
.rank-table thead th {
  position: sticky; top: 0; background: var(--panel);
  font-size: 10px; font-weight: 600; color: var(--txt-dim);
  text-align: left; padding: 4px 8px 8px; border-bottom: 1px solid var(--line);
}
.rank-table thead th:last-child,
.rank-table thead th:nth-last-child(2) { text-align: right; }
.rank-table tbody tr { border-bottom: 1px solid rgba(255,255,255,.04); }
.rank-table tbody tr:hover { background: rgba(255,255,255,.05); }
.rank-table tbody td { padding: 7px 8px; font-size: 13px; color: var(--txt-dim); }
.rank-table .col-rank { font-weight: 700; width: 38px; font-size: 13px; }
.rank-table .col-team { font-weight: 800; font-size: 16px; color: var(--txt); }
.rank-table .col-record { font-size: 12px; }
.rank-table .col-rp { text-align: right; font-weight: 700; font-size: 14px; color: var(--txt); }
.rank-table .col-epa { text-align: right; font-weight: 700; font-size: 14px; color: var(--gold); }
.rank-table tr.our-team td { background: rgba(245,158,11,.1); }
.rank-table tr.our-team .col-team, .rank-table tr.our-team .col-rank { color: var(--gold); }

/* ══════════ 手动控制台 ══════════ */
.console { position: fixed; right: 16px; bottom: 16px; z-index: 50; }
.console-toggle {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--panel-2); color: var(--txt-dim); border: 1px solid var(--line);
  font-size: 17px; cursor: pointer; transition: color .15s, border-color .15s;
}
.console-toggle:hover { color: var(--txt); border-color: #444; }
.console-body {
  position: absolute; right: 0; bottom: 48px; width: 320px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.7);
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.console.open .console-body { opacity: 1; transform: none; pointer-events: auto; }
.console-body h3 { font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.ctl-grid { display: flex; flex-direction: column; gap: 12px; }
.ctl-block label { display: block; font-size: 11px; color: var(--txt-dim); margin-bottom: 6px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 34px; height: 34px; border-radius: 6px; font-size: 18px; background: var(--panel-2); color: var(--txt); border: 1px solid var(--line); cursor: pointer; }
.stepper button:active { background: #333; }
.stepper span { flex: 1; text-align: center; font: 800 20px var(--mono); }
.seg { display: flex; gap: 5px; }
.seg-wrap { flex-wrap: wrap; }
.seg button { flex: 1; padding: 6px 4px; font-size: 11px; cursor: pointer; background: var(--panel-2); color: var(--txt-dim); border: 1px solid var(--line); border-radius: 6px; white-space: nowrap; transition: color .12s, border-color .12s; }
.seg button:hover { color: var(--txt); border-color: #444; }
.seg button.active { background: #222; color: var(--txt); border-color: #555; font-weight: 700; }
kbd { background: #111; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 1px 5px; font: 600 10px var(--mono); color: var(--txt-dim); }

/* ══════════════════════════════════════════ OCR 配置弹窗 ══════════════════════════════════════════ */
.ocr-modal { position: fixed; inset: 0; z-index: 100; display: none; }
.ocr-modal.open { display: block; }
.ocr-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(2px); }
.ocr-modal-card {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(920px, 94vw); max-height: 92vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 26px 30px; box-shadow: 0 30px 80px rgba(0,0,0,.7);
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.ocr-modal-card::-webkit-scrollbar { width: 4px; }
.ocr-modal-card::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }
.ocr-modal-head { display: flex; align-items: center; justify-content: space-between; }
.ocr-modal-head h2 { font-size: 20px; font-weight: 800; }
.ocr-modal-close {
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt-dim); font-size: 14px;
}
.ocr-modal-close:hover { color: var(--red); border-color: var(--red); }
.ocr-modal-sub { font-size: 13px; color: var(--txt-dim); margin: 4px 0 6px; }

.ocr-modal .section-label {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  color: var(--txt-dim); text-transform: uppercase; margin: 20px 0 11px;
}
.ocr-modal .btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ocr-btn {
  padding: 9px 16px; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--txt); font: 600 13px var(--sans);
  transition: border-color .15s, color .15s, background .15s;
}
.ocr-btn:hover { border-color: #555; }
.ocr-btn.primary { background: var(--accent); color: #04130c; border-color: transparent; font-weight: 800; }
.ocr-btn.primary:hover { box-shadow: 0 4px 20px rgba(20,224,138,.3); }
.ocr-btn.active-sel { border-color: var(--gold); color: var(--gold); }
.ocr-btn:disabled { opacity: .4; cursor: not-allowed; }
.cap-status { font-size: 12px; color: var(--txt-dim); }
.cap-status.ok  { color: var(--accent); }
.cap-status.err { color: var(--red); }

.cap-wrap {
  position: relative; margin-top: 12px; background: #0a0a0a;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-height: 110px;
}
.cap-wrap video { display: block; width: 100%; }
.cap-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.cap-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--txt-dim); font-size: 13px; pointer-events: none; }

.region-info { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.region-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px;
  font: 600 12px var(--mono); background: var(--panel-2); border: 1px solid var(--line); color: var(--txt-dim);
}
.region-chip .dot { width: 9px; height: 9px; border-radius: 2px; }
.region-chip.match .dot { background: var(--gold); }
.region-chip.time  .dot { background: var(--blue); }
.region-chip.set { color: var(--txt); }

.test-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.test-cell { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.test-cell h4 { font-size: 12px; color: var(--txt-dim); margin-bottom: 8px; }
.test-cell canvas { width: 100%; background: #000; border-radius: 6px; image-rendering: pixelated; }
.test-out { margin-top: 8px; font: 800 22px var(--mono); color: var(--accent); min-height: 28px; }
.test-out.err { color: var(--red); font-size: 13px; }

.field-inline { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--txt-dim); }
.field-inline input {
  width: 64px; text-align: center; background: #0a0e16; border: 1px solid var(--line);
  border-radius: 8px; color: var(--txt); padding: 8px; font: 700 15px var(--mono); outline: none;
}

/* 响应式 */
@media (max-aspect-ratio: 4/3) {
  .main-area { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
}
