/* Comms Meet. The lobby follows the system light/dark setting; the call itself is always dark,
   like any video stage, so faces are the brightest thing on screen. */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #111827;
  --muted: #5f6673;
  --border: #d9dde3;
  --field: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --notice-bg: #e8effd;
  --notice-text: #1e3a8a;
  --error: #b91c1c;

  --stage: #0f1115;
  --stage-surface: #1c1f25;
  --stage-raised: #2a2e36;
  --stage-hover: #363b45;
  --stage-text: #e8eaed;
  --stage-muted: #9aa0a8;
  --stage-border: #30343c;
  --speaking: #34d399;
  --warn-bg: #3b2f0b;
  --warn-text: #fcd34d;

  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1c1f25;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --border: #353a43;
    --field: #14171c;
    --notice-bg: #172440;
    --notice-text: #bfd3fe;
    --error: #f87171;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.sprite { display: none; }

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }

button.primary {
  border: 0;
  border-radius: 8px;
  padding: .7rem 1.3rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }

button.secondary {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 1rem;
  background: transparent;
  color: inherit;
  font-weight: 600;
}
button.secondary:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select {
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---------------------------------------------------------------- lobby */

.lobby {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 3rem;
  align-items: center;
  max-width: 1080px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage);
  color: var(--stage-text);
}
.preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* a mirror, which is what people expect of their own face */
}
.preview-note {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--stage-muted);
}
.preview-note p { margin: 0; }
.preview-detail { font-size: .78rem; opacity: .75; }
.preview-detail:empty { display: none; }
.preview-note .secondary {
  padding: .4rem 1rem;
  border-color: var(--stage-border);
  color: var(--stage-text);
}
.preview-note .secondary:hover { background: var(--stage-raised); }
.preview-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1rem;
  display: flex;
  justify-content: center;
  gap: .75rem;
}
.meter {
  position: absolute;
  left: 1rem;
  bottom: 1.35rem;
  width: 4.5rem;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .18);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--speaking);
  transition: width 80ms linear;
}

.devices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
  margin-top: 1rem;
  font-size: .85rem;
  color: var(--muted);
}
.devices label { display: grid; gap: .25rem; }
.devices select { font-size: .9rem; color: var(--text); }
@media (max-width: 560px) { .devices { grid-template-columns: minmax(0, 1fr); } }
.lobby-preview .hint { margin-top: .5rem; }
.hint:empty { display: none; }

.lobby-form h1 { font-size: 1.9rem; margin: 0 0 .25rem; }
.lobby-form .sub { margin: 0 0 1.5rem; color: var(--muted); }
.lobby-form form { display: grid; gap: .35rem; }
.lobby-form label { font-weight: 600; font-size: .92rem; margin-top: .7rem; }
.lobby-form .optional { font-weight: 400; color: var(--muted); }
.field-group { display: grid; gap: .35rem; }
.lobby-form .primary { margin-top: 1.4rem; padding: .85rem; font-size: 1.02rem; }

.input-row { display: flex; gap: .5rem; }

.hint { margin: .1rem 0 0; font-size: .82rem; color: var(--muted); }
.error { margin: .6rem 0 0; min-height: 1.4em; color: var(--error); font-size: .92rem; }

.notice {
  margin: 0 0 1rem;
  padding: .7rem .9rem;
  border-radius: 8px;
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: .92rem;
}

@media (max-width: 820px) {
  .lobby {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.75rem;
    padding: 1.25rem 1rem 2rem;
    align-items: start;
  }
}

/* ---------------------------------------------------------------- round buttons (lobby + call) */

.round {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  display: inline-grid;
  place-items: center;
  background: var(--stage-raised);
  color: var(--stage-text);
}
.round:hover:not(:disabled) { background: var(--stage-hover); }
/* Off is the state worth noticing, so it is the loud one. */
.round.off { background: var(--danger); color: #fff; }
.round.off:hover:not(:disabled) { background: var(--danger-hover); }
.round.active { background: #c7dafd; color: #0b2a6b; }
.round.active:hover:not(:disabled) { background: #b3cdfc; }
.round.leave { background: var(--danger); color: #fff; width: 64px; border-radius: 24px; }
.round.leave:hover { background: var(--danger-hover); }

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

/* ---------------------------------------------------------------- call */

.call {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--stage);
  color: var(--stage-text);
  color-scheme: dark;
}

.call-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1rem;
  padding-top: max(.7rem, env(safe-area-inset-top));
}
.call-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  font-weight: 600;
}
.call-title #call-room { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-title .icon { width: 18px; height: 18px; color: var(--speaking); }
.call-count { color: var(--stage-muted); font-weight: 400; white-space: nowrap; }

.bar-button {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  border: 1px solid var(--stage-border);
  border-radius: 8px;
  padding: .4rem .8rem;
  background: transparent;
  color: var(--stage-text);
  font-size: .9rem;
  white-space: nowrap;
}
.bar-button:hover { background: var(--stage-surface); }
.bar-button .icon { width: 18px; height: 18px; }

.banners { display: grid; gap: .4rem; padding: 0 1rem; }
.banners:empty { display: none; }
.banner {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem .85rem;
  border-radius: 8px;
  background: var(--stage-raised);
  font-size: .92rem;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner span { flex: 1; }
.banner button {
  border: 0;
  border-radius: 6px;
  padding: .3rem .8rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: .88rem;
}

.call-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: .75rem;
  padding: .75rem 1rem;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: .75rem;
}
.focus { display: none; }
.grid {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
}

/* While someone presents, their screen takes the stage and people move to a strip beside it
   (below it on a narrow screen). layout() in app.js sizes the tiles to whichever box they get. */
.stage.presenting .focus {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 8px;
}
.stage.presenting .grid {
  flex: 0 0 min(22%, 280px);
  align-content: flex-start;
  overflow-y: auto;
}
@media (max-width: 820px), (max-aspect-ratio: 1/1) {
  .stage.presenting { flex-direction: column; }
  .stage.presenting .grid {
    flex: 0 0 26%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    align-content: stretch;
  }
}

.tile {
  position: relative;
  width: var(--tile-w, 320px);
  aspect-ratio: 16 / 9;
  flex: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage-surface);
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color 150ms;
}
.tile.speaking { outline-color: var(--speaking); }
.focus .tile { width: 100%; height: 100%; aspect-ratio: auto; background: #000; }

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}
.tile.has-video video { opacity: 1; }
.tile.local video { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; }

.avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.avatar span {
  width: clamp(40px, 28%, 96px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--avatar, #4b5563);
  color: #fff;
  font-weight: 600;
  font-size: clamp(14px, 2.2vw, 34px);
}
.tile.has-video .avatar { display: none; }

.tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .55rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  font-size: .85rem;
}
.tile-label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-label .icon { width: 16px; height: 16px; display: none; }
.tile.mic-off .mic-off-icon { display: block; color: #fca5a5; }
.tile.poor .poor-icon { display: block; color: var(--warn-text); }

.tile-warning {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  padding: .4rem .6rem;
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: .82rem;
  line-height: 1.35;
}
.tile-warning .icon { width: 16px; height: 16px; margin-top: 1px; }

/* ---------------------------------------------------------------- chat */

.chat {
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--stage-surface);
  overflow: hidden;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .6rem .6rem 1rem;
}
.chat-head h2 { margin: 0; font-size: 1rem; }
.icon-button {
  border: 0;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: transparent;
  color: inherit;
}
.icon-button:hover { background: var(--stage-raised); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0 1rem;
  list-style: none;
}
.chat-log li { margin: 0 0 .8rem; overflow-wrap: anywhere; }
.chat-log .who { font-weight: 600; font-size: .85rem; }
.chat-log .when { color: var(--stage-muted); font-size: .75rem; margin-left: .4rem; }
.chat-log .text { white-space: pre-wrap; font-size: .93rem; }
.chat-log li.system { color: var(--stage-muted); font-size: .82rem; text-align: center; }
.chat-empty { color: var(--stage-muted); font-size: .88rem; text-align: center; margin-top: 2rem; }

.chat-form { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--stage-border); }
.chat-form input {
  background: var(--stage-raised);
  border-color: transparent;
  color: var(--stage-text);
}
.chat-form .primary { padding: .5rem 1rem; }

@media (max-width: 820px) {
  .chat {
    position: fixed;
    inset: 0;
    z-index: 5;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ---------------------------------------------------------------- controls */

.controls {
  display: flex;
  justify-content: center;
  gap: .75rem;
  padding: .5rem 1rem 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

@media (max-width: 480px) {
  .call-bar { padding-left: .75rem; padding-right: .75rem; }
  .bar-button span { display: none; }
  .call-body { padding: .5rem; }
  .controls { gap: .5rem; }
  .round { width: 44px; height: 44px; }
  .round.leave { width: 56px; }
}

/* ---------------------------------------------------------------- dialog + toast */

.settings {
  width: min(420px, calc(100% - 2rem));
  border: 0;
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  background: var(--stage-surface);
  color: var(--stage-text);
  color-scheme: dark;
}
.settings::backdrop { background: rgba(0, 0, 0, .55); }
.settings h2 { margin: 0 0 .75rem; font-size: 1.1rem; }
.settings label { display: grid; gap: .3rem; margin-bottom: .9rem; font-size: .9rem; color: var(--stage-muted); }
.settings select { background: var(--stage-raised); border-color: transparent; color: var(--stage-text); }
.settings .hint { color: var(--stage-muted); margin: -.5rem 0 .9rem; }
.dialog-actions { display: flex; justify-content: flex-end; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 6rem;
  transform: translateX(-50%);
  z-index: 10;
  padding: .55rem 1rem;
  border-radius: 8px;
  background: #e8eaed;
  color: #111827;
  font-size: .92rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
