:root {
  --felt-1: #15875f;
  --felt-2: #0b5a42;
  --felt-3: #07412f;
  --felt: #0d6b4f;
  --felt-press: #0a573f;

  --bg: #eef2ef;
  --card: #ffffff;
  --text: #16201b;
  --muted: #6a7a72;
  --line: #e3e9e5;
  --field: #f3f6f4;

  /* 两位选手的系列色（已用 dataviz 校验器检查：亮度带、色觉障碍区分度、对比度） */
  --a: #2563eb;
  --a-soft: #e8efff;
  --b: #dc3545;
  --b-soft: #fdecee;

  --warn: #b45309;
  --danger: #d92d20;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 6px 20px rgba(16, 40, 30, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --felt-1: #116b4c;
    --felt-2: #0a4a37;
    --felt-3: #063326;
    --felt: #14805e;
    --felt-press: #106b4e;

    --bg: #0c1210;
    --card: #151d19;
    --text: #e6eee9;
    --muted: #8c9c94;
    --line: #24302a;
    --field: #1c2621;

    --a: #5b8ef7;
    --a-soft: #1a2846;
    --b: #e8525f;
    --b-soft: #3a1d22;

    --warn: #f5b041;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- 顶部球台区 ---------- */
.hero {
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255, 255, 255, .14), transparent 60%),
    linear-gradient(180deg, var(--felt-1), var(--felt-2) 65%, var(--felt-3));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 64px;
}
.hero > * { max-width: 560px; margin-left: auto; margin-right: auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; letter-spacing: .5px; }
.brand-ball { width: 28px; height: 28px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .3)); }

.top-actions { display: flex; align-items: center; gap: 2px; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .16); color: rgba(255, 255, 255, .9); font-size: 12px; white-space: nowrap;
}
.sync-pill:active { background: rgba(0, 0, 0, .28); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: #6ee7b7; flex: none; }
.sync-pill[data-status="busy"] .sync-dot { background: #fde68a; animation: pulse 1s ease-in-out infinite; }
.sync-pill[data-status="offline"] .sync-dot { background: #fca5a5; }
@keyframes pulse { 50% { opacity: .3; } }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.ghost:active, .icon-btn.swap:active { background: rgba(255, 255, 255, .16); }

.names {
  margin-top: 14px;
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;
}
.name-field {
  display: flex; align-items: center; gap: 10px;
  height: 50px; padding: 0 14px;
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 14px;
  min-width: 0;
  transition: background .15s, border-color .15s;
}
.name-field:focus-within { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .5); }
.name-field input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; outline: none;
  color: #fff; font-size: 17px; font-weight: 600;
}
.name-field input::-webkit-calendar-picker-indicator { display: none !important; }
.name-field.b input { text-align: right; }
.name-field input::placeholder { color: rgba(255, 255, 255, .55); font-weight: 500; }
.swap { color: #fff; background: rgba(255, 255, 255, .1); }

.ball {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  box-shadow: inset -3px -3px 5px rgba(0, 0, 0, .28), 0 1px 2px rgba(0, 0, 0, .3);
}
.ball.a { background: radial-gradient(circle at 35% 30%, #8fb3ff, #2563eb 55%, #1742a8); }
.ball.b { background: radial-gradient(circle at 35% 30%, #ff9aa4, #dc3545 55%, #9e1f2c); }

.pairs {
  margin-top: 12px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding-bottom: 2px;
}
.pairs::-webkit-scrollbar { display: none; }
.pairs:empty { display: none; }
.pair-chip {
  flex: none; white-space: nowrap;
  font-size: 13px; color: rgba(255, 255, 255, .92);
  padding: 6px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, .16);
  border: 1px solid rgba(255, 255, 255, .14);
}
.pair-chip:active { background: rgba(0, 0, 0, .28); }
.pair-chip .n { opacity: .65; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* ---------- 主体 ---------- */
main {
  max-width: 592px; margin: -44px auto 0; padding: 0 16px 28px;
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
}

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2, .card-title { margin: 0; font-size: 17px; font-weight: 700; }
.card-title { margin-bottom: 14px; }

/* ---------- 录入 ---------- */
.entry-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.entry-title h2 { margin: 0; font-size: 17px; font-weight: 700; }

.score-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
}
.side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.side-name {
  text-align: center; font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side.a .side-name { color: var(--a); }
.side.b .side-name { color: var(--b); }
.score {
  width: 100%; height: 88px;
  text-align: center; font-size: 52px; font-weight: 700; line-height: 1;
  border: 2px solid transparent; border-radius: 16px; outline: none;
  caret-color: currentColor;
  transition: border-color .15s;
}
.score::placeholder { color: currentColor; opacity: .3; }
.side.a .score { background: var(--a-soft); color: var(--a); }
.side.b .score { background: var(--b-soft); color: var(--b); }
.side.a .score:focus { border-color: var(--a); }
.side.b .score:focus { border-color: var(--b); }
.score.bump { animation: bump .18s ease-out; }
@keyframes bump { 50% { transform: scale(1.06); } }

.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.steppers button {
  height: 44px; border-radius: 12px; font-size: 24px; font-weight: 500; line-height: 1;
  background: var(--field); color: var(--text);
  user-select: none; -webkit-user-select: none;
}
.steppers button:active { filter: brightness(.92); }
.side.a .steppers button[data-delta="1"] { background: var(--a); color: #fff; }
.side.b .steppers button[data-delta="1"] { background: var(--b); color: #fff; }
.colon { font-size: 40px; font-weight: 700; color: var(--muted); padding-top: 10px; }

.delta-line { margin-top: 12px; font-size: 14px; min-height: 21px; }
.delta-line:empty { display: none; }
.delta-main { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.delta-now b { font-size: 16px; }
.warn-text { color: var(--warn); font-size: 13px; margin-top: 6px; }

.time-row {
  margin-top: 16px;
  display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap;
}
.seg {
  display: inline-flex; padding: 3px; border-radius: 12px; background: var(--field);
}
.seg button {
  height: 34px; padding: 0 12px; border-radius: 9px; font-size: 14px; color: var(--muted);
  transition: background .15s, color .15s;
}
.seg button[aria-checked="true"] { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.small-seg button { height: 30px; padding: 0 10px; font-size: 13px; }
.now-text { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.now-text b { color: var(--text); font-weight: 600; }
.time-input, .field input {
  height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--field); outline: none;
  font-variant-numeric: tabular-nums;
}
.time-input { flex: 1; min-width: 190px; }
.time-input:focus, .field input:focus { border-color: var(--felt); }

.primary {
  margin-top: 16px; width: 100%; height: 52px; border-radius: 14px;
  background: var(--felt); color: #fff; font-size: 17px; font-weight: 600; letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(13, 107, 79, .28);
  transition: background .15s, transform .05s;
}
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.primary .lock { width: 17px; height: 17px; fill: currentColor; opacity: .85; flex: none; }
.primary:active { background: var(--felt-press); transform: translateY(1px); }
.primary.warn { background: var(--warn); box-shadow: none; letter-spacing: 0; }
.primary.compact { margin-top: 0; width: auto; height: 42px; padding: 0 22px; font-size: 15px; letter-spacing: 0; box-shadow: none; }
.secondary { height: 42px; padding: 0 18px; border-radius: 12px; background: var(--field); font-weight: 500; }

/* ---------- 统计范围 ---------- */
.filter-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 2px 0;
}
.range { display: inline-flex; gap: 6px; }
.range button {
  height: 32px; padding: 0 13px; border-radius: 999px; font-size: 13px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line);
}
.range button[aria-checked="true"] { background: var(--text); border-color: var(--text); color: var(--card); font-weight: 600; }

/* ---------- 战绩统计 ---------- */
.key { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.key.a { background: var(--a); }
.key.b { background: var(--b); }

.score-hero { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.score-hero .p { min-width: 0; }
.score-hero .p.b { text-align: right; }
.p-name { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.p-name span:not(.key) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p.b .p-name { justify-content: flex-end; }
.p-val { font-size: 48px; font-weight: 800; line-height: 1.08; letter-spacing: -.5px; }
.mid { text-align: center; padding-bottom: 8px; }
.mid-label { font-size: 12px; color: var(--muted); }
.lead-text { font-size: 13px; font-weight: 600; white-space: nowrap; }

.bar {
  margin-top: 12px; height: 8px; border-radius: 999px; overflow: hidden;
  display: flex; background: var(--field); gap: 2px;
}
.bar span { height: 100%; border-radius: 999px; transition: width .3s; }
.bar .ba { background: var(--a); }
.bar .bb { background: var(--b); }
.bar-legend { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.power { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.power-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.power-head h3 { margin: 0; font-size: 15px; }
.power-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  margin-top: 8px; padding: 10px 14px; border-radius: 12px; background: var(--field);
}
.power-text { font-size: 14px; color: var(--muted); min-width: 0; line-height: 1.4; }
.power-text b { color: var(--text); font-weight: 600; }
.power-val { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }

.metrics {
  margin-top: 16px; display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line); padding-top: 14px;
}
.metrics > div { text-align: center; min-width: 0; }
.metrics > div + div { border-left: 1px solid var(--line); }
.metrics b { display: block; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 0 4px; line-height: 1.3; }
.metrics span { font-size: 12px; color: var(--muted); }

.empty {
  text-align: center; color: var(--muted); padding: 22px 8px; font-size: 14px;
}
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }

/* ---------- 走势图 ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text); }
.legend:empty { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.line-key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.line-key.a { background: var(--a); }
.line-key.b { background: var(--b); }

.chart-wrap { position: relative; margin-top: 8px; touch-action: pan-y; outline: none; border-radius: 8px; }
.chart-wrap:focus-visible { outline: 2px solid var(--a); outline-offset: 4px; }
.chart { display: block; overflow: visible; user-select: none; -webkit-user-select: none; }
.chart .grid line { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.chart .grid line.ref { stroke: var(--muted); opacity: .55; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.a { stroke: var(--a); }
.chart .line.b { stroke: var(--b); }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .dot.a { fill: var(--a); }
.chart .dot.b { fill: var(--b); }
.chart .end-label { fill: var(--text); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--muted); stroke-width: 1; opacity: .7; }

.chart-tip {
  position: absolute; top: 2px; left: 0; z-index: 2; pointer-events: none;
  min-width: 128px; padding: 8px 10px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
  font-size: 12px;
}
.tip-time { color: var(--muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; line-height: 1.6; }
.tip-row strong { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 11em; }
.tip-foot { color: var(--muted); margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.chart-note { margin: 8px 0 0; }

/* ---------- 历史 ---------- */
.hist-cols, .rec { display: grid; grid-template-columns: 52px 1fr auto 14px; align-items: center; gap: 8px; }
.hist-cols { font-size: 12px; color: var(--muted); padding: 0 12px 8px; }
.hist-cols span:nth-child(3) { grid-column: 3 / 5; }
.day + .day { margin-top: 14px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--muted); padding: 0 2px 6px;
}
.day-head .tally { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.day-list { border-radius: 14px; background: var(--field); overflow: hidden; }

.rec { width: 100%; padding: 12px 12px; text-align: left; min-height: 52px; }
.rec + .rec { border-top: 1px solid var(--line); }
.rec:active { background: rgba(0, 0, 0, .04); }
.rec-time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.rec-score { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-score i { font-style: normal; color: var(--muted); font-weight: 500; margin: 0 6px; }
.rec-tag {
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--card); color: var(--muted); font-variant-numeric: tabular-nums;
}
.rec-tag.neg { color: var(--warn); }
.rec-chev { width: 14px; height: 14px; color: var(--muted); opacity: .6; }
.rec.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { background: rgba(13, 107, 79, .16); } 100% { background: transparent; } }

.more-btn {
  margin-top: 12px; width: 100%; height: 40px; border-radius: 12px;
  color: var(--felt); font-weight: 600; background: var(--field);
}

.foot { text-align: center; margin: 4px 0 0; }

/* ---------- 底部弹层 ---------- */
.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--card);
  width: 100%; max-width: 560px;
  margin: auto auto 0; border-radius: 22px 22px 0 0;
  max-height: 90vh;
}
.sheet[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.sheet::backdrop { background: rgba(5, 15, 10, .45); }
.sheet form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 22px; }
  .sheet form { padding-bottom: 18px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-head .icon-btn svg { fill: none; }
.sheet-head .icon-btn:active { background: var(--field); }

.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.field input { color: var(--text); font-size: 16px; width: 100%; height: 44px; }
.field.wide { grid-column: 1 / -1; }

.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 18px; }
.spacer { flex: 1; }
.danger-text { color: var(--danger); font-weight: 600; height: 42px; padding: 0 6px; }

.menu-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.menu-item {
  text-align: left; padding: 14px 14px; border-radius: 14px; background: var(--field);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-item strong { font-size: 15px; }
.menu-item span { font-size: 13px; color: var(--muted); }
.menu-item.danger strong { color: var(--danger); }
.menu-item:active { filter: brightness(.96); }

/* ---------- 密码框 ---------- */
.pwd-sheet { margin: 14vh auto auto; width: calc(100% - 32px); max-width: 380px; border-radius: 22px; }
.pwd-sheet form { padding: 22px 20px 18px; text-align: center; }
.pwd-icon {
  width: 48px; height: 48px; margin: 0 auto 10px; border-radius: 50%;
  display: grid; place-items: center; background: var(--field); color: var(--felt);
}
.pwd-icon svg { width: 24px; height: 24px; fill: currentColor; }
.pwd-sheet h3 { margin: 0; font-size: 18px; }
.pwd-action { margin: 6px 0 14px; line-height: 1.5; word-break: break-all; }
.pwd-input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--field); outline: none;
  font-size: 20px; letter-spacing: 3px; text-align: center; color: var(--text);
}
.pwd-input:focus { border-color: var(--felt); }
.pwd-input.shake { animation: shake .3s; border-color: var(--danger); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.pwd-error { min-height: 20px; margin: 6px 0 0; font-size: 13px; color: var(--danger); }
.pwd-sheet .sheet-actions { margin-top: 8px; }
.grow { flex: 1; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px); width: max-content;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; border-radius: 14px;
  background: #1d2622; color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  z-index: 10;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }
.toast button { color: #6ee7b7; font-weight: 700; flex: none; }

@media (max-width: 360px) {
  .score { font-size: 42px; height: 76px; }
  .range button { padding: 0 9px; }
  .p-val { font-size: 40px; }
  .power-val { font-size: 20px; }
  .metrics b { font-size: 14px; }
}
