:root {
  --font: 'Fredoka', 'Baloo 2', 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --pink: #ff4f6d; --blue: #3ec9ff; --yellow: #ffd23f; --mint: #5dff7f; --purple: #c77dff;
  --ink: #1b1b2f; --panel: rgba(20, 24, 48, 0.62); --panel-border: rgba(255,255,255,0.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #5ec6ff; font-family: var(--font); color: #fff;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
b { font-weight: 700; }
kbd { font-family: inherit; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; font-size: .85em; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.pill { border-radius: 999px; padding: 8px 18px; font-weight: 700; letter-spacing: .5px; }
.small { font-size: 13px; }
.sep { opacity: .5; margin: 0 8px; }

#me-card { position: absolute; left: 16px; top: 16px; padding: 12px 14px; min-width: 210px; }
.me-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pink); box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.me-name { font-weight: 700; font-size: 16px; }
.gauge-row { display: flex; align-items: center; gap: 12px; }
.gauge-wrap { width: 84px; height: 84px; display: grid; place-items: center; }
.gauge { width: 30px; height: 34px; border-radius: 50% 50% 48% 48%; background: var(--pink); transition: width .15s, height .15s, background .3s; display: grid; place-items: center; font-size: 12px; color: rgba(0,0,0,.65); font-weight: 700; position: relative; box-shadow: inset -6px -8px 14px rgba(0,0,0,.18), inset 6px 8px 14px rgba(255,255,255,.35); }
.gauge::after { content: ''; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: inherit; border-top: 8px solid currentColor; opacity: .0; }
.gauge.danger { animation: wobble .25s infinite; }
@keyframes wobble { 0%,100% { transform: scale(1,1) } 50% { transform: scale(1.06,.95) } }
.gauge-text { line-height: 1; }
#gauge-pct { font-size: 32px; font-weight: 700; }
.gauge-label { font-size: 11px; letter-spacing: 2px; opacity: .75; }
.bar-label { font-size: 10px; letter-spacing: 2px; opacity: .75; margin-top: 8px; }
.bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.15); overflow: hidden; margin-top: 3px; }
.bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7ef0ff, #3ec9ff); border-radius: 999px; transition: width .08s linear; }
.vent-ready { margin-top: 8px; font-size: 12px; font-weight: 700; color: #5dff7f; letter-spacing: 1px; transition: opacity .2s; }
.vent-ready.cooling { color: #fff; opacity: .5; }

#top-center { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: max-content; max-width: calc(100vw - 16px); }
#round-pill { white-space: nowrap; }
#room-pill { pointer-events: auto; cursor: pointer; background: rgba(0,0,0,.25); font-weight: 500; opacity: .85; }
#room-pill:hover { opacity: 1; background: rgba(0,0,0,.4); }
#storm-label.danger { color: #ff8ab0; }

#scoreboard { position: absolute; right: 16px; top: 16px; padding: 10px 12px; min-width: 190px; font-size: 14px; }
.score-row { display: flex; align-items: center; gap: 8px; padding: 4px 2px; border-radius: 8px; }
.score-row.me { background: rgba(255,255,255,.1); }
.score-row.dead { opacity: .5; }
.score-row .dot { width: 12px; height: 12px; box-shadow: none; flex: none; }
.score-row .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-row .bot { font-size: 10px; opacity: .6; }
.score-row .sc { font-weight: 700; min-width: 24px; text-align: right; }
.score-row .inf { font-size: 11px; opacity: .7; min-width: 36px; text-align: right; }

#feed { position: absolute; left: 16px; bottom: 56px; display: flex; flex-direction: column; gap: 6px; max-width: 46vw; }
.feed-line { background: rgba(0,0,0,.35); border-radius: 10px; padding: 6px 12px; font-size: 14px; animation: feedin .25s ease-out; }
.feed-line.fade { opacity: 0; transition: opacity .8s; }
@keyframes feedin { from { transform: translateX(-20px); opacity: 0 } to { transform: none; opacity: 1 } }

#banner a.share { pointer-events: auto; display: inline-block; margin-top: 10px; padding: 6px 14px; border-radius: 999px; background: rgba(0,0,0,.45); color: #fff; text-decoration: none; font-size: 15px; }
#banner a.share:hover { background: rgba(0,0,0,.7); }
#banner { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); text-align: center; width: min(94vw, 980px); animation: bannerin .35s cubic-bezier(.2,1.4,.4,1); }
#banner.match { background: rgba(16, 18, 44, .62); border: 1px solid rgba(255,255,255,.14); border-radius: 26px; padding: 18px 28px 22px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); width: min(92vw, 760px); }
#banner.match #banner-main { font-size: clamp(26px, 4.5vw, 54px); }
#banner.match #banner-sub { font-size: clamp(14px, 2vw, 22px); line-height: 1.35; }
#banner .awards { display: inline-block; margin-top: 6px; font-size: .8em; opacity: .95; }
#banner-main { font-size: clamp(34px, 7vw, 76px); font-weight: 700; text-shadow: 0 6px 0 rgba(0,0,0,.25), 0 0 40px rgba(255,255,255,.35); letter-spacing: 1px; }
#banner-sub { font-size: clamp(16px, 2.5vw, 26px); font-weight: 600; opacity: .95; text-shadow: 0 3px 0 rgba(0,0,0,.25); margin-top: 6px; }
@keyframes bannerin { from { transform: translateX(-50%) scale(.3); opacity: 0 } to { transform: translateX(-50%) scale(1); opacity: 1 } }

#countdown { position: absolute; left: 50%; top: 62%; transform: translate(-50%, -50%); font-size: clamp(90px, 20vw, 220px); font-weight: 700; text-shadow: 0 10px 0 rgba(0,0,0,.25); animation: pop .6s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: translate(-50%,-50%) scale(1.8); opacity: 0 } to { transform: translate(-50%,-50%) scale(1); opacity: 1 } }

#hint { position: absolute; right: 16px; bottom: 16px; padding: 8px 14px; opacity: .8; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(0,0,0,.7); padding: 10px 18px; border-radius: 12px; font-weight: 600; animation: toastin .25s; z-index: 12; pointer-events: none; max-width: 90vw; text-align: center; }
@keyframes toastin { from { transform: translateX(-50%) translateY(10px); opacity: 0 } to { transform: translateX(-50%); opacity: 1 } }

/* ---------- MENU ---------- */
#menu { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow-y: auto; background: radial-gradient(ellipse at 50% 30%, rgba(94,198,255,.1), rgba(20,20,60,.55) 70%); pointer-events: auto; }
.menu-inner { width: min(560px, 94vw); padding: 24px; background: rgba(16, 18, 44, .72); border: 1px solid rgba(255,255,255,.14); border-radius: 28px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 20px 60px rgba(0,0,0,.35); text-align: center; margin: 16px 0; }
#logo { margin: 4px 0 0; font-size: clamp(54px, 12vw, 92px); font-weight: 700; letter-spacing: -2px; line-height: 1; }
#logo span { display: inline-block; animation: bob 1.8s ease-in-out infinite; text-shadow: 0 6px 0 rgba(0,0,0,.25); }
#logo span:nth-child(1) { color: #ff4f6d; animation-delay: 0s } #logo span:nth-child(2) { color: #ff9f43; animation-delay: .1s }
#logo span:nth-child(3) { color: #ffd23f; animation-delay: .2s } #logo span:nth-child(4) { color: #5dff7f; animation-delay: .3s }
#logo span:nth-child(5) { color: #4fffe3; animation-delay: .4s } #logo span:nth-child(6) { color: #3ec9ff; animation-delay: .5s }
#logo span:nth-child(7) { color: #c77dff; animation-delay: .6s } #logo span:nth-child(8) { color: #ff4f6d; animation-delay: .7s }
@keyframes bob { 0%,100% { transform: translateY(0) scale(1,1) } 50% { transform: translateY(-8px) scale(1.06,.94) } }
.tagline { margin: 6px 0 18px; font-size: 18px; opacity: .9; }
.row { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
input[type=text], input:not([type]) { font: inherit; font-size: 18px; font-weight: 600; padding: 10px 14px; border-radius: 14px; border: 2px solid rgba(255,255,255,.2); background: rgba(0,0,0,.3); color: #fff; outline: none; width: 220px; text-align: center; }
input:focus { border-color: var(--blue); }
#code { width: 150px; text-transform: uppercase; letter-spacing: 3px; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform .1s; }
.swatch:hover { transform: scale(1.12); }
.swatch.sel { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.buttons { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.btn { font: inherit; font-size: 18px; font-weight: 700; padding: 12px 18px; border-radius: 16px; border: 0; background: rgba(255,255,255,.12); color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; transition: transform .08s, background .15s; pointer-events: auto; }
.btn small { font-weight: 500; font-size: 12px; opacity: .75; }
.btn:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.big { font-size: 22px; padding: 16px 20px; }
.btn.primary { background: linear-gradient(135deg, #ff4f6d, #ff9f43); box-shadow: 0 8px 0 rgba(0,0,0,.2); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.code-row { margin-top: 4px; }
.code-row .btn { padding: 10px 18px; font-size: 16px; }
.bots-row { font-size: 14px; opacity: .9; }
.bots-row input { accent-color: var(--pink); width: 140px; }
.status { font-size: 12px; opacity: .7; margin-top: 6px; min-height: 16px; }
.status.ok { color: #5dff7f; } .status.bad { color: #ff8ab0; }
.join-box { background: rgba(94,198,255,.15); border: 1px solid rgba(94,198,255,.4); border-radius: 18px; padding: 12px; margin: 10px 0; }
.join-title { margin-bottom: 8px; font-size: 16px; }
.howto { text-align: left; margin: 18px auto 6px; font-size: 14px; display: grid; gap: 6px; opacity: .92; max-width: 460px; }
.howto .k { display: inline-block; width: 26px; }
.credits { margin-top: 12px; font-size: 12px; opacity: .55; }
.credits a { color: inherit; }

#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; align-content: center; gap: 12px; background: #5ec6ff; color: #fff; font-size: 20px; font-weight: 700; transition: opacity .4s; }
#loading.gone { opacity: 0; pointer-events: none; }
.spinner { width: 46px; height: 52px; border-radius: 50% 50% 48% 48%; background: #ff4f6d; animation: inflate 1s ease-in-out infinite alternate; }
@keyframes inflate { from { transform: scale(.7) } to { transform: scale(1.15) } }

/* ---------- touch controls ---------- */
.stick { position: fixed; bottom: 70px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.3); pointer-events: none; z-index: 6; display: none; }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255,255,255,.5); }
#stick-l { left: 28px; } #stick-r { right: 28px; border-color: rgba(255,79,109,.6); }
#vent-btn { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; width: 80px; height: 80px; border-radius: 50%; background: rgba(93,255,127,.8); color: #113; font: inherit; font-weight: 700; font-size: 16px; border: 0; z-index: 7; display: none; box-shadow: 0 6px 0 rgba(0,0,0,.25); pointer-events: auto; }
#vent-btn:active { transform: translateX(-50%) translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#vent-btn.cooling { background: rgba(255,255,255,.35); color: rgba(0,0,0,.5); }
body.touch .stick { display: block; } body.touch #vent-btn { display: block; } body.touch #hint { display: none; }


#clip-btn { position: absolute; right: 16px; bottom: 62px; pointer-events: auto; cursor: pointer; background: rgba(0,0,0,.35); color: #fff; border: 1px solid var(--panel-border); font: inherit; font-size: 13px; font-weight: 600; }
#clip-btn:hover { background: rgba(255,79,109,.55); }
#clip-btn.hidden { display: none; }

#touch-bar { display: none; gap: 6px; }
#touch-bar button { pointer-events: auto; font: inherit; font-size: 12px; font-weight: 700; color: #fff; background: rgba(0,0,0,.35); border: 1px solid var(--panel-border); padding: 5px 10px; }
body.touch #touch-bar { display: flex; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 7; }
/* ---------- compact layout for phones & touch ---------- */
body.touch #clip-btn { display: none; }
body.touch #feed { left: 50%; right: auto; bottom: auto; top: 150px; transform: translateX(-50%); align-items: center; max-width: 80vw; }
@media (max-width: 640px) { body.touch #feed { top: auto; bottom: calc(236px + env(safe-area-inset-bottom)); } }
body.touch .feed-line { font-size: 12px; padding: 4px 10px; text-align: center; }
body.touch #me-card { min-width: 0; padding: 6px 10px; }
body.touch .me-row { margin-bottom: 2px; } body.touch .me-name { font-size: 13px; }
body.touch .gauge-wrap { width: 48px; height: 48px; } body.touch #gauge-pct { font-size: 20px; } body.touch .gauge-label { font-size: 9px; }
body.touch .bar-label { display: none; } body.touch .bar { height: 7px; width: 120px; }
body.touch .vent-ready { display: none; }
body.touch #scoreboard { min-width: 0; max-width: 46vw; font-size: 11px; padding: 6px 8px; }
body.touch .score-row { padding: 2px; gap: 5px; } body.touch .score-row .dot { width: 9px; height: 9px; } body.touch .score-row .inf { min-width: 28px; font-size: 10px; }
body.touch .score-row .bot { display: inline; font-size: 0; } body.touch .score-row .bot::before { content: '🤖'; font-size: 10px; }
body.touch #toast { bottom: 180px; font-size: 13px; }
body.touch .howto { display: none; } body.touch .howto-touch { display: grid; }
.howto-touch { display: none; text-align: left; margin: 14px auto 6px; font-size: 13px; gap: 5px; max-width: 460px; opacity: .92; }
@media (max-width: 640px) {
  #top-center { top: 6px; } #round-pill { font-size: 11px; padding: 5px 11px; } .sep { margin: 0 5px; } #room-pill { font-size: 10px; padding: 3px 10px; }
  #me-card { left: 8px; top: 60px; } #scoreboard { right: 8px; top: 60px; }
  #banner { top: 16%; width: 94vw; } #banner-main { font-size: clamp(26px, 9vw, 44px); line-height: 1.05; } #banner-sub { font-size: 15px; }
  #countdown { top: 60%; font-size: 120px; }
  .menu-inner { padding: 14px; border-radius: 20px; } .howto { font-size: 12px; gap: 4px; } #logo { font-size: 15vw; } .tagline { font-size: 15px; margin-bottom: 10px; }
  .btn.big { font-size: 19px; padding: 12px 16px; } .btn { font-size: 16px; padding: 10px 14px; } .buttons { gap: 8px; margin: 12px 0 6px; }
  input:not([type]) { width: 170px; font-size: 16px; }
}
@media (max-height: 500px) {
  #me-card { top: 8px; left: 8px; } #scoreboard { top: 8px; right: 8px; max-width: 40vw; }
  body.touch #feed { top: auto; bottom: calc(142px + env(safe-area-inset-bottom)); max-width: 46vw; }
  #top-center { top: 4px; } #room-pill { display: none; }
  #banner { top: 14%; } #banner-main { font-size: clamp(24px, 6vw, 40px); } #countdown { font-size: 90px; top: 50%; }
  body.touch #vent-btn { bottom: calc(60px + env(safe-area-inset-bottom)); width: 70px; height: 70px; font-size: 14px; }
  .menu-inner { padding: 10px 16px; margin: 6px 0; } .howto { display: none; } #logo { font-size: 40px; } .tagline { margin: 2px 0 8px; font-size: 14px; }
  .buttons { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0 4px; } .btn, .btn.big { font-size: 14px; padding: 8px 12px; }
}

/* ---------- invited via link: make JOIN the obvious button ---------- */
#menu.invited #btn-quick { background: rgba(255,255,255,.12); box-shadow: none; font-size: 16px; padding: 10px 14px; }
#menu.invited .code-row { display: none; }
.join-box .btn { width: 100%; }
/* ---------- notched phones ---------- */
body.touch #me-card { left: calc(8px + env(safe-area-inset-left)); }
body.touch #scoreboard { right: calc(8px + env(safe-area-inset-right)); }
body.touch #vent-btn { bottom: calc(84px + env(safe-area-inset-bottom)); }

/* landscape phones: these must come last to win over the safe-area rules above */
@media (max-height: 500px) {
  body.touch #vent-btn { bottom: calc(60px + env(safe-area-inset-bottom)); }
  body.touch #feed { top: auto; bottom: calc(142px + env(safe-area-inset-bottom)); }
  body.touch #touch-bar { bottom: calc(8px + env(safe-area-inset-bottom)); }
}
