:root {
  --ink: #1d2140;
  --paper: #fff7ec;
  --green: #2ec4a6;
  --pop: #ff5c8a;
  --sun: #ffd166;
  --blue: #4d7cff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fdcff; }
body { font-family: "Nunito", system-ui, sans-serif; color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; }
canvas { display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.chip { background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 3px 3px 0 var(--ink); padding: 6px 14px; }
#holeBox { position: absolute; top: 14px; left: 14px; display: flex; flex-direction: column; line-height: 1.1; }
#holeNum { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 22px; }
#holeName { font-size: 13px; opacity: 0.7; }
#holePar { font-size: 13px; font-weight: 800; color: var(--pop); }
#turn { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 20px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); display: inline-block; flex: none; }
#players { position: absolute; top: 70px; right: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#players .chip { display: flex; align-items: center; gap: 8px; font-size: 15px; padding: 4px 12px; }
#players .chip.active { background: var(--sun); }
#players b { font-family: "Baloo 2", sans-serif; font-size: 18px; min-width: 22px; text-align: right; }
#players small { opacity: 0.65; font-size: 13px; }
.round { pointer-events: auto; width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; box-shadow: 3px 3px 0 var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; }
.round:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.round svg { width: 22px; height: 22px; }
#mute { position: absolute; top: 14px; right: 14px; }
#quit { position: absolute; top: 14px; right: 70px; }
#camBtns { position: absolute; right: 14px; bottom: 16px; display: flex; gap: 10px; }
#power { position: absolute; left: 50%; bottom: 80px; transform: translateX(-50%); width: min(320px, 60vw); height: 20px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; box-shadow: 3px 3px 0 var(--ink); overflow: hidden; }
#powerFill { height: 100%; width: 0; background: linear-gradient(90deg, #2ec4a6, #ffd166 60%, #ff5c8a); background-size: min(320px, 60vw) 100%; }
#hint { position: absolute; left: 50%; bottom: 116px; transform: translateX(-50%); font-weight: 800; font-size: 15px; color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(29, 33, 64, 0.6); white-space: nowrap; transition: opacity 0.3s; }
#hint.off { opacity: 0; }

#popup { position: fixed; left: 50%; top: 34%; transform: translate(-50%, -50%); font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: clamp(40px, 9vw, 76px); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); pointer-events: none; opacity: 0; white-space: nowrap; text-align: center; line-height: 1; }
#popup small { display: block; font-size: 0.42em; -webkit-text-stroke-width: 2px; text-shadow: 3px 3px 0 var(--ink); margin-top: 6px; }
#popup.show { animation: punch 1.6s ease-out; }
@keyframes punch { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6) rotate(-4deg); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-3deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95) rotate(-3deg); } }

/* ---------- screens ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(29, 33, 64, 0.35); overflow-y: auto; }
.card { background: var(--paper); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 7px 7px 0 var(--ink); padding: 26px 26px 22px; width: min(420px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; margin: auto; }
.card.wide { width: min(720px, 100%); }
.badge { display: inline-block; font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 14px; letter-spacing: 3px; background: var(--pop); color: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 2px 14px; box-shadow: 3px 3px 0 var(--ink); transform: rotate(-3deg); }
h1 { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: clamp(48px, 12vw, 68px); line-height: 0.9; margin: 6px 0 0; }
h1 span { color: var(--green); }
h2 { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 32px; line-height: 1; margin: 0; }
.card p { margin: 0; line-height: 1.45; }
.keys { font-size: 14px; opacity: 0.7; }
.go { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 22px; letter-spacing: 1px; color: #fff; background: var(--green); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 26px 5px; box-shadow: 4px 4px 0 var(--ink); cursor: pointer; }
.go:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.go:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.go.alt { background: var(--blue); font-size: 18px; padding: 6px 20px 4px; }
.link { background: none; border: none; text-decoration: underline; cursor: pointer; font-weight: 800; opacity: 0.75; padding: 4px; }
.versus { margin-top: 8px; padding-top: 14px; border-top: 3px dashed rgba(29, 33, 64, 0.25); display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.field { font: inherit; font-size: 18px; font-weight: 800; text-align: center; color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 7px 12px; width: 210px; user-select: text; -webkit-user-select: text; }
.join { display: flex; gap: 8px; }
.join .field { width: 110px; letter-spacing: 4px; }

.code { font-family: "Baloo 2", sans-serif; font-size: 60px; font-weight: 800; letter-spacing: 8px; line-height: 1; color: var(--pop); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
#qr:not(:empty) { width: 200px; height: 200px; padding: 8px; background: #fff; border: 3px solid var(--ink); border-radius: 12px; }
#qr svg { width: 100%; height: 100%; display: block; }
.url { font-size: 12px; opacity: 0.6; word-break: break-all; }
#lobbyStatus { font-weight: 800; }

/* scorecard */
.table { width: 100%; overflow-x: auto; }
.table table { border-collapse: collapse; margin: 0 auto; font-size: 15px; }
.table th, .table td { border: 2px solid var(--ink); padding: 4px 7px; min-width: 32px; text-align: center; background: #fff; }
.table th { background: var(--sun); font-family: "Baloo 2", sans-serif; }
.table td.name { text-align: left; white-space: nowrap; font-weight: 800; }
.table .now { background: #d9fff5; }
.table .tot { font-weight: 800; background: #ffe9a8; }
.s-ace { background: #ff5c8a !important; color: #fff; }
.s-under { background: #b9f5e7 !important; }
.s-over { background: #ffe1e1 !important; }
#cardButtons { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 4px; }

@media (max-width: 560px) {
  #turn { top: 74px; font-size: 17px; }
  #players { top: 120px; }
  #holeNum { font-size: 19px; }
  #hint { font-size: 13px; }
  #camBtns { left: 50%; right: auto; transform: translateX(-50%); }
}
