* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: #111827; color: #e5e7eb; }
#app { height: 100vh; display: flex; flex-direction: column; }
.hidden { display: none !important; }
#join { margin: auto; background: #1f2937; padding: 2rem; border-radius: 12px; display: flex; flex-direction: column; gap: 1rem; width: min(360px, 90vw); }
#login { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; }
.loginLogo { position: absolute; top: 1.5rem; left: 50%; transform: translateX(-50%); height: 2rem; width: auto; }
.loginCard { background: #1f2937; padding: 2rem; border-radius: 12px; display: flex; flex-direction: column; gap: 1rem; width: min(360px, 90vw); }
#join h1, .loginCard h1 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.logo { height: 24px; width: auto; flex-shrink: 0; }
#join .logo { height: 2rem; }
#landing { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; }
.landingLogo { position: absolute; top: 1.5rem; left: 50%; transform: translateX(-50%); height: 2rem; width: auto; }
.landingCard { background: #1f2937; padding: 2rem; border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 1rem; width: min(420px, 90vw); }
.landingCard h1 { margin: 0; font-size: 1.4rem; }
#landing .altcha { width: 100%; }
.captchaHint { margin: 0; font-size: .85rem; color: #9ca3af; text-align: center; }
.captchaSubmit { position: relative; overflow: hidden; width: 100%; padding: .65rem 1rem; font-size: 1rem; font-weight: 600; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.captchaSubmitFill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: rgba(255, 255, 255, .35); pointer-events: none; }
.captchaSubmitLabel { position: relative; z-index: 1; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
input { padding: .5rem .75rem; border-radius: 8px; border: 1px solid #374151; background: #111827; color: inherit; }
button { padding: .5rem 1rem; border-radius: 8px; border: 0; background: #2563eb; color: #fff; cursor: pointer; }
button:hover { background: #1d4ed8; }
#pvc { flex: 1; min-height: 0; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: #1f2937; }
#roomUptime { font-variant-numeric: tabular-nums; }
#status { font-size: .85rem; color: #9ca3af; margin-left: auto; }
#status.error { color: #f87171; }
#e2eeStatus { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid #374151; color: #9ca3af; }
#e2eeStatus.on { color: #34d399; border-color: #34d399; }
#e2eeStatus.off { color: #f87171; border-color: #f87171; }
.controls { display: flex; gap: .5rem; align-items: center; } .controls button { background: #374151; } .controls button.off { background: #dc2626; } #micBtn, #camBtn { background: #16a34a; } #micBtn.off, #camBtn.off { background: #dc2626; } #handBtn.raised { background: #f59e0b; color: #111827; } #screenBtn.on { background: #2563eb; color: #fff; } .tile.raised { outline: 3px solid #facc15; outline-offset: -3px; } .tile.raised::after { content: ""; position: absolute; inset: 0; z-index: 5; border: 3px solid #facc15; border-radius: inherit; pointer-events: none; } .tile.raised .tileLabelName { color: #fde047; } .tileHandIcon { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); z-index: 6; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; background: rgba(245, 158, 11, .92); border-radius: 999px; font-size: 18px; line-height: 1; box-shadow: 0 2px 8px rgba(0,0,0,.35); pointer-events: none; } .participant.raised { color: #fde047; font-weight: 600; background: rgba(250, 204, 21, .12); } .participant .participantHandIcon { font-size: 1rem; line-height: 1; }
.deviceControl { position: relative; display: inline-flex; align-items: center; }
.deviceArrow { position: absolute; top: -6px; right: -8px; width: 16px; height: 16px; padding: 0; border-radius: 999px; border: 1px solid #4b5563; background: #374151; color: #e5e7eb; font-size: 9px; line-height: 1; cursor: pointer; z-index: 5; }
.deviceArrow:hover { background: #4b5563; }
.deviceArrow:disabled { opacity: .45; cursor: default; }
.deviceMenu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 180px; max-width: 240px; max-height: 220px; overflow-y: auto; background: #111827; border: 1px solid #374151; border-radius: 6px; padding: .35rem; z-index: 30; display: flex; flex-direction: column; gap: .2rem; box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
.deviceMenu.hidden { display: none; }
.deviceMenu button { text-align: left; padding: .4rem .5rem; background: transparent; color: #e5e7eb; border: 0; border-radius: 4px; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; cursor: pointer; }
.deviceMenu button:hover:not(:disabled) { background: #374151; }
.deviceMenu button.selected { background: #1d4ed8; color: #fff; }
.deviceMenu button:disabled { opacity: .6; cursor: default; }
#chatBtn.unread { background: #16a34a; }
#chatBtn.unread:hover { background: #15803d; }
#leaveBtn { background: #dc2626; }
#viewBtn { background: #16a34a; display: inline-flex; align-items: center; justify-content: center; }
#viewBtn.speaker { background: #dc2626; }
#viewBtn svg { width: 16px; height: 16px; fill: #fff; }
.settingsControl { position: relative; display: inline-flex; align-items: center; }
.settingsMenu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px; background: #111827; border: 1px solid #374151; border-radius: 6px; padding: .35rem; z-index: 30; display: flex; flex-direction: column; gap: .2rem; box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
.settingsMenu.hidden { display: none; }
.settingsMenu button { text-align: left; padding: .4rem .5rem; background: transparent; color: #e5e7eb; border: 0; border-radius: 4px; font-size: .85rem; cursor: pointer; }
.settingsMenu button:hover { background: #374151; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modalCard { width: min(420px, 92vw); background: #1f2937; border: 1px solid #374151; border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.modalCard h3 { margin: 0; font-size: 1rem; }
.modalCard label { display: flex; flex-direction: row; align-items: center; gap: .5rem; }
.modalActions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .25rem; }
.helpCard { width: min(680px, 94vw); max-height: 85vh; }
.helpBody { overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; font-size: .9rem; }
.helpBody h4 { margin: .5rem 0 0; color: #d1d5db; font-size: .9rem; }
.helpBody h4:first-child { margin-top: 0; }
.helpBody ul { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: .3rem; }
.helpBody li { line-height: 1.45; }
.hiddenMedia { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: .01; pointer-events: none; z-index: -1; }
#bgSourceVideo { left: auto; top: auto; right: 0; bottom: 0; width: 32px; height: 18px; opacity: 1; z-index: 2147483647; }
.bgCard { width: min(680px, 94vw); max-height: calc(100vh - 16px); overflow-y: auto; }
.bgPreview { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; object-fit: cover; display: block; }
.bgThumbList { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.bgThumb { flex: 0 0 auto; width: 104px; height: 66px; border-radius: 8px; border: 2px solid #374151; background: #111827; color: #e5e7eb; cursor: pointer; padding: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.bgThumb.selected { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, .4); }
.bgThumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bgThumbLabel { font-size: .8rem; text-align: center; padding: 4px; }
.bgThumbBlack { background: #000; }
.bgThumbUpload { background: #1b2a3a; border-style: dashed; }
.bgThumbUpload .bgThumbLabel { color: #9fd; font-size: .72rem; }
.bgTune { font: 12px/1.35 ui-monospace, monospace; background: rgba(0, 0, 0, .35); color: #bfe; padding: 6px 8px; border-radius: 8px; box-sizing: border-box; }
.bgTune label { display: block; margin: 5px 0 1px; }
.bgTune input[type=range] { width: 100%; display: block; height: 18px; margin: 0; }
.bgTuneHead { display: flex; justify-content: space-between; align-items: center; font-weight: bold; }
.bgTuneHead button { cursor: pointer; background: #333; color: #fff; border: 1px solid #555; border-radius: 5px; padding: 1px 8px; font: inherit; }
.bgTuneBox { margin-top: 8px; }
.bgTuneBox summary { cursor: pointer; font-weight: 600; color: #e5e7eb; padding: 6px 2px; user-select: none; }
.bgTuneBox[open] summary { margin-bottom: 6px; }
select { padding: .5rem .75rem; border-radius: 8px; border: 1px solid #374151; background: #111827; color: inherit; font-size: .9rem; }
#mediaOpts { display: flex; flex-direction: row; gap: 1.25rem; }
#mediaOpts label { flex-direction: row; align-items: center; gap: .4rem; }
.controls select { padding: .35rem .5rem; font-size: .8rem; max-width: 150px; }
main { flex: 1; min-height: 0; display: flex; }
#videoGrid { flex: 1; display: grid; gap: 8px; padding: 8px; overflow: hidden; grid-template-columns: 1fr; grid-template-rows: 1fr; }
#videoGrid.fit-aspect { justify-content: center; align-content: start; }
#participants { position: relative; width: 240px; background: #1f2937; border-right: 1px solid #374151; display: flex; flex-direction: column; }
#participants h3 { margin: 0; padding: .5rem .75rem; font-size: .9rem; color: #d1d5db; border-bottom: 1px solid #374151; }
#participantSearch { position: relative; padding: .5rem .5rem 0; }
#participantSearch input { width: 100%; padding: .4rem 1.9rem .4rem .6rem; font-size: .9rem; }
#participantSearchClear { position: absolute; top: 1rem; right: .75rem; width: 16px; height: 16px; padding: 0; border: 0; border-radius: 50%; background: #ef4444; color: #fff; font-size: 11px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
#participantSearchClear:hover { background: #dc2626; }
.tileNotice { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; pointer-events: none; opacity: 0; transition: opacity .18s ease; }
.tileNotice.show { opacity: 1; }
.tileNotice span { max-width: 90%; padding: .45rem .7rem; border-radius: 999px; background: rgba(17, 24, 39, .92); border: 1px solid #374151; color: #e5e7eb; font-size: .85rem; text-align: center; box-shadow: 0 4px 12px rgba(0, 0, 0, .35); }
.tileNotice.join span { color: #4ade80; }
.tileNotice.left span { color: #f87171; }
.tile.leaving video, .tile.leaving .tileAvatar { filter: grayscale(1); opacity: .55; transition: opacity .2s ease, filter .2s ease; }
#participantList { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.participant { display: flex; align-items: center; gap: .35rem; padding: .35rem .5rem; border-radius: 4px; background: #111827; color: #e5e7eb; font-size: .9rem; }
.participantName { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.participant .mediaIcons { margin-left: auto; padding-left: .5rem; }
.participant .modBadge { display: none; align-items: center; justify-content: center; width: 14px; height: 14px; flex: 0 0 auto; border-radius: 4px; background: rgba(34,197,94,.18); color: #22c55e; font: 700 10px/1 system-ui, sans-serif; }
.participant .modBadge.on { display: inline-flex; }
.participant.me { color: #9ca3af; }
.participant.speaking { color: #ff5252; font-weight: 600; }
.tile { position: relative; background: #000; border-radius: 8px; overflow: hidden; }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; z-index: 1; }
.tileAvatar { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #1f2937; z-index: 1; user-select: none; }
.tileInitials { font-family: system-ui, sans-serif; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.tileConn { position: absolute; top: 6px; left: 6px; width: 14px; height: 14px; color: #22c55e; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .65)); z-index: 3; pointer-events: none; }
.tileConn.lost { color: #ef4444; }
.tileConn svg { display: block; width: 100%; height: 100%; fill: currentColor; }
.tileConn.mod { display: flex; align-items: center; justify-content: center; font: 700 10px/1 system-ui, sans-serif; }
.tileMenuBtn { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; z-index: 3; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: rgba(0,0,0,.38); color: #e5e7eb; font-size: 14px; line-height: 1; cursor: pointer; opacity: 0; pointer-events: none; }
.tile.modMenus .tileMenuBtn { opacity: 1; pointer-events: auto; }
.tileMenuBtn:hover { background: rgba(0,0,0,.85); }
.tileMenu { position: absolute; top: 30px; right: 4px; z-index: 4; min-width: 130px; background: #111827; border: 1px solid #1f2937; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.5); overflow: hidden; }
.tileMenuItem { display: block; width: 100%; padding: .4rem .6rem; border: 0; background: none; color: #e5e7eb; font: .8rem/1.3 system-ui, sans-serif; text-align: left; cursor: pointer; }
.tileMenuItem:hover:not(:disabled) { background: #1f2937; }
.tileMenuItem:disabled { color: #6b7280; cursor: default; }
.tileName { position: absolute; left: 0; right: 0; bottom: 0; padding: .25rem .5rem; background: rgba(0,0,0,.75); font-size: .8rem; display: flex; align-items: center; justify-content: center; gap: .35rem; z-index: 2; pointer-events: none; }
.tileLabelName { flex: 0 1 auto; max-width: 70%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.tileName .mediaIcons { margin-left: 0; padding-left: 0; }
.mediaIcons { display: inline-flex; gap: .2rem; vertical-align: middle; }
.mediaIcon { display: inline-flex; width: 14px; height: 14px; color: #e5e7eb; }
.mediaIcon svg { width: 100%; height: 100%; fill: currentColor; }
.mediaIcon.on { color: #22c55e; }
.mediaIcon.off { color: #ef4444; }
.tile.speaking { outline: 2px solid #ef4444; outline-offset: -2px; } .tile.speaking::before { content: ""; position: absolute; inset: 0; z-index: 4; border: 2px solid #ef4444; border-radius: inherit; pointer-events: none; }
.tile.speaking .tileName { color: #ff5252; font-weight: 600; }
#videoGrid.speaker-mode .tile { display: none; }
#videoGrid.speaker-mode .tile.active { display: block; }
#chat { width: 280px; background: #1f2937; display: flex; flex-direction: column; border-left: 1px solid #374151; position: relative; }
#chatLog { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.chatMsg { font-size: .9rem; word-break: break-word; }
.chatMsg.mine { color: #4ade80; }
.chatMsg.private { background: rgba(122, 79, 5, 0.65); color: #fff; border-radius: 4px; padding: .1rem .35rem; }
.chatMsg.clickable { cursor: pointer; }
.chatMsg.clickable:hover { opacity: .85; }
.chatMsg.private.clickable:hover { background: rgba(146, 64, 14, 0.85); opacity: 1; }
#chatToSel { width: calc(100% - 1.5rem); margin: .5rem .75rem 0; background: #111827; color: #e5e7eb; border: 1px solid #374151; border-radius: 4px; padding: .35rem .5rem; }
#chatToSel.private { background: rgba(122, 79, 5, 0.65); border-color: rgba(122, 79, 5, 0.65); color: #fff; }
#chatForm { display: flex; align-items: center; gap: .4rem; padding: .6rem; width: 100%; max-width: 100%; }
#chatInput { flex: 1 1 auto; min-width: 0; padding: .45rem .6rem; }
#chatForm button[type="submit"] { flex: 0 0 auto; padding: .45rem .6rem; }
#emojiBtn { width: auto; min-width: 32px; height: 34px; flex: 0 0 auto; padding: 0 .35rem; background: #111827; color: #e5e7eb; border: 1px solid #374151; border-radius: 4px; font-size: 1rem; line-height: 1; overflow: hidden; cursor: pointer; }
#emojiBtn:hover { background: #374151; }
#emojiPicker { position: absolute; left: .6rem; right: .6rem; bottom: 50px; width: auto; max-height: 180px; overflow-y: auto; background: #111827; border: 1px solid #374151; border-radius: 6px; display: grid; grid-template-columns: repeat(6, 1fr); gap: .25rem; padding: .35rem; z-index: 20; box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
#emojiPicker.hidden { display: none; }
#emojiPicker button { font-size: 1.15rem; padding: .25rem; background: transparent; border: none; border-radius: 4px; cursor: pointer; }
#emojiPicker button:hover { background: #374151; }

/* ---------- mobile menu (visible only below the mobile breakpoint) ---------- */
.mobileControl { position: relative; display: none; align-items: center; }
.mobileMenu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px; background: #111827; border: 1px solid #374151; border-radius: 6px; padding: .35rem; z-index: 50; display: flex; flex-direction: column; gap: .2rem; box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
.mobileMenu button { text-align: left; padding: .55rem .6rem; background: transparent; color: #e5e7eb; border: 0; border-radius: 4px; font-size: .9rem; cursor: pointer; }
.mobileMenu button:hover { background: #374151; }

/* ---------- mobile layout: phones in any orientation ---------- */
@media (max-width: 960px) {
  header { flex-wrap: wrap; row-gap: .35rem; gap: .5rem; padding: .4rem .6rem; }
  .logo { height: 20px; }
  header strong { font-size: .78rem; }
  #roomName { display: inline-block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
  #roomUptime { font-size: .78rem; }
  #status { font-size: .7rem; }
  #e2eeStatus { font-size: .65rem; }
  .controls { gap: .4rem; }
  .controls button { padding: .4rem .55rem; }
  /* desktop-only controls move into the hamburger menu */
  #participantsBtn, #devRefresh, #viewBtn, #chatBtn, .settingsControl { display: none; }
  .mobileControl { display: inline-flex; }
  /* participant list is not available on mobile: force it off */
  #participants { display: none !important; }
  /* chat becomes a bottom-half panel; tiles fill the top half */
  main { position: relative; }
  #pvc.chat-bottom #videoGrid { position: absolute; top: 0; left: 0; right: 0; height: 50%; }
  #chat { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; width: 100%; max-width: 100%; border-left: 0; border-top: 1px solid #374151; z-index: 40; }
}

@media (max-width: 960px) and (orientation: portrait) {
  #e2eeStatus { display: none; }
  .tile { background: #1f2937; }
  .tileAvatar { padding: 0; }
  .tileName { font-size: .68rem; padding: .12rem .3rem; }
}
