:root {
  --bg: #f6f4ee;
  --bg-elevated: #ffffff;
  --bg-muted: #eeebe2;
  --bg-input: #faf9f5;
  --border: rgba(31, 36, 33, 0.09);
  --border-strong: rgba(31, 36, 33, 0.18);
  --text: #1c211e;
  --text-secondary: #626b65;
  --text-muted: #8a928c;

  --accent: #245c44;
  --accent-hover: #1b4734;
  --accent-soft: rgba(36, 92, 68, 0.1);

  --pos: #1f6f4a;
  --pos-soft: rgba(31, 111, 74, 0.1);
  --neg: #b83a3a;
  --neg-soft: rgba(184, 58, 58, 0.1);
  --warn: #b36b12;
  --warn-soft: rgba(179, 107, 18, 0.12);

  --p0: #245c44;
  --p1: #2b59a8;
  --p2: #c27816;
  --p3: #b83a3a;

  --shadow-sm: 0 1px 2px rgba(20, 24, 21, 0.04), 0 4px 12px rgba(20, 24, 21, 0.03);
  --shadow-md: 0 8px 28px rgba(20, 24, 21, 0.08);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;

  --font-sans: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #131614;
  --bg-elevated: #1b201d;
  --bg-muted: #232925;
  --bg-input: #161a17;
  --border: rgba(236, 232, 222, 0.09);
  --border-strong: rgba(236, 232, 222, 0.2);
  --text: #ece8de;
  --text-secondary: #a2aba4;
  --text-muted: #707972;

  --accent: #4c9a78;
  --accent-hover: #5ab08a;
  --accent-soft: rgba(76, 154, 120, 0.16);

  --pos: #52b788;
  --pos-soft: rgba(82, 183, 136, 0.14);
  --neg: #e06c6c;
  --neg-soft: rgba(224, 108, 108, 0.15);
  --warn: #e39c3b;
  --warn-soft: rgba(227, 156, 59, 0.16);

  --p0: #52b788;
  --p1: #6b9bff;
  --p2: #e3a03b;
  --p3: #e06c6c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 6px 16px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.num,
.pt-value,
input[type="number"],
.score-raw-val {
  font-variant-numeric: tabular-nums;
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-seal {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.title-row h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.session-title-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  width: 140px;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.session-title-input:hover {
  border-color: var(--border);
  background: var(--bg-elevated);
}

.session-title-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elevated);
  color: var(--text);
}

.rule-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-secondary);
  text-align: left;
}

.rule-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.rule-edit-hint {
  color: var(--accent);
  font-weight: 500;
  opacity: 0.85;
}

.rule-badge:hover .rule-edit-hint {
  text-decoration: underline;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  height: 38px;
  padding: 0 18px;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-0.5px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-muted);
}

.btn-subtle {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.btn-subtle:hover:not(:disabled) {
  color: var(--text);
  background: var(--border);
}

.btn-icon {
  width: 34px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost-danger {
  background: transparent;
  color: var(--text-muted);
  padding: 0 10px;
}

.btn-ghost-danger:hover {
  color: var(--neg);
  background: var(--neg-soft);
}

/* Cards */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Standings Grid */
.standings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.player-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 15px 16px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.player-card.is-leader {
  border-color: rgba(36, 92, 68, 0.35);
}

.player-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--player-color, var(--accent));
  opacity: 0.85;
}

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

.player-identity {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--player-color);
  flex-shrink: 0;
}

.player-name-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: -6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s, background-color 0.15s;
}

.player-name-input:hover {
  border-color: var(--border);
}

.player-name-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input);
}

.standing-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.standing-pill.rank-1 {
  background: var(--pos-soft);
  color: var(--pos);
}

.standing-pill.rank-4 {
  background: var(--neg-soft);
  color: var(--neg);
}

.player-pt-main {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 10px;
}

.pt-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.pt-value.pos { color: var(--pos); }
.pt-value.neg { color: var(--neg); }
.pt-value.zero { color: var(--text-secondary); }

.pt-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.player-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.player-meta-row strong {
  color: var(--text);
  font-weight: 600;
}

/* Score Entry Panel */
.entry-header {
  align-items: center;
}

.entry-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sum-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.sum-badge.neutral {
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.sum-badge.valid {
  background: var(--pos-soft);
  color: var(--pos);
}

.sum-badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.entry-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.score-inputs-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.score-field-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.score-field-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.score-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.score-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
}

.score-field-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-group {
  display: inline-flex;
  gap: 1px;
  padding: 2px;
  border-radius: 7px;
  background: var(--bg-muted);
  flex-shrink: 0;
}

.seat-chip {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.seat-chip:hover {
  color: var(--text);
  background: var(--border);
}

.seat-chip.is-active {
  background: var(--bg-elevated);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(20, 24, 21, 0.12);
}

.score-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  padding: 2px 0;
  outline: none;
}

.score-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 15px;
}

/* Remove number spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

.score-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.preview-pt {
  font-weight: 600;
}

.preview-pt.pos { color: var(--pos); }
.preview-pt.neg { color: var(--neg); }

.entry-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.note-field-wrap {
  flex: 1;
  min-width: 220px;
}

.note-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.note-input:focus {
  outline: none;
  border-color: var(--accent);
}

.submit-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Analytics Layout */
.analytics-layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-line {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 210px;
}

.chart-empty {
  height: 190px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.chart-svg {
  width: 100%;
  height: 230px;
  display: block;
  overflow: visible;
}

.chart-tooltip {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 4;
  min-width: 150px;
}

.chart-tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.chart-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}

/* History Table */
.count-pill {
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-btn {
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.history-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table tbody tr:hover {
  background: var(--bg-input);
}

.game-index-cell {
  white-space: nowrap;
  color: var(--text-secondary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.game-time {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.score-cell {
  white-space: nowrap;
}

.score-cell-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rank-tag {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.rank-tag.r1 { background: var(--pos-soft); color: var(--pos); }
.rank-tag.r4 { background: var(--neg-soft); color: var(--neg); }

.cell-pt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cell-pt.pos { color: var(--pos); }
.cell-pt.neg { color: var(--neg); }

.cell-raw {
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.note-cell {
  max-width: 180px;
  color: var(--text-secondary);
  font-size: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}

.empty-history {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 16, 0.45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input,
.form-field select {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.uma-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.uma-grid input {
  text-align: center;
}

.edit-scores-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  box-shadow: var(--shadow-md);
}

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

/* Responsive */
@media (max-width: 860px) {
  .standings-grid,
  .score-inputs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 16px 12px 36px;
  }

  .standings-grid,
  .score-inputs-grid,
  .form-row-2,
  .edit-scores-grid {
    grid-template-columns: 1fr;
  }

  .entry-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .submit-group {
    justify-content: flex-end;
  }
}

/* ==================================================================
   Refined layer — 视觉打磨
   在上方基础样式之上叠加：图表变量、微交互、趋势缩略图、粘性表头等
   ================================================================== */

:root {
  --chart-grid: rgba(31, 36, 33, 0.07);
  --chart-axis: rgba(31, 36, 33, 0.28);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-lg: 0 22px 60px rgba(20, 24, 21, 0.16);
  --wash-1: rgba(36, 92, 68, 0.07);
  --wash-2: rgba(194, 120, 22, 0.05);
}

[data-theme="dark"] {
  --chart-grid: rgba(236, 232, 222, 0.075);
  --chart-axis: rgba(236, 232, 222, 0.26);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.6);
  --wash-1: rgba(76, 154, 120, 0.11);
  --wash-2: rgba(227, 156, 59, 0.045);
}

/* ---------- 页面底色：极轻的双色晕染，纸感 ---------- */
body {
  background-image:
    radial-gradient(1000px 520px at 12% -8%, var(--wash-1), transparent 70%),
    radial-gradient(900px 480px at 92% -6%, var(--wash-2), transparent 68%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  background-clip: content-box;
}

/* ---------- 品牌印记 ---------- */
.brand-seal {
  background-image: radial-gradient(circle at 32% 26%, var(--accent-soft), transparent 68%);
  transition: transform 0.45s var(--ease-out), border-color 0.2s ease;
}

.brand-seal:hover {
  transform: rotate(-6deg);
  border-color: var(--border-strong);
}

.title-row h1 {
  letter-spacing: -0.025em;
}

.session-title-input::placeholder {
  color: var(--text-muted);
}

/* ---------- 按钮 ---------- */
.btn {
  transition: background-color 0.16s var(--ease-out), color 0.16s var(--ease-out),
    border-color 0.16s var(--ease-out), box-shadow 0.16s var(--ease-out),
    transform 0.16s var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.994);
}

.btn-primary {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0));
  box-shadow: 0 1px 2px rgba(20, 24, 21, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 8px 20px rgba(36, 92, 68, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn:focus-visible,
.seat-chip:focus-visible,
.rule-badge:focus-visible,
.toggle-chip input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-row {
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
  border-radius: 7px;
}

/* ---------- 卡片与积分榜 ---------- */
.player-card {
  transition: transform 0.22s var(--ease-out), box-shadow 0.22s var(--ease-out),
    border-color 0.22s var(--ease-out);
}

.player-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.player-card::before {
  height: 2.5px;
  background: linear-gradient(90deg, var(--player-color, var(--accent)), transparent 130%);
  opacity: 0.95;
}

.player-card.is-leader {
  box-shadow: 0 0 0 1px rgba(36, 92, 68, 0.16), var(--shadow-sm);
}

.player-card.is-leader::after {
  content: "";
  position: absolute;
  top: -46px;
  right: -30px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 68%);
  pointer-events: none;
}

.player-pt-main {
  gap: 3px;
}

.pt-value {
  font-feature-settings: "tnum" 1;
  font-size: 27px;
}

.standing-pill {
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* 上一局增减 */
.delta-chip {
  margin-left: auto;
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 3.5px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta-chip.pos {
  color: var(--pos);
  background: var(--pos-soft);
}

.delta-chip.neg {
  color: var(--neg);
  background: var(--neg-soft);
}

.delta-chip.zero {
  color: var(--text-muted);
  background: var(--bg-muted);
}

/* 趋势缩略图 */
.player-spark {
  margin: 8px 0 10px;
  height: 30px;
}

.spark-svg {
  width: 100%;
  height: 30px;
  display: block;
  overflow: visible;
}

.player-meta-row {
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- 点数录入 ---------- */
.score-field-card {
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.score-field-card:hover {
  border-color: var(--border-strong);
}

.score-input {
  font-feature-settings: "tnum" 1;
}

.rank-tag:empty {
  background: transparent;
}

/* 空状态下预览行不占位：录入卡更紧凑（浏览器支持 :has 时生效） */
.score-field-card:not(:has(.preview-pt:not(:empty))) .score-preview-row {
  display: none;
}

.sum-badge {
  transition: background-color 0.2s ease, color 0.2s ease;
}

.toggle-chip {
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.toggle-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

/* ---------- 走势图 ---------- */
.chart-wrap {
  min-height: 244px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-empty {
  height: 200px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: linear-gradient(180deg, var(--bg-input), transparent 78%);
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.chart-empty svg {
  opacity: 0.9;
  margin-bottom: 4px;
}

.chart-empty > span {
  font-size: 13px;
  color: var(--text-secondary);
}

.chart-empty .chart-empty-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.chart-tooltip {
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
  min-width: 148px;
  animation: tip-in 0.14s var(--ease-out);
}

@keyframes tip-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chart-tooltip-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.chart-tooltip-note {
  font-size: 11px;
  color: var(--text-muted);
  margin: -3px 0 6px;
  max-width: 168px;
  line-height: 1.35;
}

.chart-tooltip-row {
  align-items: center;
  padding: 1px 0;
  font-size: 12px;
}

.chart-tooltip-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-tooltip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-tooltip-row .pos {
  color: var(--pos);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-row .neg {
  color: var(--neg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-row .zero {
  color: var(--text-muted);
  font-weight: 600;
}

.chart-series {
  transition: opacity 0.18s ease;
}

/* ---------- 对局记录 ---------- */
.th-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.history-table thead th[data-player-index] {
  color: var(--text);
}

.th-actions {
  text-align: right;
}

.table-scroll {
  max-height: 464px;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius-sm);
}

.history-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elevated);
  border-bottom: none;
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

.history-table tbody tr {
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.history-table tbody tr:hover .game-index-cell {
  color: var(--accent);
}

.note-cell {
  line-height: 1.4;
}

.note-empty {
  color: var(--text-muted);
}

.empty-history {
  padding: 40px 16px;
  line-height: 1.7;
}

.empty-history span {
  font-size: 12px;
  opacity: 0.85;
}

/* ---------- 弹窗 ---------- */
.modal-backdrop:not([hidden]) {
  animation: backdrop-in 0.18s var(--ease-out);
}

.modal-dialog {
  animation: dialog-in 0.24s var(--ease-out);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  flex-shrink: 0;
}

.modal-body {
  overflow-y: auto;
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.uma-grid input {
  font-feature-settings: "tnum" 1;
}

/* ---------- 窄屏微调 ---------- */
@media (max-width: 860px) {
  .player-card.is-leader::after {
    display: none;
  }

  .table-scroll {
    max-height: none;
  }

  .history-table thead th {
    position: static;
    box-shadow: none;
    border-bottom: 1px solid var(--border-strong);
  }
}

/* 窄屏下把对局表折叠成卡片：局号 + 操作在首行，四家点数两列排布 */
@media (max-width: 768px) {
  .table-scroll {
    overflow: visible;
  }

  .history-table {
    display: block;
    border-collapse: separate;
  }

  .history-table thead {
    display: none;
  }

  .history-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .history-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    align-items: start;
  }

  .history-table tbody tr:hover {
    background: var(--bg-muted);
  }

  .history-table td {
    padding: 0;
    border: none;
    vertical-align: top;
  }

  .history-table tr > td:nth-child(1) {
    grid-area: 1 / 1;
  }

  .history-table tr > td:nth-child(2) {
    grid-area: 2 / 1;
  }

  .history-table tr > td:nth-child(3) {
    grid-area: 2 / 2;
  }

  .history-table tr > td:nth-child(4) {
    grid-area: 3 / 1;
  }

  .history-table tr > td:nth-child(5) {
    grid-area: 3 / 2;
  }

  .history-table tr > td:nth-child(6) {
    grid-area: 4 / 1 / 5 / 3;
  }

  .history-table tr > td:nth-child(7) {
    grid-area: 1 / 2;
    justify-self: end;
  }

  .history-table .score-cell::before {
    content: attr(data-player);
    display: block;
    margin-bottom: 3px;
    font-size: 11px;
    color: var(--text-muted);
  }

  .history-table .note-cell {
    max-width: none;
    padding-top: 9px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
  }

  .history-table .note-cell::before {
    content: "备注";
    display: block;
    margin-bottom: 2px;
    font-size: 11px;
    color: var(--text-muted);
  }

  .game-index-cell {
    font-size: 14px;
    line-height: 1.5;
  }

  .game-time {
    display: inline;
    margin-left: 8px;
    font-size: 11px;
  }

  .row-actions {
    gap: 6px;
  }
}

@media (max-width: 520px) {
  .player-spark {
    height: 26px;
  }

  .spark-svg {
    height: 26px;
  }

  .pt-value {
    font-size: 24px;
  }
}

/* ---------- 玩家卡徽标 / 大胡 / 昵称档案 ---------- */
.player-card-tags {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.bighand-count {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  white-space: nowrap;
}

/* 昵称档案命中时，卡片底部的履历行 */
.player-profile-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 9px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-muted);
  font-family: inherit;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.player-profile-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.profile-badge {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.profile-line {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.profile-line strong {
  font-weight: 700;
}

.profile-line .pos {
  color: var(--pos);
}

.profile-line .neg {
  color: var(--neg);
}

.profile-line .zero {
  color: var(--text-muted);
}

.profile-chevron {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--text-muted);
}

@keyframes profile-flash {
  0%,
  35% {
    background: var(--accent-soft);
    border-color: var(--accent);
  }
  100% {
    background: var(--bg-muted);
    border-color: var(--border);
  }
}

.player-profile-row.is-flash {
  animation: profile-flash 1.3s var(--ease-out);
}

/* 录入区的大胡输入 */
.bighand-input {
  width: 100%;
  margin: 0 -6px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--warn);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.bighand-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.8;
}

.bighand-input:hover {
  border-color: var(--border);
}

.bighand-input:focus {
  outline: none;
  border-color: var(--warn);
  background: var(--warn-soft);
}

.bighand-input-edit {
  margin: 0;
  padding: 0 10px;
  height: 30px;
  border-color: var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 12px;
}

/* 记录表中的大胡角标 */
.bighand-tag {
  margin-top: 2px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--warn);
  line-height: 1.3;
}

.game-yakuman-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: middle;
}

/* ---------- 番符点对照表 ---------- */
.modal-dialog-wide {
  max-width: 880px;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fu-role-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 9px;
  background: var(--bg-muted);
}

.fu-role-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.fu-role-btn.is-active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 24, 21, 0.1);
}

.fu-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.fu-table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.fu-table th,
.fu-table td {
  padding: 6px 4px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.fu-table thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.fu-corner {
  text-align: left;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.fu-label {
  padding-right: 8px;
  text-align: right;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.fu-cell {
  line-height: 1.35;
}

.fu-ron {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
}

.fu-tsumo {
  display: block;
  margin-top: 1px;
  font-size: 9.5px;
  color: var(--text-muted);
}

.fu-na {
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.6;
}

.fu-mangan {
  background: var(--warn-soft);
}

.fu-limit {
  background: var(--accent-soft);
}

.fu-limit .fu-ron {
  color: var(--text);
}

.fu-legend {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ---------- 玩家档案面板 ---------- */
.profiles-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 2px;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
}

.profile-main {
  min-width: 0;
}

.profile-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-meta {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.profile-meta .pos {
  color: var(--pos);
  font-weight: 600;
}

.profile-meta .neg {
  color: var(--neg);
  font-weight: 600;
}

.profile-meta .zero {
  color: var(--text-muted);
  font-weight: 600;
}

.profile-yakuman {
  color: var(--warn);
  font-weight: 600;
}

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

.profiles-empty {
  padding: 32px 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

.profiles-empty span {
  font-size: 12px;
  opacity: 0.85;
}

.profiles-footer {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0;
}

.profiles-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- 移动端整洁度 ---------- */
@media (max-width: 560px) {
  .app-shell {
    padding: 14px 12px 40px;
    gap: 14px;
  }

  .topbar {
    gap: 10px;
  }

  /* 顶栏品牌区：印章与标题左对齐，规则行压成一行 */
  .brand-group {
    align-items: flex-start;
    gap: 10px;
  }

  .brand-seal {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .brand-seal svg {
    width: 26px;
    height: 26px;
  }

  .title-row {
    gap: 8px;
  }

  .title-row h1 {
    font-size: 17px;
  }

  .session-title-input {
    width: 104px;
    font-size: 12px;
    padding: 1px 6px;
  }

  .rule-badge {
    font-size: 11px;
    gap: 5px;
  }

  .rule-edit-hint {
    display: none;
  }

  /* 六个操作压进一行 */
  .topbar-actions {
    gap: 5px;
  }

  .topbar-actions .btn {
    height: 32px;
    padding: 0 9px;
    font-size: 12px;
  }

  .topbar-actions .btn-icon {
    width: 32px;
    padding: 0;
  }

  .topbar-actions .btn-ghost-danger {
    padding: 0 7px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .standings-grid {
    gap: 10px;
  }

  /* 玩家卡压缩 */
  .player-card {
    padding: 13px 14px;
    border-radius: 14px;
  }

  .player-card-top {
    margin-bottom: 6px;
  }

  .pt-value {
    font-size: 23px;
  }

  .player-spark {
    height: 24px;
    margin: 6px 0 7px;
  }

  .spark-svg {
    height: 24px;
  }

  .player-meta-row {
    padding-top: 7px;
    font-size: 11px;
  }

  .player-profile-row {
    margin-top: 8px;
  }

  /* 录入卡压缩 */
  .score-field-card {
    padding: 9px 11px;
    gap: 5px;
  }

  .score-input {
    font-size: 19px;
  }

  .score-preview-row {
    min-height: 17px;
  }

  .bighand-input {
    font-size: 11px;
  }

  /* 座次按钮放大一点，方便点按 */
  .seat-chip {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .entry-footer {
    margin-top: 10px;
  }

  /* 档案面板在窄屏改为上下排布 */
  .profile-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .profile-actions {
    justify-content: flex-end;
  }

  .profiles-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .profiles-footer-right {
    justify-content: flex-end;
  }

  .modal-header {
    padding: 12px 14px;
  }

  .modal-body {
    padding: 14px;
  }
}

/* ==================================================================
   主题皮肤
   ================================================================== */

/* 墨：深青绿夜 */
[data-theme="ink"] {
  --bg: #0f1614;
  --bg-elevated: #17211e;
  --bg-muted: #1e2b27;
  --bg-input: #131c19;
  --border: rgba(206, 232, 222, 0.09);
  --border-strong: rgba(206, 232, 222, 0.2);
  --text: #e3ede8;
  --text-secondary: #9cb0a8;
  --text-muted: #6f817a;
  --accent: #4fb98d;
  --accent-hover: #63cda0;
  --accent-soft: rgba(79, 185, 141, 0.16);
  --pos: #58c79a;
  --pos-soft: rgba(88, 199, 154, 0.14);
  --neg: #e0776f;
  --neg-soft: rgba(224, 119, 111, 0.15);
  --warn: #e5b25a;
  --warn-soft: rgba(229, 178, 90, 0.16);
  --p0: #4fb98d;
  --p1: #6ea8ff;
  --p2: #e5b25a;
  --p3: #e0776f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 16px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.62);
  --chart-grid: rgba(206, 232, 222, 0.07);
  --chart-axis: rgba(206, 232, 222, 0.26);
  --wash-1: rgba(79, 185, 141, 0.11);
  --wash-2: rgba(110, 168, 255, 0.05);
}

/* 米：暖纸 */
[data-theme="sepia"] {
  --bg: #f2e8d5;
  --bg-elevated: #fdf8ee;
  --bg-muted: #e9dcc5;
  --bg-input: #f8f0e0;
  --border: rgba(74, 58, 38, 0.1);
  --border-strong: rgba(74, 58, 38, 0.22);
  --text: #3a2f22;
  --text-secondary: #6d5c46;
  --text-muted: #93826c;
  --accent: #8a5a2b;
  --accent-hover: #70471f;
  --accent-soft: rgba(138, 90, 43, 0.12);
  --pos: #4a7c3f;
  --pos-soft: rgba(74, 124, 63, 0.12);
  --neg: #b0432f;
  --neg-soft: rgba(176, 67, 47, 0.12);
  --warn: #a8761b;
  --warn-soft: rgba(168, 118, 27, 0.14);
  --p0: #8a5a2b;
  --p1: #3f6f9e;
  --p2: #b0801f;
  --p3: #b0432f;
  --shadow-sm: 0 1px 2px rgba(74, 58, 38, 0.05), 0 4px 12px rgba(74, 58, 38, 0.05);
  --shadow-md: 0 10px 30px rgba(74, 58, 38, 0.12);
  --shadow-lg: 0 22px 60px rgba(74, 58, 38, 0.18);
  --chart-grid: rgba(74, 58, 38, 0.08);
  --chart-axis: rgba(74, 58, 38, 0.26);
  --wash-1: rgba(138, 90, 43, 0.08);
  --wash-2: rgba(176, 128, 31, 0.05);
}

/* 樱：淡粉 */
[data-theme="sakura"] {
  --bg: #fdf2f4;
  --bg-elevated: #ffffff;
  --bg-muted: #f7e6ea;
  --bg-input: #fdf7f8;
  --border: rgba(96, 60, 68, 0.09);
  --border-strong: rgba(96, 60, 68, 0.2);
  --text: #38262a;
  --text-secondary: #6f5559;
  --text-muted: #9c8388;
  --accent: #bf4763;
  --accent-hover: #a83953;
  --accent-soft: rgba(191, 71, 99, 0.1);
  --pos: #3f7a4d;
  --pos-soft: rgba(63, 122, 77, 0.1);
  --neg: #b3403f;
  --neg-soft: rgba(179, 64, 63, 0.1);
  --warn: #b07420;
  --warn-soft: rgba(176, 116, 32, 0.12);
  --p0: #bf4763;
  --p1: #3f6f9e;
  --p2: #b0801f;
  --p3: #8a5aa8;
  --shadow-sm: 0 1px 2px rgba(96, 60, 68, 0.04), 0 4px 12px rgba(96, 60, 68, 0.04);
  --shadow-md: 0 8px 28px rgba(96, 60, 68, 0.1);
  --shadow-lg: 0 22px 60px rgba(96, 60, 68, 0.14);
  --chart-grid: rgba(96, 60, 68, 0.07);
  --chart-axis: rgba(96, 60, 68, 0.22);
  --wash-1: rgba(191, 71, 99, 0.08);
  --wash-2: rgba(176, 128, 31, 0.05);
}

/* 海：冷蓝 */
[data-theme="ocean"] {
  --bg: #eef4f9;
  --bg-elevated: #ffffff;
  --bg-muted: #e2ecf4;
  --bg-input: #f5f9fc;
  --border: rgba(28, 48, 66, 0.09);
  --border-strong: rgba(28, 48, 66, 0.2);
  --text: #16232e;
  --text-secondary: #4f6472;
  --text-muted: #7f929f;
  --accent: #1f6f9e;
  --accent-hover: #175a83;
  --accent-soft: rgba(31, 111, 158, 0.1);
  --pos: #1f7a5c;
  --pos-soft: rgba(31, 122, 92, 0.1);
  --neg: #b8483f;
  --neg-soft: rgba(184, 72, 63, 0.1);
  --warn: #a8711c;
  --warn-soft: rgba(168, 113, 28, 0.12);
  --p0: #1f6f9e;
  --p1: #2f8f7a;
  --p2: #c08a2b;
  --p3: #b8483f;
  --shadow-sm: 0 1px 2px rgba(28, 48, 66, 0.04), 0 4px 12px rgba(28, 48, 66, 0.04);
  --shadow-md: 0 8px 28px rgba(28, 48, 66, 0.1);
  --shadow-lg: 0 22px 60px rgba(28, 48, 66, 0.16);
  --chart-grid: rgba(28, 48, 66, 0.07);
  --chart-axis: rgba(28, 48, 66, 0.2);
  --wash-1: rgba(31, 111, 158, 0.08);
  --wash-2: rgba(47, 143, 122, 0.05);
}

/* ---------- 可折叠区块 ---------- */
.collapsible .card-header {
  align-items: center;
}

.collapsible.is-collapsed .card-header {
  margin-bottom: 0;
}

.collapsible .card-body[hidden] {
  display: none;
}

.collapse-trigger {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.collapse-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 6px;
}

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

.collapse-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  transition: color 0.16s ease;
}

.collapse-trigger:hover .collapse-title {
  color: var(--accent);
}

.collapse-titles .card-subtitle {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collapse-chevron {
  position: relative;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 5px;
  background: var(--bg-muted);
  transition: background-color 0.16s ease;
}

.collapse-trigger:hover .collapse-chevron {
  background: var(--accent-soft);
}

.collapse-chevron::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 6px;
  height: 6px;
  border-right: 1.7px solid var(--text-secondary);
  border-bottom: 1.7px solid var(--text-secondary);
  transform: rotate(45deg);
  transition: transform 0.22s var(--ease-out);
}

.collapsible.is-collapsed .collapse-chevron::before {
  transform: rotate(-45deg);
  top: 6px;
  left: 4px;
}

.collapsible.is-collapsed .chart-legend {
  display: none;
}

.collapsible.is-collapsed .count-pill {
  background: var(--bg-muted);
}

/* ---------- 外观设置 ---------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.theme-option:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.theme-option.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.theme-preview {
  position: relative;
  display: block;
  width: 100%;
  height: 48px;
  border-radius: 8px;
  background: var(--sw-bg);
  border: 1px solid rgba(128, 128, 128, 0.18);
  overflow: hidden;
}

.theme-preview-bar {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 6px;
  height: 7px;
  border-radius: 3px;
  background: var(--sw-accent);
  opacity: 0.92;
}

.theme-preview-line {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 21px;
  height: 4px;
  border-radius: 2px;
  background: var(--sw-text);
  opacity: 0.16;
}

.theme-preview-line.short {
  right: 46%;
  top: 30px;
}

.theme-preview::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  height: 10px;
  border-radius: 4px;
  background: var(--sw-surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.theme-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.theme-option.is-active .theme-name {
  color: var(--accent);
}

.appearance-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bg-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bg-controls[hidden] {
  display: none;
}

.range-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.range-field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.range-field label span {
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- 自定义背景层 ---------- */
.bg-layer {
  position: fixed;
  inset: -40px;
  z-index: -1;
  pointer-events: none;
  background-image: var(--bg-url, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-opacity, 0.55);
  filter: blur(var(--bg-blur, 0px)) saturate(1.06);
  transition: opacity 0.25s ease, filter 0.25s ease;
}

html.has-custom-bg .card,
html.has-custom-bg .player-card {
  background: color-mix(in srgb, var(--bg-elevated) 86%, transparent);
  backdrop-filter: blur(14px) saturate(1.08);
  -webkit-backdrop-filter: blur(14px) saturate(1.08);
}

html.has-custom-bg .score-field-card {
  background: color-mix(in srgb, var(--bg-input) 80%, transparent);
}

html.has-custom-bg .modal-dialog {
  background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

html.has-custom-bg body {
  background-color: transparent;
  background-image: none;
}

/* ---------- 无障碍：尊重“减少动态效果” ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .player-card:hover,
  .brand-seal:hover {
    transform: none;
  }
}
