/* Netex UI. Dark by default, light follows the system. No inline styles anywhere (CSP). */

:root {
  color-scheme: dark light;
  --bg: #0c1216;
  --surface: #121b21;
  --sunken: #070b0e;
  --line: #25343d;
  --line-strong: #3d5260;
  --text: #e8eff2;
  --dim: #a0b1ba;
  --primary: #7fd8c6;
  --primary-hover: #99e4d4;
  --on-primary: #06231e;
  --live: #f5b94a;
  --danger: #ff9a8f;
  --danger-line: #7a3f3a;
  --scrim: rgba(7, 11, 14, 0.78);
  --on-scrim: #eef4f6;
  --shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);

  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f2;
    --surface: #ffffff;
    --sunken: #dde5e5;
    --line: #c9d5d5;
    --line-strong: #93a8aa;
    --text: #10201f;
    --dim: #475c5e;
    --primary: #0e6a5e;
    --primary-hover: #0a564c;
    --on-primary: #ffffff;
    --live: #a65a00;
    --danger: #b3261e;
    --danger-line: #e2aaa6;
    --shadow: 0 -10px 40px rgba(16, 32, 31, 0.18);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}
body.is-room { overflow: hidden; }

h1, h2 { font-family: var(--font-display); margin: 0; line-height: 1.15; letter-spacing: -0.015em; }
p { margin: 0; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.95em; }

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

.hint { color: var(--dim); font-size: 0.9rem; }

/* ---------- Buttons and fields ---------- */

.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: 2.75rem; padding: 0 1.1rem;
  border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: transparent;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { min-height: 2.25rem; padding: 0 0.8rem; font-size: 0.9rem; }
.btn-lg { min-height: 3.25rem; padding: 0 1.75rem; font-size: 1.05rem; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-quiet { border-color: var(--line-strong); }
.btn-quiet:hover:not(:disabled) { background: var(--surface); border-color: var(--dim); }
.btn-leave { border-color: var(--danger-line); color: var(--danger); }
.btn-leave:hover { background: var(--surface); border-color: var(--danger); }
.btn-stop { background: var(--danger); color: #1a0705; }
.btn-stop:hover { filter: brightness(1.08); }
@media (prefers-color-scheme: light) { .btn-stop { color: #fff; } }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.link-btn {
  appearance: none; background: none; border: 0; padding: 0; margin-left: 0.4rem;
  font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer;
}

.field { display: grid; gap: 0.4rem; margin-bottom: 1rem; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field input {
  width: 100%; min-height: 2.9rem; padding: 0 0.85rem;
  font: inherit; color: var(--text);
  background: var(--sunken); border: 1px solid var(--line-strong); border-radius: 8px;
}
.field input:focus-visible { outline-offset: 0; border-color: var(--primary); }
.field-error {
  margin: 0 0 1rem; padding: 0.6rem 0.8rem;
  color: var(--danger); font-size: 0.92rem;
  border: 1px solid var(--danger-line); border-radius: 8px;
}

.notice {
  margin: 1.5rem 0 0; padding: 0.75rem 1rem; max-width: 40rem;
  border-left: 3px solid var(--live); background: var(--surface); font-size: 0.95rem;
}

/* ---------- Landing ---------- */

.landing {
  max-width: 62rem; margin: 0 auto;
  padding: clamp(1.5rem, 6vw, 4.5rem) clamp(1.25rem, 5vw, 3rem) 3rem;
  min-height: 100%;
}
.landing-head { display: flex; align-items: center; gap: 0.9rem; }
.landing-head h1 { font-size: clamp(2.75rem, 9vw, 5rem); font-weight: 650; letter-spacing: -0.04em; }
.landing-head .mark { width: clamp(2.5rem, 7vw, 3.5rem); height: auto; }
.lede { margin-top: 1rem; max-width: 32rem; font-size: clamp(1.1rem, 2.6vw, 1.35rem); color: var(--dim); line-height: 1.4; }

.actions {
  display: grid; grid-template-columns: 1fr 1fr;
  margin-top: clamp(2rem, 6vw, 3.5rem);
  border-top: 1px solid var(--line);
}
.action { padding: 1.75rem 0 0; display: grid; gap: 0.6rem; align-content: start; }
.action + .action { padding-left: clamp(1.5rem, 5vw, 3rem); border-left: 1px solid var(--line); }
.action:first-child { padding-right: clamp(1.5rem, 5vw, 3rem); }
.action h2 { font-size: 1.4rem; }
.action form { margin-top: 0.75rem; }
.name-line { margin-top: 2.5rem; color: var(--dim); font-size: 0.92rem; }

@media (max-width: 719px) {
  .actions { grid-template-columns: 1fr; }
  .action:first-child { padding-right: 0; padding-bottom: 1.75rem; }
  .action + .action { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
}

/* ---------- Gate and fatal ---------- */

.gate { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.gate-box { width: min(100%, 26rem); display: grid; gap: 1rem; }
.gate-box h1 { font-size: 1.75rem; }
.gate-box .mark { width: 2.5rem; height: auto; }
.gate-box form { margin-top: 0.5rem; }
.gate-box section { display: grid; gap: 0.9rem; justify-items: start; }
.gate-box form, .gate-box .field { width: 100%; }

/* ---------- Meeting shell ---------- */

.meeting {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.75rem;
  padding: 0.5rem 0.75rem;
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar .spacer { flex: 1 1 0; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-family: var(--font-display); font-weight: 650; letter-spacing: -0.02em; }
.brand .mark { display: block; width: 1.5rem; height: auto; }
.room-code {
  padding: 0.25rem 0.6rem; border: 1px solid var(--line-strong); border-radius: 6px;
  font-size: 0.9rem; letter-spacing: 0.04em; user-select: all; overflow-wrap: anywhere;
}
.count {
  display: inline-block; min-width: 1.35em; padding: 0 0.35em;
  border-radius: 999px; background: var(--line); text-align: center; font-size: 0.85em;
}

.status { display: flex; align-items: center; gap: 0.45rem; font-size: 0.88rem; color: var(--dim); }
.status-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--dim); }
.status[data-state="connected"] .status-dot { background: var(--primary); }
.status[data-state="connecting"] .status-dot,
.status[data-state="reconnecting"] .status-dot { background: var(--live); }
.status[data-state="closed"] .status-dot { background: var(--danger); }

.banner {
  padding: 0.45rem 1rem; text-align: center; font-size: 0.92rem; font-weight: 600;
  background: var(--live); color: #1b1100;
}
@media (prefers-color-scheme: light) { .banner { color: #fff; } }

.workspace { flex: 1 1 0; min-height: 0; display: flex; gap: 0.75rem; padding: 0.75rem; }

/* ---------- Stage ---------- */

.stage {
  position: relative; flex: 1 1 0; min-width: 0; min-height: 0;
  overflow: hidden;
  background: var(--sunken);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.stage:fullscreen { border: 0; border-radius: 0; background: #000; }

.screen {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}

.stage-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.9rem; padding: 1.5rem; text-align: center; overflow: auto;
}
.stage-state h2 { font-size: clamp(1.4rem, 3.5vw, 2rem); }
.stage-state .hint { max-width: 26rem; }
.share-note { color: var(--live); }

.frame {
  position: relative; width: 7.5rem; height: 4.75rem; margin-bottom: 0.5rem;
  border: 2px dashed var(--line-strong); border-radius: 10px;
}
.frame::after {
  content: ""; position: absolute; left: 50%; top: calc(100% + 0.5rem);
  width: 2.5rem; height: 2px; transform: translateX(-50%);
  background: var(--line-strong); border-radius: 2px;
}

.you-live {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-family: var(--font-display); font-size: clamp(1.3rem, 3.2vw, 1.9rem); font-weight: 650;
}
.preview {
  width: min(100%, 36rem); max-height: 45%; min-height: 0;
  object-fit: contain; background: #000;
  border: 1px solid var(--line-strong); border-radius: 8px;
}

.live-dot { flex: none; width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--live); }
@media (prefers-reduced-motion: no-preference) {
  .live-dot { animation: pulse 2.4s ease-out infinite; }
  @keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 185, 74, 0.55); }
    70%, 100% { box-shadow: 0 0 0 0.6rem rgba(245, 185, 74, 0); }
  }
}

.viewblock {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 1.5rem; text-align: center; color: var(--dim);
}

.stage-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem;
  padding: 0.6rem; pointer-events: none;
}
.chip, .chip-btn {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 0.5rem;
  min-height: 2rem; padding: 0 0.75rem;
  background: var(--scrim); color: var(--on-scrim);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 999px;
  font: inherit; font-size: 0.88rem;
  max-width: 100%;
}
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-row { display: flex; gap: 0.4rem; flex: none; }
.chip-btn { cursor: pointer; font-weight: 600; }
.chip-btn:hover { background: rgba(7, 11, 14, 0.95); }
.chip-btn[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.chip-btn:focus-visible { outline-color: #fff; }

.stats {
  position: absolute; left: 0.6rem; bottom: 0.6rem; z-index: 2; margin: 0;
  display: flex; flex-wrap: wrap; gap: 0.25rem 1rem;
  padding: 0.4rem 0.75rem; border-radius: 8px;
  background: var(--scrim); color: var(--on-scrim);
  font-size: 0.8rem; font-variant-numeric: tabular-nums;
}
.stats div { display: flex; gap: 0.35rem; }
.stats dt { opacity: 0.7; }
.stats dd { margin: 0; font-weight: 600; }

/* ---------- Participants ---------- */

.panel {
  flex: none; width: 17rem; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.8rem 0.9rem 0.5rem; }
.panel-head h2 { font-size: 1.05rem; }
.panel-close { display: none; }
.peer-list { list-style: none; margin: 0; padding: 0 0.5rem 0.5rem; overflow-y: auto; min-height: 0; }
.peer-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.4rem; border-top: 1px solid var(--line);
}
.peer-list li:first-child { border-top: 0; }
.peer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags { display: flex; gap: 0.35rem; flex: none; }
.tag { padding: 0.05rem 0.5rem; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--dim); font-size: 0.75rem; }
.tag-live { display: inline-flex; align-items: center; gap: 0.35rem; border-color: var(--live); color: var(--live); }
.tag-live .live-dot { width: 0.45rem; height: 0.45rem; animation: none; }
.peer-empty { color: var(--dim); font-size: 0.9rem; }

@media (max-width: 719px) {
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    width: auto; max-height: 55%;
    border-radius: 14px 14px 0 0; border-bottom: 0; box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel-close { display: inline-flex; }
  .workspace { padding: 0.5rem; }
  .brand-name { display: none; }
  .status-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  }
}

/* ---------- Overlays and toasts ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 1.5rem;
  background: rgba(4, 7, 9, 0.8);
}
.overlay-box {
  width: min(100%, 26rem); display: grid; gap: 0.9rem;
  padding: 1.5rem; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.overlay-box h2 { font-size: 1.4rem; }

.toasts {
  position: fixed; z-index: 50; left: 50%; bottom: 1rem; transform: translateX(-50%);
  width: min(calc(100% - 1.5rem), 28rem);
  display: grid; gap: 0.5rem; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-left: 4px solid var(--primary);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-size: 0.92rem;
}
.toast-error { border-left-color: var(--danger); }
.toast button {
  flex: none; appearance: none; background: none; border: 0; padding: 0.1rem 0.3rem;
  color: var(--dim); font: inherit; font-size: 0.85rem; text-decoration: underline; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.offscreen-copy { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }
