:root {
  color-scheme: light;
  --ink: #191a1f;
  --muted: #626671;
  --line: #d9dddc;
  --paper: #f7f2e8;
  --court: #4fa187;
  --kitchen: #d87363;
  --team-a: #f0c94a;
  --team-b: #6ba6e8;
  --panel: #fffaf0;
  --shadow: 0 18px 45px rgba(20, 25, 25, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(25, 26, 31, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(25, 26, 31, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  gap: 14px;
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}

.team-score,
.serve-pill,
.turn-card,
.side-panel {
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 6px 6px 0 var(--ink);
}

.team-score {
  min-height: 82px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transition: transform 160ms ease, background 160ms ease;
}

.team-score-a {
  border-left: 12px solid var(--team-a);
}

.team-score-b {
  border-right: 12px solid var(--team-b);
}

.team-label {
  min-width: 0;
  font-size: clamp(1.25rem, 2.2vw, 2rem);
  font-weight: 900;
  line-height: 1;
  overflow-wrap: anywhere;
}

.team-score strong {
  font-size: clamp(2.7rem, 7vw, 5.8rem);
  line-height: 0.8;
}

.serve-pill {
  min-width: 118px;
  padding: 14px 18px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 950;
}

.court-wrap {
  min-height: 360px;
  display: grid;
  place-items: stretch;
}

.court {
  position: relative;
  overflow: hidden;
  min-height: 360px;
  border: 4px solid var(--ink);
  background:
    linear-gradient(to bottom, transparent 0 43%, rgba(255, 255, 255, 0.34) 43% 57%, transparent 57%),
    linear-gradient(to right, rgba(255, 255, 255, 0.2), transparent 30% 70%, rgba(255, 255, 255, 0.2)),
    var(--court);
  box-shadow: var(--shadow);
}

.court.impact {
  animation: court-impact 260ms steps(2, end);
}

.court::before,
.court::after {
  content: "";
  position: absolute;
  inset: 10% 0 auto;
  height: 31%;
  background: color-mix(in srgb, var(--kitchen) 74%, white);
  opacity: 0.92;
}

.court::after {
  inset: auto 0 10%;
}

.court-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  z-index: 2;
}

.center-line {
  left: 50%;
  top: 10%;
  width: 3px;
  height: 80%;
  transform: translateX(-50%);
}

.kitchen-top,
.kitchen-bottom {
  left: 0;
  right: 0;
  height: 3px;
}

.kitchen-top {
  top: 41%;
}

.kitchen-bottom {
  bottom: 41%;
}

.net {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  z-index: 4;
  height: 12px;
  transform: translateY(-50%);
  background:
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(25, 26, 31, 0.5) 18px 21px),
    #f4f1e9;
  border-top: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
}

.court-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 9;
  min-width: 96px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  background: #fff0a6;
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
  font-size: clamp(1.1rem, 2.4vw, 1.7rem);
  font-weight: 950;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.75) rotate(-3deg);
}

.court-toast.show {
  animation: toast-pop 760ms cubic-bezier(.2,.75,.22,1);
}

.player {
  --x: 50%;
  --y: 50%;
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 5;
  width: clamp(70px, 10vw, 112px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  transition: transform 180ms ease, filter 180ms ease;
}

.player.active {
  filter: drop-shadow(0 0 0.8rem rgba(255, 255, 255, 0.95));
  transform: translate(-50%, -50%) scale(1.08);
}

.player.swing {
  animation: player-swing 420ms cubic-bezier(.2,.75,.22,1);
}

.player.smash-swing {
  animation: player-smash 430ms cubic-bezier(.2,.75,.22,1);
}

.player img {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.p0 { --x: 31%; --y: 72%; }
.p1 { --x: 68%; --y: 78%; }
.p2 { --x: 32%; --y: 24%; }
.p3 { --x: 69%; --y: 29%; }

.ball {
  --x: 31%;
  --y: 72%;
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 7;
  width: clamp(16px, 2.5vw, 24px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #d7ff3f;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(-50%, -50%);
  transition: left 220ms ease, top 220ms ease;
  will-change: left, top, transform;
}

.ball::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(215, 255, 63, 0.72), rgba(215, 255, 63, 0));
  opacity: 0;
  transform: scale(0.7);
}

.ball.in-flight {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.66), 2px 2px 0 var(--ink);
}

.ball.in-flight::after {
  animation: ball-glow 520ms ease infinite;
}

.ball.shot-smash {
  background: #fff07a;
}

.ball.shot-lob {
  background: #c8fffb;
}

.hud {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(360px, 1.2fr) minmax(230px, 0.9fr);
  gap: 14px;
  align-items: stretch;
}

.turn-card,
.side-panel {
  padding: 14px;
}

.minor {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 5px 0 8px;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.02;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.controls button,
.secondary {
  cursor: pointer;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: #ffffff;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 100ms ease, box-shadow 100ms ease, background 100ms ease;
}

.controls button {
  min-height: 108px;
  padding: 10px 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  font-weight: 900;
  transform-origin: center;
}

.controls button.recommended {
  background: #fff0a6;
  animation: recommend-pulse 880ms steps(2, end) infinite;
}

.shot-odds {
  min-height: 18px;
  padding: 2px 6px;
  border: 2px solid var(--ink);
  background: #eef9ff;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 950;
}

.controls button:hover,
.secondary:hover {
  background: #fff0a6;
  transform: translate(-1px, -1px);
}

.controls button:active,
.secondary:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--ink);
}

.controls button:disabled {
  cursor: default;
  opacity: 0.55;
  transform: none;
}

.score-pop {
  animation: score-pop 560ms cubic-bezier(.2,.75,.22,1);
}

@keyframes player-swing {
  0% { transform: translate(-50%, -50%) scale(1.08) rotate(0deg); }
  35% { transform: translate(-50%, -54%) scale(1.16) rotate(-6deg); }
  70% { transform: translate(-50%, -48%) scale(1.03) rotate(4deg); }
  100% { transform: translate(-50%, -50%) scale(1.08) rotate(0deg); }
}

@keyframes player-smash {
  0% { transform: translate(-50%, -50%) scale(1.08) rotate(0deg); }
  32% { transform: translate(-50%, -58%) scale(1.2) rotate(8deg); }
  68% { transform: translate(-50%, -45%) scale(1.1) rotate(-7deg); }
  100% { transform: translate(-50%, -50%) scale(1.08) rotate(0deg); }
}

@keyframes court-impact {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(3px, -2px); }
  50% { transform: translate(-2px, 2px); }
  75% { transform: translate(2px, 1px); }
}

@keyframes ball-glow {
  0%, 100% { opacity: 0.18; transform: scale(0.78); }
  50% { opacity: 0.75; transform: scale(1.28); }
}

@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, -44%) scale(0.7) rotate(-4deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(0.9) rotate(2deg); }
}

@keyframes score-pop {
  0% { transform: translate(0, 0); background: var(--panel); }
  35% { transform: translate(-2px, -4px) scale(1.025); background: #dfff3c; }
  100% { transform: translate(0, 0); background: var(--panel); }
}

@keyframes recommend-pulse {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-1px, -2px); }
}

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

.icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--team-a);
  font-weight: 950;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  min-height: 140px;
}

.mode-switch,
.difficulty-switch {
  display: grid;
  gap: 8px;
}

.mode-switch {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.difficulty-switch {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-switch button,
.difficulty-switch button {
  min-height: 38px;
  cursor: pointer;
  border: 2px solid var(--ink);
  background: #ffffff;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 0.86rem;
  font-weight: 950;
}

.mode-switch button.active,
.difficulty-switch button.active {
  background: #d7ff3f;
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

.secondary {
  min-height: 44px;
  padding: 8px 12px;
  font-weight: 950;
}

.log {
  min-height: 76px;
  max-height: 136px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.3;
}

.log div + div {
  margin-top: 6px;
}

.league-panel {
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 14px;
}

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

.league-header h2 {
  margin: 4px 0 0;
  font-size: clamp(1.35rem, 2.4vw, 2.2rem);
  line-height: 1;
}

.league-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.league-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 0.85fr;
  gap: 12px;
}

.league-card {
  min-height: 170px;
  border: 2px solid var(--ink);
  background: #ffffff;
  padding: 12px;
}

.league-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  line-height: 1;
  text-transform: uppercase;
}

.standing-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  border-top: 1px solid rgba(25, 26, 31, 0.14);
  font-size: 0.9rem;
}

.standing-row:first-child {
  border-top: 0;
}

.standing-row span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.standing-row strong,
.standing-row small {
  font-weight: 950;
}

.league-today {
  display: grid;
  gap: 8px;
}

.league-match {
  cursor: pointer;
  min-height: 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 2px solid var(--ink);
  background: #f6efd9;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 900;
}

.league-match.featured {
  background: #d7ff3f;
}

.league-match span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mint-card {
  min-height: 128px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 12px;
  border: 2px dashed var(--ink);
  background: #eef9ff;
}

.mint-card p,
.mint-card strong,
.mint-card small {
  margin: 0;
}

.mint-card strong {
  font-size: 2rem;
  line-height: 1;
}

.secondary:disabled,
.mode-switch button:disabled,
.difficulty-switch button:disabled {
  cursor: default;
  opacity: 0.55;
}

@media (max-width: 820px) {
  .game-shell {
    width: min(100vw - 18px, 640px);
    grid-template-rows: auto minmax(330px, 46vh) auto;
  }

  .scorebar,
  .hud,
  .league-grid {
    grid-template-columns: 1fr;
  }

  .league-header {
    align-items: stretch;
    flex-direction: column;
  }

  .serve-pill {
    width: 100%;
  }

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .controls button {
    min-height: 82px;
  }

  .team-score {
    min-height: 66px;
  }
}

@media (max-width: 460px) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
