/* Lovelace meetings. House style (Charter, ink on paper) for the pages; a dark
   stage for the meeting itself, where faces should be the brightest thing. */
@font-face { font-family: "Charter"; src: url("/app/fonts/XCharter-Roman.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Charter"; src: url("/app/fonts/XCharter-Bold.otf") format("opentype"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light dark;
  --paper: #ffffff; --ink: #141414; --quiet: #6a6a6a; --faint: #d6d6d6; --wash: #f4f4f2;
  --bad: #a3261d; --live: #1f6b3a; --hl: #e8b23a;
  --stage: #121212; --stage-2: #1d1d1d; --stage-3: #2a2a2a; --on-stage: #ececec; --on-stage-quiet: #a0a0a0;
  --serif: "Charter", "Bitstream Charter", "Charis SIL", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", "DejaVu Sans Mono", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #121212; --ink: #e8e8e8; --quiet: #9b9b9b; --faint: #3c3c3c; --wash: #1b1b1b;
          --bad: #ef8a80; --live: #7fcf98; --stage: #0b0b0b; --stage-2: #181818; --stage-3: #262626; }
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 18px; line-height: 1.5;
       font-kerning: normal; text-rendering: optimizeLegibility; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; }
::selection { background: var(--ink); color: var(--paper); }
[hidden] { display: none !important; }

.masthead { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
            max-width: 46rem; margin: 0 auto; padding: 1.4rem 1.25rem 0; }
.mark { color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.mark span { font-weight: 400; color: var(--quiet); margin-left: .35rem; }
.who { display: flex; gap: .9rem; align-items: baseline; color: var(--quiet); font-size: .9rem; }

main { max-width: 46rem; margin: 0 auto; padding: 1rem 1.25rem 4rem; }
h1 { font-size: 2rem; font-weight: 400; margin: 1.6rem 0 .6rem; letter-spacing: -.01em; line-height: 1.2; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 0 0 .7rem; }
h3 { font-size: 1.15rem; font-weight: 700; margin: 0; }
.lede { color: var(--quiet); max-width: 32rem; margin: 0 0 1.4rem; }
.aside, .hint { color: var(--quiet); font-size: .88rem; margin: .6rem 0 0; }
.error { color: var(--bad); min-height: 1.2em; margin: .4rem 0 0; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--quiet); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); font-size: .95rem; }
input, select, button, .button { font: inherit; font-size: 1rem; color: var(--ink); }
input:not([type=checkbox]), select {
  background: var(--paper); border: 1px solid var(--faint); border-radius: 6px; padding: .5rem .65rem; min-width: 0; width: 100%; }
input:disabled { color: var(--quiet); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--ink); margin: 0; }

button, .button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; cursor: pointer;
  border-radius: 6px; padding: .5rem .95rem; border: 1px solid var(--faint); background: var(--paper); text-decoration: none; line-height: 1.2; }
button:hover, .button:hover { border-color: var(--ink); }
.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.primary:hover { opacity: .88; }
.danger { color: var(--bad); }
.danger:hover { border-color: var(--bad); }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: .18em; font-size: .9rem; }
button:disabled { opacity: .45; cursor: not-allowed; }
.wide { width: 100%; }
.icon { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.stack { display: grid; gap: 1rem; max-width: 24rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.row label { flex: 0 1 auto; }
.grow { flex: 1 1 14rem !important; }
code { font-family: var(--mono); font-size: .8rem; word-break: break-all; background: var(--wash); padding: .15rem .4rem; border-radius: 4px; }

/* home */
.room-list { list-style: none; padding: 0; margin: 1.2rem 0 0; display: grid; gap: 1rem; }
.room { border: 1px solid var(--faint); border-radius: var(--r); padding: 1.1rem 1.2rem; }
.room-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.now { color: var(--quiet); font-size: .88rem; }
.now.live { color: var(--live); }
.now.live::before { content: "● "; }
.address { display: flex; gap: .8rem; align-items: baseline; margin: .55rem 0 0; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .9rem; }
.extra:not(:empty) { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--faint); }
.invite-list { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .6rem; }
.invite { display: flex; flex-wrap: wrap; gap: .3rem .9rem; align-items: baseline; }
.invite code { flex: 1 1 100%; }
.invite .meta { color: var(--quiet); font-size: .85rem; margin-right: auto; }
.create { margin-top: 2.4rem; padding-top: 1.4rem; border-top: 1px solid var(--faint); }

/* check-in, waiting, after */
body.in-room main { max-width: 64rem; }
.checkin { display: grid; grid-template-columns: minmax(0, 3fr) minmax(16rem, 2fr); gap: 2rem; align-items: center; margin-top: 1rem; }
.checkin h1 { margin-top: 0; }
.preview { position: relative; aspect-ratio: 16 / 9; background: var(--stage); border-radius: var(--r); overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--on-stage-quiet); }
.checkin-toggles { display: flex; gap: .7rem; justify-content: center; margin-top: -1.6rem; position: relative; }
.round { width: 3.1rem; height: 3.1rem; border-radius: 50%; padding: 0; background: var(--stage-3); color: var(--on-stage); border: 0; }
.round.off { background: var(--bad); color: #fff; }
.devices { display: grid; gap: .8rem; }
.waiting, .after { text-align: center; max-width: 30rem; margin: 3rem auto; }
.waiting .lede, .after .lede { margin-left: auto; margin-right: auto; }
.after .actions { justify-content: center; }
.pulse { width: 3.5rem; height: 3.5rem; margin: 0 auto 1rem; border-radius: 50%; background: var(--ink); opacity: .15;
         animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.25); opacity: .35; } }
.mirror { transform: scaleX(-1); }

/* the meeting: full window, dark stage */
body.in-room:has(.meeting) { background: var(--stage); }
body.in-room:has(.meeting) .masthead { display: none; }
body.in-room:has(.meeting) main { max-width: none; padding: 0; }
.meeting { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; background: var(--stage); color: var(--on-stage); }
.meeting .top { display: flex; align-items: baseline; gap: 1rem; padding: .7rem 1.1rem .3rem; }
.meeting .top h1 { font-size: 1.05rem; font-weight: 700; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meeting .state { color: var(--on-stage-quiet); font-size: .85rem; }
.badge { display: inline-flex; align-items: center; gap: .3rem; }
.stage { position: relative; min-height: 0; display: flex; gap: .6rem; padding: .4rem .8rem; }
.tiles { flex: 1; min-width: 0; min-height: 0; display: grid; gap: .5rem; align-content: center; justify-content: center; }
.tiles.grid { --cols: 1;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
.tiles.grid:has(> :nth-child(2)) { --cols: 2; }
.tiles.grid:has(> :nth-child(5)) { --cols: 3; }
.tiles.grid:has(> :nth-child(10)) { --cols: 4; }
.tiles.grid > .tile { aspect-ratio: 16 / 9; max-height: calc((100vh - 9rem) / max(1, round(up, calc(var(--n) / var(--cols)))));
  justify-self: stretch; }
.tiles.speaker { grid-template-columns: minmax(0, 1fr) 13rem; grid-auto-rows: 7.3rem; grid-auto-flow: dense; align-content: start; height: 100%; }
.tiles.speaker > .tile.main { grid-column: 1; grid-row: 1 / span 20; aspect-ratio: auto; height: 100%; }
.tiles.speaker > .tile:not(.main) { grid-column: 2; }
.tile { position: relative; background: var(--stage-2); border-radius: var(--r); overflow: hidden; min-height: 0;
        outline: 2px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--hl); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.tile.screen video { object-fit: contain; background: #000; }
.tile.has-video video { opacity: 1; }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; }
.tile.has-video .avatar { display: none; }
.tile .avatar span { width: 4.2rem; height: 4.2rem; border-radius: 50%; display: grid; place-items: center;
                     background: var(--stage-3); font-size: 1.4rem; font-weight: 700; color: var(--on-stage); }
.tile .label { position: absolute; left: .45rem; bottom: .45rem; right: 2.8rem; display: flex; align-items: center; gap: .35rem;
               font-size: .82rem; }
.tile .name { background: rgba(0,0,0,.55); color: #fff; padding: .12rem .45rem; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .flags { display: inline-flex; gap: .25rem; align-items: center; }
.tile .flags > * { background: rgba(0,0,0,.55); color: #fff; border-radius: 4px; padding: .12rem .25rem; display: inline-flex; }
.tile .flags .hand { color: var(--hl); }
.tile .flags .weak { color: #f0a29b; }
.tile .flags .tag { font-size: .72rem; padding: .12rem .35rem; }
.tile .pin { position: absolute; top: .4rem; right: .4rem; padding: .3rem; background: rgba(0,0,0,.5); color: #fff; border: 0; opacity: 0; }
.tile:hover .pin, .tile .pin:focus-visible { opacity: 1; }

.bar { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .6rem 1rem calc(.8rem + env(safe-area-inset-bottom)); }
.bar .group { display: flex; gap: .45rem; }
.ctl { position: relative; flex-direction: column; gap: .15rem; min-width: 4.2rem; padding: .45rem .55rem; border: 0;
       background: var(--stage-3); color: var(--on-stage); border-radius: 12px; font-size: .72rem; }
.ctl .icon { width: 1.35rem; height: 1.35rem; }
.ctl:hover { background: #3a3a3a; }
.ctl.off { background: var(--bad); color: #fff; }
.ctl.on { background: var(--on-stage); color: var(--stage); }
.ctl.leave { background: #b3261e; color: #fff; }
.ctl .count { position: absolute; top: .15rem; right: .35rem; background: var(--hl); color: #000; border-radius: 99px; font-size: .68rem; padding: 0 .35rem; }
.audio-unlock { position: fixed; top: 4rem; left: 50%; transform: translateX(-50%); z-index: 5; }

.side { width: 21rem; flex: none; background: var(--paper); color: var(--ink); border-radius: var(--r); padding: .9rem 1rem;
        overflow-y: auto; display: flex; flex-direction: column; gap: .8rem; }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.side-head h2 { margin: 0; }
.icon-only { padding: .3rem; border: 0; background: none; }
.people h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--quiet); margin: .9rem 0 .4rem; }
.person { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--faint); }
.person .who { display: flex; align-items: center; gap: .35rem; min-width: 0; font-size: .95rem; color: var(--ink); }
.person .acts { display: flex; gap: .3rem; flex: none; }
.small { padding: .25rem .45rem; font-size: .82rem; }
.tag { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--quiet); border: 1px solid var(--faint); border-radius: 4px; padding: 0 .3rem; }
.tag.owner { color: var(--ink); border-color: var(--ink); }
.person .hand { color: var(--hl); display: inline-flex; }
.owner-actions { display: grid; gap: .45rem; margin-top: 1rem; }
.chat { display: flex; flex-direction: column; gap: .6rem; min-height: 0; flex: 1; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .55rem; min-height: 8rem; }
.msg { background: var(--wash); border-radius: 8px; padding: .4rem .6rem; }
.msg.mine { align-self: flex-end; background: var(--ink); color: var(--paper); }
.msg .from { font-size: .75rem; opacity: .75; display: flex; gap: .5rem; }
.msg p { margin: .1rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: .4rem; }
.settings h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--quiet); margin: .4rem 0 0; }

.toasts { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .4rem; z-index: 10; width: min(28rem, 92vw); }
.toast { background: var(--ink); color: var(--paper); padding: .55rem .9rem; border-radius: 8px; font-size: .92rem; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  html { font-size: 17px; }
  .checkin { grid-template-columns: 1fr; gap: 1.2rem; }
  .side { position: absolute; inset: 0 0 0 auto; width: min(100vw, 24rem); z-index: 4; border-radius: 0; }
  .ctl { min-width: 3rem; padding: .5rem; }
  .ctl .ctl-label { display: none; }
  .hide-narrow { display: none; }
  .tiles.speaker { grid-template-columns: 1fr; grid-auto-rows: 5.5rem; }
  .tiles.speaker > .tile.main { grid-row: auto; height: auto; aspect-ratio: 16 / 10; }
  .tiles.speaker > .tile:not(.main) { grid-column: 1; }
  .tiles.grid:has(> :nth-child(3)) { --cols: 2; }
  .tiles.grid:has(> :nth-child(5)) { --cols: 2; }
}
