*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #070b15;
  --surface: #11182a;
  --surface-soft: rgba(17, 24, 42, 0.82);
  --border: rgba(162, 180, 220, 0.16);
  --text: #f7f8fd;
  --muted: #94a1bc;
  --accent: #71f6c2;
  --danger: #ff8da0;
  --font: Inter, "Segoe UI", system-ui, sans-serif;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 75% -10%, rgba(83, 94, 229, 0.23), transparent 36%),
    radial-gradient(circle at -10% 70%, rgba(35, 201, 148, 0.1), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 21, 0.72);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(113, 246, 194, 0.5);
  border-radius: 10px;
  background:
    radial-gradient(circle, var(--accent) 0 2px, transparent 3px),
    radial-gradient(circle, transparent 0 8px, rgba(113, 246, 194, 0.6) 9px 10px, transparent 11px),
    rgba(113, 246, 194, 0.06);
}

.connection {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.connection span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #69738a;
}

.connection.online {
  color: #b8f8df;
}

.connection.online span {
  background: var(--accent);
  box-shadow: 0 0 9px rgba(113, 246, 194, 0.9);
}

main {
  min-height: calc(100vh - 66px);
}

.join-view {
  min-height: calc(100vh - 66px);
  display: grid;
  place-items: center;
  padding: 36px 20px;
}

.join-card {
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-soft);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(20px);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 38px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.join-card > p:not(.eyebrow) {
  margin: 14px 0 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

form label {
  display: block;
  margin-bottom: 7px;
  color: #cbd4e8;
  font-size: 11px;
  font-weight: 650;
}

form input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: rgba(5, 8, 16, 0.72);
  color: var(--text);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

form input:focus {
  border-color: rgba(113, 246, 194, 0.7);
  box-shadow: 0 0 0 3px rgba(113, 246, 194, 0.08);
}

form button {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #07150f;
  cursor: pointer;
  font-weight: 760;
}

form button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.install-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 4px;
  border: 1px solid rgba(113, 246, 194, 0.3);
  border-radius: 12px;
  background: rgba(113, 246, 194, 0.08);
  color: #b8f8df;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.install-button:hover {
  border-color: rgba(113, 246, 194, 0.55);
  background: rgba(113, 246, 194, 0.13);
}

.form-error {
  min-height: 18px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 11px;
}

.privacy-note {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.privacy-note > span {
  color: var(--accent);
}

.privacy-note p {
  margin: 0;
  font-size: 10px;
  line-height: 1.5;
}

.workspace {
  min-height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  padding: 20px 22px 114px;
}

.workspace-head {
  width: min(1400px, 100%);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 14px;
}

.workspace-head h1 {
  font-size: 23px;
}

.leave-button {
  padding: 7px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}

.leave-button:hover {
  color: var(--danger);
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.second-room-form {
  width: min(1400px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 auto 18px;
}

.second-room-form label {
  flex: 0 0 auto;
  margin: 0;
}

.second-room-form input {
  width: min(220px, 100%);
  height: 38px;
  font-size: 14px;
}

.second-room-form button {
  width: auto;
  min-height: 38px;
  margin: 0;
  padding: 0 12px;
  font-size: 11px;
  white-space: nowrap;
}

.second-room-form .form-error {
  margin: 0;
}

.participants-trigger {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid rgba(113, 246, 194, 0.2);
  border-radius: 9px;
  background: rgba(113, 246, 194, 0.06);
  color: #b8f8df;
  cursor: pointer;
  font-size: 10px;
}

.participants-trigger:hover {
  border-color: rgba(113, 246, 194, 0.5);
}

.status-dot,
.remote-participant small i {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(113, 246, 194, 0.75);
}

.workspace-body {
  position: relative;
  width: min(1400px, 100%);
  flex: 1;
  margin: auto;
}

.screen-grid {
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.screen-pane {
  min-width: 0;
  flex: 0 1 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 18px;
}

.screen-grid.two-screens .screen-pane {
  flex-basis: 50%;
}

.screen-pane.selected {
  border-color: rgba(113, 246, 194, 0.5);
  background: rgba(113, 246, 194, 0.035);
}

.screen-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
}

.screen-caption strong {
  color: var(--accent);
  font: 700 11px "Cascadia Mono", Consolas, monospace;
}

.screen-caption button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
}

.screen-caption button:hover { color: var(--danger); }

.workspace-body .stage-shell {
  width: 100%;
}

.participants-panel {
  position: fixed;
  top: 88px;
  right: 22px;
  z-index: 10;
  width: 252px;
  padding: 18px;
  border: 1px solid rgba(162, 180, 220, 0.2);
  border-radius: 16px;
  background: rgba(14, 20, 35, 0.95);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: 150ms ease;
}

.participants-panel.open,
.participants-panel:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.participants-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.participants-panel-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.025em;
}

.participants-count {
  min-width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(113, 246, 194, 0.3);
  border-radius: 9px;
  background: rgba(113, 246, 194, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}

.participants-note {
  margin: 12px 0 14px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.remote-participant-list {
  display: grid;
  gap: 7px;
}

.remote-participant {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid rgba(162, 180, 220, 0.13);
  border-radius: 10px;
  background: rgba(5, 8, 16, 0.38);
}

.remote-avatar {
  width: 25px;
  height: 25px;
  display: grid;
  flex: 0 0 25px;
  place-items: center;
  border: 1px solid rgba(113, 246, 194, 0.3);
  border-radius: 8px;
  background: rgba(113, 246, 194, 0.09);
  color: var(--accent);
  font-size: 10px;
}

.remote-participant strong,
.remote-participant small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remote-participant strong { max-width: 175px; font-size: 10px; }
.remote-participant small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.remote-participant small i { margin-right: 4px; }

.remote-invite {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.remote-invite span,
.remote-invite small {
  display: block;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.remote-invite strong {
  display: block;
  margin: 5px 0;
  color: var(--accent);
  font: 700 16px "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.1em;
}

.remote-invite button {
  width: 100%;
  height: 32px;
  margin-top: 10px;
  border: 1px solid rgba(113, 246, 194, 0.25);
  border-radius: 8px;
  background: rgba(113, 246, 194, 0.07);
  color: #b8f8df;
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
}

.remote-invite button:hover { border-color: rgba(113, 246, 194, 0.55); }

.stage-shell {
  width: 100%;
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 210px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  outline: 1px solid rgba(160, 179, 221, 0.2);
  border-radius: 14px;
  background: #020306;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  touch-action: none;
  cursor: crosshair;
}

.stage video,
.stage img,
.stage canvas,
.stage-wait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage video {
  display: block;
  object-fit: contain;
  pointer-events: none;
}
.stage img { object-fit: contain; pointer-events: none; }

.stage canvas {
  z-index: 2;
}

.stage-wait {
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: #050812;
  color: var(--muted);
  font-size: 12px;
}

.stage-wait p {
  margin: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(113, 246, 194, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.toolbar {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 24px);
  padding: 9px;
  border: 1px solid rgba(162, 180, 220, 0.2);
  border-radius: 16px;
  background: rgba(14, 20, 35, 0.92);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  transform: translateX(-50%);
}

.colors {
  display: flex;
  align-items: center;
  gap: 5px;
}

.brush-label {
  min-width: 58px;
  height: 48px;
  display: grid;
  place-content: center;
  gap: 2px;
  border: 1px solid rgba(113, 246, 194, 0.22);
  border-radius: 10px;
  background: rgba(113, 246, 194, 0.1);
  color: var(--accent);
}

.brush-label > span {
  color: #dce3f2;
  font-size: 20px;
  line-height: 1;
}

.brush-label small {
  font-size: 8px;
}

.divider {
  width: 1px;
  height: 34px;
  background: var(--border);
}

.color {
  width: 25px;
  height: 25px;
  padding: 0;
  border: 3px solid rgba(14, 20, 35, 0.92);
  border-radius: 50%;
  outline: 1px solid transparent;
  background: #ffcf5b;
  cursor: pointer;
}

.color.mint { background: #71f6c2; }
.color.pink { background: #ff6f91; }
.color.blue { background: #6da8ff; }
.color.white { background: #ffffff; }
.color.black {
  border-color: rgba(255, 255, 255, 0.48);
  background: #000000;
}
.color.active { outline-color: rgba(255, 255, 255, 0.82); }

.width-control {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 8px;
}

.width-control input {
  width: 76px;
  accent-color: var(--accent);
}

.clear-button {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  color: #d8dfef;
  cursor: pointer;
  font-size: 10px;
}

.clear-button:hover {
  border-color: rgba(255, 141, 160, 0.35);
  color: #ffadba;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 40;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: #dfe6f5;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 7px);
  transition: 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .topbar { padding: 11px 14px; }
  .workspace { padding: 16px 10px 122px; }
  .workspace-head { padding: 0 4px; }
  .second-room-form { flex-wrap: wrap; padding: 0 4px; }
  .second-room-form label { flex-basis: 100%; }
  .second-room-form .form-error { flex-basis: 100%; }
  .screen-grid.two-screens {
    justify-content: flex-start;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }
  .screen-grid.two-screens .screen-pane {
    min-width: min(78vw, 520px);
    flex: 0 0 min(78vw, 520px);
    scroll-snap-align: start;
  }
  .width-control,
  .divider { display: none; }
  .toolbar { gap: 7px; }
  .brush-label { min-width: 48px; }
  .clear-button { padding: 0 9px; }
  .participants-panel {
    top: 76px;
    right: 10px;
    width: min(252px, calc(100vw - 20px));
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
  }
  .participants-panel.open,
  .participants-panel:focus-within {
    opacity: 0.97;
    pointer-events: auto;
    transform: translateY(0);
  }
}

@media (max-width: 460px) {
  .join-card { padding: 26px 20px; }
  .toolbar { padding: 7px; }
  .brush-label small { display: none; }
  .brush-label { min-width: 38px; height: 40px; }
  .clear-button { height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
