/* UvioCall: clean, calm, clinical look. Light by default, dark mode on request (or follows the device). */
:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f3f7f9;
  --line: #dde5ea;
  --text: #15232b;
  --muted: #5d6f7a;
  --brand: #0b7f95;
  --brand-2: #086a7c;
  --brand-soft: #e3f3f6;
  --danger: #d6404a;
  --ok: #1f9d6b;
  --warn-bg: #fff4d6;
  --warn-text: #7a5a00;
  --err-bg: #fdecee;
  --err-text: #a12630;
  --err-line: #f3c6cb;
  --off-bg: #fdecee;
  --off-line: #f3c6cb;
  --off-text: #a12630;
  --tile-bg: #ffffff;
  --frame: #2b3a44;
  --avatar-bg: #dfe5ea;
  --avatar-circle: #6b7c88;
  --speak: #22c55e;
  --shadow: 0 1px 2px rgba(21,35,43,.06), 0 6px 20px rgba(21,35,43,.06);
  --radius: 14px;
  --gap: 20px; /* standard space between video containers, sideways and underneath */
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e151a;
  --panel: #151e25;
  --panel-2: #1c2730;
  --line: #2a3843;
  --text: #eaf1f5;
  --muted: #92a5b1;
  --brand: #2bb3c9;
  --brand-2: #4cc4d8;
  --brand-soft: #12333b;
  --danger: #e5555f;
  --ok: #3fc08a;
  --warn-bg: #3a2f12;
  --warn-text: #ffd98a;
  --err-bg: #3a1f22;
  --err-text: #ffb4b6;
  --err-line: #5a2a2c;
  --off-bg: #3a2022;
  --off-line: #6b2f33;
  --off-text: #ffb4b6;
  --tile-bg: #1c2730;
  --frame: #7d93a3;
  --avatar-bg: #26313a;
  --avatar-circle: #5c6e7b;
  --speak: #3ddc84;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
header.bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: .2px; font-size: 18px; }
.brand span { color: var(--brand); }
.title { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-btn { margin-left: auto; padding: 6px 12px; font-size: 13px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.title + .theme-btn { margin-left: 0; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }

/* ---- cards (lobby, host page, ended) ---- */
.card {
  width: calc(100% - 32px); max-width: 460px; margin: 24px auto; padding: 22px 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card h1 { font-size: 21px; margin: 0 0 4px; }
.card p { color: var(--muted); margin: 0 0 16px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=password], select {
  width: 100%; padding: 12px; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

button {
  font: inherit; color: var(--text); cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
.full { width: 100%; margin-top: 18px; }

.notice { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--panel-2); color: var(--muted); font-size: 14px; }
.notice.error { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-line); }

.preview {
  position: relative; aspect-ratio: 16 / 10; margin-top: 8px; overflow: hidden;
  background: #0b1217; border-radius: 12px;
}
.preview video { width: 100%; height: 100%; object-fit: cover; }
.preview.mirror video { transform: scaleX(-1); }
.preview .empty { position: absolute; inset: 0; display: grid; place-items: center; color: #9db0bb; font-size: 14px; padding: 12px; text-align: center; }

/* ---- call room ---- */
#room { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.grid {
  flex: 1; min-height: 0; display: grid; gap: var(--gap); padding: 8px;
  grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr);
}
@media (min-width: 700px) {
  .grid[data-count="2"], .grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
  .grid[data-count="5"], .grid[data-count="6"], .grid[data-count="7"], .grid[data-count="8"], .grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }
}
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: 1fr 1fr; }

/* Two people: the other person fills the screen and you are a small picture in the corner. */
.grid.pair { grid-template-columns: 1fr; position: relative; }
.grid.pair .tile.self {
  position: absolute; right: 16px; bottom: 16px; width: 28%; min-width: 110px; max-width: 220px;
  aspect-ratio: 3 / 4; z-index: 2; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* On a computer, each person is a 16:9 tile about 45% of the window width. Alone you are centred; with a guest you sit side by side. */
@media (min-width: 700px) {
  .grid[data-count="1"], .grid.pair {
    container-type: size; align-items: center; justify-items: center;
  }
  .grid.pair { grid-template-columns: auto auto; justify-content: center; column-gap: var(--gap); }
  .grid[data-count="1"] .tile,
  .grid.pair .tile,
  .grid.pair .tile.self {
    position: relative; right: auto; bottom: auto; max-width: none; min-width: 0;
    width: min(45cqw, calc((100cqh - 16px) * 16 / 9)); height: auto; aspect-ratio: 16 / 9;
    box-shadow: none;
  }
}
.tile { position: relative; background: var(--tile-bg); border: 1px solid var(--frame); border-radius: 12px; overflow: hidden; min-height: 0; min-width: 0; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--tile-bg); }
.tile.self.mirror video { transform: scaleX(-1); }
/* The frame thickens and turns green around whoever is speaking. Drawn above the video so it is always visible. */
.tile::after {
  content: ''; position: absolute; inset: 0; z-index: 2; border: 3px solid transparent; border-radius: inherit;
  pointer-events: none; transition: border-color .15s ease;
}
.tile.speaking::after { border-color: var(--speak); }
.tile.speaking { box-shadow: 0 0 0 3px rgba(34,197,94,.35); }
/* No browser overlay buttons (picture-in-picture, enhance video) on the video. */
.tile video, .prevbox video, .preview video { pointer-events: none; }
.tile .bar { position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); display: flex; align-items: center; gap: 6px; z-index: 1; }
.tile .name {
  min-width: 0; color: #fff; background: rgba(8,16,22,.65); padding: 4px 9px; border-radius: 8px; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .avatar {
  position: absolute; inset: 0; display: grid; place-items: center; background: var(--avatar-bg); container-type: size;
}
.tile .avatar span {
  display: grid; place-items: center; width: min(40%, 120px); min-width: 44px; aspect-ratio: 1; border-radius: 50%;
  background: var(--avatar-circle); color: #fff; font-weight: 600; font-size: clamp(14px, 14cqmin, 44px); letter-spacing: .5px;
}
.tile:not(.has-video) video { visibility: hidden; }
.tile.has-video .avatar { display: none; }
.tile .badge { position: absolute; right: 8px; top: 8px; color: #fff; background: rgba(8,16,22,.65); padding: 3px 8px; border-radius: 8px; font-size: 12px; }

/* Floating control island: icon buttons with tooltips. Fades out when nothing moves. */
.controls {
  position: absolute; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 8;
  display: flex; gap: 10px; padding: 10px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 8px 28px rgba(0,0,0,.2);
  transition: opacity .3s ease, transform .3s ease;
}
.controls.idle { opacity: 0; transform: translate(-50%, 14px); pointer-events: none; }
.controls button {
  position: relative; width: 48px; height: 48px; min-width: 0; padding: 0; border-radius: 50%;
  display: grid; place-items: center; line-height: 0;
}
.controls button svg { display: block; }
.controls button.off { background: var(--off-bg); border-color: var(--off-line); color: var(--off-text); }
.controls button.endall { background: transparent; border-color: var(--danger); color: var(--danger); }
.controls button.endall:hover { background: var(--danger); color: #fff; }
.controls button[data-tip]::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 14px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 12px; line-height: 1.2; color: #fff; background: #15232b; padding: 6px 9px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .15s ease; z-index: 9;
}
.controls button[data-tip]:hover::after, .controls button[data-tip]:focus-visible::after { opacity: 1; }
.devices {
  position: absolute; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 7;
  width: min(520px, calc(100% - 24px)); display: grid; gap: 4px; padding: 6px 16px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.2);
}
@media (min-width: 700px) { .devices { grid-template-columns: 1fr 1fr; gap: 12px; } }

.meter { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.meter-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.meter-bar { flex: 1; height: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter-bar i { display: block; height: 100%; width: 100%; transform-origin: left center; transform: scaleX(0); background: var(--ok); transition: transform .08s linear; }
.meter-bar i.hot { background: #e0a100; }
.meter-bar i.clip { background: var(--danger); }
.devprev { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; margin-top: 6px; }
.prevbox { position: relative; flex: none; width: 200px; aspect-ratio: 16 / 9; background: var(--tile-bg); border: 1px solid var(--frame); border-radius: 10px; overflow: hidden; }
.prevbox video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.prevbox.mirror video { transform: scaleX(-1); }
.prevbox .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 8px; background: var(--panel-2); }
.prevbox.live .empty { display: none; }
.meter-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.speaker { grid-column: 1 / -1; margin-top: 4px; }
.spk-row { display: flex; align-items: center; gap: 14px; }
.spk-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--brand); }
.spk-row button { padding: 8px 14px; white-space: nowrap; }
.meter-note { font-size: 12px; color: var(--muted); }
.meter-col .meter-bar { flex: none; width: 100%; }
@media (max-width: 520px) { .devprev { flex-direction: column; align-items: stretch; } .prevbox { width: min(100%, 240px); align-self: center; } }
.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--warn-bg); color: var(--warn-text); padding: 8px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}
.pill {
  position: absolute; top: 12px; left: 12px; z-index: 6; display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 24px); padding: 9px 14px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.pill #clock, .pill #timer { font-variant-numeric: tabular-nums; }
.pill .sep { width: 1px; height: 18px; background: var(--text); opacity: .6; flex: none; }
.pill #pillTitle { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbox { display: flex; gap: 8px; margin-top: 8px; }
.linkbox input { flex: 1; }

/* ---- Phones: portrait, equal 16:9 tiles stacked one above the other; scroll when there are more than fit. ---- */
@media (max-width: 699px), (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  .grid, .grid.pair, .grid[data-count] {
    display: flex; flex-direction: column; align-items: center; gap: var(--gap);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 8px; /* three tiles fit on a normal phone; more scroll. The control island fades away when idle. */
  }
  .grid > .tile:first-child { margin-top: auto; }
  .grid > .tile:last-child { margin-bottom: auto; }
  .grid .tile, .grid.pair .tile, .grid.pair .tile.self {
    position: relative; right: auto; bottom: auto; flex: none;
    width: min(100%, 420px); max-width: none; min-width: 0; height: auto; aspect-ratio: 16 / 9;
    box-shadow: none;
  }
  .tile.speaking { box-shadow: 0 0 0 3px rgba(34,197,94,.35); }
}

/* ---- Join screen on phones: tight spacing so the whole form fits on one screen, nothing floating over it. ---- */
@media (max-width: 699px) {
  header.bar { padding: 8px 16px; }
  .card { margin: 10px auto; padding: 14px 14px 16px; }
  .card h1 { font-size: 19px; }
  .card > p { margin: 0 0 8px; font-size: 14px; }
  label { margin: 10px 0 4px; font-size: 13px; }
  input[type=text], input[type=password], select { padding: 9px 12px; }
  .preview { aspect-ratio: 16 / 9; max-height: 22vh; width: 100%; margin-top: 4px; }
  .meter { margin-top: 8px; }
  .card .full { margin-top: 12px; padding: 12px 16px; }
  .notice { margin-top: 10px; }
  main { padding-bottom: env(safe-area-inset-bottom); }
}
