:root {
  color-scheme: dark;
  --bg: #0e0e10;
  --panel: #18181b;
  --panel-2: #1f1f23;
  --panel-3: #26262c;
  --text: #efeff1;
  --muted: #adadb8;
  --line: #303032;
  --accent: #e91916;
  --accent-hover: #b9100e;
  --accent-2: #ffd37a;
  --danger: #eb0400;
  --danger-hover: #c20000;
}

* {
  box-sizing: border-box;
  margin: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  border: none;
  border-radius: 4px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: background 0.12s ease, transform 0.08s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

button.secondary {
  background: var(--panel-3);
  color: var(--text);
}

button.secondary:hover:not(:disabled) {
  background: #3a3a42;
}

button.warn {
  background: var(--danger);
}

button.warn:hover:not(:disabled) {
  background: var(--danger-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 10px;
  background: #0b0b0d;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Range slider styling (Twitch-like red) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  padding: 0;
  background: var(--line);
  border-radius: 2px;
  border: none;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

.volume-wrap,
.mic-volume-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-value,
.mic-volume-value {
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

/* Layout */
.shell {
  display: grid;
  height: 100vh;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand strong {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.brand span,
.status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

/* LIVE badge */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(233, 25, 22, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.live-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: livePulse 2s infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.home {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.home-panel {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.home-panel h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.home-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
  align-items: end;
}

.developer-link {
  display: inline-flex;
  width: fit-content;
  margin-top: 16px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.developer-link:hover {
  text-decoration: underline;
}

.workspace {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
}

.section {
  display: grid;
  gap: 8px;
}

.section h2 {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.camera-list {
  display: grid;
  gap: 6px;
}

.camera-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #18181b;
  color: var(--muted);
  font-size: 12px;
}

.camera-meta {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.camera-meta span,
.camera-meta small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-meta span {
  color: var(--text);
  font-weight: 500;
}

.camera-meta small {
  color: var(--muted);
}

.camera-copy {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 11px;
}

.stage {
  min-width: 0;
  padding: 12px;
  overflow: auto;
}

.grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 8px;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  align-content: center;
}

.tile {
  position: relative;
  overflow: hidden;
  min-height: 180px;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #000;
  contain: strict;
  isolation: isolate;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

/* GPU acceleration только для solo-источника в OBS, где видео одно */
.solo .tile video,
.lite .tile video {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.tile .name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

/* Guest page */
.guest {
  display: grid;
  height: 100vh;
  grid-template-columns: minmax(280px, 380px) 1fr;
  overflow: hidden;
}

.guest-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
}

.guest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.guest-actions button {
  flex: 1 1 auto;
}

.quality-grid {
  display: grid;
  grid-template-columns: 1fr 80px;
  gap: 10px;
}

.quality-grid label:first-child,
.quality-grid label:last-child {
  grid-column: 1 / -1;
}

.quality-apply {
  grid-column: 1 / -1;
}

.preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* OBS clean mode — hide UI chrome */
.clean .topbar,
.clean .sidebar {
  display: none;
}

.clean .shell,
.clean .workspace {
  display: block;
  height: 100vh;
}

/* Solo source — single video full-bleed for OBS */
.solo .stage {
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.solo .grid,
.solo .empty {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  gap: 0;
  align-content: stretch;
}

.solo .tile {
  border: 0;
  border-radius: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
}

.solo .tile .name {
  display: none;
}

/* Lite mode for OBS Browser Source — pure performance */
.lite {
  background: #000;
}

.lite .tile,
.lite .tile video {
  background: #000;
}

/* Reduced motion / performance hint for OBS */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 860px) {
  .workspace,
  .guest {
    grid-template-columns: 1fr;
  }

  .guest {
    display: grid;
    grid-template-rows: 1fr 1fr;
    height: 100vh;
    overflow: hidden;
  }

  .guest-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-y: auto;
    min-height: 0;
  }

  .preview {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}
