:root {
  color-scheme: dark;
  --bg: #111312;
  --panel: #191c1b;
  --panel-strong: #202423;
  --line: #303735;
  --text: #f0f4ef;
  --muted: #9da8a2;
  --accent: #78d68a;
  --danger: #ff7066;
  --shadow: 0 18px 60px rgb(0 0 0 / 34%);
  --topbar-height: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #151817;
  border-bottom: 1px solid var(--line);
  display: grid;
  column-gap: 16px;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  height: var(--topbar-height);
  padding: 0 16px;
  transition: transform 180ms ease;
}

.brand,
.status-row,
.actions {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.brand {
  font-size: 15px;
  font-weight: 650;
}

.brand-mark {
  background: var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 24px rgb(120 214 138 / 36%);
  display: inline-block;
  height: 14px;
  width: 14px;
}

.status-row {
  color: var(--muted);
  font-size: 13px;
  justify-content: flex-start;
  overflow: hidden;
}

.actions {
  justify-content: flex-end;
  overflow: hidden;
  transform-origin: right center;
  transition:
    max-width 180ms ease,
    opacity 140ms ease,
    transform 180ms ease;
  max-width: 860px;
}

body.controls-collapsed .topbar {
  transform: translateX(calc(100vw - 58px));
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 5px 10px;
}

.status.connected {
  border-color: rgb(120 214 138 / 42%);
  color: var(--accent);
}

.status.disconnected {
  border-color: rgb(255 112 102 / 32%);
  color: var(--danger);
}

.meta {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta.wide {
  flex: 1 1 180px;
  max-width: min(320px, 32vw);
  min-width: 110px;
}

.toggle {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 13px;
  gap: 7px;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
  height: 15px;
  width: 15px;
}

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

.control span {
  color: var(--muted);
  font-size: 12px;
}

select {
  appearance: none;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  height: 32px;
  outline: none;
  padding: 0 26px 0 9px;
}

select:focus {
  border-color: rgb(120 214 138 / 70%);
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #071109;
  cursor: pointer;
  font-weight: 650;
  min-height: 36px;
  padding: 0 14px;
  transition:
    opacity 140ms ease,
    transform 140ms ease,
    background 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.48;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.icon-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  display: inline-flex;
  height: 36px;
  justify-content: center;
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  width: 36px;
}

.controls-toggle::before {
  content: ">";
  display: block;
  font-size: 18px;
  line-height: 1;
  transform: rotate(180deg);
  transition: transform 160ms ease;
}

body.controls-collapsed .controls-toggle::before {
  transform: rotate(0deg);
}

.power-button {
  border-color: rgb(255 112 102 / 46%);
  color: var(--danger);
}

.power-button::before {
  content: "\23FB";
  font-size: 18px;
  line-height: 1;
}

.settings-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  max-height: calc(100svh - var(--topbar-height) - 16px);
  max-width: calc(100vw - 32px);
  overscroll-behavior: contain;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  position: fixed;
  right: 16px;
  scrollbar-gutter: stable;
  top: calc(var(--topbar-height) + 8px);
  touch-action: pan-y;
  width: 300px;
  z-index: 10;
}

.settings-panel[hidden] {
  display: none;
}

.settings-panel .control {
  display: grid;
  gap: 6px;
}

.settings-panel select {
  width: 100%;
}

.settings-actions {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  padding-bottom: 11px;
}

.settings-actions button {
  width: 100%;
}

.diagnostics {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 7px;
  margin-top: 2px;
  padding-top: 11px;
}

.diagnostics-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.diagnostic-row {
  align-items: baseline;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 12px;
  justify-content: space-between;
}

.diagnostic-row strong {
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}

#streamSettingsButton[aria-expanded="true"] {
  border-color: rgb(120 214 138 / 62%);
  color: var(--accent);
}

@media (max-width: 1200px) {
  :root {
    --topbar-height: 96px;
  }

  .topbar {
    align-content: center;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-rows: 44px 44px;
    row-gap: 0;
  }

  .status-row {
    justify-content: flex-end;
  }

  .actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .actions::-webkit-scrollbar {
    display: none;
  }

  body.controls-collapsed .topbar {
    transform: translateX(calc(100vw - 58px));
  }
}

.workspace {
  height: calc(100svh - var(--topbar-height));
  position: relative;
}

.workspace:fullscreen {
  height: 100svh;
  width: 100vw;
}

:fullscreen .topbar {
  background: rgb(21 24 23 / 86%);
  left: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
  transform: translateY(-100%);
  z-index: 20;
}

:fullscreen.fullscreen-ui-visible .topbar {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

:fullscreen .settings-panel {
  max-height: calc(100svh - 32px);
  top: 16px;
  z-index: 30;
}

:fullscreen.fullscreen-ui-visible .settings-panel {
  top: calc(var(--topbar-height) + 8px);
}

:fullscreen .workspace {
  height: 100svh;
  width: 100vw;
}

#screen,
#screenVideo {
  background: #090a0a;
  display: block;
  height: 100%;
  object-fit: contain;
  outline: none;
  width: 100%;
}

#screenVideo {
  display: none;
}

.workspace.video-active #screen {
  display: none;
}

.workspace.video-active #screenVideo {
  display: block;
}

#screen:focus-visible,
#screenVideo:focus-visible {
  box-shadow: inset 0 0 0 2px rgb(120 214 138 / 74%);
}

.workspace.mouse-locked #screen,
.workspace.mouse-locked #screenVideo {
  cursor: none;
}

.fullscreen-hud {
  background: rgb(9 10 10 / 68%);
  border: 1px solid rgb(240 244 239 / 18%);
  border-radius: 6px;
  color: var(--muted);
  display: none;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  left: 14px;
  padding: 6px 8px;
  pointer-events: none;
  position: absolute;
  top: 14px;
  z-index: 8;
}

.fullscreen-hud strong {
  color: var(--text);
}

:fullscreen.fullscreen-overlay-visible .fullscreen-hud {
  display: block;
}

.empty-state {
  color: var(--muted);
  left: 50%;
  pointer-events: none;
  position: absolute;
  text-align: center;
  top: 42%;
  transform: translate(-50%, -50%);
}

.empty-title {
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
  margin-bottom: 8px;
}

.empty-line {
  font-size: 13px;
}

.connect-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  left: 50%;
  max-width: min(360px, calc(100vw - 32px));
  padding: 18px;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
}

.connect-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-50% + 10px));
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.form-title {
  font-size: 18px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 12px;
}

input {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  height: 40px;
  outline: none;
  padding: 0 10px;
  width: 100%;
}

input:focus {
  border-color: rgb(120 214 138 / 70%);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

@media (max-width: 760px) {
  :root {
    --topbar-height: 136px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .status-row {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  .actions {
    gap: 8px;
    grid-column: 1 / -1;
    grid-row: 3;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .meta {
    max-width: 42vw;
  }

  body.controls-collapsed .topbar {
    transform: translateX(calc(100vw - 58px));
  }
}

:fullscreen {
  background: var(--bg);
}
