:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #18352a;
  background: #f3f6f2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #18352a;
  --muted: #76847b;
  --line: #dce4dc;
  --court: #227d5e;
  --lime: #d9f36a;
  --coral: #f47b5b;
  --sky: #75c7ec;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #f3f6f2;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 28px 20px;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.brand-light {
  color: #87938b;
  font-weight: 600;
}

.brand-ball {
  width: 23px;
  aspect-ratio: 1;
  display: inline-block;
  position: relative;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: inset -3px -2px 0 rgb(24 53 42 / 9%);
}

.brand-ball::after {
  content: "";
  position: absolute;
  inset: 4px 6px;
  border-right: 1.5px solid #47744c;
  border-radius: 50%;
  transform: rotate(28deg);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.audio-toggle {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 1px solid #dce5dd;
  border-radius: 999px;
  color: #64766a;
  background: #fbfdf9;
  cursor: pointer;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease, transform 140ms ease;
}

.audio-toggle:hover {
  border-color: #8bb99a;
  color: #2f7955;
  background: #f2f8ef;
  transform: translateY(-1px);
}

.audio-toggle[data-muted="true"] {
  color: #9ba69e;
  background: #f4f6f3;
}

.audio-icon {
  color: #4ca678;
  font-size: 12px;
  line-height: 1;
}

.audio-toggle[data-muted="true"] .audio-icon {
  color: #a7b2aa;
}

.connection-indicator,
.version-label,
.latency-readout {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #77857c;
  font-family: "DM Mono", monospace;
  font-size: 11px;
}

.connection-dot,
.latency-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d1a342;
}

.connection-indicator[data-state="online"] .connection-dot,
.latency-dot {
  background: #43a87c;
}

.connection-indicator[data-state="offline"] .connection-dot {
  background: var(--coral);
}

.version-label {
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 28px;
  align-items: start;
  padding: 42px 0 32px;
}

.arena-column {
  min-width: 0;
}

.arena-heading {
  min-height: 68px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #76877c;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 25px;
  font-weight: 700;
  line-height: 1.2;
}

.heading-period {
  color: #43a87c;
}

.match-status {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 0 10px;
  border: 1px solid #dce4dc;
  border-radius: 3px;
  color: #65756a;
  background: #fafcf9;
  font-size: 11px;
  white-space: nowrap;
}

.status-mark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a8b5ab;
}

.match-status[data-phase="flight"] .status-mark,
.match-status[data-phase="receive"] .status-mark,
.match-status[data-phase="serve"] .status-mark,
.match-status[data-phase="countdown"] .status-mark {
  background: #54ac7c;
  box-shadow: 0 0 0 3px rgb(84 172 124 / 14%);
}

.match-status[data-phase="finished"] .status-mark {
  background: var(--coral);
}

.court-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid #264b3d;
  border-radius: 4px;
  background: #143f31;
  box-shadow: 0 14px 32px rgb(26 63 48 / 12%);
  isolation: isolate;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.court-frame.is-impact {
  border-color: var(--impact-color, #d9f36a);
  box-shadow: 0 18px 42px rgb(31 91 61 / 26%), 0 0 0 2px color-mix(in srgb, var(--impact-color, #d9f36a) 20%, transparent);
}

.impact-flash {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 52%, rgb(255 255 220 / 66%), rgb(217 243 106 / 12%) 25%, transparent 62%);
  mix-blend-mode: screen;
}

.court-frame.is-impact .impact-flash {
  animation: impact-flash 360ms cubic-bezier(.2,.8,.25,1) both;
}

.shot-callout {
  position: absolute;
  z-index: 4;
  top: 16px;
  right: 18px;
  display: grid;
  gap: 4px;
  min-width: 148px;
  padding: 10px 15px 11px;
  border: 1px solid rgb(229 246 159 / 42%);
  border-radius: 5px;
  color: #eff8d8;
  background: linear-gradient(135deg, rgb(15 59 43 / 92%), rgb(17 87 61 / 82%));
  box-shadow: 0 10px 32px rgb(0 24 15 / 24%), inset 0 1px 0 rgb(255 255 255 / 16%);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translateY(8px) scale(.94);
  transform-origin: top right;
}

.court-frame.is-impact .shot-callout {
  animation: shot-callout 620ms cubic-bezier(.16,1,.3,1) both;
}

.shot-callout[data-quality="perfect"] {
  border-color: rgb(255 235 126 / 76%);
  background: linear-gradient(135deg, rgb(66 65 23 / 96%), rgb(95 83 24 / 90%));
}

.shot-callout strong {
  color: #e7f877;
  font-family: "DM Mono", monospace;
  font-size: 16px;
  letter-spacing: .06em;
  text-shadow: 0 0 15px rgb(217 243 106 / 44%);
}

.shot-callout[data-quality="perfect"] strong {
  color: #fff19a;
  text-shadow: 0 0 18px rgb(255 235 126 / 60%);
}

.shot-callout span {
  color: rgb(235 248 222 / 78%);
  font-size: 10px;
}

@keyframes impact-flash {
  0% { opacity: 0; }
  16% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes shot-callout {
  0% { opacity: 0; transform: translateY(8px) scale(.94); }
  15% { opacity: 1; transform: translateY(0) scale(1.02); }
  70% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-6px) scale(.98); }
}

@media (prefers-reduced-motion: reduce) {
  .court-frame.is-impact .impact-flash,
  .court-frame.is-impact .shot-callout {
    animation-duration: 1ms;
  }
}

#court {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 1000 / 620;
  visibility: hidden;
}

#court-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.court-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: rgb(14 42 32 / 76%);
  text-align: center;
  backdrop-filter: blur(3px);
}

.court-overlay[hidden] {
  display: none;
}

.overlay-kicker {
  color: var(--lime);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.court-overlay strong {
  font-size: 23px;
}

.court-overlay > span:last-child {
  color: #c3d2c8;
  font-size: 13px;
}

.arena-footer {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.game-message {
  margin: 0;
  color: #52665a;
  font-size: 12px;
}

.latency-readout {
  flex: 0 0 auto;
}

.latency-dot {
  width: 6px;
  height: 6px;
}

.control-legend {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-top: 17px;
  color: #718077;
  font-size: 11px;
}

.legend-title {
  color: #a0aaa2;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.control-legend > span:not(.legend-title) {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

kbd {
  min-width: 23px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 1px solid #d4ddd5;
  border-bottom-width: 2px;
  border-radius: 3px;
  color: #48594e;
  background: #fbfcfa;
  font-family: "DM Mono", monospace;
  font-size: 10px;
}

.side-panel {
  padding-top: 3px;
}

.score-section {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  min-height: 25px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.section-heading > span:not(.open-label):not(.search-pulse) {
  color: #8b968d;
  font-family: "DM Mono", monospace;
  font-size: 10px;
}

.scoreboard {
  border-top: 1px solid #e5ebe5;
}

.score-row {
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 16px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #e5ebe5;
}

.score-player {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #53645a;
  font-size: 12px;
}

.score-player > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-swatch {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.player-swatch-one {
  background: var(--coral);
}

.player-swatch-two {
  background: var(--sky);
}

.score-number {
  color: #1d3b2d;
  font-family: "DM Mono", monospace;
  font-size: 22px;
  font-weight: 500;
  text-align: right;
}

.serve-indicator {
  width: 6px;
  height: 6px;
  justify-self: center;
  border-radius: 50%;
  background: transparent;
}

.serve-indicator.active {
  background: #58ac7e;
}

.action-section {
  padding: 23px 0 22px;
  border-bottom: 1px solid var(--line);
}

.action-section .section-heading {
  margin-bottom: 19px;
}

.open-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #86928a;
  font-family: "DM Mono", monospace;
  font-size: 9px;
}

.open-label span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #55aa7b;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: #738177;
  font-size: 11px;
}

.text-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #d8e1d9;
  border-radius: 3px;
  outline: none;
  color: var(--ink);
  background: #fbfcfa;
  font-size: 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.text-input:focus {
  border-color: #5baa81;
  box-shadow: 0 0 0 3px rgb(91 170 129 / 14%);
}

.text-input::placeholder {
  color: #a2ada4;
}

.button {
  width: 100%;
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:focus-visible,
.copy-button:focus-visible {
  outline: 3px solid rgb(77 159 115 / 30%);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.66;
  transform: none;
}

.button-primary {
  color: #173b2d;
  background: var(--lime);
}

.button-primary:hover {
  background: #cdeb5c;
}

.button-secondary {
  border-color: #d9e2da;
  color: #40564a;
  background: #fbfcfa;
}

.button-secondary:hover {
  border-color: #adbdaf;
  background: #fff;
}

#quick-match {
  justify-content: flex-start;
  margin-top: 14px;
  padding: 0 13px;
}

.button-icon {
  width: 18px;
  color: #3d7657;
  font-size: 18px;
  font-weight: 400;
  text-align: left;
}

.button-end {
  margin-left: auto;
  color: #638043;
  font-size: 17px;
  font-weight: 400;
}

#bot-match,
#create-room {
  margin-top: 8px;
}

.join-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 19px 0 12px;
  color: #99a49b;
  font-size: 10px;
  white-space: nowrap;
}

.join-divider::before,
.join-divider::after {
  height: 1px;
  flex: 1;
  content: "";
  background: #e3e9e3;
}

.join-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 7px;
}

.room-code-input {
  font-family: "DM Mono", monospace;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.button-join {
  min-height: 42px;
  border-color: #d7e0d8;
  color: #42634d;
  background: #e9f0e8;
}

.button-join:hover {
  background: #dceadd;
}

.state-panel {
  padding-bottom: 24px;
}

.state-copy {
  margin: -5px 0 17px;
  color: #748279;
  font-size: 12px;
  line-height: 1.65;
}

.search-pulse {
  width: 10px;
  height: 10px;
  border: 2px solid #5bb184;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(91 177 132 / 13%);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 7px rgb(91 177 132 / 5%);
  }
}

.room-mode,
.phase-tag {
  padding: 4px 6px;
  border-radius: 2px;
  color: #5d7f67 !important;
  background: #e8f0e7;
  font-family: "DM Mono", monospace;
  font-size: 9px !important;
}

.room-code-display {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 3px 0 16px;
  padding: 0 11px;
  border: 1px dashed #b7c8b8;
  border-radius: 3px;
  background: #f8faf6;
}

.room-code-display[hidden] {
  display: none;
}

#room-code-value {
  color: #244d37;
  font-family: "DM Mono", monospace;
  font-size: 22px;
  font-weight: 500;
}

.copy-button {
  min-width: 48px;
  height: 30px;
  border: 1px solid #d4ded4;
  border-radius: 3px;
  color: #607268;
  background: #fff;
  cursor: pointer;
  font-size: 10px;
}

.room-opponent {
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 5px 0 14px;
  color: #52655a;
  font-size: 11px;
}

.opponent-avatar {
  width: 25px;
  height: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #dce4dc;
  border-radius: 50%;
  color: #9aa69c;
  background: #f8faf7;
  font-family: "DM Mono", monospace;
}

.opponent-connection {
  margin-left: auto;
  color: #9aa49b;
  font-size: 10px;
}

.phase-tag {
  color: #537c5d !important;
  background: #edf4df;
}

.rematch-status {
  margin: 0 0 12px;
  padding: 10px 0;
  border-top: 1px solid #e3eae2;
  border-bottom: 1px solid #e3eae2;
  color: #5e7867;
  font-size: 11px;
  line-height: 1.5;
}

.finished-actions {
  display: grid;
  gap: 8px;
}

.finished-actions[hidden] {
  display: none;
}

.notice {
  margin-top: 15px;
  padding: 10px 11px;
  border-left: 2px solid #e39a53;
  color: #755d3c;
  background: #fff5e9;
  font-size: 11px;
  line-height: 1.5;
}

.notice[hidden] {
  display: none;
}

.notice[data-level="error"] {
  border-color: var(--coral);
  color: #8d5141;
  background: #fff0ec;
}

.rules-note {
  margin: 18px 0 0;
  color: #8a968d;
  font-size: 10px;
  line-height: 1.7;
}

.page-footer {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  color: #9aa49c;
  font-family: "DM Mono", monospace;
  font-size: 9px;
}

.page-footer > span:last-child {
  font-family: "DM Sans", "Noto Sans SC", sans-serif;
  font-size: 10px;
}

[hidden] {
  display: none !important;
}

@media (min-width: 1500px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 292px;
    gap: 32px;
  }
}

@media (max-width: 960px) {
  .app-shell {
    padding-right: 26px;
    padding-left: 26px;
  }

  .main-layout {
    grid-template-columns: minmax(0, 1fr) 276px;
    gap: 24px;
  }

  .control-legend {
    gap: 14px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .topbar {
    height: 62px;
  }

  .topbar-right {
    gap: 10px;
  }

  .version-label {
    display: none;
  }

  .main-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 26px;
    padding-top: 27px;
  }

  .arena-heading {
    min-height: 59px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .match-status {
    margin-top: 12px;
  }

  .shot-callout {
    top: 10px;
    right: 10px;
    min-width: 0;
    padding: 7px 10px 8px;
  }

  .shot-callout strong {
    font-size: 13px;
  }

  .side-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding-top: 0;
  }

  .score-section {
    padding-bottom: 17px;
  }

  .control-legend {
    flex-wrap: wrap;
    gap: 10px 17px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-right: 13px;
    padding-left: 13px;
  }

  .arena-heading {
    align-items: center;
  }

  .match-status {
    max-width: 132px;
    overflow: hidden;
    margin-top: 11px;
    font-size: 10px;
    text-overflow: ellipsis;
  }

  .arena-footer {
    min-height: 46px;
  }

  .game-message {
    font-size: 11px;
  }

  .latency-readout {
    font-size: 9px;
  }

  .control-legend {
    gap: 9px 12px;
  }

  .page-footer > span:last-child {
    max-width: 165px;
    text-align: right;
  }
}
