/* ShareDoom shell. Text is drawn from the IWAD's own fonts into canvases;
   CSS only lays them out. --s is the integer pixel scale (menu.js), --frame
   the bevelled border built from a game texture (theme.js). */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; color: #ccc;
  font: 14px/1.3 system-ui, sans-serif; -webkit-tap-highlight-color: transparent; user-select: none; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---- the game view: always the whole window ---------------------------- */
/* Behind the engine canvas: the theme's floor texture, so a moment between
   engines (or before the first frame) shows Doom, never plain black. */
#game { position: fixed; inset: 0; transition: filter .3s;
  background: #000 var(--tile, none) repeat; background-size: calc(var(--s, 3) * 64px); }
#game canvas { transition: opacity .25s; }
#game canvas.starting { opacity: 0; transition: none; }
#game .wipe-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: none;
  pointer-events: none; }
#game .engine-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important;
  outline: none; display: block; }

/* CRT filter without WebGL (src/shell/crt.js): scanlines and curved corners over the picture */
#game .crt-css { position: absolute; z-index: 1; display: none; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 50%, var(--crt-dark) 50% 100%);
  background-size: 100% var(--crt-line, 3px); }
#game .crt-css.on { display: block; }
#game .crt-css.curve { border-radius: 3vmin; box-shadow: 0 0 0 100vmax #000, inset 0 0 6vmin rgba(0, 0, 0, .45); }
#game .crt-css.strong { border-radius: 7vmin; box-shadow: 0 0 0 100vmax #000, inset 0 0 10vmin rgba(0, 0, 0, .6); }

/* Behind the menu the game (or the attract demo) is blurred, darkened and
   dithered, so the menu reads clearly but the game still shows through. */
body.menu-open #game { filter: blur(3px) brightness(.5) saturate(.85); }
#game .pause-snap { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; display: none; pointer-events: none; }
body.snap #game { filter: none; transition: none; }
body.snap #game .pause-snap { display: block; }
#dither { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
  background-image: var(--dither); background-size: var(--dither-size, 6px); image-rendering: pixelated; }
body.menu-open #dither { opacity: 1; }

/* ---- the menu ----------------------------------------------------------- */
#menu {
  --s: 3;
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: calc(var(--s) * 6px);
  padding: calc(var(--s) * 8px) calc(var(--s) * 4px);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
body.menu-open.ready #menu { opacity: 1; pointer-events: auto; }

#menu header.mtitle { display: flex; justify-content: center; align-items: flex-end; flex: 0 0 auto;
  max-width: 96vw; }
#menu header .logo { max-width: 92vw; height: auto !important; }

/* A box: dark glass inside a bevelled metal frame, like Doom's own panels. */
.dbox {
  position: relative; background: rgba(0, 0, 0, .74);
  border: calc(var(--s) * 5px) solid transparent;
  border-image: var(--frame) 5 / calc(var(--s) * 5px) round;
  padding: calc(var(--s) * 5px) calc(var(--s) * 7px);
  box-shadow: 0 calc(var(--s) * 2px) calc(var(--s) * 10px) rgba(0, 0, 0, .6);
  max-width: 94vw; max-height: 100%; display: flex; flex-direction: column; min-height: 0;
}
#menu .dbox.list { width: min(94vw, calc(var(--s) * 290px)); flex: 0 1 auto; }
#menu .dbox.big { width: auto; padding: calc(var(--s) * 5px) calc(var(--s) * 12px) calc(var(--s) * 5px) calc(var(--s) * 4px); }
#menu .dbox.page { width: min(94vw, calc(var(--s) * 480px)); }   /* (pages draw at 0.6x the menu scale: about as wide as before) */

#menu .items { overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #6a6a6a transparent;
  min-height: 0; }
#menu .item { display: grid; grid-template-columns: calc(var(--s) * 11px) auto minmax(0, 1fr); align-items: center;
  column-gap: calc(var(--s) * 3px); min-height: calc(var(--s) * 12px); cursor: pointer; }
#menu .item.big { grid-template-columns: calc(var(--s) * 22px) auto; min-height: calc(var(--s) * 20px); }
#menu .item.disabled { cursor: default; }
#menu .item .cur { display: flex; justify-content: center; align-items: center; }
#menu .item .lab { display: flex; min-width: 0; }
/* big menus on a narrow phone: a label wider than its box shrinks to fit instead of being cut */
#menu .dbox.big { max-width: 96vw; box-sizing: border-box; }
#menu .dbox.big .item .lab canvas { max-width: 100%; height: auto !important; object-fit: contain; }
#menu .item .val { display: flex; gap: calc(var(--s) * 6px); align-items: center; justify-content: flex-end; position: relative;
  min-width: 0; overflow: hidden; margin-left: calc(var(--s) * 6px); }
#menu .item .val canvas { flex: 0 0 auto; }
#menu .item .val input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: text; }
#menu .item .slot { min-width: calc(var(--s) * 36px); display: flex; justify-content: flex-end; }
#menu .item .slot:hover canvas { filter: brightness(1.3); }
#menu .heading { display: flex; justify-content: center; margin: calc(var(--s) * 4px) 0 calc(var(--s) * 2px); }
#menu .heading.left { justify-content: flex-start; }
#menu .para { display: grid; gap: calc(var(--s) * 2px); margin-bottom: calc(var(--s) * 2px); }
#menu .para.center { justify-items: center; }
#menu .gap { height: calc(var(--s) * 5px); }
#menu .rule { height: calc(var(--s) * 1px); background: rgba(255, 255, 255, .12); margin: calc(var(--s) * 4px) 0; }

#menu footer.hint { flex: 0 0 auto; display: flex; gap: calc(var(--s) * 8px); align-items: center; }
#menu footer .back-btn { background: none; border: 0; padding: 4px; cursor: pointer; }
#menu footer .back-btn:hover canvas { filter: brightness(1.4); }

/* ---- "click to play" (pointer lock needs a click to come back) ----------- */
#lockhint { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none;
  pointer-events: none; }
body.need-lock #lockhint { display: block; }
body.need-lock #game { filter: brightness(.6); cursor: pointer; }

/* Touch controls (src/input/touch.js). The layer lets pointers through until
   touch play is on, so a mouse still reaches the game. */
#game .touch-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2;
  pointer-events: none; touch-action: none; }
body.touch-active #game .touch-layer { pointer-events: auto; }
body.touch-editing #game .touch-layer { position: fixed; inset: 0; z-index: 20; pointer-events: auto; }
body[data-state="game"], body.touch-editing { touch-action: none; overscroll-behavior: none; }
body.touch-editing #game { filter: none; }

/* "New version ready" (src/shell/updates.js): under the main menu, never in or over a game. */
#update-notice { position: fixed; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 15; cursor: pointer; padding: 6px 10px; color: inherit; font: inherit; }
body:not([data-state="title"]) #update-notice { display: none; }

/* ---- menu widgets: drop-downs, read-only rows, custom rows (menu.js) ------ */
#menu .item.readonly { cursor: default; }
#menu .item .val .arrow { margin-left: calc(var(--s) * -3px); }
#menu .item.wide { grid-template-columns: calc(var(--s) * 11px) auto 1fr; }
#menu .item.wide .val { justify-content: flex-start; min-width: 0; overflow: hidden; }
#menu .item.custom { display: block; min-height: 0; }
#menu .item.custom.static { cursor: default; }
.dpopup { position: fixed; inset: 0; z-index: 30; }
/* a drop-down's popover: anchored under its row (menu.js placePopup), nothing dimmed */
.dpopup .pop { position: fixed; display: flex; flex-direction: column; width: max-content;
  padding: calc(var(--s) * 2px); border-width: calc(var(--s) * 3px); border-image-width: calc(var(--s) * 3px);
  background: rgba(0, 0, 0, .9); box-shadow: 0 calc(var(--s) * 2px) calc(var(--s) * 6px) rgba(0, 0, 0, .7); }
.dpopup .opts { overflow-y: auto; overscroll-behavior: contain; min-height: 0; scrollbar-width: thin; scrollbar-color: #6a6a6a transparent;
  touch-action: pan-y; }
.dpopup .opt { padding: calc(var(--s) * 1px) calc(var(--s) * 3px); cursor: pointer; display: flex; white-space: nowrap; }
.dpopup .opt.sel { background: rgba(255, 255, 255, .12); box-shadow: inset calc(var(--s) * 1px) 0 0 #f0c040; }

/* ---- panels: several boxes on one screen (the online lobby) --------------- */
#menu.wide { justify-content: flex-start; gap: calc(var(--s) * 3px); padding: calc(var(--s) * 4px) calc(var(--s) * 3px); }
#menu.wide header.mtitle { max-height: calc(var(--s) * 18px); }
#menu.wide header.mtitle canvas { max-height: calc(var(--s) * 16px); width: auto !important; }
#menu .panels { display: grid; gap: calc(var(--s) * 3px); min-height: 0; max-width: 100%; flex: 0 1 auto;
  overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #6a6a6a transparent; }
#menu .panel { max-width: none; max-height: none; min-height: auto; padding: calc(var(--s) * 3px) calc(var(--s) * 4px); min-width: 0; }
#menu .layout-lobby3 .panel { max-height: 100%; min-height: 0; }
#menu .panel .ptitle { display: flex; align-items: center; margin-bottom: calc(var(--s) * 2px); }
#menu .panel .ptitle .ptag { margin-left: auto; }
#menu .panel .item { min-height: calc(var(--s) * 10px); grid-template-columns: calc(var(--s) * 9px) auto minmax(0, 1fr); }
#menu .panel.row .items { display: flex; flex-wrap: wrap; gap: 0 calc(var(--s) * 6px); align-items: center; justify-content: center; }
#menu .panel.row .item { grid-template-columns: calc(var(--s) * 9px) auto auto; }
#menu .panel .item.wide { grid-template-columns: calc(var(--s) * 9px) auto 1fr; }
#menu .panel.row .para { flex-basis: 100%; }

#menu .layout-lobby3 { grid-template-columns: calc(var(--s) * 204px) calc(var(--s) * 158px) calc(var(--s) * 204px);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "players map settings" "players room settings" "chat room settings" "buttons buttons settings";
  flex: 1 1 0; height: auto; min-height: 0; overflow: hidden; }
/* the lobby's (and WADs', Find Game's) boxes end just above the status bar of the game behind (32 of its 200 lines) */
#menu.wide:has(.layout-lobby3, .layout-wads:not(.wads1), .layout-find:not(.find1)) { padding-bottom: calc(16vh + var(--s) * 2px); }
#menu .layout-lobby3 [data-panel="settings"] .item { min-height: calc(var(--s) * 9px); }
#menu .layout-lobby3 [data-panel="settings"] .items, #menu .layout-lobby3 [data-panel="chat"] { min-height: 0; }
#menu .layout-lobby2 { width: 100%; grid-template-columns: 1fr 1fr;
  grid-template-areas: "players settings" "buttons settings" "chat settings" "map room"; }
#menu .layout-lobby1 { width: 100%; grid-template-columns: 1fr;
  grid-template-areas: "players" "buttons" "chat" "map" "room" "settings"; }
#menu .layout-lobby2 .panel .items, #menu .layout-lobby1 .panel .items { overflow: visible; }
#menu [data-panel="players"] { grid-area: players; }
#menu [data-panel="chat"] { grid-area: chat; }
#menu [data-panel="map"] { grid-area: map; }
#menu [data-panel="room"] { grid-area: room; }
#menu [data-panel="settings"] { grid-area: settings; }
#menu [data-panel="buttons"] { grid-area: buttons; }

/* a player slot: a bar in the player's colour, the status bar face, name and tags */
#menu .pslot { display: flex; align-items: center; gap: calc(var(--s) * 4px); margin: calc(var(--s) * 1px) 0;
  padding: calc(var(--s) * 1px); min-height: calc(var(--s) * 34px);
  background: linear-gradient(90deg, var(--pc), var(--pd) 70%, rgba(0, 0, 0, .5));
  box-shadow: inset 0 0 0 calc(var(--s) * 1px) rgba(0, 0, 0, .6), inset 0 calc(var(--s) * 1px) 0 calc(var(--s) * 1px) rgba(255, 255, 255, .15); }
#menu .pslot.empty { background: linear-gradient(90deg, var(--pd), rgba(0, 0, 0, .55) 60%); opacity: .7; }
#menu .pslot.sel { outline: calc(var(--s) * 1px) solid #f0c040; }
#menu .pslot .face { flex: 0 0 auto; width: calc(var(--s) * 32px); height: calc(var(--s) * 32px);
  display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .45); }
#menu .pslot .face canvas { max-width: 100%; max-height: 100%; }
#menu .pslot .pinfo { display: grid; gap: calc(var(--s) * 2px); min-width: 0; }
#menu .pslot .pname, #menu .pslot .ptags { display: flex; align-items: center; gap: calc(var(--s) * 4px); flex-wrap: wrap; }
#menu .pslot .pinfo canvas { filter: drop-shadow(calc(var(--s) * 1px) calc(var(--s) * 1px) 0 rgba(0, 0, 0, .85)); }

#menu .chatlog { height: calc(var(--s) * 74px); overflow-y: auto; display: flex; flex-direction: column; gap: calc(var(--s) * 1px);
  background: rgba(0, 0, 0, .35); padding: calc(var(--s) * 2px); scrollbar-width: thin; scrollbar-color: #6a6a6a transparent; }
#menu .layout-lobby3 .chatlog { height: auto; min-height: calc(var(--s) * 40px); max-height: calc(var(--s) * 74px); }
#menu .chatlog .cline { display: flex; flex-wrap: nowrap; }
/* The chat box is a column: the log takes the space, the input line sits on the box's bottom
   edge, its text in line with the log's (the cursor uses the log's left padding). */
#menu [data-panel="chat"] { display: flex; flex-direction: column; }
#menu [data-panel="chat"] .items { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
#menu [data-panel="chat"] .items > .item.custom { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: stretch; }
#menu [data-panel="chat"] .chatlog { flex: 1 1 auto; width: 100%; box-sizing: border-box; justify-content: flex-end;
  padding-left: calc(var(--s) * 9px); }
#menu [data-panel="chat"] .items > .item:last-child { margin: calc(var(--s) * 2px) 0 0; padding: 0; }
#menu .automap { display: block; margin: 0 auto; background: #000; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
/* never wider than its box (the canvas is drawn at the pixel scale and would be cropped): shrink to fit, centred */
#menu .automap { max-width: 100% !important; height: auto !important; }
#menu .roomcode { display: flex; justify-content: center; padding: calc(var(--s) * 2px) 0; }

/* the room list */
#menu .roomline { display: grid; gap: calc(var(--s) * 2px); padding: calc(var(--s) * 2px) calc(var(--s) * 3px); }
#menu .roomline.sel { background: rgba(255, 255, 255, .08); box-shadow: inset calc(var(--s) * 1px) 0 0 #f0c040; }
#menu .roomline .rtop, #menu .roomline .rsub { display: flex; align-items: center; gap: calc(var(--s) * 5px); }
#menu .roomline .dots { display: flex; gap: calc(var(--s) * 2px); margin-left: auto; }
#menu .roomline .dot { width: calc(var(--s) * 5px); height: calc(var(--s) * 5px); background: var(--pc); box-shadow: 0 0 0 1px #000; }
#menu .roomline .dot.empty { background: transparent; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3); }
#menu .roomline .dot.bot { opacity: .55; }

/* ---- Multiplayer > Find game: one Doom box per room ----------------------- */
#menu .layout-find { width: min(96vw, calc(var(--s) * 460px)); grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr);
  flex: 1 1 0; height: auto; min-height: 0; overflow: hidden; }
#menu .layout-find [data-panel="rooms"] { max-height: 100%; min-height: 0; }
#menu .layout-find [data-panel="controls"] .items { gap: 0 calc(var(--s) * 4px); }
#menu .layout-find [data-panel="controls"] .item .val { min-width: calc(var(--s) * 34px); justify-content: flex-start; }
#menu .roomcard { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: calc(var(--s) * 5px);
  margin: calc(var(--s) * 2px) 0; padding: calc(var(--s) * 3px);
  border: calc(var(--s) * 3px) solid transparent; border-image: var(--frame) 5 / calc(var(--s) * 3px) round;
  background: rgba(0, 0, 0, .55); }
#menu .roomcard.sel { background: rgba(255, 255, 255, .09); box-shadow: inset calc(var(--s) * 1px) 0 0 #f0c040; }
#menu .roomcard.full { opacity: .75; }
#menu .roomcard .thumb { width: calc(var(--s) * 64px); height: calc(var(--s) * 40px); background: #000; overflow: hidden;
  box-shadow: 0 0 0 calc(var(--s) * 1px) rgba(0, 0, 0, .8); }
#menu .roomcard .rtext { display: grid; gap: calc(var(--s) * 3px); min-width: 0; }
#menu .roomcard .rtext > div { display: flex; overflow: hidden; white-space: nowrap; min-width: 0; }
#menu .roomcard .rtext canvas { flex: 0 0 auto; }
#menu .roomcard .rside { display: grid; gap: calc(var(--s) * 2px); justify-items: end; }
#menu .roomcard .rcount, #menu .roomcard .rnet, #menu .roomcard .rtags { display: flex; align-items: center; gap: calc(var(--s) * 3px); }
#menu .roomcard .marine { height: calc(var(--s) * 16px) !important; width: auto !important; }
#menu .roomcard .flag { display: inline-block; image-rendering: auto; box-shadow: 0 0 0 1px rgba(0, 0, 0, .8); }
#menu .layout-find.find1 { height: auto; overflow-y: auto; }
#menu .layout-find.find1 [data-panel="rooms"] { max-height: none; }
#menu .layout-find.find1 .roomcard { grid-template-columns: auto minmax(0, 1fr); gap: calc(var(--s) * 3px); }
#menu .layout-find.find1 .roomcard .thumb { width: calc(var(--s) * 40px); height: calc(var(--s) * 25px); }
#menu .layout-find.find1 .roomcard .rside { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: space-between;
  align-items: center; gap: calc(var(--s) * 2px) calc(var(--s) * 6px); }
#menu .layout-find.find1 .roomcard .marine { height: calc(var(--s) * 12px) !important; }

/* ---- the scoreboard (scoreboard.js): a compact translucent strip at the top ---- */
/* The game goes on underneath, not dimmed; the board takes no input and never covers the middle. */
/* (one .sbview per board: the window, or a splitscreen player's view; scoreboard.js sizes the box) */
#scoreboard { position: fixed; inset: 0; display: none; pointer-events: none; z-index: 5; }
body.scoreboard-open:not(.menu-open) #scoreboard { display: block; }
#scoreboard .sbview { --s: 2; position: absolute; display: flex; align-items: flex-start; justify-content: center;
  overflow: hidden; padding-top: calc(var(--s) * 3px); }
#scoreboard .sbview.whole { padding-top: calc(var(--s) * 4px); }
#scoreboard .board { gap: calc(var(--s) * 1px); max-width: 100%; flex: 0 0 auto;
  background: rgba(0, 0, 0, .42); padding: calc(var(--s) * 2px) calc(var(--s) * 3px);
  border-width: calc(var(--s) * 3px); border-image-width: calc(var(--s) * 3px); box-shadow: none; opacity: .94; }
#scoreboard .bhead { display: flex; flex-direction: column; align-items: center; gap: calc(var(--s) * 1px);
  margin-bottom: calc(var(--s) * 2px); }
#scoreboard .bline { display: flex; justify-content: center; align-items: flex-end; flex-wrap: wrap;
  gap: calc(var(--s) * 1px) calc(var(--s) * 5px); max-width: 100%; }
#scoreboard .bline.info { gap: calc(var(--s) * 1px) calc(var(--s) * 6px); }
#scoreboard canvas { filter: drop-shadow(calc(var(--s) * .5px) calc(var(--s) * .5px) 0 rgba(0, 0, 0, .85)); flex: 0 0 auto; }
#scoreboard .bgrid { display: flex; flex-direction: column; gap: calc(var(--s) * 1px); }
#scoreboard .brow { display: grid; align-items: center; column-gap: calc(var(--s) * 3px); }
#scoreboard .brow.player { min-height: calc(var(--s) * 17px); padding: calc(var(--s) * .5px);
  background: linear-gradient(90deg, var(--pc), var(--pd) 55%, rgba(0, 0, 0, .25));
  box-shadow: inset 0 0 0 calc(var(--s) * .5px) rgba(0, 0, 0, .6); opacity: .92; }
#scoreboard .brow.team { margin-top: calc(var(--s) * 2px); padding: calc(var(--s) * .5px) calc(var(--s) * .5px) 0;
  border-bottom: calc(var(--s) * 1px) solid var(--pc); }
#scoreboard .brow.team .bc.face { height: auto; background: none; }
#scoreboard .brow.lead { outline: calc(var(--s) * 1px) solid #f0c040; }
#scoreboard .brow.you .face { box-shadow: inset 0 0 0 calc(var(--s) * 1px) #f0f0f0; }
#scoreboard .bc { display: flex; align-items: center; min-width: 0; }
#scoreboard .bc.num { justify-content: flex-end; padding-right: calc(var(--s) * 2px); }
#scoreboard .bc.face { justify-content: center; height: calc(var(--s) * 16px); background: rgba(0, 0, 0, .35); overflow: hidden; }
#scoreboard .bc.face canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
#scoreboard .brow.hdr .bc.face { height: auto; background: none; }
#scoreboard .bc.name { flex-direction: row; align-items: center; gap: calc(var(--s) * 5px); overflow: hidden; white-space: nowrap; }
#scoreboard .btags { display: flex; align-items: center; gap: calc(var(--s) * 3px); flex-wrap: nowrap; }
/* tight (a short splitscreen view): short rows, less space around */
#scoreboard .board.tight { padding: calc(var(--s) * 1px) calc(var(--s) * 2px); }
#scoreboard .board.tight .bhead { margin-bottom: calc(var(--s) * 1px); }
#scoreboard .board.tight .brow.player { min-height: calc(var(--s) * 9px); }
/* a short row: the tags go under the name */
#scoreboard .board.stack .brow.player .bc.name { flex-direction: column; align-items: flex-start; gap: calc(var(--s) * 1px); }
/* ---- the WADs tab (screens-wads.js): tabs, controls, a grid of cards ------ */
#menu .layout-wads { width: min(96vw, calc(var(--s) * 480px)); grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr); flex: 1 1 0; height: auto; min-height: 0; overflow: hidden; }
#menu .layout-wads [data-panel="cards"] { max-height: 100%; min-height: 0; }
#menu .layout-wads [data-panel="tabs"] .items { gap: 0 calc(var(--s) * 8px); }
#menu .layout-wads [data-panel="controls"] .items { gap: 0 calc(var(--s) * 5px); }
#menu .layout-wads [data-panel="controls"] .item .val { min-width: calc(var(--s) * 30px); justify-content: flex-start; }
#menu .wgrid .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--s) * 150px), 1fr));
  grid-auto-rows: max-content; gap: calc(var(--s) * 3px); align-content: start; }
#menu .wgrid .items > :not(.wad-card) { grid-column: 1 / -1; }
#menu .wtab { padding: calc(var(--s) * 2px) calc(var(--s) * 3px); border-bottom: calc(var(--s) * 1px) solid transparent; }
#menu .wtab.on { border-bottom-color: #f0c040; }
#menu .wtab.sel { background: rgba(255, 255, 255, .09); }
#menu .wcard { display: grid; grid-template-rows: auto auto 1fr auto auto; gap: calc(var(--s) * 2px); height: 100%;
  padding: calc(var(--s) * 3px) calc(var(--s) * 4px);
  border: calc(var(--s) * 3px) solid transparent; border-image: var(--frame) 5 / calc(var(--s) * 3px) round;
  background: rgba(0, 0, 0, .55); box-sizing: border-box; }
#menu .wcard.sel { background: rgba(255, 255, 255, .09); box-shadow: inset calc(var(--s) * 1px) 0 0 #f0c040; }
#menu .wcard.subscribed { background: rgba(20, 60, 20, .45); }
#menu .wcard.subscribed.sel { background: rgba(60, 110, 60, .45); }
#menu .wcard > div { display: flex; align-items: center; gap: calc(var(--s) * 3px); min-width: 0; overflow: hidden; white-space: nowrap; }
#menu .wcard canvas { flex: 0 0 auto; }
#menu .wcard .wd { display: grid; align-content: start; gap: calc(var(--s) * 1px); }
#menu .wcard .wf { justify-content: flex-start; overflow: visible; min-height: calc(var(--s) * 11px); }
#menu .wcard .wm { display: flex; align-items: center; gap: calc(var(--s) * 4px); min-width: 0; overflow: hidden; }
#menu .wcard .wsub { flex: 0 0 auto; margin-left: auto; background: rgba(0, 0, 0, .6); cursor: pointer; padding: calc(var(--s) * 2px) calc(var(--s) * 3px);
  border: calc(var(--s) * 1px) solid rgba(255, 255, 255, .25); min-height: calc(var(--s) * 9px); }
#menu .wcard .wsub:hover:not(:disabled) { border-color: #f0c040; }
#menu .wcard .wsub:disabled { cursor: default; opacity: .7; }
#menu .wmore { display: flex; justify-content: center; padding: calc(var(--s) * 4px); }
#menu .wmore.sel { background: rgba(255, 255, 255, .09); }
#menu .layout-wads.wads1 { height: auto; max-height: 100%; overflow-y: auto; grid-template-rows: auto; }
#menu .layout-wads.wads1 [data-panel="cards"] { max-height: none; }
#menu .layout-wads.wads1 .wgrid .items { grid-template-columns: repeat(auto-fill, minmax(calc(var(--s) * 140px), 1fr)); overflow: visible; }

/* ---- UI polish (agent/ui) ------------------------------------------------- */
/* sliders: the bar, then its number */
#menu .item .val .thermo { display: flex; align-items: center; cursor: pointer; touch-action: none; }
#menu .item .val .snum { min-width: calc(var(--s) * 12px); }
/* the lobby chat: the log fills the box, the input line pinned under it, both on one left edge */
#menu .chatbox .items { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#menu .chatbox .items > .item.custom { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: stretch; }
#menu .chatbox .chatlog { flex: 1 1 auto; }
#menu .layout-lobby3 .chatbox .chatlog { max-height: none; }
#menu .item.chatline { grid-template-columns: auto minmax(0, 1fr); flex: 0 0 auto; padding: calc(var(--s) * 2px) calc(var(--s) * 2px) 0;
  min-height: calc(var(--s) * 11px); }
#menu .item.chatline .cur { display: none; }
#menu .item.chatline .val { margin-left: calc(var(--s) * 3px); }
/* the lobby room box: code centred, Copy link and WADs... on one row, then the privacy line */
#menu .roombox .items { row-gap: calc(var(--s) * 2px); }
#menu .roombox .item.custom.code-row { flex-basis: 100%; }
#menu .roombox .para { margin: 0; }
/* (the skull hangs left of a room-box item instead of taking a gutter, so all lines share one centre) */
#menu .roombox .item:not(.custom) { position: relative; grid-template-columns: auto auto; }
#menu .roombox .item:not(.custom) .cur { position: absolute; right: 100%; top: 0; bottom: 0; padding-right: calc(var(--s) * 2px); }
#menu .roombox .item:not(.custom) .val:empty { display: none; }
/* WADs cards: the Subscribe / Unsubscribe button on its own row; the idgames controls on a fixed grid */
#menu .wcard { grid-template-rows: auto auto 1fr auto auto auto; }
#menu .wcard .wb { justify-content: flex-end; overflow: visible; }
#menu .wcard .wb .wsub { margin-left: 0; }
#menu .layout-wads [data-panel="controls"] .items { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 calc(var(--s) * 5px); }
#menu .layout-wads.wads1 [data-panel="controls"] .items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#menu .layout-wads [data-panel="controls"] .item { min-width: 0; }
#menu .layout-wads [data-panel="controls"] .item .val { min-width: 0; justify-content: flex-start; }
/* binding rows: the label takes what the three slots leave, on two lines if it must */
#menu .item.bind { grid-template-columns: calc(var(--s) * 11px) minmax(0, 1fr) auto; }
#menu .item.bind .lab { overflow: hidden; }
#menu .item.bind .lab.two { flex-direction: column; gap: calc(var(--s) * 1px); padding: calc(var(--s) * 1px) 0; }
#menu .item.bind .val { overflow: visible; }
#menu .item.bind .slot { min-width: calc(var(--s) * 30px); }
#menu .layout-wads [data-panel="controls"] .items { grid-template-columns: minmax(0, 1.1fr) repeat(3, minmax(0, 1fr)); }
#menu .layout-wads.wads1 [data-panel="controls"] .items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#menu .layout-wads [data-panel="controls"] .item .val { margin-left: calc(var(--s) * 3px); }
/* narrow: each control's label over its value, two controls a row */
#menu .layout-wads.wads1 [data-panel="controls"] .item { grid-template-columns: calc(var(--s) * 9px) minmax(0, 1fr); grid-template-rows: auto auto; }
#menu .layout-wads.wads1 [data-panel="controls"] .item .cur { grid-row: 1 / 3; }
#menu .layout-wads.wads1 [data-panel="controls"] .item .val { grid-column: 2; margin-left: 0; }

/* ---- Chocolate Doom servers (screens-choco.js): the list reuses Find game's cards ---------- */
#menu .roomcard.choco.pinned { box-shadow: inset calc(var(--s) * 1px) 0 0 #f0c040, inset 0 0 0 calc(var(--s) * 1px) rgba(240, 192, 64, .35); }
#menu .roomcard .rl1 .pin-star { flex: 0 0 auto; align-self: center; }
#menu .layout-choco2 { width: min(96vw, calc(var(--s) * 440px)); grid-template-columns: 1fr 1fr;
  grid-template-areas: "players settings" "buttons buttons"; }
#menu .layout-choco1 { width: 100%; grid-template-columns: 1fr; grid-template-areas: "players" "buttons" "settings"; }
#menu .layout-choco2 .panel .items, #menu .layout-choco1 .panel .items { overflow: visible; }
/* Chocolate lobby: a long value on full-width lines under its label (never clipped) */
#menu .kvstack { display: grid; gap: calc(var(--s) * 2px); padding: calc(var(--s) * 1px) 0 calc(var(--s) * 1px) calc(var(--s) * 9px); min-width: 0; }
#menu .kvstack .kvline { display: flex; justify-content: flex-end; overflow: hidden; min-width: 0; }
#menu .kvstack .kvlab { display: flex; }

/* Screensaver caption (src/shell/saver.js): map, game and mode, a few seconds in a corner. */
#saverinfo { position: fixed; left: 14px; top: 12px; z-index: 3; pointer-events: none; opacity: 0;
  transition: opacity .6s; display: flex; flex-direction: column; gap: 4px; }
#saverinfo.show { opacity: .85; }
body:not([data-state="game"]) #saverinfo { display: none; }
