:root {
  --bg: #080b10;
  --panel: #111722;
  --panel-2: #18202d;
  --line: #232d3d;
  --line-strong: #334055;
  --text: #edf2fa;
  --muted: #8592a6;
  --dim: #5b6779;
  --a: #4c8dff;
  --b: #ffb020;
  --ok: #34d399;
  --bad: #f87171;
  --r: 20px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro SC', 'PingFang SC',
    'Helvetica Neue', 'Microsoft YaHei', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- display ---------- */

body.display {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  transition: background-color 0.45s ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 22px 6px;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--dim);
}

.topbar b {
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.conn i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.2s;
}

.conn.online i {
  background: var(--ok);
}

.conn.offline i {
  background: var(--bad);
}

.tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.tool {
  height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.06em;
  transition: background 0.15s, color 0.15s;
}

.tool:active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.board {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 0 12px 10px;
  min-height: 0;
}

.side {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, filter 0.12s ease;
}

.side:active {
  filter: brightness(1.18);
}

.side::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  opacity: 0.55;
  transition: opacity 0.25s ease;
}

.side.a::before {
  background: var(--a);
}

.side.b::before {
  background: var(--b);
}

.side.serving::before {
  opacity: 1;
  height: 4px;
}

.side.a.serving {
  background: rgba(76, 141, 255, 0.09);
  border-color: rgba(76, 141, 255, 0.45);
}

.side.b.serving {
  background: rgba(255, 176, 32, 0.08);
  border-color: rgba(255, 176, 32, 0.42);
}

.side .name {
  font-size: clamp(13px, 2.4vmin, 22px);
  letter-spacing: 0.16em;
  color: var(--muted);
  max-width: 88%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side .score {
  font-size: clamp(104px, 48vmin, 460px);
  line-height: 0.84;
  font-weight: 500;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
  margin: 0.03em 0;
}

.side .serve {
  height: clamp(16px, 3vmin, 28px);
  display: flex;
  align-items: center;
  font-size: clamp(10px, 1.5vmin, 14px);
  letter-spacing: 0.3em;
  color: var(--dim);
  opacity: 0;
  transition: opacity 0.25s;
}

.side.serving .serve {
  opacity: 1;
}

.side.a.serving .serve {
  color: var(--a);
}

.side.b.serving .serve {
  color: var(--b);
}

.side .sets {
  display: flex;
  gap: 7px;
  margin-top: 6px;
  height: 9px;
}

.side .sets i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
}

.side.a .sets i.on {
  background: var(--a);
  border-color: var(--a);
}

.side.b .sets i.on {
  background: var(--b);
  border-color: var(--b);
}

.side .minus {
  position: absolute;
  bottom: 10px;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-strong);
  transition: transform 0.1s ease, background 0.15s ease, color 0.15s ease;
  z-index: 2;
}

.side.a .minus {
  left: 12px;
}

.side.b .minus {
  right: 12px;
}

.side .minus:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

/* 关键时刻：局点暗红，赛点亮红 */
body.display.game-point {
  --mp-bg: #7d1a20;
}

body.display.match-point {
  --mp-bg: #b8222a;
}

body.display.game-point,
body.display.match-point {
  background-color: var(--mp-bg);
}

body.display.game-point .topbar,
body.display.match-point .topbar {
  color: rgba(255, 255, 255, 0.7);
}

body.display.game-point .topbar b,
body.display.match-point .topbar b {
  color: #fff;
}

body.display.game-point .side,
body.display.game-point .side.serving,
body.display.match-point .side,
body.display.match-point .side.serving {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.24);
}

body.display.game-point .side.serving,
body.display.match-point .side.serving {
  border-color: rgba(255, 255, 255, 0.7);
}

body.display.game-point .side::before,
body.display.match-point .side::before {
  background: rgba(255, 255, 255, 0.85);
  opacity: 1;
}

body.display.game-point .name,
body.display.game-point .serve,
body.display.match-point .name,
body.display.match-point .serve {
  color: rgba(255, 255, 255, 0.86);
}

body.display.game-point .sets i,
body.display.match-point .sets i {
  border-color: rgba(255, 255, 255, 0.45);
}

body.display.game-point .sets i.on,
body.display.match-point .sets i.on {
  background: #fff;
  border-color: #fff;
}

body.display.game-point .minus,
body.display.game-point .tool,
body.display.match-point .minus,
body.display.match-point .tool {
  background: rgba(0, 0, 0, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.86);
}

body.display.game-point .conn i,
body.display.match-point .conn i {
  background: #fff;
}

body.display.game-point .hint,
body.display.match-point .hint {
  color: #fff;
  opacity: 1;
  letter-spacing: 0.3em;
}

body.display.match-point .hint {
  font-size: clamp(13px, 2.1vmin, 19px);
  font-weight: 500;
}

.hint {
  padding: 0 22px 10px;
  text-align: center;
  font-size: clamp(11px, 1.6vmin, 15px);
  letter-spacing: 0.12em;
  color: var(--dim);
  min-height: 22px;
}

.hint.hot {
  color: var(--text);
}

@keyframes bump {
  0% {
    transform: scale(1);
  }
  38% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.side.bump .score {
  animation: bump 0.34s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .side.bump .score {
    animation: none;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.overlay .ov-kicker {
  font-size: clamp(11px, 1.6vmin, 15px);
  letter-spacing: 0.4em;
  color: var(--dim);
}

.overlay .ov-title {
  font-size: clamp(38px, 9vmin, 96px);
  font-weight: 500;
  letter-spacing: -0.02em;
}

.overlay .ov-sub {
  font-size: clamp(13px, 2vmin, 20px);
  color: var(--muted);
  letter-spacing: 0.08em;
}

.ov-btn {
  margin-top: 18px;
  min-width: 200px;
  height: 56px;
  padding: 0 34px;
  border-radius: 16px;
  background: rgba(76, 141, 255, 0.18);
  border: 1px solid rgba(76, 141, 255, 0.5);
  color: var(--text);
  font-size: 17px;
  letter-spacing: 0.08em;
}

.ov-btn:active {
  transform: scale(0.97);
}

.ov-link {
  margin-top: 4px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--dim);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.hint.action {
  color: var(--text);
  cursor: pointer;
}

/* ---------- control ---------- */

body.control {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.chead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.1em;
}

.chead-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chead b {
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.18em;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 14px;
  gap: 10px;
}

.hud-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hud-side.b {
  align-items: flex-end;
  text-align: right;
}

.hud-score {
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.hud-side.a .hud-score {
  color: var(--a);
}

.hud-side.b .hud-score {
  color: var(--b);
}

.hud-name {
  font-size: 12px;
  color: var(--muted);
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-mid {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.12em;
  line-height: 1.7;
}

.hud-mid .hot {
  color: var(--text);
}

.pads {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 10px;
  min-height: 0;
}

.pad-wrap {
  position: relative;
  display: flex;
  min-height: 0;
}

.pad-wrap .pad {
  flex: 1;
}

.pad-minus {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-strong);
  z-index: 2;
  transition: transform 0.1s ease, background 0.15s ease, color 0.15s ease;
}

.pad-minus:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.pad {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform 0.09s ease, background 0.12s ease, border-color 0.12s ease;
}

.pad::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 22px 22px 0 0;
  opacity: 0.6;
}

.pad-a::after {
  background: var(--a);
}

.pad-b::after {
  background: var(--b);
}

.pad em {
  font-style: normal;
  font-size: clamp(40px, 11vmin, 76px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
}

.pad span {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.1em;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pad:active {
  transform: scale(0.975);
}

.pad-a:active {
  background: rgba(76, 141, 255, 0.16);
  border-color: rgba(76, 141, 255, 0.5);
}

.pad-b:active {
  background: rgba(255, 176, 32, 0.14);
  border-color: rgba(255, 176, 32, 0.48);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 12px 14px;
}

.actions button {
  height: 56px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 15px;
  letter-spacing: 0.06em;
  transition: transform 0.09s ease, background 0.12s ease;
}

.actions button:active {
  transform: scale(0.97);
  background: #1f2836;
}

.actions button:disabled {
  opacity: 0.32;
}

.actions button.primary {
  background: rgba(76, 141, 255, 0.16);
  border-color: rgba(76, 141, 255, 0.4);
}

.actions button.warn {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.42);
  color: #ffd9d9;
}

.banner {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #1f2836;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 88vw;
  text-align: center;
  z-index: 25;
  transition: opacity 0.5s;
}

.banner[hidden] {
  display: none;
}

.banner.fade {
  opacity: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1f2836;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 30;
}

.toast.show {
  opacity: 1;
}

/* ---------- index ---------- */

body.home {
  overflow-y: auto;
  display: block;
}

.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: 32px 20px calc(40px + env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
}

.brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(76, 141, 255, 0.14);
  border: 1px solid rgba(76, 141, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--a);
}

.brand h1 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--dim);
}

.addr-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  margin-bottom: 22px;
  border-radius: 16px;
  background: rgba(76, 141, 255, 0.1);
  border: 1px solid rgba(76, 141, 255, 0.32);
}

.addr-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.addr-value {
  font-size: 18px;
  color: var(--a);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  letter-spacing: -0.01em;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.field input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  font-family: inherit;
}

.field input:focus {
  border-color: rgba(76, 141, 255, 0.55);
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}

.seg button {
  height: 46px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.seg button.on {
  background: rgba(76, 141, 255, 0.14);
  border-color: rgba(76, 141, 255, 0.5);
  color: var(--text);
}

.go {
  width: 100%;
  height: 54px;
  border-radius: 16px;
  background: var(--a);
  color: #06101f;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.go:active {
  opacity: 0.9;
}

.result {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  padding: 22px;
  margin-top: 18px;
}

.result[hidden] {
  display: none;
}

.code {
  font-size: 44px;
  font-weight: 500;
  letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 6px 0 4px;
}

.share-url {
  font-size: 19px;
  line-height: 1.5;
  text-align: center;
  color: var(--a);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  word-break: break-all;
  margin: 8px 0 14px;
  letter-spacing: -0.01em;
}

.copy-btn {
  display: block;
  width: 100%;
  height: 44px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}

.code-label {
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.2em;
}

.links {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 15px;
}

.links a.primary {
  background: rgba(76, 141, 255, 0.16);
  border-color: rgba(76, 141, 255, 0.42);
}

.links a i {
  font-style: normal;
  font-size: 12px;
  color: var(--dim);
}

.tip {
  margin-top: 18px;
  font-size: 12px;
  line-height: 1.8;
  color: var(--dim);
}
