:root {
  --felt: #0f4937;
  --felt-deep: #09372a;
  --felt-light: #1e644d;
  --paper: #fffaf0;
  --paper-soft: #f5ecda;
  --ink: #242421;
  --muted: #746f63;
  --line: #d8c8a8;
  --line-strong: #bdaa84;
  --red: #ba302b;
  --red-dark: #92231f;
  --green: #2f6f43;
  --shadow: rgba(2, 25, 18, 0.32);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--felt-deep);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: var(--felt-deep);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.035) 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 65%, rgba(0, 0, 0, 0.055) 0 1px, transparent 1.5px);
  background-size: 9px 9px, 13px 13px;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #f0c968;
  outline-offset: 3px;
}

.table-shell {
  width: min(1440px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  padding: 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  background-color: var(--felt);
  background-image:
    radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.07), transparent 48%),
    repeating-linear-gradient(25deg, transparent 0 8px, rgba(255, 255, 255, 0.009) 9px 10px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28), inset 0 0 70px rgba(0, 0, 0, 0.08);
}

.app-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(100px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: 24px;
  min-height: 90px;
  margin-bottom: 24px;
  padding-inline: 56px;
  color: #f7edcf;
}

.app-header h1 {
  margin: 0;
  font-family: STKaiti, KaiTi, "Songti SC", serif;
  font-size: clamp(2.4rem, 4.5vw, 4.4rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.title-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(235, 210, 151, 0.72));
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.utility-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid rgba(247, 237, 207, 0.75);
  border-radius: var(--radius-sm);
  color: #fff6da;
  background: rgba(4, 42, 31, 0.38);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.utility-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.11);
  transform: translateY(-1px);
}

.utility-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.utility-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.corner-suits {
  position: absolute;
  top: -28px;
  display: grid;
  width: 78px;
  height: 78px;
  place-content: center;
  border-radius: 0 0 18px 0;
  color: #20221f;
  background: var(--paper-soft);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
  transform: rotate(-5deg);
}

.corner-suits span {
  position: relative;
  display: block;
  font-family: Georgia, serif;
  font-size: 1.5rem;
  line-height: 1;
}

.corner-suits span + span {
  left: 16px;
  color: var(--red);
}

.corner-suits--left {
  left: -28px;
}

.corner-suits--right {
  right: -28px;
  border-radius: 0 0 0 18px;
  transform: rotate(5deg);
}

.corner-suits--right span:first-child {
  color: var(--red);
}

.corner-suits--right span + span {
  color: #20221f;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.player-card {
  position: relative;
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background-color: var(--paper);
  background-image: linear-gradient(rgba(126, 93, 38, 0.025) 1px, transparent 1px);
  background-size: 100% 25px;
  box-shadow: 0 8px 20px var(--shadow), inset 0 0 0 4px rgba(255, 255, 255, 0.5);
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.player-card.is-recent {
  box-shadow: 0 8px 20px var(--shadow), inset 0 0 0 3px #7ca562;
}

.name-wrap {
  position: relative;
}

.player-name {
  width: 100%;
  height: 50px;
  padding: 0 46px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.38);
  font-family: STKaiti, KaiTi, "Songti SC", serif;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.edit-mark {
  position: absolute;
  top: 50%;
  right: 15px;
  width: 18px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.edit-mark path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.score-stage {
  position: relative;
  display: grid;
  min-height: 142px;
  place-content: center;
  border-bottom: 1px solid var(--line);
}

.score {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(4rem, 7vw, 6.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
}

.score.is-negative {
  color: var(--red-dark);
}

.recent-change {
  position: absolute;
  right: 50%;
  bottom: 8px;
  color: var(--green);
  font-size: 1.05rem;
  font-weight: 800;
  opacity: 0;
  transform: translateX(50%) translateY(3px);
}

.player-card.is-recent .recent-change {
  opacity: 1;
  transform: translateX(50%) translateY(0);
}

.quick-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0 20px;
}

.score-button {
  min-height: 48px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.32);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(111, 83, 40, 0.08);
  transition: border-color 130ms ease, background 130ms ease, transform 100ms ease;
}

.score-button[data-delta^="-"] {
  color: var(--red);
}

.score-button:hover {
  border-color: var(--line-strong);
  background: white;
}

.score-button:active {
  transform: translateY(2px);
}

.custom-label {
  display: block;
  margin-bottom: 8px;
  color: #433f37;
  font-size: 0.9rem;
  font-weight: 700;
}

.custom-row {
  display: grid;
  grid-template-columns: minmax(86px, 1fr) auto auto;
  gap: 8px;
}

.custom-input {
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.custom-action {
  min-width: 60px;
  height: 48px;
  border: 0;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  transition: filter 130ms ease, transform 100ms ease;
}

.custom-action:hover {
  filter: brightness(1.08);
}

.custom-action:active {
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
  transform: translateY(2px);
}

.custom-action--minus {
  background: var(--red);
}

.custom-action--plus {
  background: #292c2a;
}

.history-panel {
  margin-top: 22px;
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: 0 8px 20px var(--shadow), inset 0 0 0 4px rgba(255, 255, 255, 0.48);
}

.history-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.history-heading h2 {
  margin: 0;
  font-family: STKaiti, KaiTi, "Songti SC", serif;
  font-size: 1.75rem;
}

.history-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.history-count {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  margin: 14px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.history-item {
  display: grid;
  grid-template-columns: 96px minmax(100px, 1fr) 82px 112px;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid #e5dac3;
  border-radius: var(--radius-sm);
  background: rgba(236, 242, 220, 0.45);
  font-size: 0.92rem;
}

.history-time,
.history-total {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.history-player {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delta {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  font-weight: 800;
  text-align: right;
}

.history-delta.is-positive {
  color: var(--green);
}

.history-delta.is-negative {
  color: var(--red);
}

.empty-state {
  display: grid;
  min-height: 170px;
  place-items: center;
  align-content: center;
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state svg {
  width: 34px;
  margin-bottom: 8px;
  fill: none;
  stroke: #9a9487;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.empty-state p {
  margin: 0 0 4px;
  font-weight: 700;
}

.empty-state span {
  font-size: 0.82rem;
}

.reset-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.reset-dialog::backdrop {
  background: rgba(2, 20, 14, 0.7);
  backdrop-filter: blur(3px);
}

.reset-dialog form {
  padding: 28px;
  text-align: center;
}

.dialog-suit {
  color: var(--felt);
  font-family: Georgia, serif;
  font-size: 2.4rem;
}

.reset-dialog h2 {
  margin: 8px 0;
  font-family: STKaiti, KaiTi, "Songti SC", serif;
  font-size: 1.65rem;
}

.reset-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
}

.dialog-button {
  min-height: 46px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  cursor: pointer;
}

.dialog-button--quiet {
  border: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
}

.dialog-button--danger {
  border: 1px solid var(--red-dark);
  color: white;
  background: var(--red);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: min(360px, calc(100% - 48px));
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-sm);
  color: white;
  background: #1d211f;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .table-shell {
    width: min(760px, calc(100% - 24px));
    padding: 20px;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 18px;
    padding-inline: 30px;
    text-align: center;
  }

  .app-header h1 {
    grid-row: 1;
  }

  .title-rule {
    display: none;
  }

  .header-actions {
    justify-content: center;
  }

  .players-grid {
    grid-template-columns: 1fr;
  }

  .player-card {
    display: grid;
    grid-template-columns: minmax(160px, 0.8fr) minmax(260px, 1.2fr);
    gap: 0 20px;
  }

  .name-wrap,
  .score-stage {
    grid-column: 1;
  }

  .quick-controls,
  .custom-controls {
    grid-column: 2;
  }

  .quick-controls {
    grid-row: 1 / span 2;
    align-self: end;
  }
}

@media (max-width: 620px) {
  body {
    background: var(--felt);
  }

  .table-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    padding: 16px 12px 28px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-header {
    min-height: 104px;
    margin-bottom: 16px;
    padding-inline: 20px;
  }

  .app-header h1 {
    font-size: 2.4rem;
  }

  .corner-suits {
    top: -16px;
    width: 58px;
    height: 58px;
  }

  .corner-suits--left {
    left: -12px;
  }

  .corner-suits--right {
    right: -12px;
  }

  .header-actions {
    gap: 8px;
  }

  .utility-button {
    flex: 1;
    min-width: 0;
    padding-inline: 10px;
    font-size: 0.86rem;
  }

  .players-grid {
    gap: 12px;
  }

  .player-card {
    display: grid;
    grid-template-columns: minmax(96px, 0.7fr) minmax(0, 1.3fr);
    gap: 0 10px;
    padding: 14px;
    border-radius: 14px;
  }

  .player-name {
    height: 44px;
    padding-left: 8px;
    font-size: 1.05rem;
    text-align: left;
  }

  .score-stage {
    min-height: 110px;
  }

  .score {
    font-size: 4.5rem;
  }

  .quick-controls {
    gap: 6px;
    margin: 0 0 12px;
  }

  .score-button {
    min-height: 44px;
    font-size: 1rem;
  }

  .custom-row {
    grid-template-columns: minmax(70px, 1fr) 54px 54px;
    gap: 6px;
  }

  .custom-input,
  .custom-action {
    height: 44px;
  }

  .custom-action {
    min-width: 0;
    font-size: 0.86rem;
  }

  .history-panel {
    margin-top: 14px;
    padding: 16px 14px;
    border-radius: 14px;
  }

  .history-heading h2 {
    font-size: 1.45rem;
  }

  .history-heading p {
    display: none;
  }

  .history-list {
    max-height: 300px;
  }

  .history-item {
    grid-template-columns: minmax(70px, 1fr) 62px 86px;
    gap: 8px;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  .history-time {
    display: none;
  }

  .history-total {
    text-align: right;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
