:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #17120f;
  background: #f6eedf;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #17120f;
  --paper: #fffaf0;
  --red: #e44335;
  --green: #d7edc5;
  --court: #27613e;
  --court-dark: #19492d;
  --blue: #cfe6ec;
  --yellow: #f4d56f;
  --muted: #6e6258;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 93% 3%, rgba(215, 237, 197, 0.95), transparent 330px),
    linear-gradient(90deg, rgba(23, 18, 15, 0.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 18, 15, 0.045) 1px, transparent 1px),
    #f6eedf;
  background-size: auto, 32px 32px, 32px 32px, auto;
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 3px;
}

a { color: inherit; }

[hidden] { display: none !important; }

.app {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar,
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand,
.rule-pill {
  border: 2px solid var(--ink);
  background: var(--paper);
  font-weight: 950;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 10px 13px;
  text-decoration: none;
}

.brand span { color: var(--red); font-size: 19px; }

.rule-pill {
  border-radius: 999px;
  padding: 8px 12px;
  color: #403830;
  font-size: 13px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 30px;
  padding: 44px 0 26px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--red);
  font-size: 13px;
  font-weight: 1000;
  letter-spacing: 0.14em;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 16px;
  font-size: clamp(43px, 6.3vw, 74px);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

h1 span { color: var(--red); }

.lead {
  max-width: 760px;
  margin: 0;
  color: #4d4239;
  font-size: 18px;
  font-weight: 720;
  line-height: 1.7;
}

.serve-stamp {
  display: grid;
  min-width: 198px;
  justify-items: center;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--yellow);
  box-shadow: 7px 7px 0 var(--ink);
  padding: 16px 19px;
  text-align: center;
  transform: rotate(2deg);
}

.serve-stamp span,
.serve-stamp small { font-weight: 900; }
.serve-stamp strong { margin: 5px 0; font-size: 27px; line-height: 1.05; }
.serve-stamp small { color: #6a5840; font-size: 12px; }

.setup-layout,
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(310px, 0.62fr);
  align-items: start;
  gap: 20px;
}

.panel {
  min-width: 0;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 22px;
}

.quick-guide,
.history-panel { position: sticky; top: 16px; }

.panel-title {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.panel-title h2 { margin-bottom: 4px; font-size: 25px; line-height: 1.08; }
.panel-title p { margin: 0; color: var(--muted); font-size: 14px; font-weight: 720; }

.step-number {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--green);
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 1000;
}

.step-number.red { background: #ffc9c1; color: #a32319; }

fieldset { min-width: 0; }

.team-setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.team-box,
.control-block {
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 16px;
}

.team-box { margin: 0; }
.team-box.team-a { background: #ffe2dd; }
.team-box.team-b { background: var(--blue); }

legend {
  padding: 0 8px;
  font-weight: 1000;
}

.team-box label,
.setup-row label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 900;
}

.team-box label + label { margin-top: 11px; }

input,
select {
  width: 100%;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #fffefa;
  padding: 9px 11px;
  color: var(--ink);
  font-weight: 850;
}

.control-block { margin: 18px 0 0; background: #fffdf7; }

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

.mode-block {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mode-choice { display: block; cursor: pointer; }
.mode-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.mode-choice span {
  display: grid;
  min-height: 70px;
  align-content: center;
  gap: 3px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 11px 13px;
}
.mode-choice input:checked + span { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.mode-choice input:focus-visible + span { outline: 3px solid var(--red); outline-offset: 3px; }
.mode-choice strong { font-size: 16px; }
.mode-choice small { color: #665a50; font-weight: 760; }

.form-error {
  margin: 14px 0 0;
  border-left: 5px solid var(--red);
  background: #ffe4df;
  padding: 10px 12px;
  color: #8b211a;
  font-weight: 850;
}

.setup-actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; }

.primary-button,
.text-button,
.tool-actions button {
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-weight: 950;
}

.primary-button {
  min-height: 50px;
  background: var(--red);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 11px 20px;
  color: #fff;
}

.primary-button:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }

.text-button { min-height: 44px; background: #fff; padding: 9px 14px; }

.quick-guide ol { display: grid; gap: 15px; margin: 0; padding: 0; list-style: none; }
.quick-guide li { display: grid; grid-template-columns: 36px 1fr; align-items: start; gap: 10px; }
.quick-guide li > span {
  display: grid; width: 34px; height: 34px; place-items: center;
  border: 2px solid var(--ink); border-radius: 50%; background: var(--yellow); font-weight: 1000;
}
.quick-guide li strong { font-size: 15px; }
.quick-guide li p { margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; font-weight: 700; }

.mini-rule,
.history-note {
  margin-top: 18px;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--green);
  padding: 13px;
}
.mini-rule p,
.history-note p { margin: 4px 0 0; color: #38442f; line-height: 1.55; font-size: 13px; font-weight: 750; }

.score-panel { background: #fffdf7; }

.score-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.team-score {
  display: grid;
  justify-items: center;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
}
.team-score.team-a { background: #ffe2dd; }
.team-score.team-b { background: var(--blue); }
.team-score span { font-size: 14px; font-weight: 950; }
.team-score strong { font-size: 48px; line-height: 1; }
.team-score small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }

.score-middle { display: grid; justify-items: center; gap: 2px; }
.score-middle span { border-radius: 999px; background: var(--yellow); padding: 5px 8px; font-size: 11px; font-weight: 950; }
.score-middle strong { font-size: 33px; }
.score-middle small { color: var(--muted); font-size: 11px; font-weight: 800; }

.service-call {
  margin: 16px 0;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  padding: 15px;
  text-align: center;
}
.service-call > span { display: inline-block; border-radius: 999px; background: var(--red); padding: 5px 10px; color: white; font-size: 12px; font-weight: 950; }
.service-call h2 { margin: 8px 0 3px; font-size: clamp(24px, 4vw, 34px); }
.service-call p { margin: 0; color: #4b423a; font-weight: 900; }
.service-call small { display: block; margin-top: 8px; color: var(--muted); font-weight: 750; }

.court-wrap { width: min(100%, 600px); margin: 0 auto; }
.court-label { color: #6c6259; font-size: 12px; font-weight: 950; letter-spacing: .08em; text-align: center; }
.top-label { margin-bottom: 5px; }
.bottom-label { margin-top: 5px; }

.court {
  position: relative;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 9px;
  background: var(--court);
  box-shadow: inset 0 0 0 2px #fff;
}

.court-half { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: 154px; }
.court-cell {
  position: relative;
  display: grid;
  min-width: 0;
  place-content: center;
  justify-items: center;
  gap: 3px;
  border: 1px solid rgba(255, 255, 255, .95);
  padding: 15px 8px;
  color: #fff;
  text-align: center;
}
.court-cell small { opacity: .78; font-size: 11px; font-weight: 850; }
.court-cell strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 999px;
  background: var(--court-dark);
  padding: 8px 13px;
  font-size: 17px;
}
.court-cell em { min-height: 18px; font-size: 11px; font-style: normal; font-weight: 950; }
.court-cell.server { background: #c94738; }
.court-cell.receiver { background: #317895; }
.court-cell.server strong,
.court-cell.receiver strong { background: #fff; color: var(--ink); }
.court-cell.server em::before { content: "发球"; }
.court-cell.receiver em::before { content: "接球"; }
.court-cell.server::after,
.court-cell.receiver::after {
  position: absolute; top: 7px; right: 8px; border-radius: 999px; background: #fff; color: var(--ink); padding: 2px 6px; font-size: 10px; font-weight: 1000;
}
.court-cell.server::after { content: "SERVE"; }
.court-cell.receiver::after { content: "RECEIVE"; }

.net {
  position: relative;
  z-index: 2;
  height: 14px;
  border-top: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  background: repeating-linear-gradient(90deg, #fff 0 8px, var(--ink) 8px 10px);
}
.net span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: 2px solid var(--ink); border-radius: 999px; background: var(--yellow); padding: 2px 7px; font-size: 9px; font-weight: 1000;
}

.score-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 17px; }
.score-button {
  display: grid;
  min-height: 76px;
  place-content: center;
  gap: 3px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  box-shadow: 5px 5px 0 var(--ink);
  color: var(--ink);
}
.score-button.a { background: #ffb9ae; }
.score-button.b { background: #a8d7e2; }
.score-button:hover { transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--ink); }
.score-button span { font-size: 20px; font-weight: 1000; }
.score-button small { font-weight: 800; }
.score-button:disabled { cursor: not-allowed; filter: grayscale(.7); opacity: .55; transform: none; }

.game-over-actions {
  margin-top: 17px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--yellow);
  padding: 14px;
  text-align: center;
}
.game-over-actions strong { display: block; margin-bottom: 10px; font-size: 20px; }

.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.tool-actions button { min-height: 42px; background: #fff; padding: 8px 12px; }
.tool-actions button:disabled { cursor: not-allowed; opacity: .45; }
.tool-actions .danger { margin-left: auto; color: #a32319; }

.compact-title { margin-bottom: 14px; }
.event-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; counter-reset: event; }
.event-list li {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 10px 11px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.5;
}
.event-list li:first-child { background: var(--yellow); }
.event-list li.empty { border-style: dashed; background: #fff; color: var(--muted); }

.rules-note {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 18px;
  margin-top: 25px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--green);
  padding: 18px;
}
.rules-note p { margin: 4px 0 0; color: #3e4936; font-size: 13px; line-height: 1.55; font-weight: 720; }
.rules-note a { display: inline-block; border: 2px solid var(--ink); border-radius: 7px; background: #fff; padding: 9px 11px; font-weight: 950; text-decoration: none; white-space: nowrap; }

.footer { margin-top: 26px; border-top: 2px solid var(--ink); padding-top: 18px; font-weight: 850; }
.footer > a { font-weight: 1000; }
.footer nav { display: flex; flex-wrap: wrap; gap: 16px; }

@media (max-width: 850px) {
  .setup-layout,
  .game-layout { grid-template-columns: 1fr; }
  .quick-guide,
  .history-panel { position: static; }
  .rules-note { grid-template-columns: 1fr; }
  .rules-note nav { justify-self: start; }
}

@media (max-width: 620px) {
  .app { width: min(100% - 20px, 1160px); padding-top: 11px; }
  .rule-pill { display: none; }
  .hero { grid-template-columns: 1fr; gap: 18px; padding: 33px 0 22px; }
  .serve-stamp { width: 100%; min-width: 0; grid-template-columns: auto 1fr; align-items: center; justify-items: start; gap: 10px; padding: 12px 14px; text-align: left; transform: none; }
  .serve-stamp strong { font-size: 20px; }
  .serve-stamp small { grid-column: 1 / -1; }
  h1 { font-size: clamp(38px, 12vw, 54px); }
  .lead { font-size: 16px; }
  .panel { box-shadow: 5px 5px 0 var(--ink); padding: 16px; }
  .team-setup-grid,
  .mode-block { grid-template-columns: 1fr; }
  .setup-row { grid-template-columns: 1fr; }
  .setup-actions { align-items: stretch; flex-direction: column; }
  .score-head { gap: 6px; }
  .team-score { padding: 9px 6px; }
  .team-score strong { font-size: 40px; }
  .team-score small { font-size: 11px; }
  .score-middle span { font-size: 9px; }
  .score-middle small { display: none; }
  .service-call { padding: 13px 8px; }
  .court-half { min-height: 126px; }
  .court-cell { padding: 12px 5px; }
  .court-cell strong { padding: 7px 10px; font-size: 15px; }
  .court-cell.server::after,
  .court-cell.receiver::after { display: none; }
  .score-button { min-height: 82px; }
  .score-button span { font-size: 18px; }
  .tool-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-actions .danger { grid-column: 1 / -1; margin-left: 0; }
  .footer { align-items: flex-start; flex-direction: column; }
}

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