:root{
  --bg: oklch(0.91 0.01 70);
  --ink: oklch(0.22 0.02 60);
  --muted: oklch(0.55 0.02 60);
  --line: oklch(0.85 0.015 70);
  --court: oklch(0.78 0.08 55);
  --court-dk: oklch(0.68 0.09 50);
  --ball: oklch(0.66 0.18 45);
  --ball-dk: oklch(0.48 0.17 40);
  --rim: oklch(0.58 0.19 30);
  --net: oklch(0.98 0.005 70);
  --good: oklch(0.68 0.17 145);
  --bad:  oklch(0.60 0.20 25);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
  font-family: Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-feature-settings: "ss01","cv11";
  -webkit-font-smoothing: antialiased;
  overflow:hidden;
}
#stage{
  position:fixed; inset:0;
  display:grid; place-items:center;
  overflow:hidden;
}
canvas{
  display:block;
  background: var(--bg);
  cursor: none;
}
.hud{
  position: fixed; inset: 0;
  pointer-events: none;
  padding: 22px 26px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.hud .group{
  display:flex; flex-direction:column; gap:6px;
}
.hud .group.right{ align-items:flex-end; text-align:right }
.hud .group.center{ align-items:center; text-align:center }
.label{
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 600;
}
.value{
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.value.sm{ font-size: 16px; font-weight:500 }
.mute-btn{
  position: fixed; bottom: 20px; right: 22px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; padding: 0;
  pointer-events: auto;
  z-index: 5;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.mute-btn:hover{ color: var(--ink); border-color: var(--ink); }
.mute-btn svg{ width: 16px; height: 16px; display:block; }
.mute-btn .mute-off{ display: none; }
.mute-btn[aria-pressed="true"] .mute-on{ display: none; }
.mute-btn[aria-pressed="true"] .mute-off{ display: block; }
.mute-btn[aria-pressed="true"]{ color: var(--muted); }
body.mobile-on .mute-btn{ bottom: 14px; right: 14px; }
.pill{
  display:inline-flex; gap:8px; align-items:center;
  padding: 6px 10px; border:1px solid var(--line);
  border-radius: 999px; background: color-mix(in oklab, var(--bg), white 30%);
  font-size: 11.5px; color: var(--muted);
}
.pill kbd{
  font: 600 10.5px/1 ui-monospace,Menlo,Consolas,monospace;
  background: var(--ink); color: var(--bg);
  padding: 3px 5px; border-radius: 4px;
  letter-spacing: 0.04em;
}
.share-pill{
  position: fixed; bottom: 20px; left: 22px;
  display: inline-flex; gap: 8px; align-items: center;
  padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in oklab, var(--bg), white 30%);
  font-size: 11.5px; color: var(--muted);
  cursor: pointer; pointer-events: auto;
  z-index: 6;
  transition: color 120ms, border-color 120ms;
}
.share-pill:hover{ color: var(--ink); border-color: var(--ink); }
.share-pill .room-id{
  font: 600 11.5px/1 ui-monospace,Menlo,Consolas,monospace;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.share-pill svg{ width: 13px; height: 13px; }
.share-pill.copied{ color: var(--good); border-color: var(--good); }
body.mobile-on .share-pill{ bottom: 14px; left: 14px; }
.scoreboard{
  position: fixed; bottom: 62px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
  max-width: 80vw;
}
body.mobile-on .scoreboard{ bottom: 78px; }
.scoreboard .row{
  display: inline-flex; gap: 8px; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  background: color-mix(in oklab, var(--bg), white 40%);
  border: 1px solid var(--line);
}
.scoreboard .dot{
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.scoreboard .name{ color: var(--ink); font-weight: 600; }
.scoreboard .score{
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}
.scoreboard .row.me .name::after{
  content: ' (you)';
  color: var(--muted);
  font-weight: 400;
}
.scoreboard .row.poss{
  background: oklch(0.98 0.005 70);
  border-color: var(--ink);
}
.scoreboard .row.poss .name::before{
  content: '🏀 ';
}
.toast{
  position:fixed; left: 50%; top: 110px;
  transform: translate(-50%, 8px);
  font-weight: 600; font-size: 42px; letter-spacing:-0.02em;
  opacity: 0; transition: opacity .25s, transform .35s;
  color: var(--good);
  pointer-events:none;
  text-align: center;
  text-shadow: 0 1px 0 color-mix(in oklab, var(--bg), white 50%);
}
.toast.show{ opacity:1; transform: translate(-50%, 0) }
.toast.miss{ color: var(--bad) }
.footer{
  position: fixed; left:0; right:0; bottom: 14px;
  display:flex; justify-content:center; gap:10px;
  pointer-events:none;
}
.timer-wrap{
  display:flex; flex-direction:column; align-items:center; gap:6px;
}
.value.timer{
  font-variant-numeric: tabular-nums;
  transition: color .2s, transform .15s;
}
.value.timer.warn{
  color: var(--bad);
  animation: timerPulse 1s ease-in-out infinite;
}
@keyframes timerPulse{
  0%,100%{ transform: scale(1); }
  50%{ transform: scale(1.08); }
}
/* Game-over overlay */
#gameover{
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: oklch(0.22 0.02 60 / 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 40;
  animation: gofade .35s ease-out;
}
#gameover.open{ display:flex; }
@keyframes gofade{
  from{ opacity:0; }
  to{ opacity:1; }
}
#gameover .card{
  background: oklch(0.98 0.005 70);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 44px 32px;
  min-width: 360px;
  box-shadow: 0 30px 80px oklch(0 0 0 / 0.25);
  text-align: center;
  animation: gopop .4s cubic-bezier(.2,1.4,.4,1);
}
@keyframes gopop{
  from{ transform: translateY(14px) scale(.94); opacity:0; }
  to{ transform: translateY(0) scale(1); opacity:1; }
}
#gameover .eyebrow{
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
#gameover h1{
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 22px;
  color: var(--ink);
}
#gameover .stats{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}
#gameover .stat .label{
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 4px;
}
#gameover .stat .num{
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
#gameover .newbest{
  display:inline-block;
  margin-bottom: 18px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--good);
  color: oklch(0.98 0.005 70);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#gameover .actions{
  display:flex; gap:10px; justify-content:center; flex-wrap:wrap;
}
#gameover button.play{
  border: 0;
  background: var(--ink);
  color: oklch(0.98 0.005 70);
  font: 600 15px/1 Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.02em;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .12s, background .2s;
}
#gameover button.play:hover{
  background: var(--ball-dk);
  transform: translateY(-1px);
}
#gameover button.share{
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: 600 15px/1 Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.02em;
  padding: 14px 22px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform .12s, background .2s, border-color .2s;
}
#gameover button.share:hover{
  background: color-mix(in oklab, var(--bg), white 20%);
  border-color: var(--ink);
  transform: translateY(-1px);
}
#gameover button.share svg{ width:16px; height:16px; }
#gameover button.share.copied{
  background: var(--good);
  color: oklch(0.98 0.005 70);
  border-color: var(--good);
}
#gameover .hint{
  display:block;
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
@media (max-width: 640px){
  .value{font-size:22px}
}

/* ---------- Mobile controls ---------- */
/* Everything under .mobile-on only renders on touch devices. */
#mobileControls{ display: none; }
body.mobile-on #mobileControls{ display: block; }
body.mobile-on .footer{ display: none; }
body.mobile-on canvas{ cursor: default; }

/* Reflow HUD: bigger values so they're legible over the action. */
body.mobile-on .hud{
  padding: 14px 16px;
  font-size: 13px;
}
body.mobile-on .hud .value{ font-size: 26px; }
body.mobile-on .hud .value.sm{ font-size: 13px; }
body.mobile-on .hud .label{ font-size: 10px; letter-spacing: 0.14em; }

/* Portrait: a bit tighter to leave more room for the action. */
@media (orientation: portrait){
  body.mobile-on .hud{ padding: 10px 12px; }
  body.mobile-on .hud .value{ font-size: 22px; }
  body.mobile-on .hud .value.sm{ font-size: 12px; }
}

/* Joystick layout + base/knob come from <virtual-joystick>.
   Everything below is game-specific: right-stick charge ring
   and the warm "charging" tint on the knob. */
virtual-joystick[side="right"].charging .vj-knob{
  background: var(--ball);
  box-shadow: 0 2px 14px oklch(0.66 0.18 45 / 0.5), 0 0 0 3px oklch(0.66 0.18 45 / 0.25);
}
virtual-joystick[side="right"] .charge-ring{
  position: absolute;
  left: 50%; top: 50%;
  width: 132px; height: 132px;
  transform: translate(-50%,-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
@media (orientation: portrait){
  virtual-joystick[side="right"] .charge-ring{ width: 118px; height: 118px; }
}
virtual-joystick[side="right"].charging .charge-ring{ opacity: 1; }
.charge-ring circle{
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
}
.charge-ring .track{ stroke: oklch(0.22 0.02 60 / 0.15); }
.charge-ring .fill{ stroke: var(--ball); transition: none; }

/* Dunk button — middle-right, above the right stick */
.dunk-btn{
  position: fixed;
  right: 30px;
  bottom: 212px;
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--ink);
  color: oklch(0.98 0.005 70);
  border: 0;
  font: 700 11px/1 Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 4px 14px oklch(0 0 0 / 0.25);
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  z-index: 30;
  transition: opacity .2s, transform .1s, background .2s;
  display: none;
}
body.mobile-on .dunk-btn{ display: flex; align-items: center; justify-content: center; }
.dunk-btn.disabled{
  opacity: 0.28;
  background: var(--muted);
}
.dunk-btn:active:not(.disabled){
  transform: scale(0.92);
  background: var(--ball-dk);
}
.dunk-btn .dunk-icon{
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.dunk-btn .dunk-icon svg{ width: 22px; height: 22px; }
@media (orientation: portrait){
  .dunk-btn{ right: 20px; bottom: 182px; width: 66px; height: 66px; font-size: 10px; }
  .dunk-btn .dunk-icon svg{ width: 20px; height: 20px; }
}

/* First-run tutorial overlay */
#tutorial{
  position: fixed; inset: 0;
  background: oklch(0.22 0.02 60 / 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 60;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  animation: gofade .3s ease-out;
}
#tutorial.open{ display: flex; }
#tutorial .card{
  background: oklch(0.98 0.005 70);
  border-radius: 20px;
  padding: 26px 26px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 30px 80px oklch(0 0 0 / 0.35);
  text-align: center;
}
#tutorial h2{
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
#tutorial .sub{
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 20px;
  letter-spacing: 0.02em;
}
#tutorial .steps{
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}
#tutorial .step{
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  align-items: center;
  text-align: left;
}
#tutorial .step .glyph{
  width: 48px; height: 48px;
  border-radius: 50%;
  background: oklch(0.94 0.01 70);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#tutorial .step .glyph.circle-o{
  border: 1.5px solid var(--ink);
  background: transparent;
  position: relative;
}
#tutorial .step .glyph.circle-o::after{
  content:'';
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ink);
  position: absolute;
}
#tutorial .step .glyph.dunk{
  background: var(--ink);
}
#tutorial .step .glyph.dunk svg{ width: 22px; height: 22px; color: oklch(0.98 0.005 70); }
#tutorial .step .txt strong{
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
#tutorial .step .txt span{
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.35;
}
#tutorial button.go{
  border: 0;
  background: var(--ink);
  color: oklch(0.98 0.005 70);
  font: 600 15px/1 Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.02em;
  padding: 14px 34px;
  border-radius: 999px;
  cursor: pointer;
  width: 100%;
}
#tutorial button.go:active{ transform: scale(0.98); }
/* Tweaks panel */
#tweaks{
  position:fixed; right:16px; bottom:16px; z-index:50;
  width:260px;
  background: oklch(0.98 0.005 70 / 0.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
  box-shadow: 0 10px 30px oklch(0 0 0 / 0.12);
  font-size: 13px;
  display: none;
}
#tweaks.open{ display:block; }
#tweaks header{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:10px;
}
#tweaks h3{ margin:0; font-size:13px; font-weight:600; letter-spacing:.02em; text-transform:uppercase; color:var(--muted); }
#tweaks button.close{
  border:0; background:transparent; color:var(--muted); font-size:18px; line-height:1;
  cursor:pointer; padding:0 2px;
}
#tweaks .row{ display:block; margin: 10px 0; }
#tweaks .row label{ display:flex; justify-content:space-between; font-size:12px; color:var(--ink); margin-bottom:4px; }
#tweaks .row label .v{ color:var(--muted); font-variant-numeric: tabular-nums; }
#tweaks input[type=range]{ width:100%; }
#tweaks .foot{ display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:10px; font-size:11px; color:var(--muted); }
#tweaks .foot .btns{ display:flex; gap:6px; }
#tweaks .foot button{
  border:1px solid var(--line); background:transparent; color:var(--ink);
  border-radius:8px; padding:4px 8px; cursor:pointer; font-size:11px;
}
#tweaks .foot button:hover{ background:rgba(0,0,0,0.04); }
#tweaks .foot button.copied{ color:#1a7f3c; border-color:#1a7f3c; }
