/* ===== Fit screens to the viewport with scrollable content where needed ===== */
html,body{height:100%}
body:not(.ingame){overflow:hidden}
body:not(.ingame) #app{height:100vh;height:100dvh;display:flex;flex-direction:column;overflow:hidden}
body:not(.ingame) header{flex:0 0 auto;min-height:0!important;padding:4px 14px!important}
body:not(.ingame) header .brand{gap:8px}
body:not(.ingame) header .logo-gem{width:26px!important;height:26px!important}
body:not(.ingame) header .brand span{font-size:18px!important}
body:not(.ingame) header .brand small{display:none}
body:not(.ingame) footer{display:none!important}
body:not(.ingame) main{flex:1 1 0;min-height:0;width:100%;max-width:none!important;margin:0!important;padding:6px max(8px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left))!important;display:flex;align-items:center;justify-content:center;box-sizing:border-box}
body:not(.ingame) main>section.panel{width:min(100%,560px);max-height:100%;margin:0!important;padding:12px 14px!important;overflow:hidden;box-sizing:border-box}
body:not(.ingame) main>section.hidden{display:none!important}

/* ---------- Entry ---------- */
body:not(.ingame) main>section#entry{overflow-y:auto;overscroll-behavior:contain}
#entry:not(.hidden){display:grid;gap:8px;grid-template-columns:minmax(0,1fr) auto;grid-template-areas:"hero hero" "h1 h1" "name name" "skin skin" "create create" "code join" "err err" "auth auth";align-content:safe center}
#entry .titlehero{grid-area:hero;height:clamp(64px,17dvh,170px);margin:0;overflow:hidden;border-radius:14px}
#entry .titlehero img{width:100%;height:100%;object-fit:cover}
#entry>h1{grid-area:h1;margin:0;font-size:clamp(18px,3.4dvh,26px);text-align:center}
#entry>p,#entry>label,#entry>.or,#entry>small,#entry>.howto{display:none!important}
#entry #playerName{grid-area:name;margin:0}
#entry .skinselect{grid-area:skin;margin:0}
#entry .skinselect>span,#entry #skinName{display:none}
#entry .skinpick{display:flex;justify-content:center;gap:8px}
#entry #createBtn{grid-area:create;margin:0}
#entry #roomCode{grid-area:code;margin:0;min-width:0}
#entry #joinBtn{grid-area:join;margin:0;padding-left:20px;padding-right:20px}
#entry #entryError{grid-area:err;margin:0;min-height:0}
#entry .authfold{grid-area:auth;margin:0}
#entry input,#entry button{min-height:44px}
@media(max-height:560px) and (min-width:640px){
  body:not(.ingame) main>section#entry{width:min(100%,860px)}
  #entry:not(.hidden){grid-template-columns:minmax(0,1fr) minmax(0,1fr) auto;grid-template-areas:"hero name name" "hero skin skin" "hero create create" "hero code join" "hero err err" "hero auth auth"}
  #entry .titlehero{height:100%;min-height:150px}
  #entry>h1{display:none}
  #entry input,#entry button{min-height:38px}
  #entry .skinpick button{width:44px;height:44px}
}

/* ---------- Lobby ---------- */
#lobby:not(.hidden){display:flex;flex-direction:column;gap:8px;overscroll-behavior:contain}
#lobby .lobby-content{display:grid;gap:10px;align-items:start;min-height:0;overflow:auto;overscroll-behavior:contain;padding:2px}
#lobby .lobby-overview{display:grid;grid-template-columns:minmax(0,1fr);min-width:0;gap:8px}
#lobby .lobby-overview>*{margin:0}
#lobby .roomline{padding:6px 10px!important}
#lobby .roomline strong{font-size:clamp(22px,4dvh,34px)!important}
#lobby .lobby-overview h2{font-size:15px}
#lobby #lobbyPlayers{max-height:58px;overflow:auto}
#lobby .lobby-overview>h3,#lobby #lobbyTeams{display:none}
#lobby .lobby-footer{
 display:flex;align-items:center;gap:8px;flex:0 0 auto;
 border-top:1px solid #718da364;padding:8px 2px 0;
}
#lobby .lobby-footer>*{margin:0}
#lobby #startBtn{flex:1 1 auto;width:auto;min-width:0;margin:0}
#lobby .practice-option{flex:0 1 auto;min-height:44px;padding:5px 9px;border:1px solid #7897a8;border-radius:9px;cursor:pointer}
#lobby .practice-option input{width:17px;height:17px;flex:0 0 auto;accent-color:#f5d588}
#lobby .practice-option:focus-within{outline:2px solid #ffe492;outline-offset:1px}
#lobby .lobby-footer:has(#startBtn.hidden) .practice-option{display:none}
@media (max-width:500px) and (orientation:portrait){
 #lobby .lobby-footer{align-items:stretch;flex-direction:column}
}
#lobby #teacherSettings{padding:10px!important}
#lobby #teacherSettings.hidden{display:none}
#lobby #teacherSettings>h3{display:none}
#lobby #teacherSettings:not(.hidden){display:grid;grid-template-columns:1fr 1fr;gap:6px 10px}
#lobby #teacherSettings label{font-size:12px;margin:0}
#lobby #teacherSettings select{min-height:40px;margin:0}
#lobby #teacherSettings #themeCards,#lobby #teacherSettings .checkrow{grid-column:1/-1}
#lobby #teacherSettings>label:nth-of-type(2){grid-column:1/-1;order:3}
#lobby #teacherSettings #themeCards{order:4}
#lobby #teacherSettings .checkrow{order:5}
#lobby .themecards{display:grid;grid-template-columns:repeat(4,1fr);gap:6px}
#lobby .themecards .tc{min-height:54px;padding:4px}
#lobby .themecards .tc small{display:none}
#lobby #saveSettingsBtn{display:none}
#lobby #hostHint{font-size:13px;text-align:center}
#lobby #hostHint:empty{display:none}
#lobby #startBtn{min-height:50px}
#lobby #startBtn.hidden{display:none}
@media(min-width:640px){
  body:not(.ingame) main>section#lobby{width:min(100%,900px)}
  #lobby .lobby-content:has(#teacherSettings:not(.hidden)){grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
  #lobby .themecards .tc small{display:block;font-size:10px}
  #lobby .themecards{grid-template-columns:1fr 1fr}
}
@media(min-width:560px) and (orientation:landscape){
 #lobby .lobby-content:has(#teacherSettings:not(.hidden)){grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
 #lobby .themecards{grid-template-columns:repeat(2,minmax(0,1fr))}
 #lobby .roomline{gap:6px}
 #lobby .roomline>div{display:grid;min-width:0}
 #lobby .roomline strong{padding-inline:clamp(14px,3vw,30px)}
}
@media(max-height:460px){#lobby .themecards .tc{min-height:44px}#lobby #startBtn{min-height:42px}}

/* ---------- Results ---------- */
#results:not(.hidden){display:flex;flex-direction:column;gap:6px;height:100%;max-height:100%}
#results>*{margin:0}
#results .rbanner{display:none}
#results>h1{font-size:clamp(18px,3.4dvh,26px);text-align:center}
#results .wincard{padding:6px 10px}
#results .podium{max-height:22dvh;overflow:hidden}
@media(max-height:620px){#results .podium{display:none}}
#results>h3{font-size:13px}
#results #finalTeams,#results #finalBoard{margin:0;padding:0;overflow:auto;min-height:0}
#results #finalTeams{flex:0 0 auto;max-height:18dvh}
#results #finalBoard{flex:1 1 0}
#results>button,#results>p{flex:0 0 auto;min-height:44px}
#results #againHint{min-height:0;font-size:12px}

/* ---- refinements ---- */
#lobby:has(#startBtn:not(.hidden)) #hostHint{display:none}
@media(max-height:460px){
  body:not(.ingame) header{display:none!important}
  #lobby .roomline{display:flex;align-items:center;justify-content:space-between;padding:4px 8px!important}
  #lobby .roomline strong{font-size:24px!important}
  #lobby .roomline .small{padding:4px 8px;font-size:12px;white-space:nowrap}
  #lobby .themecards .tc small{display:none!important}
}
#entry .titlehero{display:block}
#entry .titlehero img{height:100%!important;max-height:none!important;width:100%!important;object-fit:cover}
@media(max-height:820px){#results .podium{display:none}}
#results #finalTeams{max-height:28dvh;flex:0 0 auto}
