/* Tokens: light by default, dark when the system asks for it. */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --stage: #e4e6ea;
  --text: #16181d; --muted: #6b7280; --line: rgb(22 24 29 / .12);
  --accent: #3b6cf6; --on-accent: #ffffff; --accent-soft: rgb(59 108 246 / .12);
  --yes: #1f9d55; --on-yes: #ffffff; --no: #d9384a; --on-no: #ffffff;
  --scrim: rgb(0 0 0 / .5); --float: rgb(255 255 255 / .92); --shadow: 0 8px 24px rgb(0 0 0 / .14);
  --pill: 999px; --card: 20px; --tile: 14px; --small: 10px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --control: 44px; --column: 400px; --narrow: 520px;
  --bar-room: calc(var(--control) + var(--s6) + var(--s4));
  --quick: 160ms ease-out; --screen: 240ms ease-out;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --surface: #1d1f24; --stage: #0b0c0e;
    --text: #ecedef; --muted: #9aa0aa; --line: rgb(236 237 239 / .14);
    --accent: #7c9cff; --on-accent: #0b0c0e; --accent-soft: rgb(124 156 255 / .16);
    --yes: #3ec47a; --on-yes: #0b0c0e; --no: #ff6b7a; --on-no: #0b0c0e;
    --scrim: rgb(0 0 0 / .6); --float: rgb(29 31 36 / .92); --shadow: 0 8px 24px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
@media (prefers-reduced-motion: reduce) {
  :root { --quick: 0s; --screen: 0s; }
  *, *::before, *::after { animation: none !important; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 400 15px/1.4 var(--sans); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
main { height: 100%; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill, .field, .round {
  height: var(--control); border-radius: var(--pill); display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--quick), color var(--quick), transform var(--quick), opacity var(--quick);
}
.pill { padding: 0 var(--s5); gap: var(--s2); font-weight: 600; white-space: nowrap; }
.pill:active:not(:disabled), .round:active { transform: scale(.97); }
.pill:disabled { opacity: .45; cursor: default; }
.pill.primary { background: var(--accent); color: var(--on-accent); }
.pill.primary:hover:not(:disabled) { filter: brightness(1.06); }
.pill.yes { background: var(--yes); color: var(--on-yes); }
.pill.quiet { background: var(--accent-soft); }
.pill.outline { box-shadow: inset 0 0 0 1.5px var(--line); }
.pill.outline:hover:not(:disabled), .pill.quiet:hover:not(:disabled) { background: var(--accent-soft); filter: brightness(1.04); }
.pill.danger { background: var(--no); color: var(--on-no); }
.pill.wide { width: 100%; }
.link { color: var(--accent); font-weight: 500; }
.link:hover { text-decoration: underline; }
.field { width: 100%; padding: 0 var(--s4); background: var(--surface); border: 1.5px solid var(--line); text-align: center; }
.field:focus { border-color: var(--accent); outline: none; }
.field::placeholder { color: var(--muted); }
.field.mono { font-family: var(--mono); font-size: 13px; text-align: left; }
.round { width: var(--control); position: relative; background: var(--float); box-shadow: var(--shadow); }
.round:hover { background: var(--accent-soft); }
.round.danger { background: var(--no); color: var(--on-no); }
.icons { display: none; }
.round svg, .pill svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--pill);
  background: var(--no); color: var(--on-no); font-size: 11px; font-weight: 600; line-height: 18px;
}
.code {
  font-family: var(--mono); font-size: 13px; letter-spacing: .08em;
  padding: 2px 8px; border-radius: var(--pill); background: var(--accent-soft); color: var(--text);
}

/* The mark: three rings, breathing while waiting, green once let in, grey once turned back or left. */
.mark { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; position: relative; flex: none; }
.mark::before, .mark::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); opacity: .35; }
.mark::after { inset: 10px; opacity: .6; }
.mark span { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); }
.mark.wait::before { animation: breathe 2s ease-in-out infinite; }
.mark.wait::after { animation: breathe 2s ease-in-out .4s infinite; }
.mark.wait span { animation: breathe 2s ease-in-out .8s infinite; }
.mark.ok span { background: var(--yes); }
.mark.ok::before, .mark.ok::after { border-color: var(--yes); }
.mark.gone span { background: var(--muted); }
.mark.gone::before, .mark.gone::after { border-color: var(--muted); }

/* Start, Join and Left: one centred column. */
.centre { min-height: 100%; display: grid; place-items: center; padding: var(--s6) var(--s4); animation: rise var(--screen) both; }
.column { width: 100%; max-width: var(--column); display: flex; flex-direction: column; align-items: center; gap: var(--s4); text-align: center; }
.column .lead { max-width: 32ch; }
.column .gap { height: var(--s2); }
.column .group { width: 100%; display: flex; flex-direction: column; align-items: center; gap: var(--s4); }
.brand { display: flex; flex-direction: column; align-items: center; gap: var(--s3); }
#join h1 { margin-top: calc(var(--s3) - var(--s4)); }
.footnote { margin-top: var(--s5); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.reveal { width: 100%; display: flex; flex-direction: column; gap: var(--s3); align-items: center; animation: rise var(--quick) both; }
.reveal .field.narrow { width: min(300px, 100%); text-overflow: ellipsis; }
.or { display: flex; align-items: center; gap: var(--s3); width: 100%; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.notices { width: 100%; display: flex; flex-direction: column; gap: var(--s2); }
.notices:empty { display: none; }
.notice { width: 100%; padding: var(--s3) var(--s4); border-radius: var(--tile); background: var(--accent-soft); text-align: left; animation: rise var(--quick) both; }
.notice.warn { background: color-mix(in srgb, var(--no) 14%, transparent); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* Share: a stage of screens with its controls floating over it. */
#room { height: 100%; position: relative; overflow: hidden; display: flex; flex-direction: column; background: var(--stage); }
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: var(--s4); padding-bottom: var(--bar-room); }
#room[data-enlarged] .stage { padding: 0; }
#room:not([data-stage="screens"]) #screens, #room:not([data-stage="alone"]) [data-part="alone"], #room:not([data-stage="nobody"]) [data-part="nobody"] { display: none; }
.card, .empty { width: 100%; max-width: var(--column); display: flex; flex-direction: column; gap: var(--s4); text-align: center; }
.card { background: var(--surface); border-radius: var(--card); padding: var(--s5); }
.empty { align-items: center; }
.linkbox { display: flex; gap: var(--s2); align-items: center; }
.linkbox .field { flex: 1; min-width: 0; text-overflow: ellipsis; }
.linkbox .pill { flex: none; }

/* The screens: tiles sized to their picture, each row no taller than its share of the window. */
.grid { width: 100%; height: 100%; display: flex; flex-wrap: wrap; gap: var(--s3); align-content: center; justify-content: center; }
.tile {
  position: relative; margin: 0; flex: none; aspect-ratio: var(--ratio, 16 / 9); border-radius: var(--tile); overflow: hidden; background: var(--stage);
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; transition: box-shadow var(--quick);
  width: min(calc((100% - (var(--cols) - 1) * var(--s3)) / var(--cols)), calc((100dvh - 150px - (var(--rows) - 1) * var(--s3)) / var(--rows) * var(--ratio, 16 / 9)));
}
.tile:hover { box-shadow: 0 0 0 2px var(--accent); }
.tile video { width: 100%; height: 100%; display: block; object-fit: contain; }
#room[data-enlarged] .tile:not(.enlarged) { display: none; }
.tile.enlarged { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; box-shadow: none; background: #000; }
.who {
  position: absolute; left: var(--s3); bottom: var(--s3); display: inline-flex; align-items: center; gap: var(--s2);
  padding: 4px 10px 4px 6px; border-radius: var(--pill); background: var(--float); box-shadow: var(--shadow); font-size: 13px; font-weight: 600;
}
.who .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--yes); }
.tile .enlarge { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
.tile .enlarge:focus-visible { outline-offset: -4px; }
.tile .fullscreen { position: absolute; right: var(--s3); bottom: var(--s3); transition: opacity var(--quick); }
.tile:not(.enlarged) .fullscreen, #room[data-idle] .tile .fullscreen:not(:focus-visible) { opacity: 0; pointer-events: none; }
.tile:not(.enlarged) .fullscreen { visibility: hidden; }
.figures {
  position: absolute; right: var(--s3); top: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--small); text-align: left;
  background: var(--float); box-shadow: var(--shadow); font: 12px/1.5 var(--mono); white-space: nowrap; animation: rise var(--quick) both;
}
#room:not([data-details]) .figures, .figures:empty { display: none; }

/* This member's own screen: a card on the stage while it is the only one, a floating preview beside others' screens. */
.outgoing { display: flex; align-items: center; animation: rise var(--quick) both; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--small); overflow: hidden; flex: none; background: #000; }
.thumb video { width: 100%; height: 100%; display: block; object-fit: contain; }
.outgoing .text { display: flex; flex-direction: column; gap: 2px; }
.live { display: flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--no); animation: breathe 1.4s ease-in-out infinite; }
#room[data-stage="outgoing"] .outgoing {
  width: 100%; max-width: var(--column); flex-direction: column; align-items: stretch; gap: var(--s4); text-align: center;
  background: var(--surface); border-radius: var(--card); padding: var(--s5);
}
#room[data-stage="outgoing"] .thumb { width: 100%; border-radius: var(--tile); }
#room[data-stage="outgoing"] .outgoing .text { align-items: center; }
#room[data-stage="outgoing"] #stop-button { align-self: center; }
#room:not([data-stage="outgoing"]) .outgoing {
  position: absolute; left: var(--s4); bottom: var(--bar-room); gap: var(--s3); z-index: 1;
  padding: var(--s2) var(--s3) var(--s2) var(--s2); border-radius: var(--tile); background: var(--float); box-shadow: var(--shadow); backdrop-filter: blur(12px);
}
#room:not([data-stage="outgoing"]) .thumb { position: static; width: 96px; }
#room:not([data-stage="outgoing"]) .outgoing .figures { display: none; }
#room:not([data-stage="outgoing"]) .outgoing .text { font-size: 13px; }
#room:not([data-stage="outgoing"]) #outgoing-seen { display: none; }
#room:not([data-stage="outgoing"]) #stop-button { height: 36px; padding: 0 var(--s4); }
#room[data-enlarged] .outgoing { display: none; }

/* The bar: hidden while a screen fills the window, until the pointer moves. */
.bar {
  position: absolute; left: 50%; bottom: var(--s5); transform: translateX(-50%); display: flex; gap: var(--s3); align-items: center; z-index: 1;
  padding: var(--s2); border-radius: var(--pill); background: var(--float); box-shadow: var(--shadow); backdrop-filter: blur(12px);
  transition: opacity var(--quick), transform var(--quick);
}
.bar .round { box-shadow: none; background: transparent; }
.bar .round:hover { background: var(--accent-soft); }
.bar .round.danger, .bar .round.danger:hover { background: var(--no); }
#room:not([data-stage="screens"]) #share-button { display: none; }
#room[data-idle] .bar { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
#room[data-idle] .bar:focus-within { opacity: 1; transform: translateX(-50%); pointer-events: auto; }

/* Requests to join, over everything on the stage. */
.requests { position: absolute; left: 0; right: 0; top: var(--s4); margin: 0 auto; width: min(100% - 2 * var(--s4), 440px); display: flex; flex-direction: column; gap: var(--s2); z-index: 2; }
.request {
  padding: var(--s3) var(--s4); border-radius: var(--card); background: var(--float); box-shadow: var(--shadow); backdrop-filter: blur(12px);
  display: flex; flex-direction: column; gap: var(--s3); animation: rise var(--quick) both;
}
.request .head { display: flex; align-items: center; gap: var(--s3); }
.request .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.request .text b, .person .text b { display: flex; align-items: center; gap: var(--s2); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 600; flex: none; }
.request .answers { display: flex; gap: var(--s2); }
.request .answers .pill { flex: 1; height: 40px; }
.request .waiting { font-size: 13px; color: var(--muted); }
.request .waiting:empty { display: none; }
.request .answered { display: flex; align-items: center; gap: var(--s2); font-size: 13px; }
.tick { width: 22px; height: 22px; border-radius: 50%; background: var(--yes); color: var(--on-yes); display: grid; place-items: center; flex: none; }
.tick.refuse { background: var(--muted); color: var(--surface); }
.tick svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* Notices on the stage: at the top, or above the bar while a request holds the top. */
#room .notices { position: absolute; left: 50%; top: var(--s4); transform: translateX(-50%); width: min(100% - 2 * var(--s4), 440px); align-items: center; z-index: 1; }
#room[data-requests] .notices { top: auto; bottom: var(--bar-room); }
#room .notice {
  width: auto; padding: var(--s2) var(--s4); border-radius: var(--tile); background: var(--float); box-shadow: var(--shadow); backdrop-filter: blur(12px);
  font-size: 13px; text-align: center;
}
#room .notice.warn { box-shadow: var(--shadow), inset 0 0 0 1.5px color-mix(in srgb, var(--no) 50%, transparent); }

/* Sheets: the people and the picture choices, one step away. */
.scrim { position: absolute; inset: 0; background: var(--scrim); z-index: 3; animation: fade var(--quick) both; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: var(--s5); margin: 0 auto; width: min(100% - 2 * var(--s4), 420px); max-height: calc(100% - 2 * var(--s5));
  overflow: auto; background: var(--surface); border-radius: var(--card); box-shadow: var(--shadow); padding: var(--s4); z-index: 4;
  display: flex; flex-direction: column; gap: var(--s3); animation: rise var(--quick) both;
}
.sheet:focus { outline: none; }
.sheet[data-more] { mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); }
.sheet > * { flex: none; }
.sheet .head { display: flex; align-items: center; justify-content: space-between; }
.sheet .head .round { box-shadow: none; background: transparent; width: 36px; height: 36px; }
.sheet .head .round:hover { background: var(--accent-soft); }
.sheet h3 { margin: var(--s2) 0 0; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sheet .pill.wide { margin-top: var(--s1); }
.sheet .divider { height: 1px; background: var(--line); margin: var(--s1) 0; }
#room[data-sharing="yes"] #picture-sheet [data-part="idle"], #room:not([data-sharing="yes"]) #picture-sheet [data-part="sharing"] { display: none; }
.people { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s3); }
.person { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) 0; }
.person .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.person .state { font-size: 13px; color: var(--muted); }
.person .state:empty { display: none; }
.person .state.sharing { color: var(--yes); }
.person .state.failed { color: var(--no); }
.options { display: flex; flex-direction: column; gap: var(--s3); }
.option { display: grid; grid-template-columns: var(--control) 1fr; align-items: center; column-gap: var(--s3); padding: 6px var(--s3); border-radius: var(--tile); cursor: pointer; }
.option:hover { background: var(--accent-soft); }
.option .text { display: flex; flex-direction: column; }
.option .text span { font-size: 13px; line-height: 21px; color: var(--muted); }
.option input { appearance: none; margin: 0; flex: none; position: relative; cursor: pointer; transition: background var(--quick); }
.option input[type="radio"] { justify-self: center; width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--line); }
.option input[type="radio"]:checked { background: var(--accent); box-shadow: none; }
.option input[type="radio"]:checked::after {
  content: ""; position: absolute; left: 8px; top: 4.5px; width: 4px; height: 9px;
  border: solid var(--on-accent); border-width: 0 2.2px 2.2px 0; transform: rotate(45deg);
}
.toggle { width: 44px; height: 26px; border-radius: var(--pill); background: var(--line); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / .2); transition: transform var(--quick);
}
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(18px); }
#room:not([data-details]) .sheet .details { display: none; }
.details { display: flex; flex-direction: column; gap: var(--s2); }
.details .scroll { overflow-x: auto; }
.details table { border-collapse: collapse; font: 12px/1.5 var(--mono); }
.details th, .details td { padding: var(--s1) var(--s3) var(--s1) 0; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.details p { color: var(--muted); font-size: 13px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Narrow: the window at `--narrow` or less, marked on the room by the page, since a media query can't read a token. */
#room[data-narrow] .bar .pill span { display: none; }
#room[data-narrow] .bar .pill { width: var(--control); padding: 0; }
#room[data-narrow]:not([data-stage="outgoing"]) .outgoing { right: var(--s4); }
#room[data-narrow]:not([data-stage="outgoing"]) .thumb { width: 72px; }
