:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-strong: #071314;
  --surface-soft: #eef4f3;
  --text: #0a1718;
  --muted: #647172;
  --line: #dce5e3;
  --line-strong: #b9c9c6;
  --accent: #0c8f87;
  --accent-strong: #06635f;
  --accent-soft: #dff5f2;
  --amber: #c4851a;
  --amber-soft: #fff4da;
  --danger: #bd3b3b;
  --danger-soft: #fde8e8;
  --shadow: 0 18px 48px rgba(12, 28, 28, .08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, #ffffff 0, var(--bg) 340px), var(--bg);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(12, 143, 135, .24);
  outline-offset: 2px;
}

.icon-sprite,
.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon,
.effect-icon,
.placeholder-icon {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(210px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 74px;
  padding: 12px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid rgba(220, 229, 227, .82);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--surface-strong);
  font-size: 13px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.main-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.nav-tab {
  min-width: 92px;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #435151;
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.nav-tab.is-active {
  color: var(--text);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(7, 19, 20, .08);
}

.account-strip {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #405052;
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

.account-strip a {
  color: inherit;
  text-decoration: none;
}

.account-strip.is-active {
  border-color: #b7ddd8;
  background: var(--accent-soft);
}

.account-strip.is-error {
  border-color: #efcaca;
  color: #8f2930;
  background: var(--danger-soft);
}

.signal-dot,
.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.operator-main {
  width: min(1800px, 100%);
  margin: 0 auto;
  padding: 28px clamp(18px, 3vw, 44px) 56px;
}

.workspace-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.workspace-heading h1,
.workspace-heading p,
.panel-title h2,
.control-heading h2 {
  margin: 0;
}

.workspace-heading h1 {
  margin-top: 5px;
  font-size: 30px;
  line-height: 1.15;
}

.workspace-heading p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.panel-label {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.heading-actions,
.source-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.heading-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.close-curtain-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 16px;
  border-radius: 7px;
  font-weight: 780;
}

.primary-button {
  border: 1px solid var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: #ffffff;
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #ffffff;
}

.icon-button:hover,
.icon-button.accent {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.event-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 26px;
  min-height: 74px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.event-name-field {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr);
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.event-name-field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 14px;
  font-weight: 760;
  text-transform: none;
}

.event-state {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 138px;
}

.event-state small,
.event-state strong {
  display: block;
}

.event-state small {
  color: var(--muted);
  font-size: 11px;
}

.event-state strong {
  margin-top: 2px;
  font-size: 13px;
}

.event-access {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto minmax(190px, .8fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  margin: -4px 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.event-access[hidden] {
  display: none;
}

.event-picker,
.event-access-value {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.event-picker span,
.event-access-value small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.event-picker select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-soft);
  font-weight: 720;
}

.event-access-value strong,
.event-access-value code {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-stream-key code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.event-access-actions {
  display: flex;
  gap: 7px;
}

.curtain-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

.curtain-dot.is-open {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 330px;
  align-items: start;
  gap: 16px;
}

.panel,
.control-deck {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-title,
.control-heading {
  display: flex;
  min-height: 45px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-title h2,
.control-heading h2 {
  margin-top: 4px;
  font-size: 17px;
  line-height: 1.2;
}

.status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.status.ready {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.status.muted {
  color: #566364;
  background: var(--surface-soft);
}

.video-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: #060b0c;
}

.video-stage video,
.video-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.source-stage video {
  object-fit: contain;
}

.source-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: #aab8b7;
  background: radial-gradient(circle at 50% 40%, #172526, #070d0e 65%);
}

.source-placeholder[hidden] {
  display: none;
}

.placeholder-icon {
  width: 42px;
  height: 42px;
  color: #7e9290;
}

.source-placeholder strong {
  font-size: 13px;
}

.private-badge,
.program-label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  padding: 5px 7px;
  border-radius: 4px;
  color: #ffffff;
  background: rgba(5, 11, 12, .78);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .08em;
}

.program-label {
  color: #ffffff;
  background: rgba(189, 59, 59, .9);
}

.crop-mask {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: rgba(221, 60, 60, .24);
  border-color: rgba(255, 116, 116, .72);
  border-style: solid;
}

.crop-mask-top {
  inset: 0 0 auto;
  height: var(--crop-top, 6%);
  border-width: 0 0 1px;
}

.crop-mask-right {
  inset: 0 0 0 auto;
  width: var(--crop-right, 5%);
  border-width: 0 0 0 1px;
}

.crop-mask-bottom {
  inset: auto 0 0;
  height: var(--crop-bottom, 7%);
  border-width: 1px 0 0;
}

.crop-mask-left {
  inset: 0 auto 0 0;
  width: var(--crop-left, 5%);
  border-width: 0 1px 0 0;
}

.source-controls,
.program-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.source-controls .secondary-button {
  min-height: 40px;
  padding: 0 12px;
  font-size: 12px;
}

.source-controls .compact-button {
  min-height: 40px;
  padding: 0 12px;
  font-size: 12px;
}

.source-url-form {
  display: flex;
  min-width: 0;
  flex: 1 1 260px;
  gap: 7px;
}

.source-url-form input,
.custom-effect input {
  min-width: 0;
  min-height: 40px;
  flex: 1 1 auto;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-soft);
}

.program-footer {
  min-height: 40px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.control-deck {
  overflow: hidden;
  box-shadow: var(--shadow);
}

.control-section {
  padding: 16px;
}

.control-section + .control-section {
  border-top: 1px solid var(--line);
}

.crop-controls {
  display: grid;
  gap: 13px;
  margin-top: 12px;
}

.range-field {
  display: grid;
  gap: 7px;
}

.range-field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #435151;
  font-size: 12px;
  font-weight: 720;
}

.range-field output {
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.effect-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.effect-button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #ffffff;
  text-align: left;
}

.effect-button:hover {
  border-color: var(--effect-color, var(--accent));
  background: var(--effect-soft, var(--accent-soft));
}

.effect-button.is-selected {
  border-color: var(--effect-color, var(--accent));
  background: var(--effect-soft, var(--accent-soft));
  box-shadow: inset 0 0 0 1px var(--effect-color, var(--accent));
}

.effect-button .effect-icon {
  width: 26px;
  height: 26px;
  justify-self: center;
  color: var(--effect-color, var(--accent));
}

.effect-button strong,
.effect-button small {
  display: block;
  overflow-wrap: anywhere;
}

.effect-button strong {
  font-size: 13px;
}

.effect-button small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.effect-kiss {
  --effect-color: #cc355f;
  --effect-soft: #fff0f4;
}

.effect-blank {
  --effect-color: #526160;
  --effect-soft: #eef3f2;
}

.effect-custom {
  --effect-color: #0c8f87;
  --effect-soft: #e4f7f4;
}

.effect-hearts {
  --effect-color: #b63c87;
  --effect-soft: #fbecf7;
}

.effect-fireworks {
  --effect-color: #b7780c;
  --effect-soft: #fff5dc;
}

.custom-effect {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.custom-effect[hidden] {
  display: none;
}

.custom-effect label {
  color: #435151;
  font-size: 12px;
  font-weight: 720;
}

.text-style-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 8px;
}

.select-field,
.color-field {
  display: grid;
  gap: 5px;
  color: #435151;
  font-size: 11px;
  font-weight: 720;
}

.select-field select,
.color-field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.select-field select {
  padding: 0 9px;
  color: var(--text);
}

.color-field input {
  padding: 4px;
  cursor: pointer;
}

.launch-effect-button {
  display: inline-flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 14px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

.launch-effect-button:hover {
  background: var(--accent-strong);
}

.close-curtain-button {
  width: 100%;
  margin-top: 8px;
  border: 1px solid #8f2930;
  color: #ffffff;
  background: #a73038;
}

.close-curtain-button:hover {
  background: #84242b;
}

.public-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000000;
}

.public-screen canvas {
  display: block;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
}

.offscreen-video {
  position: fixed;
  left: -10px;
  bottom: -10px;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

.public-brand {
  position: fixed;
  left: 18px;
  top: 18px;
  z-index: 4;
  max-width: min(62vw, 620px);
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 5px;
  color: rgba(255, 255, 255, .86);
  background: rgba(4, 8, 9, .52);
  font-size: 12px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: opacity .25s ease;
}

.public-fullscreen {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 4;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 6px;
  color: #ffffff;
  background: rgba(4, 8, 9, .56);
  transition: opacity .25s ease;
}

body.is-public .public-brand,
body.is-public .public-fullscreen {
  opacity: .38;
}

body.is-public .public-screen:hover .public-brand,
body.is-public .public-screen:hover .public-fullscreen,
body.is-public .public-fullscreen:focus-visible {
  opacity: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 200;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 14px;
  border-radius: 6px;
  color: #ffffff;
  background: #132526;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .18);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease;
}

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

@media (max-width: 1320px) {
  .studio-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .control-deck {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: minmax(260px, .8fr) minmax(420px, 1.2fr);
  }

  .control-section + .control-section {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .effect-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .event-access {
    grid-template-columns: minmax(220px, 1fr) auto auto minmax(180px, .8fr) auto;
  }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .main-nav {
    order: 3;
    grid-column: 1 / -1;
    justify-self: center;
  }

  .account-strip {
    max-width: 230px;
  }

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

  .control-deck {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .control-section + .control-section {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

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

  .event-stream-key {
    grid-column: 1 / 3;
  }

  .event-name-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .topbar {
    gap: 10px;
    padding: 10px 14px;
  }

  .brand small,
  .account-strip {
    display: none;
  }

  .main-nav {
    width: 100%;
  }

  .nav-tab {
    min-width: 0;
    flex: 1 1 50%;
  }

  .operator-main {
    padding: 20px 12px 40px;
  }

  .workspace-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-heading h1 {
    font-size: 25px;
  }

  .heading-actions > * {
    flex: 1 1 50%;
  }

  .event-access {
    grid-template-columns: 1fr auto;
  }

  .event-picker,
  .event-stream-key {
    grid-column: 1 / -1;
  }

  .event-bar {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .event-name-field {
    grid-column: auto;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .source-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .source-actions > * {
    flex: 1 1 50%;
  }

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

  .panel,
  .control-section {
    padding: 13px;
  }

  .public-brand {
    left: 10px;
    top: 10px;
  }

  .public-fullscreen {
    right: 10px;
    top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
