:root {
  --paper: #f4f3ee;
  --paper-deep: #e7e3d8;
  --ink: #17202a;
  --ink-soft: #49515a;
  --sun: #ffc84a;
  --coral: #f4596e;
  --coral-dark: #d94761;
  --mint: #4fc6a4;
  --pool: #43bad1;
  --cream: #fff2c3;
  --white: #fffdf5;
  --line: 3px solid var(--ink);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 28px;
  --display: "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  --body: "Trebuchet MS", "Avenir Next", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--sun); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--sun);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 4px solid var(--pool);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.game-shell {
  min-height: 100vh;
  margin: 12px;
  overflow: hidden;
  background: var(--paper);
  border: var(--line);
  box-shadow: 8px 8px 0 rgba(23, 32, 42, 0.18);
}

.topbar {
  min-height: 88px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--sun);
  border-bottom: var(--line);
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -1px;
  text-decoration: none;
  transform: rotate(-1deg);
}

.wordmark strong {
  padding: 2px 7px 3px;
  color: var(--white);
  background: var(--coral);
  border: 2px solid var(--ink);
  transform: rotate(2deg);
}

.wordmark em { font-style: normal; }

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

.connection-pill {
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.2px;
}

.connection-pill.is-live::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--mint);
  border: 1px solid var(--ink);
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  font-family: var(--display);
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms cubic-bezier(.23,1,.32,1), background-color 120ms;
}

.icon-button:hover, .icon-button[aria-pressed="true"] { background: var(--mint); }
.icon-button:active { transform: scale(.96) rotate(-5deg); }

.view { min-height: calc(100vh - 116px); }

.lobby-view {
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) minmax(250px, .9fr);
  grid-template-areas:
    "copy sync"
    "sports sync"
    "roster roster";
  gap: 24px 48px;
  padding: clamp(32px, 5vw, 72px);
  background-image: radial-gradient(circle at 10px 10px, rgba(23,32,42,.09) 2px, transparent 2.5px);
  background-size: 48px 48px;
}

.lobby-copy { grid-area: copy; max-width: 680px; }
.eyebrow {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1.8px;
}

.lobby-copy h1,
.join-view h1,
.waiting-view h1,
.finish-view h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(42px, 6vw, 80px);
  font-weight: 900;
  line-height: .93;
  letter-spacing: -4px;
  text-wrap: balance;
}

.lobby-copy > p:last-child {
  max-width: 560px;
  margin: 24px 0 0;
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1.55;
  text-wrap: pretty;
}

.sport-picker {
  grid-area: sports;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-self: end;
  gap: 12px;
}

.sport-card {
  min-height: 126px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  border: 2px solid var(--ink);
  border-radius: var(--radius-md);
  background: var(--paper);
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 130ms cubic-bezier(.23,1,.32,1), background-color 130ms;
}

.sport-card:hover { transform: translate(-2px, -2px); }
.sport-card:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.sport-card.is-selected { background: var(--mint); }
.sport-card:nth-child(2).is-selected { background: var(--sun); }
.sport-card:nth-child(3).is-selected { background: var(--pool); }
.sport-card:nth-child(4).is-selected { background: var(--cream); }
.sport-card:nth-child(5).is-selected { background: var(--coral); }
.sport-card:nth-child(6).is-selected { background: var(--mint); }
.sport-card:disabled { opacity: .42; cursor: not-allowed; box-shadow: 2px 2px 0 var(--ink); transform: none; }
.sport-card b { display: block; font-family: var(--display); font-size: 20px; }
.sport-card small { display: block; margin-top: 2px; font-size: 11px; font-weight: 700; }
.sport-doodle { position: relative; width: 54px; height: 46px; flex: 0 0 54px; display: inline-flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 36px; line-height: 1; }
.run-doodle i { position: absolute; left: 8px; bottom: 7px; width: 36px; height: 17px; background: var(--mint); border: 3px solid var(--ink); border-radius: 12px 16px 7px 8px; transform: rotate(-10deg); }
.run-doodle i::before { content: ""; position: absolute; left: 4px; top: -14px; width: 18px; height: 17px; background: var(--coral); border: 3px solid var(--ink); border-bottom: 0; border-radius: 10px 10px 2px 2px; transform: skewX(12deg); }
.run-doodle i::after { content: ""; position: absolute; left: -4px; right: -4px; bottom: -7px; height: 5px; background: var(--sun); border: 3px solid var(--ink); border-radius: 5px; }
.cycle-doodle { gap: 5px; }
.cycle-doodle i { position: relative; z-index: 1; width: 19px; height: 19px; border: 4px solid var(--ink); border-radius: 50%; background: var(--pool); }
.cycle-doodle i:last-child { background: var(--sun); }
.cycle-doodle::before { content: ""; position: absolute; left: 15px; top: 14px; width: 24px; height: 17px; border: 4px solid var(--coral); transform: skewX(-18deg) rotate(-7deg); }
.swim-doodle { flex-direction: column; gap: 1px; }
.swim-doodle i { width: 39px; height: 8px; border-top: 5px solid var(--pool); border-radius: 50%; transform: rotate(-5deg); }
.swim-doodle i:nth-child(2) { width: 46px; border-color: var(--mint); transform: rotate(4deg); }
.swim-doodle i:nth-child(3) { width: 34px; border-color: var(--coral); }
.pickle-doodle { position: relative; display: flex; align-items: center; gap: 5px; font-size: 13px; }
.pickle-doodle i { width: 25px; height: 32px; display: inline-block; background: var(--coral); border: 3px solid var(--ink); border-radius: 50% 50% 44% 44%; transform: rotate(-28deg); }
.pickle-doodle i::after { content: ""; position: absolute; width: 7px; height: 17px; margin: 24px 0 0 -3px; background: var(--cream); border: 3px solid var(--ink); border-radius: 3px; }
.hurdle-doodle i { position: absolute; top: 10px; width: 44px; height: 10px; background: var(--coral); border: 3px solid var(--ink); border-radius: 4px; }
.hurdle-doodle i::before, .hurdle-doodle i::after { content: ""; position: absolute; top: 8px; width: 5px; height: 27px; background: var(--sun); border: 3px solid var(--ink); border-radius: 0 0 4px 4px; }
.hurdle-doodle i::before { left: 4px; transform: rotate(7deg); }
.hurdle-doodle i::after { right: 4px; transform: rotate(-7deg); }
.bowling-doodle i:first-child { position: absolute; left: 3px; bottom: 3px; width: 29px; height: 29px; background: var(--mint); border: 3px solid var(--ink); border-radius: 50%; }
.bowling-doodle i:first-child::before { content: ""; position: absolute; left: 9px; top: 7px; width: 4px; height: 4px; background: var(--ink); border-radius: 50%; box-shadow: 7px 2px 0 var(--ink), 2px 8px 0 var(--ink); }
.bowling-doodle i:last-child { position: absolute; right: 3px; top: 2px; width: 15px; height: 38px; background: var(--cream); border: 3px solid var(--ink); border-radius: 50% 50% 42% 42%; transform: rotate(9deg); }
.bowling-doodle i:last-child::before { content: ""; position: absolute; left: -1px; right: -1px; top: 10px; height: 4px; border-top: 3px solid var(--coral); border-bottom: 3px solid var(--coral); }

.sync-card {
  grid-area: sync;
  align-self: stretch;
  min-height: 490px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--coral);
  border: var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 0 var(--ink);
  transform: rotate(1deg);
}

.sync-step { display: flex; align-items: center; gap: 10px; align-self: stretch; }
.sync-step > span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--sun);
  font-family: var(--display);
  font-weight: 900;
}
.sync-step p { margin: 0; font-family: var(--display); font-size: 15px; font-weight: 900; line-height: 1.05; }

.qr-frame {
  width: min(210px, 70%);
  aspect-ratio: 1;
  margin: 18px 0 12px;
  padding: 12px;
  background: var(--white);
  border: var(--line);
  border-radius: var(--radius-md);
  transform: rotate(-2deg);
}
.qr-frame img { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.sync-divider { width: 100%; display: flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 900; letter-spacing: 1px; }
.sync-divider::before, .sync-divider::after { content: ""; height: 2px; flex: 1; background: var(--ink); }

.room-code {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: clamp(42px, 6vw, 68px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 10px;
  font-variant-numeric: tabular-nums;
}

.join-link {
  max-width: 100%;
  margin-top: 10px;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-panel {
  grid-area: roster;
  padding-top: 28px;
  border-top: 2px dashed var(--ink);
}

.roster-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.roster-heading h2 { margin: 0; font-family: var(--display); font-size: 28px; letter-spacing: -1px; }
.roster-heading p { max-width: 340px; margin: 0 0 4px; color: var(--ink-soft); text-align: right; }
.player-roster { min-height: 112px; padding: 18px 0; display: flex; gap: 12px; overflow-x: auto; }

.racer-chip {
  width: 110px;
  min-width: 110px;
  padding: 10px 8px;
  text-align: center;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius-md);
  animation: pop-in 240ms cubic-bezier(.23,1,.32,1) both;
}
.racer-chip svg { width: 54px; height: 48px; overflow: visible; }
.racer-chip b { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.racer-chip.is-empty { display: grid; place-items: center; color: rgba(23,32,42,.38); background: transparent; border-style: dashed; font-family: var(--display); font-size: 28px; }

.start-button,
.controller-primary {
  min-height: 64px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--ink);
  background: var(--sun);
  border: var(--line);
  border-radius: var(--radius-md);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms cubic-bezier(.23,1,.32,1), box-shadow 120ms;
}
.start-button { width: 100%; }
.start-button span, .controller-primary { font-family: var(--display); font-size: 22px; font-weight: 900; }
.start-button small { font-size: 12px; font-weight: 700; }
.start-button:hover:not(:disabled), .controller-primary:hover { transform: translate(-2px, -2px); }
.start-button:active:not(:disabled), .controller-primary:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.start-button:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }

/* Race */
.race-view { background: var(--mint); }
.race-hud {
  height: 82px;
  padding: 10px 20px;
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  align-items: center;
  gap: 16px;
  background: var(--paper);
  border-bottom: var(--line);
}
.sport-badge { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 22px; }
.sport-badge > span { width: 44px; height: 44px; display: grid; place-items: center; background: var(--sun); border: 2px solid var(--ink); border-radius: 50%; }
.race-callout { text-align: center; font-family: var(--display); font-size: clamp(18px, 3vw, 34px); font-weight: 900; letter-spacing: -1px; }
.timer-box { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.timer-box > span { font-size: 10px; font-weight: 900; letter-spacing: 1.4px; }
.timer-box output { padding: 7px 10px; color: var(--white); background: var(--ink); border: 3px solid var(--ink); border-radius: 7px; font-family: monospace; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.canvas-frame { position: relative; height: calc(100vh - 250px); min-height: 440px; }
#raceCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; color: var(--white); font-family: var(--display); font-size: min(30vw, 240px); font-weight: 900; -webkit-text-stroke: 7px var(--ink); text-shadow: 10px 10px 0 var(--coral-dark); }
.countdown.is-pop { animation: countdown-pop 460ms cubic-bezier(.23,1,.32,1) both; }
.standings { min-height: 70px; padding: 9px 18px; display: flex; gap: 8px; background: var(--paper); border-top: var(--line); overflow-x: auto; }
.standing-item { min-width: 128px; display: flex; align-items: center; gap: 8px; }
.standing-place { width: 28px; height: 28px; display: grid; place-items: center; background: var(--cream); border: 2px solid var(--ink); border-radius: 6px; font-family: var(--display); font-weight: 900; }
.standing-item:first-child .standing-place { background: var(--sun); }
.standing-item svg { width: 34px; height: 34px; }
.standing-copy { min-width: 0; }
.standing-copy b { display: block; max-width: 76px; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.standing-copy span { display: block; color: var(--ink-soft); font-size: 10px; font-variant-numeric: tabular-nums; }

.results-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(23,32,42,.76); }
.results-card { width: min(640px, 100%); max-height: 90vh; padding: clamp(24px, 5vw, 48px); overflow-y: auto; background: var(--paper); border: 4px solid var(--ink); border-radius: var(--radius-lg); box-shadow: 12px 12px 0 var(--sun); animation: results-in 280ms cubic-bezier(.23,1,.32,1) both; }
.results-card h2 { margin: 0 0 20px; font-family: var(--display); font-size: clamp(38px, 7vw, 70px); line-height: .9; letter-spacing: -3px; }
.results-list { display: grid; gap: 8px; }
.result-row { min-height: 58px; padding: 8px 12px; display: grid; grid-template-columns: 40px 42px 1fr auto; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 10px; background: var(--white); }
.result-row:first-child { background: var(--sun); transform: rotate(-1deg); }
.result-row > b:first-child { font-family: var(--display); font-size: 24px; }
.result-row svg { width: 38px; height: 38px; }
.result-row time { font-family: monospace; font-weight: 900; }
.results-actions { margin-top: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.paper-button { min-height: 64px; padding: 10px 16px; background: var(--white); border: var(--line); border-radius: var(--radius-md); font-family: var(--display); font-size: 18px; font-weight: 900; cursor: pointer; }
.paper-button:active { transform: scale(.97); }

/* Controller */
.controller-page { min-height: 100dvh; background: var(--coral); overscroll-behavior: none; }
.controller-shell { min-height: 100dvh; display: flex; flex-direction: column; background-image: radial-gradient(circle at 8px 8px, rgba(23,32,42,.13) 1.5px, transparent 2px); background-size: 22px 22px; }
.controller-header { min-height: 64px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--sun); border-bottom: var(--line); }
.mini-wordmark { color: var(--ink); font-family: var(--display); font-size: 14px; font-weight: 900; text-decoration: none; }
.mini-wordmark b { padding: 2px 4px; color: var(--white); background: var(--coral); border: 1px solid var(--ink); }
.controller-header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.language-button { min-height: 40px; padding: 3px; display: inline-grid; grid-template-columns: 1fr 1fr; gap: 2px; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; font-family: var(--display); font-size: 10px; font-weight: 900; cursor: pointer; }
.language-button span { min-width: 32px; padding: 7px 6px; border-radius: 999px; opacity: .5; }
.language-button span.is-active { color: var(--white); background: var(--ink); opacity: 1; }
.language-button:active { transform: scale(.97); }
.controller-status { font-size: 9px; font-weight: 900; letter-spacing: 1.3px; }
.motion-button { min-height: 40px; padding: 6px 9px; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; font-size: 9px; font-weight: 900; letter-spacing: .7px; cursor: pointer; }
.motion-button[aria-pressed="true"] { background: var(--mint); }
.motion-button:disabled { opacity: .48; cursor: not-allowed; }
.controller-view { flex: 1; min-height: calc(100dvh - 64px); padding: 28px 20px; }
.join-view { background: var(--paper); }
.join-view h1 { max-width: 480px; font-size: clamp(50px, 16vw, 78px); }
.join-form { max-width: 560px; margin: 32px auto 0; display: grid; gap: 9px; }
.join-form label, .join-form legend { font-size: 11px; font-weight: 900; letter-spacing: 1.5px; }
.join-form input { width: 100%; height: 56px; padding: 8px 14px; color: var(--ink); background: var(--paper-deep); border: 2px solid var(--ink); border-radius: var(--radius-sm); font-family: var(--display); font-size: 22px; font-weight: 900; text-transform: uppercase; }
.join-form input::placeholder { color: rgba(23,32,42,.35); }
.join-form fieldset { min-width: 0; margin: 12px 0 0; padding: 0; border: 0; }
.join-form legend { margin-bottom: 8px; }
.avatar-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-choice { min-width: 0; aspect-ratio: 1; padding: 4px; display: grid; place-items: center; background: var(--white); border: 2px solid var(--ink); border-radius: 12px; cursor: pointer; }
.avatar-choice svg { width: 56px; height: 52px; max-width: 100%; }
.avatar-choice.is-selected { background: var(--mint); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.form-error { min-height: 18px; margin: 0; color: #a21f38; font-size: 12px; font-weight: 900; }
.controller-primary { width: 100%; margin-top: 4px; background: var(--sun); }

.waiting-view { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; overflow-y: auto; text-align: center; background: var(--mint); }
.hero-avatar { width: 112px; height: 112px; display: grid; flex: 0 0 auto; place-items: center; background: var(--paper); border: var(--line); border-radius: 50%; box-shadow: 6px 6px 0 var(--ink); transform: rotate(-4deg); }
.hero-avatar svg { width: 80px; height: 80px; }
.waiting-view .eyebrow { margin-top: 18px; }
.waiting-view h1 { font-size: clamp(42px, 13vw, 64px); }
.waiting-view > p:not(.eyebrow) { max-width: 330px; margin: 8px 0 14px; font-size: 14px; line-height: 1.4; }
.waiting-playbook { width: min(100%, 430px); color: var(--ink); background: var(--paper); border: var(--line); border-radius: var(--radius-md); box-shadow: 5px 5px 0 var(--ink); text-align: left; }
.waiting-playbook header { min-height: 48px; padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--sun); border-bottom: 3px solid var(--ink); border-radius: calc(var(--radius-md) - 3px) calc(var(--radius-md) - 3px) 0 0; }
.waiting-playbook header span { font-size: 9px; font-weight: 900; letter-spacing: 1.4px; }
.waiting-playbook header strong { font-family: var(--display); font-size: 22px; }
.waiting-playbook > p { margin: 0; padding: 12px; font-family: var(--display); font-size: 15px; font-weight: 900; line-height: 1.25; text-wrap: pretty; }
.waiting-playbook > div { padding: 9px 12px; display: grid; grid-template-columns: 62px 1fr; gap: 8px; align-items: start; border-top: 2px dashed rgba(23,32,42,.35); font-size: 11px; font-weight: 800; line-height: 1.35; }
.waiting-playbook > div b { padding: 3px 5px; background: var(--coral); border: 2px solid var(--ink); border-radius: 999px; font-size: 9px; letter-spacing: .7px; text-align: center; }
.waiting-playbook > div:last-child b { background: var(--mint); }
.wiggle-phone { margin-top: 12px; display: grid; gap: 2px; font-size: 10px; font-weight: 900; letter-spacing: 1px; }
.wiggle-phone span { font-family: var(--display); font-size: 34px; animation: wiggle 900ms cubic-bezier(.77,0,.175,1) infinite alternate; }

.control-view { padding: 0; display: flex; flex-direction: column; background: var(--coral); user-select: none; touch-action: none; }
.control-meta { min-height: 72px; padding: 10px 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--paper); border-bottom: var(--line); }
.control-meta > div { text-align: center; }
.control-meta span { display: block; color: var(--ink-soft); font-size: 9px; font-weight: 900; letter-spacing: 1.2px; }
.control-meta b { display: block; margin-top: 3px; font-family: var(--display); font-size: 20px; font-variant-numeric: tabular-nums; }
.bowling-setup[hidden] { display: none; }
.bowling-setup { min-height: 98px; padding: 9px 12px; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(128px, .88fr); gap: 9px; color: var(--ink); background: var(--paper); border-bottom: var(--line); }
.bowling-setup-group { min-width: 0; display: grid; align-content: center; gap: 5px; }
.bowling-setup-group > b { font-size: 9px; font-weight: 900; letter-spacing: 1.1px; }
.bowling-stepper, .bowling-aim { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 5px; }
.bowling-aim { grid-template-columns: repeat(3, minmax(44px, 1fr)); }
.bowling-setup button { min-width: 44px; height: 44px; padding: 0; display: grid; place-items: center; color: var(--ink); background: var(--cream); border: 2px solid var(--ink); border-radius: 9px; font: 900 22px/1 var(--display); box-shadow: 2px 2px 0 var(--ink); cursor: pointer; }
.bowling-setup button[aria-pressed="true"] { background: var(--mint); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.bowling-setup button:active:not(:disabled) { box-shadow: 0 0 0 var(--ink); transform: translate(2px, 2px); }
.bowling-setup button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }
.bowling-stepper output { min-width: 0; height: 44px; padding: 0 3px; display: grid; place-items: center; overflow: hidden; background: var(--sun); border: 2px solid var(--ink); border-radius: 9px; font: 900 10px/1 var(--display); text-align: center; text-overflow: ellipsis; }
.gesture-pad { position: relative; flex: 1; min-height: 260px; overflow: hidden; background: var(--coral); border-bottom: var(--line); cursor: grab; }
.gesture-pad:active { cursor: grabbing; }
.gesture-pattern { position: absolute; inset: 0; opacity: .4; background-image: radial-gradient(circle, var(--ink) 1.4px, transparent 1.7px); background-size: 13px 13px; mask-image: linear-gradient(to bottom, transparent, black 20%, black 80%, transparent); }
.gesture-guide { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; place-items: center; pointer-events: none; }
.gesture-guide i { width: 22px; height: 22px; border: 4px solid var(--white); border-radius: 50%; box-shadow: 0 0 0 3px var(--ink); }
.gesture-guide i:first-child::after, .gesture-guide i:last-of-type::after { content: ""; position: absolute; top: calc(50% - 2px); width: 28%; border-top: 4px dashed var(--white); }
.gesture-guide i:first-child::after { left: 16%; }
.gesture-guide i:last-of-type::after { right: 16%; }
.gesture-guide b { position: absolute; top: 61%; padding: 7px 10px; background: var(--sun); border: 2px solid var(--ink); border-radius: 999px; font-size: 11px; letter-spacing: 1.3px; }
.gesture-burst { position: absolute; width: 68px; height: 68px; margin: -34px 0 0 -34px; border: 5px solid var(--sun); border-radius: 50%; opacity: 0; pointer-events: none; }
.gesture-burst.is-live { animation: burst 260ms cubic-bezier(.23,1,.32,1); }
.gesture-instruction { min-height: 58px; margin: 0; padding: 12px 20px; display: grid; place-items: center; background: var(--sun); font-family: var(--display); font-size: 16px; font-weight: 900; text-align: center; }
.control-help { padding: 10px 14px; display: grid; gap: 7px; background: var(--paper); border-top: 3px solid var(--ink); }
.control-help p { margin: 0; display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: start; color: var(--ink-soft); font-size: 11px; font-weight: 800; line-height: 1.3; }
.control-help b { padding: 3px 5px; color: var(--ink); background: var(--mint); border: 2px solid var(--ink); border-radius: 999px; font-size: 9px; letter-spacing: .7px; text-align: center; }
.control-help p:first-child b { background: var(--sun); }
.progress-rail { height: 18px; padding: 3px; background: var(--paper); border-top: 2px solid var(--ink); }
.progress-rail span { display: block; width: 0; height: 100%; background: var(--mint); border-right: 2px solid var(--ink); transition: width 120ms linear; }
.control-view[data-sport="cycle"] .gesture-pad { background: var(--sun); }
.control-view[data-sport="cycle"] .gesture-guide { grid-template-columns: 1fr; }
.control-view[data-sport="cycle"] .gesture-guide i:first-child { width: 160px; height: 160px; border-style: dashed; }
.control-view[data-sport="cycle"] .gesture-guide i:last-of-type { display: none; }
.control-view[data-sport="cycle"] .gesture-guide i:first-child::after { display: none; }
.control-view[data-sport="cycle"] .gesture-guide b { top: 66%; }
.control-view[data-sport="swim"] .gesture-pad { background: var(--pool); }
.control-view[data-sport="swim"] .gesture-guide { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.control-view[data-sport="swim"] .gesture-guide i:first-child::after, .control-view[data-sport="swim"] .gesture-guide i:last-of-type::after { width: 0; height: 23%; top: auto; left: calc(50% - 2px); border-top: 0; border-left: 4px dashed var(--white); }
.control-view[data-sport="swim"] .gesture-guide i:first-child::after { top: 19%; }
.control-view[data-sport="swim"] .gesture-guide i:last-of-type::after { bottom: 19%; }
.control-view[data-sport="pickleball"] .gesture-pad { background: var(--cream); }
.control-view[data-sport="pickleball"] .gesture-pad::after { content: ""; position: absolute; inset: 8% 50% 8% auto; border-right: 5px dashed var(--ink); opacity: .32; }
.control-view[data-sport="pickleball"] .gesture-guide b { background: var(--coral); }
.control-view[data-sport="hurdles"] .gesture-pad { background: var(--coral); }
.control-view[data-sport="hurdles"] .gesture-pad::after { content: "↑\A JUMP"; white-space: pre; position: absolute; left: 50%; top: 20%; z-index: 1; width: 86px; height: 86px; display: grid; place-items: center; transform: translateX(-50%); color: var(--white); border: 4px dashed var(--white); border-radius: 50%; font-family: var(--display); font-size: 13px; font-weight: 900; line-height: 1.15; text-align: center; pointer-events: none; }
.control-view[data-sport="hurdles"] .gesture-guide b { top: 67%; background: var(--sun); }
.control-view[data-sport="bowling"] .gesture-pad { background: var(--sun); }
.control-view[data-sport="bowling"] .gesture-pad::after { content: ""; position: absolute; left: 20%; right: 20%; top: 8%; bottom: 0; background: rgba(255,253,245,.28); border: 4px solid var(--ink); clip-path: polygon(35% 0, 65% 0, 100% 100%, 0 100%); pointer-events: none; }
.control-view[data-sport="bowling"] .gesture-guide { z-index: 1; grid-template-columns: 1fr; }
.control-view[data-sport="bowling"] .gesture-guide i:first-child { width: 58px; height: 58px; align-self: end; margin-bottom: 68px; border-width: 5px; background: var(--mint); }
.control-view[data-sport="bowling"] .gesture-guide i:first-child::before { content: ""; position: absolute; left: 50%; bottom: 31%; height: 42%; border-left: 5px dashed var(--white); }
.control-view[data-sport="bowling"] .gesture-guide i:first-child::after { width: 0; height: 0; left: calc(50% - 12px); top: 23%; border: 12px solid transparent; border-bottom-color: var(--white); }
.control-view[data-sport="bowling"] .gesture-guide i:last-of-type { display: none; }
.control-view[data-sport="bowling"] .gesture-guide b { top: 68%; background: var(--coral); }

@media (max-height: 780px) {
  .control-view[data-sport="bowling"] .gesture-pad { min-height: 210px; }
  .control-view[data-sport="bowling"] .control-help { display: none; }
}

.finish-view { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: var(--sun); }
.finish-kicker { margin: 0; font-size: 12px; font-weight: 900; letter-spacing: 2px; }
.finish-place { margin: 10px 0; font-family: var(--display); font-size: min(42vw, 190px); font-weight: 900; line-height: .8; letter-spacing: -10px; -webkit-text-stroke: 5px var(--ink); color: var(--coral); text-shadow: 8px 8px 0 var(--paper); }
.finish-place sup { margin-left: 4px; font-size: .2em; letter-spacing: 0; -webkit-text-stroke: 1px var(--ink); vertical-align: top; }
.finish-view h1 { margin-top: 14px; font-size: clamp(42px, 14vw, 70px); }
.finish-view > p:last-child { max-width: 290px; line-height: 1.45; }

@keyframes pop-in { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes countdown-pop { 0% { opacity: 0; transform: scale(.75) rotate(-5deg); } 40% { opacity: 1; transform: scale(1.05) rotate(2deg); } 100% { opacity: 0; transform: scale(1.18); } }
@keyframes results-in { from { opacity: 0; transform: scale(.95) rotate(-2deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes wiggle { from { transform: translateX(-18px) rotate(-8deg); } to { transform: translateX(18px) rotate(8deg); } }
@keyframes burst { from { opacity: 1; transform: scale(.4); } to { opacity: 0; transform: scale(1.5); } }

@media (max-width: 820px) {
  .game-shell { margin: 6px; }
  .lobby-view { grid-template-columns: 1fr; grid-template-areas: "copy" "sports" "sync" "roster"; padding: 28px 20px 40px; }
  .sync-card { min-height: 440px; transform: none; }
  .race-hud { grid-template-columns: auto 1fr auto; }
  .sport-badge b, .timer-box > span { display: none; }
  .timer-box output { font-size: 20px; }
  .results-actions { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar { min-height: 70px; padding: 10px 12px; }
  .wordmark { gap: 4px; font-size: 14px; }
  .connection-pill { display: none; }
  .lobby-copy h1 { font-size: 48px; letter-spacing: -3px; }
  .sport-picker { grid-template-columns: 1fr; }
  .sport-card { min-height: 82px; flex-direction: row; align-items: center; }
  .roster-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .roster-heading p { text-align: left; }
  .room-code { font-size: 52px; }
  .race-hud { height: 72px; padding: 8px; }
  .race-callout { font-size: 15px; }
  .canvas-frame { height: calc(100vh - 220px); min-height: 440px; }
}

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