:root {
  --bg: #1b1d21;
  --surface: #2a2d33;
  --surface-2: #383c44;
  --text: #eceef2;
  --muted: #a3a8b3;
  --huddle: #f2b84b;
  --speaking: #4fd1b0;
  --focus: #8f95a3;
  --danger: #e0503f;
  --tile-w: 320px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
[hidden] { display: none !important; }

/* ---------- Join ---------- */
.join {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  gap: 12px; padding: 16px; text-align: center; overflow-y: auto;
}
.join h1 { margin: 0; font-size: 32px; font-weight: 600; }
.join p { margin: 0; color: var(--muted); }
.join input {
  width: min(320px, 100%); padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--surface-2); background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.join input:focus { outline: 2px solid var(--speaking); outline-offset: 1px; }
.join > button {
  padding: 10px 28px; border-radius: 999px; background: var(--speaking); color: #0d2b24; font-weight: 600; font-size: 15px;
}
.join > button:disabled { opacity: .6; cursor: default; }
.error { color: #ff9c8f; min-height: 1.4em; }

/* ---------- Room layout ---------- */
.room { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }

/* The wall holds the stage (large tiles), or the shares, plus the strip (small tiles). */
.wall { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.wall.strip-side { flex-direction: row; }

.stage { flex: 1 1 0; min-width: 0; min-height: 0; padding: 16px; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.stage-head { height: 24px; flex: none; padding: 0 4px; color: var(--muted); font-size: 12.5px; font-weight: 600; letter-spacing: .02em; }
.stage-tiles {
  flex: 1 1 0; min-height: 0; display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; align-content: center; justify-content: center; border-radius: 14px;
}
.stage.huddle { padding: 24px; }
.stage.huddle .stage-head { color: var(--huddle); }
.stage.huddle .stage-tiles { outline: 2px solid var(--huddle); outline-offset: 6px; background: rgba(242, 184, 75, .05); }
.stage-empty { max-width: 420px; margin: 0; text-align: center; color: var(--muted); font-size: 15px; }

.strip {
  flex: none; --tile-w: var(--strip-w, 168px);
  display: flex; flex-direction: row; gap: 8px; align-items: flex-start;
  padding: 0 12px 8px; overflow-x: auto; overflow-y: hidden;
}
.wall.strip-side .strip { flex-direction: column; align-items: stretch; padding: 16px 10px 8px 0; overflow-x: hidden; overflow-y: auto; }

.group {
  flex: none; display: flex; flex-direction: column; gap: 4px;
  padding: 4px; border-radius: 12px; border: 2px solid transparent;
}
.group-head { display: flex; align-items: center; gap: 8px; height: 22px; padding: 0 4px; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.group-head .title { font-weight: 600; letter-spacing: .02em; }
.group-tiles { display: flex; flex-direction: row; gap: 6px; }
.wall.strip-side .group-tiles { flex-direction: column; }

.group.huddle { border-color: var(--huddle); background: rgba(242, 184, 75, .07); }
.group.huddle .title { color: var(--huddle); }
.group.focus .tile { opacity: .72; }
.group .join-huddle {
  margin-left: auto; padding: 1px 10px; border-radius: 999px; background: var(--huddle); color: #2b1f05; font-weight: 600; font-size: 11.5px;
}
.strip .tile { border-radius: 8px; }
.strip .tile .label { left: 5px; bottom: 5px; padding: 2px 6px; font-size: 11.5px; }
.strip .tile .badge { right: 5px; top: 5px; font-size: 11px; padding: 1px 6px; }
.strip .tile .action { padding: 5px 10px; font-size: 11.5px; }

/* ---------- Tiles ---------- */
.tile {
  position: relative; width: var(--tile-w); max-width: 100%; aspect-ratio: 16 / 9;
  background: var(--surface); border-radius: 12px; overflow: hidden;
  outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .12s;
}
.tile.speaking { outline-color: var(--speaking); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #111; }
.tile.me video { transform: scaleX(-1); }
.tile.nocam video { visibility: hidden; }
.tile .avatar {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
}
.tile.nocam .avatar { display: flex; }
.tile .avatar span {
  width: 30%; aspect-ratio: 1; max-width: 96px; border-radius: 50%; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: clamp(18px, calc(var(--tile-w) / 9), 40px); font-weight: 600;
}
.tile .label {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  display: flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 6px;
  background: rgba(0, 0, 0, .55); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .micoff { display: none; width: 14px; height: 14px; fill: #ff9c8f; color: #ff9c8f; flex: none; }
.tile.muted .micoff { display: block; }
.tile .badge {
  position: absolute; right: 8px; top: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, .55); color: var(--text); font-size: 11.5px; display: none;
}
.tile.is-focus .badge, .tile.is-talking .badge { display: block; }
.tile.is-talking .badge { background: var(--speaking); color: #0d2b24; font-weight: 600; }

.tile .action {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 8px 16px; border-radius: 999px; background: rgba(20, 22, 26, .88); color: var(--text);
  font-weight: 600; font-size: 13px; white-space: nowrap; border: 1px solid rgba(255, 255, 255, .25);
  opacity: 0; transition: opacity .12s; user-select: none; touch-action: none;
}
.tile:hover .action, .tile .action:focus-visible, .tile .action.holding { opacity: 1; }
.tile .action.holding { background: var(--speaking); color: #0d2b24; border-color: transparent; }
.tile .action:empty { display: none; }

/* ---------- Screen shares ---------- */
.shares { flex: 1 1 0; display: flex; gap: 12px; padding: 16px; min-height: 0; min-width: 0; overflow: hidden; }
.shares.stack { flex-direction: column; }
.share { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; background: #000; border-radius: 12px; overflow: hidden; }
/* Absolutely positioned so the video's own pixel size can never stretch the layout. */
.share video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.share .label { position: absolute; left: 10px; bottom: 10px; padding: 3px 8px; border-radius: 6px; background: rgba(0, 0, 0, .6); font-size: 12.5px; }
.share.local { outline: 2px solid var(--speaking); outline-offset: -2px; }

/* ---------- Bottom bar ---------- */
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 12px 20px 16px; }
.bar-center { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.bar-right { text-align: right; }
.status { color: var(--muted); font-size: 13px; }
.sep { width: 1px; height: 28px; background: var(--surface-2); margin: 0 4px; }

.ctl {
  height: 48px; min-width: 48px; border-radius: 999px; background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 12px;
  user-select: none; touch-action: none;
}
.ctl.wide { padding: 0 18px 0 14px; font-weight: 600; font-size: 13px; }
.ctl svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.ctl:hover { background: #474c56; }
.ctl:focus-visible { outline: 2px solid var(--speaking); outline-offset: 2px; }
.ctl .off { display: none; }
.ctl.is-off { background: var(--danger); }
.ctl.is-off .on { display: none; }
.ctl.is-off .off { display: block; }
.ctl.active { background: var(--speaking); color: #0d2b24; }
.ctl.danger { background: var(--danger); }
.ctl.danger:hover { background: #ea6a5a; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: #0f1012; border: 1px solid var(--surface-2); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 5;
}

@media (max-width: 720px) {
  .bar { grid-template-columns: 1fr; padding: 10px 16px 14px; }
  .bar-left, .bar-right { display: none; }
  .ctl.wide span { display: none; }
  .ctl.wide { padding: 0 12px; }
  .shares { padding: 12px 16px; }
}

/* ---------- Bar extras ---------- */
.bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.ctl { position: relative; }
.dot {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* ---------- Chat ---------- */
.room.chat-open { grid-template-columns: minmax(0, 1fr) 320px; }
.bar { grid-column: 1 / -1; }
.chat { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; min-height: 0; margin: 16px 16px 0 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.chat header { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 14px; font-weight: 600; border-bottom: 1px solid var(--surface-2); }
.chat .x { background: none; font-size: 22px; line-height: 1; padding: 2px 8px; border-radius: 6px; color: var(--muted); }
.chat .x:hover { background: var(--surface-2); color: var(--text); }
.chat-log { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { margin: auto 0; color: var(--muted); text-align: center; font-size: 13px; }
.msg .who { color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .body a { color: var(--speaking); }
.msg.mine .who { color: var(--speaking); }
.chat form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--surface-2); }
.chat input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 999px; border: 1px solid var(--surface-2); background: var(--bg); color: var(--text); font: inherit; }
.chat input:focus { outline: 2px solid var(--speaking); outline-offset: 1px; }
.chat form button { padding: 0 14px; border-radius: 999px; background: var(--speaking); color: #0d2b24; font-weight: 600; }

/* ---------- Settings ---------- */
.settings { width: min(440px, calc(100vw - 32px)); border: 1px solid var(--surface-2); border-radius: 14px; background: var(--surface); color: var(--text); padding: 20px; }
.settings::backdrop { background: rgba(0, 0, 0, .55); }
.settings h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.settings label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 13px; }
.settings label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 10px 0 0; }
.settings select { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--surface-2); background: var(--bg); color: var(--text); font: inherit; }
.settings video { display: block; width: 100%; aspect-ratio: 16 / 9; margin-top: 8px; border-radius: 10px; background: #111; object-fit: cover; transform: scaleX(-1); }
.settings .hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; min-height: 1em; }
.meter { height: 8px; margin-top: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--speaking); transition: width .06s linear; }
.settings .plain { margin-top: 8px; padding: 7px 14px; border-radius: 999px; background: var(--surface-2); }
.settings .actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.settings .primary { padding: 9px 22px; border-radius: 999px; background: var(--speaking); color: #0d2b24; font-weight: 600; }

/* ---------- Mini window ---------- */
.away { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 16px; }
.away button { padding: 10px 24px; border-radius: 999px; background: var(--speaking); color: #0d2b24; font-weight: 600; }
.room.mini .bar { grid-template-columns: 1fr; padding: 8px 10px 10px; gap: 8px; }
.room.mini .bar-left, .room.mini .sep, .room.mini #clock,
.room.mini #camBtn, .room.mini #shareBtn, .room.mini #announceBtn,
.room.mini #chatBtn, .room.mini #miniBtn, .room.mini #settingsBtn { display: none; }
.room.mini .bar-center, .room.mini .bar-right { justify-content: center; }
.room.mini .bar { display: flex; flex-wrap: wrap; justify-content: center; }
.room.mini .ctl { height: 40px; min-width: 40px; }
.room.mini .ctl.wide { padding: 0 12px; }
.room.mini .ctl.wide span { display: none; }
.room.mini .chat { display: none; }

@media (max-width: 720px) {
  .bar { display: flex; flex-wrap: wrap; justify-content: center; }
  .bar-right { display: flex; }
  #clock { display: none; }
  .room.chat-open { grid-template-columns: minmax(0, 1fr); }
  .chat { position: fixed; inset: 0 0 0 0; margin: 0; border-radius: 0; z-index: 4; }
}

/* ---------- Mute someone, leave huddle, leave office ---------- */
.tile .mute {
  position: absolute; left: 8px; top: 8px; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 22, 26, .88); border: 1px solid rgba(255, 255, 255, .25);
  opacity: 0; transition: opacity .12s;
}
.tile .mute .micoff { display: block; width: 16px; height: 16px; fill: var(--text); color: var(--text); }
.tile:hover .mute, .tile .mute:focus-visible { opacity: 1; }
.tile .mute:hover { background: var(--danger); border-color: transparent; }
.tile.me .mute, .tile.muted .mute { display: none; }
.strip .tile .mute { left: 5px; top: 5px; width: 24px; height: 24px; }
.strip .tile .mute .micoff { width: 13px; height: 13px; }
.ctl.huddle-leave { background: var(--huddle); color: #2b1f05; }
.ctl.huddle-leave:hover { background: #f7c96e; }
.ctl.exit { background: var(--danger); margin-left: 6px; }
.ctl.exit:hover { background: #ea6a5a; }
.room.mini #exitBtn { display: none; }

/* ---------- Background picker ---------- */
.bg-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.bg-opt {
  position: relative; aspect-ratio: 16 / 9; padding: 0; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 2px solid transparent; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.bg-opt canvas, .bg-opt img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.bg-opt span { position: relative; padding: 1px 6px; border-radius: 5px; font-size: 11px; background: rgba(0, 0, 0, .55); }
.bg-opt:hover { border-color: var(--muted); }
.bg-opt.sel { border-color: var(--speaking); box-shadow: 0 0 0 2px rgba(79, 209, 176, .3); }
.bg-opt.upload { border: 2px dashed var(--muted); background: none; }
.bg-opt.blur-light { background: linear-gradient(135deg, #59606b, #3b4049); }
.bg-opt.blur-medium { background: linear-gradient(135deg, #6c7481, #3b4049); }
.bg-opt.blur-heavy { background: linear-gradient(135deg, #838c9a, #3b4049); }

/* ---------- Sign-in screen ---------- */
.join .google { padding: 11px 26px; border-radius: 999px; background: #fff; color: #1b1d21; font-weight: 600; font-size: 15px; text-decoration: none; }
.join .google:hover { background: #e9ebef; }
.join .quiet { color: var(--muted); font-size: 13px; }
.join #joinLead { max-width: 420px; }
.whoami { display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px 14px; border-radius: 12px; background: var(--surface); }
.whoami img { width: 40px; height: 40px; border-radius: 50%; }
.whoami div { display: flex; flex-direction: column; }
.whoami span { color: var(--muted); font-size: 12.5px; }

/* ---------- Tile tools: mute, remove ---------- */
.tile .tools { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.tile:hover .tools, .tile .tools:focus-within { opacity: 1; }
.tile .tools .mute { position: static; opacity: 1; }
.tile .kick {
  width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--text);
  background: rgba(20, 22, 26, .88); border: 1px solid rgba(255, 255, 255, .25);
}
.tile .kick:hover { background: var(--danger); border-color: transparent; }
.tile.me .tools, .room.guest .kick, .room.mini .kick { display: none; }
.strip .tile .tools { left: 5px; top: 5px; gap: 4px; }
.strip .tile .kick { width: 24px; height: 24px; font-size: 16px; }
.tile .avatar span { background-size: cover; background-position: center; }

/* ---------- Guests waiting to be let in ---------- */
.knocks { position: fixed; right: 16px; top: 16px; z-index: 6; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.knock { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #0f1012; border: 1px solid var(--huddle); }
.knock .face { width: 36px; height: 36px; flex: none; border-radius: 50%; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-weight: 600; }
.knock .face img { width: 100%; height: 100%; object-fit: cover; }
.knock .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.knock .text b, .knock .text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.knock .text span { color: var(--muted); font-size: 12px; }
.knock button { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 12.5px; }
.knock .admit { background: var(--speaking); color: #0d2b24; }
.knock .deny { background: var(--surface-2); }

/* ---------- Whiteboards (a live Google file shown to the group) ---------- */
.split { position: relative; display: inline-flex; }
.split #boardBtn { border-radius: 999px 0 0 999px; padding-right: 8px; }
.split .caret { border-radius: 0 999px 999px 0; min-width: 30px; padding: 0 8px 0 2px; margin-left: 1px; }
.split .caret svg { width: 18px; height: 18px; }
.ctl.busy { opacity: .6; pointer-events: none; }
.menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 6; min-width: 170px; padding: 6px;
  background: var(--surface); border: 1px solid var(--surface-2); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column;
}
.menu button { text-align: left; padding: 9px 12px; border-radius: 6px; font-size: 14px; background: transparent; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button[aria-checked="true"]::after { content: '✓'; float: right; color: var(--speaking); }
.share.board { display: flex; flex-direction: column; background: var(--surface); }
.board-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 7px 12px; font-size: 13px; }
.board-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-head a { color: var(--speaking); white-space: nowrap; }
.board-head button { padding: 4px 10px; border-radius: 6px; background: var(--surface-2); font-size: 12.5px; white-space: nowrap; }
.board-head button:hover { background: #474c56; }
.share.board iframe { flex: 1 1 0; min-height: 0; width: 100%; border: 0; background: #fff; display: block; }
.room.mini #boardSplit { display: none; }
.menu hr { border: 0; border-top: 1px solid var(--surface-2); margin: 5px 4px; }
.settings input[type="url"] { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--surface-2); background: var(--bg); color: var(--text); font: inherit; }
.settings input[type="url"]:focus-visible { outline: 2px solid var(--speaking); outline-offset: 1px; }
.settings .hint.bad { color: #ff9d90; }
.settings .actions { gap: 10px; align-items: center; }
.settings .actions .plain { margin-top: 0; padding: 9px 18px; }
.recent { display: flex; flex-direction: column; gap: 2px; max-height: 210px; overflow-y: auto; }
.recent button { display: flex; gap: 10px; align-items: baseline; text-align: left; padding: 8px 10px; border-radius: 8px; background: transparent; }
.recent button:hover, .recent button:focus-visible { background: var(--surface-2); outline: none; }
.recent .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .meta { flex: none; color: var(--muted); font-size: 12.5px; }

/* ---------- Before joining: camera preview and how you will arrive ---------- */
.pre { width: min(520px, 100%); display: flex; flex-direction: column; gap: 10px; flex: none; }
.pre-view { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #0f1012; }
.pre-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.pre-note { position: absolute; inset: 0 0 64px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 0 16px; color: var(--muted); }
.pre-note button { padding: 7px 16px; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.pre-note button:hover { background: #474c56; }
.pre-ctl { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; justify-content: center; gap: 10px; }
.pre-ctl .ctl { background: rgba(42, 45, 51, .88); }
.pre-ctl .ctl:hover { background: #474c56; }
.pre-ctl .ctl.is-off { background: var(--danger); }
.pre-ctl .ctl.active { background: var(--speaking); }
.pre .hint { margin: 0; font-size: 12.5px; min-height: 1em; }
@media (max-width: 480px) { .pre .bg-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
