/* Race screen. The tunnel is never covered: percentage, position and runs sit beside it (desktop, landscape)
   or above and below it (portrait phone). The map is a separate dotted strip over the tunnel, not on it. */
#race{position:absolute;inset:0;display:none;padding:0;overflow:hidden;touch-action:none;align-items:start;justify-items:stretch;
  --strip:72px;--side:240px;
  --gh:calc(100dvh - var(--strip));
  --cw:min(calc(100vw - 2*var(--side)),calc(var(--gh)*384/312));
  grid-template-columns:minmax(0,1fr) var(--cw) minmax(0,1fr);
  grid-template-rows:auto auto 1fr auto auto;
  grid-template-areas:"pct gc list" "last gc list" ". gc list" "pl gc menu" "pl gc pr"}
#hud-pct{grid-area:pct}#hud-last{grid-area:last}#game-col{grid-area:gc}#hud-list{grid-area:list}#hud-menu{grid-area:menu}
#controls{display:contents}#pad-left{grid-area:pl}#pad-right{grid-area:pr}

#hud-pct{display:flex;flex-direction:column;align-items:flex-end;text-align:right;gap:12px;padding:calc(28px + var(--sat)) 20px 0 max(16px,var(--sal));min-width:0}
#hud-pct .mark{width:calc(43px*var(--logo));height:auto;margin-bottom:12px}
.pct{font-size:64px;line-height:1;white-space:nowrap;color:var(--cream)}
.pct small{font-size:32px;color:var(--gold)}
.rank{font-size:32px;line-height:1;white-space:nowrap;color:var(--gold)}
.rank small{font-size:16px;color:var(--dim)}
.score{font-size:var(--f0);color:var(--cream);font-variant-numeric:tabular-nums}
.score::before{content:'SCORE ';color:var(--dim)}
.watching{font-size:var(--f0);color:var(--gold);line-height:1.4;overflow-wrap:anywhere}
.state{font-size:var(--f0);color:var(--dim);line-height:1.5;min-height:1.5em}
#hud-last{display:flex;flex-direction:column;align-items:flex-end;text-align:right;padding:28px 20px 0 max(16px,var(--sal));gap:10px;min-width:0}
.last3{display:flex;flex-direction:column;gap:10px;font-size:16px}
.last3 li.clear{color:var(--green)}
.last3 li em{font-style:normal;color:var(--dim);font-size:12px;margin-left:.6em}

#game-col{display:flex;flex-direction:column;height:100dvh;min-width:0}
#strip-wrap{height:var(--strip);flex:none;position:relative}
#strip-wrap{display:flex;justify-content:center}
#strip{height:100%;width:auto;max-width:100%;aspect-ratio:384/37;display:block;image-rendering:pixelated;touch-action:manipulation}
#strip.can-pick{cursor:pointer}
#game-space{flex:1;min-height:0;display:flex;align-items:flex-start;justify-content:center;overflow:hidden}
#stage{position:relative;flex:none;line-height:0;overflow:hidden}
canvas#game{display:block;background:#000;image-rendering:pixelated;touch-action:none}

#hud-list{display:flex;flex-direction:column;gap:24px;padding:calc(28px + var(--sat)) max(16px,var(--sar)) 0 20px;min-width:0;font-size:16px}
.ranks{display:flex;flex-direction:column;gap:10px}
.ranks li{display:flex;gap:.8em;white-space:nowrap;color:var(--dim);min-width:0}
.ranks li.party{color:var(--cream)} .ranks li.me{color:var(--gold)}
.ranks li span:nth-child(2){flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}
.ranks li span:last-child{margin-left:auto}
#chat-panel{display:none;font-size:12px}
#chat-panel .chat-log{font-size:12px;max-height:calc(12px*1.5*5);overflow-y:auto;touch-action:pan-y}
#chat-panel .chat-form{margin-top:10px}
#chat-input{width:100%;min-height:44px;outline:0;border-bottom:2px solid var(--dim);color:var(--cream);caret-color:var(--green);padding:.4em 0;font-size:12px;user-select:text;-webkit-user-select:text}
#chat-input:focus{border-color:var(--gold)}#chat-input::placeholder{color:var(--dim)}
.keys{font-size:16px;line-height:1.9;color:var(--dim)}

#hud-menu{display:flex;flex-direction:column;align-items:flex-start;gap:4px;padding:0 max(16px,var(--sar)) 12px 20px}
body.racing #hud-menu{display:none}
button.act{min-height:44px;min-width:44px;padding:8px 0;color:var(--dim);cursor:pointer;font-size:var(--f0);text-align:left}
button.act:hover,button.act:focus-visible{color:var(--gold);outline:0}
#btn-prev,#btn-next{display:none}
body[data-spectating=true] #btn-prev,body[data-spectating=true] #btn-next{display:block}

/* ---- touch controls: shown only after a touch is seen ---- */
.pad{display:none;pointer-events:none}
body.touch #controls .pad{display:flex;align-items:flex-end}
body:not(.racing) #controls .pad{visibility:hidden}
#pad-left{padding:0 0 max(16px,var(--sab)) max(16px,var(--sal));justify-content:center}
#pad-right{padding:0 max(16px,var(--sar)) max(16px,var(--sab)) 0;justify-content:center}
body.touch #controls #pad-right{flex-direction:column;align-items:center;gap:10px}
#thumb-pad{display:none;width:136px;height:136px;border:4px solid var(--green-dk);border-radius:50%;position:relative;pointer-events:auto;touch-action:none;outline-offset:5px}
body.touch #thumb-pad{display:block}
.thumb-knob{position:absolute;width:52px;height:52px;top:calc(50% - 26px);left:calc(50% - 26px);border-radius:50%;background:var(--green-dk);transform:translate(var(--thumb-x,0px),var(--thumb-y,0px))}
#thumb-pad.down{border-color:var(--green)}#thumb-pad.down .thumb-knob{background:var(--green)}
button.ctl{display:none}
body.touch button.ctl{display:flex}
button.ctl.jump{width:112px;height:112px;border-radius:50%;border:4px solid var(--gold);color:var(--gold);font-size:16px;align-items:center;justify-content:center;pointer-events:auto;touch-action:none;cursor:pointer}
button.ctl.jump.down{background:#fcd85440;color:var(--cream)}
#thumb-pad:focus-visible,button.ctl:focus-visible{outline:3px solid var(--gold)}

/* ---- tablets and small windows: narrower side columns ---- */
@media (max-width:1099px){#race{--side:200px}}
@media (min-width:2000px) and (min-height:1200px){#race{--strip:80px;--side:320px}.pct{font-size:96px}.pct small{font-size:48px}.rank{font-size:48px}}

/* ---- landscape phone: same three columns, smaller type ---- */
@media (orientation:landscape) and (max-height:520px){
  #race{--strip:40px;--side:0px}
  #hud-pct{padding:calc(8px + var(--sat)) 10px 0 max(10px,var(--sal));gap:4px}
  #hud-pct .mark{display:none}
  .pct{font-size:32px}.pct small{font-size:16px}.rank{font-size:16px}.rank small{font-size:12px}
  .score,.state,.watching,.keys{font-size:12px}
  #hud-last{padding:6px 10px 0 max(10px,var(--sal));gap:4px}
  .last3{flex-direction:row;gap:10px;font-size:12px}.last3 li em{display:none}
  #hud-list{padding:calc(8px + var(--sat)) max(10px,var(--sar)) 0 10px;gap:8px;font-size:12px}
  .ranks{gap:4px}
  .ranks li:nth-child(n+5){display:none}
  #chat-panel{display:none!important}
  #hud-menu{padding:0 max(10px,var(--sar)) 4px 10px;flex-direction:row;flex-wrap:wrap;gap:0 12px}
  button.act{font-size:12px}
  #thumb-pad{width:120px;height:120px;border-width:3px}.thumb-knob{width:46px;height:46px;top:calc(50% - 23px);left:calc(50% - 23px)}
  button.ctl.jump{width:104px;height:104px;border-width:3px;font-size:12px}
  #pad-left{padding-bottom:max(8px,var(--sab))}#pad-right{padding-bottom:max(8px,var(--sab))}
}

/* ---- portrait phone: percentage and position above the tunnel, last three and menu below it ---- */
@media (max-width:700px) and (orientation:portrait){
  #race{--strip:40px;--side:0px;display:none;overflow:hidden;
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:auto auto auto 1fr;
    grid-template-areas:"pct pct" "gc gc" "last menu" "pl pr"}
  body[data-screen=race] #race{display:grid}
  #hud-list,#hud-pct .mark{display:none}
  #hud-pct{flex-direction:row;align-items:baseline;justify-content:flex-start;flex-wrap:wrap;text-align:left;gap:4px 14px;padding:calc(10px + var(--sat)) max(12px,var(--sar)) 4px max(12px,var(--sal))}
  .pct{font-size:32px}.pct small{font-size:16px}.rank{font-size:16px}.rank small{font-size:12px}
  .score{margin-left:auto}
  .watching{flex:1 0 100%}.state{flex:1 0 100%;min-height:0}
  .state:empty{display:none}
  #game-col{height:auto}
  #game-space{flex:none;aspect-ratio:384/312;width:100%}
  #hud-last{flex-direction:row;align-items:center;text-align:left;padding:8px 0 0 max(12px,var(--sal));gap:10px}
  #hud-last .lbl,#history-empty{margin:0;white-space:nowrap}
  .last3{flex-direction:row;gap:12px;font-size:12px}.last3 li em{display:none}
  #history-empty{font-size:12px}
  #hud-menu{flex-direction:row;justify-content:flex-end;align-items:center;gap:12px;padding:0 max(12px,var(--sar)) 0 0;flex-wrap:wrap}
  button.act{font-size:12px}
  #pad-left{justify-self:start;align-self:end}#pad-right{justify-self:end;align-self:end}
  #thumb-pad{width:128px;height:128px}
  button.ctl.jump{width:108px;height:108px}
}
@media (max-width:700px) and (orientation:portrait) and (max-height:620px){
  #thumb-pad{width:96px;height:96px}.thumb-knob{width:38px;height:38px;top:calc(50% - 19px);left:calc(50% - 19px)}
  button.ctl.jump{width:88px;height:88px}
}
/* ---- wide screens with room: chat sits on the right of the tunnel, non-modal ---- */
@media (min-width:1100px) and (min-height:700px){#chat-panel{display:block}}

/* ---- auto spectate: the tunnel and the map stay on screen behind the title and results menus. The HUD keeps its
   place in the layout (so the tunnel does not move when the menu opens) but is not shown; the tunnel is dimmed so
   the menu reads. The menu takes input as on any other screen; only the map strip is lifted above it, bright,
   so a rider's icon can be clicked or tapped with the menu up. ---- */
body[data-backdrop=true] #race{display:grid;pointer-events:none}
body[data-backdrop=true] #race>*{visibility:hidden}
body[data-backdrop=true] #race>#game-col{visibility:visible}
body[data-backdrop=true] #game-space{opacity:.38}
body[data-backdrop=true] #strip-wrap{z-index:2}
body[data-backdrop=true] #strip{pointer-events:auto;cursor:pointer}
body[data-backdrop=true] #title,body[data-backdrop=true] #results{z-index:1;background:none;text-shadow:calc(var(--f0)/8) calc(var(--f0)/8) 0 #000,calc(var(--f0)/-8) calc(var(--f0)/8) 0 #000,calc(var(--f0)/8) calc(var(--f0)/-8) 0 #000,calc(var(--f0)/-8) calc(var(--f0)/-8) 0 #000}
/* portrait phone: the title logo sits where the map is, so the map is left out there (it is on results and in the watch view) */
@media (max-width:700px) and (orientation:portrait){body[data-backdrop=true][data-screen=title] #strip-wrap{visibility:hidden}}
