/* ==========================================================
   双打分组器 — 样式
   移动端优先，基准 375px；桌面端显示为手机外框预览。
   ========================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

html, body {
  height: 100%;
}

/* ---------- 设计令牌 ---------- */
:root {
  --bg: #eef2f0;
  --bg-grad-a: #eef2f0;
  --bg-grad-b: #e3e9e6;
  --surface: #fff;
  --surface-2: #fafafa;
  --text: #1a1a1a;
  --text-2: #555;
  --muted: #999;
  --faint: #b5bdb9;
  --border: #ececec;
  --line: #f4f4f4;
  --accent: #07C160;
  --accent-dark: #06AD56;
  --accent-soft: #E8F8EF;
  --accent-2: #FF9500;
  --accent-2-dark: #ef8b00;
  --accent-2-soft: #FFF3E0;
  --danger: #FA5151;
  --warn: #B8860B;
  --warn-soft: #FFF8E1;
  --shadow: 0 1px 3px rgba(0, 0, 0, .04);
  --radius: 14px;
}

body[data-theme="dark"] {
  --bg: #0f1412;
  --bg-grad-a: #131a17;
  --bg-grad-b: #0c110f;
  --surface: #1b2320;
  --surface-2: #222b27;
  --text: #e8edeb;
  --text-2: #c3ccc8;
  --muted: #8d9a95;
  --faint: #66726e;
  --border: #2a3430;
  --line: #26302c;
  --accent-soft: #14301f;
  --accent-2-soft: #33240c;
  --warn-soft: #302a12;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, var(--bg-grad-a) 0%, var(--bg-grad-b) 100%);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- 手机外框 ---------- */
.stage {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 12px;
}

.phone {
  width: min(402px, 100vw);
  height: min(860px, calc(100vh - 80px));
  height: min(860px, calc(100dvh - 80px));
  background: var(--surface);
  border-radius: 40px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .08);
  display: flex;
  flex-direction: column;
  position: relative;
}

.stage-caption {
  font-size: 12px;
  color: #8a9490;
}

/* ---------- 顶栏 ---------- */
.mp-bar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.mp-title {
  font-size: 16px;
  font-weight: 600;
}

.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 28px;
  -webkit-overflow-scrolling: touch;
}

.content::-webkit-scrollbar { width: 0; }

/* ---------- 卡片 / 按钮 ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-head b { font-size: 15px; }
.card-head .sub { font-size: 12px; color: var(--muted); text-align: right; flex: 1; min-width: 0; }

.pill {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.primary-btn {
  width: 100%;
  height: 47px;
  border: none;
  border-radius: 13px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:active { background: var(--accent-dark); }
.primary-btn:disabled { background: #c9ecd7; cursor: not-allowed; }

body[data-theme="dark"] .primary-btn:disabled { background: #234a35; }

.ghost-btn {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 13.5px;
  color: var(--text-2);
  cursor: pointer;
  margin-top: 8px;
}

.ghost-btn:active { background: var(--surface-2); }

.link-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.link-btn:active { color: var(--text-2); }

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 10px 0;
}

.hint.err { color: var(--danger); }

.foot-note {
  text-align: center;
  font-size: 11px;
  color: var(--faint);
  margin-top: 14px;
}

/* ---------- 报名页 ---------- */
.p-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px 10px;
}

.p-cell { position: relative; }

.p-cell input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  font-size: 15px;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
}

.p-cell input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.p-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.p-del:active { background: #e64340; }

.mode-item {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin-bottom: 9px;
  cursor: pointer;
  align-items: flex-start;
}

.mode-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.mode-item input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.mode-item .mt { font-size: 15px; font-weight: 600; }

.mode-item .mt small {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
}

.mode-item .md {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.5;
}

/* ---------- 设置行 ---------- */
.opt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  min-width: 0;
  max-width: 100%;
}

.opt-label {
  flex: none;
  width: 60px;
  font-size: 13.5px;
  color: var(--text-2);
}

.opt-row .seg { flex: 1 1 0%; min-width: 0; margin-bottom: 0; }

.name-row {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
  display: flex;
  gap: 8px;
}

.mini-input {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 9px;
  font-size: 14px;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
}

.mini-input:focus { border-color: var(--accent); }

/* ---------- 主界面 ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main .content { padding-bottom: 16px; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.seg {
  display: flex;
  background: #EDEDED;
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 10px;
}

body[data-theme="dark"] .seg { background: #232c28; }

.seg-item {
  flex: 1 1 0%;
  min-width: 0;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seg-item.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

/* ---------- 球场 ---------- */
.court {
  position: relative;
  height: 138px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
  align-items: stretch;
  background:
    radial-gradient(120% 120% at 50% 40%, #34a06b 0%, #2c8a5c 70%, #257550 100%);
  box-shadow: inset 0 0 0 2.5px rgba(255, 255, 255, .9), 0 3px 10px rgba(0, 0, 0, .12);
}

.court .side {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.court .vline {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: rgba(255, 255, 255, .5);
}

.court .vline.v1 { left: 14%; }
.court .vline.v2 { right: 14%; }

.court .team-tag {
  position: absolute;
  top: 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
}

.court .team-tag.a { left: 8px; background: rgba(7, 193, 96, .9); }
.court .team-tag.b { right: 8px; background: rgba(255, 149, 0, .95); }

.court .net-v {
  width: 9px;
  background: repeating-linear-gradient(180deg, #ffffff 0 5px, #dfe6e2 5px 8px);
  border-left: 2px solid #fff;
  border-right: 2px solid #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, .28);
  position: relative;
}

.court .net-v::before,
.court .net-v::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 5px;
  background: #f3f3f3;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

.court .net-v::before { top: -2px; }
.court .net-v::after { bottom: -2px; }

.pchip {
  position: relative;
  z-index: 1;
  writing-mode: vertical-rl;
  height: 58px;
  padding: 5px 7px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: #fff;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1;
  letter-spacing: 1px;
}

.pchip.a { border-color: var(--accent); }
.pchip.b { border-color: var(--accent-2); }

.pchip.sel {
  outline: 3px solid #FFE100;
  transform: scale(1.06);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .3);
}

/* ---------- 休息区 ---------- */
.rest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rchip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1.5px dashed var(--border);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  font-weight: 600;
}

.rchip:active { border-color: var(--accent); color: var(--accent); }

.next-line {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2);
}

.next-line b { color: var(--accent); }

/* ---------- 比分录入 ---------- */
.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 10px;
}

.score-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.score-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-name.a { color: var(--accent); }
.score-name.b { color: var(--accent-2); }

.score-input {
  width: 100%;
  max-width: 88px;
  height: 50px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  -moz-appearance: textfield;
}

.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.score-input:focus { border-color: var(--accent); background: var(--surface); }

.score-sep {
  font-size: 22px;
  font-weight: 700;
  color: var(--faint);
  padding-bottom: 12px;
}

/* 比分快捷加减 */
.score-step {
  display: flex;
  gap: 6px;
  margin-top: -4px;
}

.step-btn {
  width: 36px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.step-btn:active { border-color: var(--accent); color: var(--accent); }

.result-row {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.win-btn {
  flex: 1;
  border: none;
  border-radius: 13px;
  padding: 10px 6px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.3;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .12);
}

.win-btn small {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  opacity: .92;
  margin-top: 2px;
}

.win-btn.a { background: var(--accent); }
.win-btn.a:active { background: var(--accent-dark); }
.win-btn.b { background: var(--accent-2); }
.win-btn.b:active { background: var(--accent-2-dark); }

/* ---------- 统计 ---------- */
.stat-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.stat-row:last-child { border-bottom: none; }

.rank {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f2f2f2;
  color: #888;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

body[data-theme="dark"] .rank { background: #2a3430; color: #9aa5a0; }

.rank.top { background: var(--accent); color: #fff; }

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

.s-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  font-size: 10px;
  padding: 1.5px 7px;
  border-radius: 999px;
  font-weight: 600;
  flex: none;
}

.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #F2F2F2; color: #999; }

body[data-theme="dark"] .badge.off { background: #2a3430; color: #8d9a95; }

.s-bar {
  height: 4px;
  background: #f0f0f0;
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

body[data-theme="dark"] .s-bar { background: #2a3430; }

.s-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.s-nums {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  line-height: 1.5;
}

.s-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.tstat {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
}

.tstat.pos { background: var(--accent-soft); color: var(--accent); }
.tstat.neg { background: #FDEBEB; color: var(--danger); }
.tstat.zero { background: var(--surface-2); color: var(--muted); }

body[data-theme="dark"] .tstat.neg { background: #3a1e1e; color: #ff8080; }

/* ---------- 记录 ---------- */
.h-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.h-row:last-child { border-bottom: none; }

.h-no {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  width: 46px;
}

.h-main {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
  min-width: 0;
}

.h-main .vs {
  color: var(--faint);
  font-size: 11px;
  padding: 0 4px;
}

.h-main .ta { color: var(--accent); font-weight: 600; }
.h-main .tb { color: var(--accent-2); font-weight: 600; }

.h-res {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 54px;
}

.h-score {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  padding: 0 2px;
  white-space: nowrap;
}

.h-score .sc-a { color: var(--accent); }
.h-score .sc-b { color: var(--accent-2); }
.h-score.none { color: var(--faint); font-size: 12px; font-weight: 600; }

.h-badge {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.h-badge.a { background: var(--accent-soft); color: var(--accent); }
.h-badge.b { background: var(--accent-2-soft); color: var(--accent-2); }
.h-badge.n { background: #F2F2F2; color: #999; }

body[data-theme="dark"] .h-badge.n { background: #2a3430; color: #8d9a95; }

/* ---------- 搭档明细 ---------- */
.partner-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.partner-row:last-child { border-bottom: none; }

.partner-name { flex: 1; color: var(--text); font-weight: 600; }
.partner-count { color: var(--muted); font-size: 12px; }
.partner-none { color: var(--faint); font-size: 12.5px; padding: 6px 0; }

/* ---------- 提示条 ---------- */
.banner {
  border-radius: 11px;
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.banner.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid rgba(184, 134, 11, .25);
}

.banner.info {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(7, 193, 96, .25);
}

.empty {
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  padding: 30px 0;
}

/* ---------- 应用内弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
}

.modal-box {
  position: relative;
  width: min(340px, 100%);
  background: var(--surface);
  border-radius: 16px;
  padding: 18px 18px 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
  animation: modal-in .18s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.modal-body {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-2);
  white-space: pre-wrap;
  max-height: 46vh;
  overflow-y: auto;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-btn {
  flex: 1;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

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

.modal-input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 11px;
  font-size: 15px;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  text-align: center;
}

.modal-input:focus { border-color: var(--accent); }

.modal-btn.primary:active { background: var(--accent-dark); }
.modal-btn:active { filter: brightness(.96); }

/* ---------- 底部 Tab ---------- */
.tabbar {
  flex: none;
  height: 56px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
}

.tab-item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--muted);
}

.tab-item .ic {
  font-size: 21px;
  line-height: 1;
  filter: grayscale(1);
  opacity: .55;
}

.tab-item .lb { font-size: 10.5px; }

.tab-item.active { color: var(--accent); }
.tab-item.active .ic { filter: none; opacity: 1; }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(8px);
  background: rgba(17, 17, 17, .82);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 9px;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  max-width: 82%;
  text-align: center;
  z-index: 99;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 字号档位 ---------- */
html[data-fontscale="0.9"] { font-size: 90%; }
html[data-fontscale="1"] { font-size: 100%; }
html[data-fontscale="1.25"] { font-size: 125%; }
html[data-fontscale="1.5"] { font-size: 150%; }

/* ---------- 手机浏览器全屏适配 ---------- */
@media (max-width: 480px) {
  .stage { padding: 0; gap: 0; }
  .phone {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .stage-caption { display: none; }
  .mp-bar {
    height: calc(52px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
  }
  .tabbar {
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .content, .main .content {
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
  #toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
