* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1226; font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif; color: #fff; user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(10,16,40,.45), rgba(5,8,20,.8)); z-index: 20; }
.join-card { background: rgba(255,255,255,.08); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.18); border-radius: 22px; padding: 28px 34px; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-width: 720px; width: calc(100% - 40px); }
.join-card.small { max-width: 460px; text-align: center; }
h1 { margin: 0; font-size: 46px; letter-spacing: 1px; color: #fff; text-shadow: 0 0 18px #ff5e5e, 0 3px 0 #b3202a; }
h1::before { content: '❄ '; } h1::after { content: ' ❄'; }
h2 { margin: 0 0 12px; }
.sub { color: #c9d4ff; margin: 6px 0 18px; }
.join-grid { display: flex; gap: 24px; align-items: center; }
.join-form { flex: 1; display: flex; flex-direction: column; gap: 14px; }
#preview { width: 260px; height: 320px; border-radius: 16px; background: radial-gradient(circle at 50% 40%, #2c3a6e, #141a36); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #dfe6ff; }
input[type=text], input:not([type]) { font: inherit; font-size: 18px; padding: 10px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: rgba(0,0,0,.3); color: #fff; outline: none; }
input:focus { border-color: #ff6b6b; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #dfe6ff; }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; }
button { font: inherit; cursor: pointer; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; padding: 8px 14px; border-radius: 12px; }
button.on { background: #c0392b; border-color: #ff8a80; }
button.big { background: linear-gradient(#e74c3c, #b3202a); border: none; font-size: 20px; padding: 14px; font-weight: bold; box-shadow: 0 4px 0 #7a1219; width: 100%; }
button.big:active { transform: translateY(2px); box-shadow: 0 2px 0 #7a1219; }
button.ghost { margin-top: 14px; width: 100%; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 2px #ff6b6b; }
.status { color: #ffd2d2; min-height: 1em; margin: 0; font-size: 14px; }
.tip { margin: 16px 0 0; color: #9fb0ea; font-size: 13px; text-align: center; }
.settings { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; text-align: left; }
.settings .check { flex-direction: row; align-items: center; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; text-align: left; font-size: 14px; color: #dfe6ff; }
.controls b { color: #fff; display: inline-block; min-width: 64px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#crosshair { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#crosshair .ch { width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.4); transition: all .12s; }
#crosshair.far .ch { width: 14px; height: 14px; background: transparent; border: 2px solid rgba(255,255,255,.75); box-shadow: 0 0 0 1px rgba(0,0,0,.3); transform: translate(-4px,-4px); }
#crosshair.empty .ch { opacity: .35; }
#hitmarker { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; transform: translate(-50%,-50%) rotate(45deg); opacity: 0; }
#hitmarker::before, #hitmarker::after { content: ''; position: absolute; background: #fff; box-shadow: 0 0 3px #000; }
#hitmarker::before { left: 12px; top: 0; width: 2px; height: 26px; }
#hitmarker::after { top: 12px; left: 0; height: 2px; width: 26px; }
#hitmarker.show { animation: hm .35s ease-out; }
#hitmarker.face::before, #hitmarker.face::after { background: #ff4d4d; }
@keyframes hm { 0% { opacity: 1; transform: translate(-50%,-50%) rotate(45deg) scale(1.4); } 100% { opacity: 0; transform: translate(-50%,-50%) rotate(45deg) scale(1); } }

#scoopMeter { position: absolute; left: 50%; top: calc(50% + 46px); transform: translateX(-50%); text-align: center; }
#scoopMeter .bar { width: 180px; height: 12px; border-radius: 6px; background: rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.6); overflow: hidden; position: relative; }
#scoopMeter .fill { height: 100%; width: 0; background: linear-gradient(90deg, #9fd8ff, #ffffff); }
#scoopMeter .mark { position: absolute; top: 0; bottom: 0; width: 2px; background: #ff6b6b; }
#scoopMeter .label { font-size: 13px; margin-top: 4px; text-shadow: 0 1px 3px #000; }

#ammo { position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.ball { width: 34px; height: 34px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.35); position: relative; }
.ball.full { border: 2px solid rgba(255,255,255,.9); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.ball.next { transform: scale(1.18); box-shadow: 0 0 12px rgba(255,255,255,.6); }
.ball .pk { position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%); font-size: 10px; color: #cfe; white-space: nowrap; text-shadow: 0 1px 2px #000; }
.ball.cake { background: radial-gradient(circle at 40% 35%, #a0522d, #5a2d0c) !important; border-color: #f5deb3; }

#health { position: absolute; left: 24px; bottom: 24px; width: 240px; }
#health .lbl { font-size: 13px; margin-bottom: 4px; text-shadow: 0 1px 3px #000; }
#health .bar { height: 16px; border-radius: 8px; background: rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.6); overflow: hidden; }
#health .fill { height: 100%; width: 100%; background: linear-gradient(90deg, #5dade2, #f5b041, #e74c3c); background-size: 240px 100%; transition: width .2s; }

#lb { position: absolute; top: 16px; left: 16px; background: rgba(6,10,30,.5); border-radius: 12px; padding: 8px 12px; font-size: 13px; min-width: 210px; }
#lb.big { font-size: 16px; min-width: 300px; padding: 12px 16px; }
#lb table { border-collapse: collapse; width: 100%; }
#lb td { padding: 2px 4px; } #lb td.n { text-align: right; width: 34px; }
#lb tr.me td { color: #ffd966; font-weight: bold; }
#lb th { font-weight: normal; color: #9fb0ea; text-align: right; padding: 0 4px 4px; font-size: 11px; }
#lb th:first-child { text-align: left; }

#feed { position: absolute; top: 16px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 440px; }
.feed-item { background: rgba(6,10,30,.55); padding: 6px 12px; border-radius: 10px; font-size: 14px; animation: fin .3s ease-out; transition: opacity .8s; text-align: right; }
.feed-item.me { background: rgba(160,30,40,.7); }
@keyframes fin { from { transform: translateX(30px); opacity: 0; } }

#center { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); text-align: center; font-size: 34px; font-weight: bold; text-shadow: 0 3px 10px #000; transition: opacity .5s; opacity: 0; white-space: nowrap; }
#center small { display: block; font-size: 18px; font-weight: normal; color: #cfe2ff; }
#toast { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); background: rgba(6,10,30,.7); padding: 8px 16px; border-radius: 10px; opacity: 0; transition: opacity .4s; }
#fcBanner { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); background: linear-gradient(#8b4513, #5a2d0c); border: 2px solid #f5deb3; padding: 8px 18px; border-radius: 12px; font-weight: bold; animation: wob 1s infinite; }
@keyframes wob { 50% { transform: translateX(-50%) rotate(-1.5deg); } }
#damageDir { position: absolute; inset: 0; }
.dmg-arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transition: opacity 1s; }
.dmg-arrow::after { content: ''; position: absolute; left: -40px; top: -190px; width: 80px; height: 30px; border-radius: 50% 50% 0 0; background: radial-gradient(ellipse at 50% 100%, rgba(255,255,255,.95), rgba(160,210,255,0) 70%); }
#splat { position: absolute; inset: 0; }
.splat { position: absolute; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.95) 30%, rgba(235,245,255,.7) 55%, rgba(255,255,255,0) 72%); transition: opacity 1.6s ease-in, transform 1.6s ease-in; }
#frost { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(170,215,255,.7) 100%); opacity: 0; transition: opacity .3s; }
#clickToPlay { position: absolute; top: 60%; left: 50%; transform: translateX(-50%); background: rgba(6,10,30,.7); padding: 10px 20px; border-radius: 12px; }
#help { position: absolute; bottom: 8px; right: 14px; font-size: 12px; color: rgba(255,255,255,.6); }
.dmg-num { position: absolute; font-weight: bold; font-size: 22px; color: #fff; text-shadow: 0 2px 4px #000, 0 0 8px #5dade2; pointer-events: none; transition: transform 1s ease-out, opacity 1s ease-in; }

/* ---------- phones & tablets ---------- */
.touch-only { display: none; }
body.touch .touch-only { display: revert; }
body.touch .controls.touch-only { display: grid; }
body.touch .desktop-only, body.touch #help, body.touch #clickToPlay { display: none !important; }
body.touch, body.touch * { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
body.touch #game { touch-action: none; }

/* join screen: scroll if the phone is short, stack the preview */
.overlay { overflow-y: auto; }
@media (max-width: 720px), (max-height: 520px) {
  .overlay { align-items: flex-start; padding: max(12px, env(safe-area-inset-top)) 0 12px; }
  .join-card { padding: 16px 18px; border-radius: 16px; margin: auto; }
  h1 { font-size: 30px; }
  .sub { margin: 2px 0 10px; font-size: 14px; }
  .join-grid { gap: 14px; }
  .join-form { gap: 10px; }
  #preview { width: 150px; height: 185px; }
  button.big { font-size: 18px; padding: 11px; }
  .tip { margin-top: 10px; }
  .settings { margin: 10px 0; }
  .controls { font-size: 12px; }
}
@media (max-width: 520px) {
  .join-grid { flex-direction: column-reverse; }
  .join-form { width: 100%; }
}
@media (max-height: 520px) and (min-width: 521px) {
  .join-card.small { max-width: 560px; }
}

/* in-game HUD rearranged around the thumbs */
body.touch #health { left: 50%; transform: translateX(-50%); top: max(8px, env(safe-area-inset-top)); bottom: auto; width: 180px; }
body.touch #health .lbl { display: none; }
body.touch #lb { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); font-size: 11px; min-width: 150px; padding: 6px 8px; }
body.touch #lb.big { font-size: 14px; min-width: 260px; }
body.touch #feed { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); max-width: 38%; gap: 4px; }
body.touch .feed-item { font-size: 11px; padding: 4px 8px; }
body.touch #center { font-size: 22px; white-space: normal; width: 80%; top: 24%; }
body.touch #center small { font-size: 14px; }
body.touch #toast { bottom: auto; top: 64px; font-size: 13px; }
body.touch #ammo { bottom: max(14px, env(safe-area-inset-bottom)); gap: 6px; }
body.touch .ball { width: 26px; height: 26px; }
body.touch .ball .pk { font-size: 8px; bottom: -12px; }
body.touch #scoopMeter { top: calc(50% + 34px); }
body.touch #fcBanner { top: 40px; font-size: 13px; }

#touch { position: fixed; inset: 0; z-index: 12; touch-action: none; user-select: none; -webkit-user-select: none; }
.t-zone { position: absolute; top: 56px; bottom: 0; }
.t-left { left: 0; width: 45%; }
.t-right { right: 0; width: 55%; }
.t-stick { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.t-stick::before { content: ''; position: absolute; left: -64px; top: -64px; width: 128px; height: 128px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.07); }
.t-stick.run::before { border-color: rgba(255,217,102,.8); box-shadow: 0 0 16px rgba(255,217,102,.45); }
.t-knob { position: absolute; left: -28px; top: -28px; width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.55); box-shadow: 0 2px 8px rgba(0,0,0,.4); }

.t-btn { position: absolute; border-radius: 50%; padding: 0; font-weight: bold; font-size: 13px; color: #fff; text-shadow: 0 1px 2px #000;
  background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.45); touch-action: none; }
.t-btn.down { background: rgba(255,255,255,.38); transform: scale(.94); }
.t-btn.on { background: rgba(192,57,43,.65); border-color: #ff8a80; }
.t-throw { width: 92px; height: 92px; right: calc(22px + env(safe-area-inset-right)); bottom: calc(34px + env(safe-area-inset-bottom)); font-size: 16px;
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,.45), rgba(200,225,255,.18)); }
.t-scoop { width: 70px; height: 70px; right: calc(128px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); }
.t-jump { width: 62px; height: 62px; right: calc(36px + env(safe-area-inset-right)); bottom: calc(140px + env(safe-area-inset-bottom)); }
.t-crouch { width: 56px; height: 56px; right: calc(118px + env(safe-area-inset-right)); bottom: calc(110px + env(safe-area-inset-bottom)); }
.t-small { width: 40px; height: 40px; font-size: 18px; border-radius: 12px; top: max(8px, env(safe-area-inset-top)); }
.t-scores { left: calc(50% - 140px); }
.t-menu { left: calc(50% + 100px); }
.t-shoulder { top: auto; right: calc(118px + env(safe-area-inset-right)); bottom: calc(176px + env(safe-area-inset-bottom)); font-size: 16px; }

/* the game needs landscape on a phone */
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  body.touch.playing #rotate { display: flex; position: fixed; inset: 0; z-index: 30; background: #0d1226; align-items: center; justify-content: center; text-align: center; font-size: 56px; }
  #rotate p { font-size: 18px; color: #c9d4ff; }
}

/* sideways phone: two-column join form so "Go to the park" fits without scrolling */
@media (max-height: 520px) and (min-width: 521px) {
  .join-card:not(.small) { max-width: 780px; padding: 12px 16px; }
  #join h1 { font-size: 24px; }
  #join .sub, #join .tip { display: none; }
  .join-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; align-items: end; margin-top: 8px; }
  .join-form .status { grid-column: 1 / -1; }
  .join-form input:not([type]) { font-size: 15px; padding: 7px 10px; }
  .join-form .seg button { padding: 6px 10px; }
  .swatches { gap: 6px; }
  .swatches button { width: 26px; height: 26px; }
  .field, label { gap: 4px; font-size: 12px; }
  button.big { font-size: 16px; padding: 9px; }
  #preview { width: 130px; height: 160px; }
}
