:root{--bg:#0b1020;--panel:rgba(255,255,255,.12);--panel2:rgba(255,255,255,.07);--text:#0b1020;--muted:rgba(11,16,32,.62);--accent:#2563eb;--danger:#e11d48;--ok:#059669;--stroke:#2563eb;--dot:#0b1020;}
*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Apple Color Emoji","Segoe UI Emoji";}
body{margin:0;color:var(--text);
	background-color: #0b1020;
	/* Use image background; keep subtle fallback gradients behind it */
	background-image:
		url('/static/9dots_bg.png'),
		radial-gradient(900px 650px at 10% 12%, rgba(255, 99, 164, .22) 0%, rgba(255, 99, 164, 0) 58%),
		radial-gradient(900px 700px at 88% 14%, rgba(103, 232, 249, .18) 0%, rgba(103, 232, 249, 0) 58%),
		linear-gradient(120deg, #0b1020, #0b1020);
	background-size: cover, 120% 120%, 120% 120%, cover;
	background-position: center, 0% 0%, 100% 0%, center;
	background-repeat: no-repeat;
	background-attachment: fixed;
}

body::before{content:"";position:fixed;inset:0;pointer-events:none;z-index:-1;
	background:
		radial-gradient(circle at 20% 20%, rgba(37, 99, 235, .12), transparent 55%),
		radial-gradient(circle at 80% 30%, rgba(225, 29, 72, .10), transparent 55%),
		radial-gradient(circle at 55% 85%, rgba(5, 150, 105, .10), transparent 60%);
	filter:saturate(1.05);
}

@keyframes bgShift{
	0%{background-position: 0% 0%, 100% 0%, 50% 100%, 0% 100%, 0% 50%}
	50%{background-position: 18% 10%, 82% 8%, 55% 88%, 8% 86%, 100% 50%}
	100%{background-position: 0% 0%, 100% 0%, 50% 100%, 0% 100%, 0% 50%}
}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}

header{padding:18px 18px 8px;display:flex;gap:12px;align-items:center;justify-content:center;position:relative}
header .brand{display:flex;flex-direction:column;align-items:center;justify-content:center}
.titleImg{max-width:min(740px, 92vw);height:auto;display:block;filter:drop-shadow(0 10px 30px rgba(0,0,0,.35))}
.logoImg{max-width:min(680px, 90vw);max-height:78px;width:auto;height:auto;display:none;object-fit:contain;
	filter:drop-shadow(0 10px 26px rgba(0,0,0,.22))}
.brandFallback{display:none;flex-direction:column;align-items:center;justify-content:center}
header .sub{color:rgba(255,255,255,.82);font-size:12px;margin-top:6px}
.headerRight{position:absolute;right:18px;top:18px;display:flex;gap:10px;align-items:center}
.participantCount{min-width:44px;height:36px;display:none;align-items:center;justify-content:center;
	padding:0 12px;border-radius:10px;
	background:rgba(255,255,255,.14);
	border:1px solid rgba(255,255,255,.18);
	color:white;font-weight:900;font-size:18px;
	backdrop-filter: blur(10px);
}

/* If title image fails, show fallback text */
header .titleImg[style*="display: none"], header .titleImg[style*="display:none"]{display:none}
header .titleImg[style*="display: none"] ~ .brandFallback, header .titleImg[style*="display:none"] ~ .brandFallback{display:flex}
header h1{margin:0;font-size:22px;letter-spacing:.2px;
	background:linear-gradient(90deg, #2563eb, #db2777, #f59e0b, #059669);
	-webkit-background-clip:text;background-clip:text;color:transparent;
}
header h1 .titleNine{font-size:1.25em;line-height:1;display:inline-block;transform:translateY(1px)}
header .sub{color:var(--muted);font-size:12px;margin-top:2px}

main{display:grid;grid-template-columns:380px 1fr;gap:14px;padding:0 18px 18px;align-items:start}
@media (max-width: 980px){main{grid-template-columns:1fr;}}

/* Participant join screen (QR scan) */
#playerJoinScreen{display:none}
body[data-role="player"] main{grid-template-columns:1fr;justify-items:center}
body[data-role="player"] #leftPanel{display:none}
body[data-role="player"] #playerJoinScreen{display:flex;flex-direction:column;align-items:center;gap:14px;
	width:100%;padding:14px 12px 18px;
}
body[data-role="player"][data-started="true"] #playerJoinScreen{display:none}

/* Player waiting (joined, not started): switch to white background */
body[data-role="player"][data-joined="true"][data-started="false"]{
	background:#ffffff !important;
	background-image:none !important;
}
body[data-role="player"][data-joined="true"][data-started="false"]::before{display:none}
body[data-role="player"][data-joined="true"][data-started="false"] header .sub{color:rgba(11,16,32,.58)}
body[data-role="player"][data-joined="true"][data-started="false"] .playerWelcome{color:#004282;text-shadow:none}

/* Player started: also white background + logo header */
body[data-role="player"][data-started="true"]{
	--text:#004282;
	--muted:rgba(0,66,130,.70);
	background:#ffffff !important;
	background-image:none !important;
}
body[data-role="player"][data-started="true"]::before{display:none}
body[data-role="player"][data-started="true"] .titleImg{display:none}
body[data-role="player"][data-started="true"] .logoImg{display:block;filter:none;
	max-width:min(680px, 90vw);max-height:78px}
body[data-role="player"][data-started="true"] header .sub{color:rgba(0,66,130,.75)}

/* Countdown (shared) */
.countdownBlock{display:none;flex-direction:column;align-items:center;justify-content:center;gap:10px}
.countdownLabel{font-weight:900;letter-spacing:.02em}
.countdownNumber{font-weight:900;line-height:1;font-size:84px}
@media (max-width: 520px){.countdownNumber{font-size:72px}}

/* Waiting page header uses logo instead of title */
body[data-role="player"][data-joined="true"][data-started="false"] .titleImg{display:none}
body[data-role="player"][data-joined="true"][data-started="false"] .logoImg{display:block;filter:none;
	max-width:min(680px, 90vw);max-height:78px}

body[data-role="player"][data-joined="true"][data-started="false"] .playerJoinCard{
	background:transparent;
	border:none;
	box-shadow:none;
	padding:0;
	width:min(520px, calc(100vw - 44px));
}
body[data-role="player"][data-joined="true"][data-started="false"] .playerHint{color:rgba(11,16,32,.55)}

/* Player countdown: replace waiting content under Welcome */
body[data-role="player"][data-countdown="true"] #playerCountdown{display:flex;color:#004282}
body[data-role="player"][data-countdown="true"] .playerFrame,
body[data-role="player"][data-countdown="true"] .rulesCard,
body[data-role="player"][data-countdown="true"] .startingSoon{display:none}

.playerWelcome{margin-top:10px;text-align:center;color:rgba(255,255,255,.92);
	font-weight:800;line-height:1.25;
	text-shadow:0 10px 30px rgba(0,0,0,.35);
}
.playerWelcomeTitle{font-weight:900}

.playerJoinCard{width:min(420px, calc(100vw - 44px));
	background:rgba(255,255,255,.92);
	border:1px solid rgba(255,255,255,.65);
	border-radius:14px;
	box-shadow:0 30px 90px rgba(0,0,0,.28);
	padding:18px 18px 16px;
}

.playerJoinForm{display:flex;flex-direction:column;gap:12px}
/* Keep room input for JS but hide it on participant view */
body[data-role="player"] .playerJoinForm #roomInput{display:none}

body[data-role="player"] .playerJoinForm #nameInput{
	height:46px;
	border-radius:10px;
	background:white;
	border:2px solid rgba(11,16,32,.20);
	text-align:center;
	font-size:16px;
}
body[data-role="player"] .playerJoinForm #btnJoin{
	height:48px;
	border-radius:10px;
	background:linear-gradient(180deg, #0b4a7a, #073b63);
	border-color:rgba(255,255,255,.22);
	box-shadow:0 14px 40px rgba(0,0,0,.22);
	font-weight:900;
	letter-spacing:.02em;
}

.playerWaiting{display:none;text-align:center;color:rgba(11,16,32,.78);font-weight:800}
body[data-role="player"][data-joined="true"] #playerJoinForm{display:none}
body[data-role="player"][data-joined="true"] .playerWaiting{display:block}

.playerWaitingWrap{display:flex;flex-direction:column;align-items:center;gap:14px;
	width:100%;
	padding:10px 0 0;
}

.playerFrame{width:min(220px, 62vw);height:auto;display:block}

.rulesCard{width:100%;
	background:rgb(202,238,251);
	border-radius:18px;
	padding:14px 16px 12px;
	color:#000;
	box-shadow:0 14px 40px rgba(0,0,0,.10);
}
.rulesCardTitle{font-weight:900;color:#000;text-align:center;margin-bottom:10px}
.rulesOl{margin:0;padding-left:22px;color:#000;font-weight:700;line-height:1.35;text-align:left}
.rulesOl li{margin:6px 0}

.startingSoon{margin-top:10px;
	width:100%;
	text-align:center;
	color:#004282;
	font-weight:900;
	padding:14px 8px;
}

.playerHint{margin-top:10px;text-align:center;color:rgba(11,16,32,.66);font-size:12px;min-height:16px}

/* Host: single column, focus on QR + Start + Leaderboard */
body[data-role="host"] main{grid-template-columns:1fr;}
body[data-role="host"]{--text:#ffffff;--muted:rgba(255,255,255,.80);}
body[data-role="host"] #statusBadge{display:none}
body[data-role="player"] #participantCount{display:none}

/* Host started play screen (white background) */
.hostPlayScreen{display:none;width:100%}
.hostPlayWrap{width:min(920px, calc(100vw - 44px));
	margin:0 auto;
	display:flex;
	flex-direction:column;
	align-items:center;
	gap:16px;
	padding:18px 0 26px;
}
.hostIntroText{text-align:center;color:#004282}
.hostPlayWrap{width:clamp(320px, 90vw, 980px);padding:clamp(10px, 2.6vh, 22px) 0 clamp(16px, 3vh, 30px)}
.hostPuzzleTitle{font-weight:900;font-size:clamp(18px, 2.2vw, 26px);letter-spacing:.02em}
.hostPuzzleSub{margin-top:6px;font-weight:800;font-size:clamp(12px, 1.5vw, 16px)}
.hostFrameImg{width:clamp(200px, 28vmin, 320px);height:auto;display:block}
.hostSloganPill{width:min(560px, 92vw);
	background:rgb(255,192,0);
	color:#fff;
	font-weight:900;
	text-align:center;
	padding:clamp(10px, 1.8vh, 14px) clamp(14px, 2.2vw, 20px);
	border-radius:10px;
	box-shadow:0 16px 40px rgba(0,0,0,.12);
}
.hostTimerBar{width:min(860px, 92vw);
	height:18px;
	border-radius:999px;
	background:rgba(11,16,32,.08);
	overflow:hidden;
	border:1px solid rgba(11,16,32,.10);
}
.hostTimerFill{height:100%;width:0%;
	background:linear-gradient(90deg, rgba(0,66,130,1), rgba(0,66,130,.75));
	border-radius:999px;
	transition:width 120ms linear;
}

.hostTimerMeta{width:min(860px, 92vw);
	display:flex;
	justify-content:flex-end;
	margin-top:6px;
}
.hostTimeLeft{
	font-weight:900;
	font-size:14px;
	letter-spacing:.02em;
	color:rgba(0,66,130,.92);
	background:rgba(255,255,255,.85);
	border:1px solid rgba(11,16,32,.10);
	border-radius:999px;
	padding:6px 10px;
	box-shadow:0 10px 22px rgba(0,0,0,.06);
}

.hostCompletedWrap{position:relative;display:flex;align-items:center;justify-content:center;
	width:min(300px, 86vw);
	margin-top:6px;
}
.hostCompletedImg{width:100%;height:auto;display:block}
.hostCompletedText{position:absolute;inset:0;
	display:flex;align-items:center;justify-content:center;
	color:#ffffff;
	font-weight:900;
	font-size:16px;
	letter-spacing:.02em;
	text-shadow:0 2px 8px rgba(0,0,0,.18);
}

.hostFinishBtn{height:44px;
	min-width:160px;
	padding:10px 18px;
	border-radius:10px;
	border:2px solid rgba(11,16,32,.35);
	background:#ffffff;
	color:#0b1020;
	font-weight:800;
	box-shadow:0 10px 22px rgba(0,0,0,.10);
}
.hostFinishBtn:disabled{opacity:.55;cursor:not-allowed}

/* When host is started, show the play screen and hide the admin panels */
body[data-role="host"][data-started="true"]{
	--text:#004282;
	--muted:rgba(0,66,130,.70);
	background:#ffffff !important;
	background-image:none !important;
}
body[data-role="host"][data-started="true"]::before{display:none}
body[data-role="host"][data-started="true"] main{grid-template-columns:1fr;justify-items:center}
body[data-role="host"][data-started="true"] #hostPlayScreen{display:block}
body[data-role="host"][data-started="true"] #leftPanel,
body[data-role="host"][data-started="true"] #gameCard{display:none}

/* Host ended/results: show leaderboard results instead of play screen */
body[data-role="host"][data-ended="true"] #hostPlayScreen{display:none !important}
body[data-role="host"][data-ended="true"] #leftPanel{display:block !important}
body[data-role="host"][data-ended="true"] #gameCard{display:none !important}
body[data-role="host"][data-ended="true"] .hostBottomBar{display:none !important}
body[data-role="host"][data-ended="true"] #hostResultIntro{display:block}
body[data-role="host"][data-ended="true"] #leaderboardTitle{display:none}
body[data-role="host"][data-ended="true"] .grid2{display:none !important}
body[data-role="host"][data-ended="true"] #qrCard{display:none !important}
body[data-role="host"][data-ended="true"] #leftPanel{padding-bottom:28px}

/* Host started header uses logo instead of title */
body[data-role="host"][data-started="true"] .titleImg{display:none}
body[data-role="host"][data-started="true"] .logoImg{display:block;filter:none;
	max-width:min(680px, 90vw);max-height:78px}
body[data-role="host"][data-started="true"] header .sub{color:rgba(0,66,130,.75)}

body[data-role="host"] #leftPanel{max-width:980px;margin:0 auto;background:transparent;border:none;box-shadow:none;backdrop-filter:none}
body[data-role="host"] #leftPanel{padding-bottom:72px}
body[data-role="host"] #leftPanel > h2{display:none}
body[data-role="host"] #leaderboardCard{padding:10px;background:transparent;border:none;box-shadow:none;backdrop-filter:none}
body[data-role="host"] .table th,body[data-role="host"] .table td{font-size:15px;padding:12px}

/* Host layout: ensure the top join banner stays centered */
body[data-role="host"] .grid2{grid-template-columns:1fr;justify-items:center}
body[data-role="host"] #qrCard{width:min(760px, 100%);margin:0 auto}

/* Host doesn't join as a player */
body[data-role="host"] #joinControls{display:none}
body[data-role="host"] #scanHint{display:none}
body[data-role="host"] #playerControls{display:none}
body[data-role="host"] #btnCreate{display:none}

body[data-role="host"] #gameCard{display:none}
body[data-role="player"] #leaderboardCard{display:none}
body[data-role="player"] #btnCreate{display:none}
body[data-role="player"] #roomInput{display:none}
body[data-role="player"] #qr{display:none}
body[data-role="player"] #joinUrl{display:none}
body[data-role="player"] #scanHint{display:none}
body[data-role="player"] #qrCard{display:none}

/* After player joined, hide the join inputs (they already got in via QR link). */
body[data-role="player"][data-joined="true"] #joinControls{display:none}

/* Player controls are only useful after start. */
body[data-role="player"] #hostControls{display:none}
body[data-role="player"] #playerControls{display:none}
body[data-role="player"][data-started="true"] #playerControls{display:flex}

/* Default: hide game; only show for players after host starts */
#gameCard{display:none}
body[data-role="player"][data-started="true"] #gameCard{display:block}

/* Player started layout: center + simplify */
body[data-role="player"][data-started="true"] main{grid-template-columns:1fr;justify-items:center}
body[data-role="player"][data-started="true"] #gameCard{
	width:clamp(320px, 94vw, 680px);
	background:transparent;
	border:none;
	box-shadow:none;
	backdrop-filter:none;
	padding:0 0 20px;
}
body[data-role="player"][data-started="true"] #gameCard > h2{display:none}

.playerPlayIntro{display:none;text-align:center;color:#004282;margin:6px 0 10px}
.playerPlayTitle{font-weight:900;font-size:clamp(16px, 2.0vw, 22px);letter-spacing:.02em}
.playerPlaySub{margin-top:4px;font-weight:800;font-size:clamp(12px, 1.4vw, 14px)}
body[data-role="player"][data-started="true"] .playerPlayIntro{display:block}

body[data-role="player"][data-started="true"] .kpis,
body[data-role="player"][data-started="true"] .canvasWrap .small{display:none}

/* Keep the success overlay clipped to the play area */
body[data-role="player"][data-started="true"] .canvasWrap{overflow:hidden;border-radius:12px}

body[data-role="player"][data-started="true"] #gameCanvas{
	width:clamp(320px, 92vw, 600px);
	background:transparent;
	border:none;
	border-radius:0;
}

.playerPlayButtons{display:none;gap:10px;justify-content:center;align-items:center;margin-top:clamp(10px, 2vh, 16px);flex-wrap:wrap}
body[data-role="player"][data-started="true"] .playerPlayButtons{display:flex}
.playerPlayBtn{height:clamp(44px, 6vh, 52px);min-width:clamp(120px, 34vw, 180px);
	border-radius:0;
	background:rgba(0,66,130,1);
	border:1px solid rgba(0,66,130,1);
	color:#fff;
	font-weight:900;
	line-height:1.05;
	padding:clamp(8px, 1.2vh, 10px) clamp(10px, 1.6vw, 14px);
}
.playerPlayBtn:hover{filter:brightness(1.02)}

/* Player success overlay */
.playerSuccessOverlay{display:none;position:absolute;inset:0;
	background:rgb(131,193,108);
	align-items:center;justify-content:center;
	padding:clamp(10px, 3vh, 18px);
	z-index:5;
}
body[data-role="player"][data-success="true"] .playerSuccessOverlay{display:flex}
body[data-role="player"][data-success="true"] .playerPlayButtons{pointer-events:none;opacity:.35}

.playerSuccessCard{width:clamp(200px, 64%, 300px);
	background:#fff;
	border:1px solid rgba(11,16,32,.10);
	box-shadow:0 18px 50px rgba(0,0,0,.18);
	padding:clamp(12px, 2.6vh, 18px) clamp(12px, 2.4vw, 16px);
	text-align:center;
}
.playerSuccessTitle{color:rgb(78,167,46);font-weight:900;
	font-size:clamp(18px, 3.0vw, 26px);
	letter-spacing:.02em;
}
.playerSuccessTime{margin-top:6px;color:rgb(78,167,46);font-weight:900;
	font-size:clamp(14px, 2.4vw, 18px);
}
.playerCongratsImg{margin-top:10px;width:clamp(46px, 12vw, 72px);height:auto;display:block;margin-left:auto;margin-right:auto}

/* When success shows, keep the green area a bit lower so it doesn't visually crowd the subtitle */
body[data-role="player"][data-success="true"] .playerSuccessOverlay{top:clamp(10px, 2vh, 18px)}

/* Simplify UI: no reset button */
#btnReset{display:none}

body[data-role="host"][data-started="true"] main,body[data-role="host"].started main{grid-template-columns:1fr;}
body[data-role="host"][data-started="true"] #leftPanel,body[data-role="host"].started #leftPanel{max-width:1100px;margin:0 auto;}

/* Host started: make QR + control smaller, leaderboard bigger */
body[data-role="host"][data-started="true"] .grid2,body[data-role="host"].started .grid2{grid-template-columns:minmax(260px,340px) minmax(260px,340px);justify-content:center}
body[data-role="host"][data-started="true"] #qrCard,body[data-role="host"].started #qrCard,
body[data-role="host"][data-started="true"] #controlCard,body[data-role="host"].started #controlCard{padding:10px;max-width:340px;width:100%;justify-self:center}
body[data-role="host"][data-started="true"] #qr,body[data-role="host"].started #qr{min-height:240px}
body[data-role="host"][data-started="true"] #qr img,body[data-role="host"].started #qr img{max-width:220px !important;max-height:220px !important;width:220px !important;height:220px !important}

body[data-role="host"][data-started="true"] #leaderboardCard{padding:26px;}
body[data-role="host"][data-started="true"] #leaderboardCard,body[data-role="host"].started #leaderboardCard{padding:34px;}
body[data-role="host"][data-started="true"] #leaderboardCard h2,body[data-role="host"].started #leaderboardCard h2{font-size:20px}
body[data-role="host"][data-started="true"] .table th,body[data-role="host"][data-started="true"] .table td,
body[data-role="host"].started .table th,body[data-role="host"].started .table td{font-size:22px;padding:16px}

.card{background:linear-gradient(180deg,var(--panel) 0%, var(--panel2) 100%);
	border:1px solid rgba(11,16,32,.12);
	border-radius:16px;
	padding:14px;
	box-shadow:0 18px 55px rgba(11,16,32,.12);
	backdrop-filter: blur(14px);
}
.card:hover{box-shadow:0 22px 70px rgba(11,16,32,.16)}
.card h2{margin:0 0 10px;font-size:12px;color:rgba(11,16,32,.55);font-weight:800;text-transform:uppercase;letter-spacing:.10em}

.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.row > *{flex:1}

input,button,select{height:42px;border-radius:12px;border:1px solid rgba(11,16,32,.14);background:rgba(255,255,255,.55);color:var(--text);padding:0 12px;outline:none}
input:focus,button:focus{border-color:rgba(37,99,235,.45);box-shadow:0 0 0 3px rgba(37,99,235,.16)}
button{cursor:pointer;flex:0 0 auto}
button{white-space:normal;line-height:1.2}
#btnCreate,#btnStart{height:auto;padding:10px 12px}
button.primary{background:linear-gradient(90deg, rgba(37,99,235,.95), rgba(219,39,119,.85));border-color:rgba(37,99,235,.20);color:white;box-shadow:0 10px 26px rgba(37,99,235,.20)}
button.primary:hover{filter:brightness(1.02);transform:translateY(-1px)}
button.danger{background:linear-gradient(90deg, rgba(225,29,72,.90), rgba(251,191,36,.85));border-color:rgba(225,29,72,.20);color:white;box-shadow:0 10px 26px rgba(225,29,72,.16)}
button:disabled{opacity:.55;cursor:not-allowed}

.badge{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;border-radius:999px;border:1px solid rgba(11,16,32,.14);background:rgba(255,255,255,.55);color:rgba(11,16,32,.65);font-size:12px;font-weight:700}
.badge.ok{border-color:rgba(5,150,105,.20);color:rgba(5,150,105,1)}
.badge.warn{border-color:rgba(245,158,11,.22);color:rgba(161,98,7,1)}
.badge.err{border-color:rgba(225,29,72,.22);color:rgba(225,29,72,1)}

.grid2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (max-width: 980px){.grid2{grid-template-columns:1fr}}

#qr{display:flex;align-items:center;justify-content:center;min-height:320px;border-radius:12px;border:1px dashed rgba(11,16,32,.16);background:rgba(255,255,255,.32)}
.small{font-size:12px;color:var(--muted)}

/* Host join banner (match screenshot style) */
body[data-role="host"] #qrCard{background:rgba(255,255,255,.10);border:1px solid rgba(255,255,255,.18);box-shadow:0 18px 55px rgba(0,0,0,.18)}
body[data-role="host"] #qrCard > h2{display:none}
.joinBanner{display:flex;align-items:center;justify-content:space-between;gap:16px}
.joinText{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center}
.joinTitle{font-weight:900;letter-spacing:.02em;color:white;font-size:18px;line-height:1.1}
.joinSub{margin-top:6px;color:rgba(255,255,255,.92);font-weight:700}
.joinRight{flex:0 0 auto;display:flex;align-items:center;justify-content:center;gap:12px}
.joinQr{flex:0 0 auto;display:flex;align-items:center;justify-content:center}
body[data-role="host"] #qr{min-height:unset;border:none;background:transparent}
body[data-role="host"] #qr img{border-radius:8px !important;padding:4px !important}
body[data-role="host"] #joinUrl{display:none}

/* Participant count lives beside the join banner on host view */
body[data-role="host"] #participantCount{display:flex}
body[data-role="host"] #qrCard #participantCount{height:40px;min-width:48px;font-size:18px;border-radius:8px;
	background:rgba(255,255,255,.14);
	border:1px solid rgba(255,255,255,.18);
	box-shadow:0 14px 40px rgba(0,0,0,.22);
}

/* Host controls: hide the control card, use bottom bar under participants */
body[data-role="host"] #controlCard{display:none}
body[data-role="host"] #hostControls{display:none}

/* Stick host buttons lower on the screen */
.hostBottomBar{display:none;justify-content:center;gap:18px;margin-top:18px}
body[data-role="host"] .hostBottomBar{display:flex;position:fixed;left:50%;transform:translateX(-50%);bottom:18px;z-index:20;
	padding:10px 12px;border-radius:14px;
	background:rgba(11,16,32,.10);
	border:1px solid rgba(255,255,255,.16);
	backdrop-filter: blur(10px);
}
body[data-role="host"] .hostBottomBar button{min-width:150px;height:auto;padding:12px 16px}
body[data-role="host"] .hostBottomBar #btnRules{background:rgba(255,255,255,.92);border-color:rgba(255,255,255,.35);color:#0b1020;font-weight:900}

/* Host countdown replaces Rules/Start buttons */
body[data-role="host"] #hostCountdown{display:none;min-width:360px;padding:6px 18px;color:#fff}
body[data-role="host"][data-countdown="true"] #btnRules,
body[data-role="host"][data-countdown="true"] #btnStart{display:none}
body[data-role="host"][data-countdown="true"] #hostCountdown{display:flex}

/* Host participants: keep the original floating chips animation */
body[data-role="host"] #leaderboardTitle{display:block;text-align:center;color:rgba(255,255,255,.92);font-size:16px;letter-spacing:.02em;text-transform:none;margin:10px 0 10px}

/* Results intro (only visible when ended) */
#hostResultIntro{display:none;text-align:center;margin:10px auto 14px;max-width:740px}
.hostResultPuzzleTitle{color:#004282;font-weight:900;font-size:22px;letter-spacing:.02em}
.hostResultPuzzleSub{margin-top:6px;color:rgba(0,66,130,.75);font-weight:800}
body[data-role="host"] .lobbyStage{
	border:none;
	background:transparent;
	/* Keep participants visible without scrolling */
	width:min(980px, 100%);
	margin:0 auto;
	min-height:38vh;
	max-height:52vh;
	height:46vh;
	overflow:visible;
}
body[data-role="host"] #lobbyHint{display:none}

/* Host rules panel: swaps into the participants area */
.hostRulesPanel{display:none}
body[data-role="host"][data-host-rules="true"] #lobbyStage{display:none !important}
body[data-role="host"][data-host-rules="true"] #leaderboardTable{display:none !important}
body[data-role="host"][data-host-rules="true"] #leaderboardTitle{display:none !important}
body[data-role="host"][data-host-rules="true"] .hostRulesPanel{display:block}

body[data-role="host"] .hostRulesPanel{
	position:relative;
	width:min(980px, 100%);
	margin:0 auto;
	min-height:38vh;
	max-height:52vh;
	height:46vh;
	background:#fff;
	border:1px solid rgba(11,16,32,.18);
	border-radius:10px;
	box-shadow:0 22px 70px rgba(0,0,0,.18);
	overflow:hidden;
}

body[data-role="host"] .hostRulesClose{
	position:absolute;
	right:10px;
	top:10px;
	width:30px;
	height:30px;
	border-radius:999px;
	border:1px solid rgba(11,16,32,.22);
	background:rgba(255,255,255,.95);
	color:rgba(11,16,32,.70);
	font-weight:900;
	line-height:1;
	padding:0;
	display:flex;
	align-items:center;
	justify-content:center;
	box-shadow:0 10px 26px rgba(0,0,0,.12);
}
body[data-role="host"] .hostRulesClose:hover{filter:brightness(0.98)}

body[data-role="host"] .hostRulesBody{
	display:flex;
	align-items:center;
	justify-content:center;
	gap:28px;
	height:100%;
	padding:22px 26px;
}
body[data-role="host"] .hostRulesFrame{width:min(240px, 32vw);height:auto;display:block}
body[data-role="host"] .hostRulesText{max-width:min(520px, 58vw);color:#0b1020}
body[data-role="host"] .hostRulesTitle{font-weight:900;color:#0b1020;margin-bottom:10px}
body[data-role="host"] .hostRulesList{margin:0;padding-left:22px;color:#0b1020;font-weight:700;line-height:1.4;text-align:left}
body[data-role="host"] .hostRulesList li{margin:8px 0}

@media (max-width: 760px){
	body[data-role="host"] .hostRulesBody{flex-direction:column;gap:16px;justify-content:flex-start;align-items:center;padding:18px 16px}
	body[data-role="host"] .hostRulesText{max-width:92vw}
}

/* Make the floating chips more vibrant on host view */
body[data-role="host"] .lobbyChip{
	background:rgba(255,255,255,.16);
	border:1px solid rgba(255,255,255,.22);
	box-shadow:0 22px 70px rgba(0,0,0,.35);
	color:rgba(255,255,255,.96);
	text-shadow:0 1px 0 rgba(0,0,0,.28);
}
body[data-role="host"] .lobbyChip::before{
	opacity:.62;
	filter: blur(12px) saturate(1.25);
}
body[data-role="host"] .lobbyChip::after{content:"";position:absolute;inset:0;border-radius:999px;pointer-events:none;
	background:linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0));
	opacity:.65;
}

.table{width:100%;border-collapse:collapse;border-radius:12px;overflow:hidden;table-layout:fixed;background:rgba(255,255,255,.35)}
.table th,.table td{padding:10px 10px;border-bottom:1px solid rgba(11,16,32,.10);font-size:13px}
.table th{color:rgba(11,16,32,.55);text-align:left;font-weight:800}
.table tr:last-child td{border-bottom:none}

/* Lobby stage (host before start): floating joined usernames */
.lobbyStage{position:relative;min-height:340px;border-radius:12px;border:1px dashed rgba(11,16,32,.18);background:rgba(255,255,255,.32);overflow:hidden}
body[data-role="host"][data-started="true"] .lobbyStage,body[data-role="host"].started .lobbyStage{display:none}

/* Hide table before start for host; show it only after started */
body[data-role="host"] #leaderboardTable{display:none}
body[data-role="host"][data-started="true"] #leaderboardTable,body[data-role="host"].started #leaderboardTable{display:table}
body[data-role="host"][data-started="true"] #lobbyStage,body[data-role="host"].started #lobbyStage{display:none}

.lobbyStage #lobbyHint{position:absolute;left:12px;bottom:10px;opacity:.9}

.lobbyChip{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
	padding:10px 14px;border-radius:999px;
	background:rgba(255,255,255,.70);
	border:1px solid rgba(11,16,32,.14);
	box-shadow:0 16px 45px rgba(11,16,32,.18);
	backdrop-filter: blur(10px);
	color:var(--text);
	font-weight:700;
	letter-spacing:.2px;
	user-select:none;
	white-space:nowrap;
	opacity:0;
	animation: chipIn .55s ease forwards, chipFloat var(--floatDur, 6.5s) ease-in-out var(--floatDelay, 0s) infinite;
}

.lobbyChip::before{content:"";position:absolute;inset:-2px;border-radius:999px;z-index:-1;
	background:linear-gradient(90deg, rgba(103,232,249,.55), rgba(251,113,133,.55), rgba(251,191,36,.55), rgba(52,211,153,.55));
	filter: blur(10px);
	opacity:.35;
}

@keyframes chipIn{
	from{opacity:0;transform:translate(-50%,-50%) scale(.92)}
	to{opacity:1;transform:translate(-50%,-50%) scale(1)}
}

@keyframes chipFloat{
	0%{transform:translate(-50%,-50%) translate(0px,0px) rotate(-.4deg)}
	50%{transform:translate(-50%,-50%) translate(var(--dx, 18px), var(--dy, -14px)) rotate(.4deg)}
	100%{transform:translate(-50%,-50%) translate(0px,0px) rotate(-.4deg)}
}

/* Prevent long names from overlapping the time column */
/* Leaderboard (Rank / Time / Participant) */
.rankImg{width:28px;height:auto;display:inline-block;vertical-align:middle}
.table th:nth-child(1),.table td:nth-child(1){width:16%;text-align:center;white-space:nowrap}
.table th:nth-child(2),.table td:nth-child(2){width:22%;text-align:center;white-space:nowrap}
.table th:nth-child(3),.table td:nth-child(3){width:62%;text-align:center;white-space:normal;word-break:break-word;overflow-wrap:anywhere}

.canvasWrap{display:flex;flex-direction:column;gap:10px;align-items:center;position:relative}
#gameCanvas{width:min(78vmin, 720px);aspect-ratio:1/1;background:rgba(255,255,255,.35);border:1px solid rgba(11,16,32,.12);border-radius:14px;touch-action:none}

.kpis{display:flex;gap:10px;flex-wrap:wrap}
.kpi{flex:1;min-width:140px;background:rgba(255,255,255,.45);border:1px solid rgba(11,16,32,.12);border-radius:12px;padding:10px}
.kpi .label{font-size:12px;color:var(--muted)}
.kpi .value{font-size:18px;margin-top:4px}

/* Player rules box (waiting room) */
.rulesBox{margin-top:12px;padding:12px;border-radius:14px;
	background:linear-gradient(180deg, rgba(255,255,255,.60), rgba(255,255,255,.40));
	border:1px solid rgba(11,16,32,.12);
}
.rulesTitle{font-weight:900;letter-spacing:.06em;color:rgba(11,16,32,.78);margin-bottom:8px}
.rulesList{margin:0;padding-left:18px;color:rgba(11,16,32,.74);line-height:1.55}
.rulesList li{margin:6px 0}
.rulesTip{margin-top:8px;font-size:12px;color:rgba(11,16,32,.58)}

/* Only show rules while player is waiting (pre-start) */
body[data-role="host"] #rulesBox{display:none}
body[data-role="player"] #rulesBox{display:none}
body[data-role="player"][data-started="false"] #rulesBox{display:block}

footer{padding:0 18px 18px;color:var(--muted);font-size:12px}

/* Replay modal */
.modal{position:fixed;inset:0;display:none;z-index:50}
.modal[aria-hidden="false"]{display:block}
.modalBackdrop{position:absolute;inset:0;background:rgba(11,16,32,.40);backdrop-filter: blur(6px)}
.modalCard{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
	width:min(920px, calc(100vw - 24px));
	max-height:min(92vh, 980px);
	overflow:hidden;
	border-radius:18px;
	background:linear-gradient(180deg, rgba(255,255,255,.78), rgba(255,255,255,.56));
	border:1px solid rgba(11,16,32,.14);
	box-shadow:0 30px 100px rgba(11,16,32,.22);
}
.modalHeader{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:14px 16px;border-bottom:1px solid rgba(11,16,32,.10)}
.modalTitle{font-weight:900;letter-spacing:.06em;color:rgba(11,16,32,.75)}
.modalClose{height:36px;border-radius:12px}
.modalBody{padding:14px 16px;display:flex;flex-direction:column;gap:10px}
#replayCanvas{width:min(72vmin, 760px);aspect-ratio:1/1;border-radius:14px;background:rgba(255,255,255,.38);border:1px solid rgba(11,16,32,.12)}
