:root {
  color-scheme: dark;
  --bg: #0f1316;
  --ink: #f3f6f2;
  --muted: #aab5b7;
  --line: #334047;
  --accent: #28a66f;
  --surface: #1a2227;
  --surface-2: #253039;
  --danger: #ff8a80;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
}

a { color: inherit; }
a[href] { cursor: pointer; }

button,
a[role="button"] {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled,
a[role="button"][aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

button.is-busy::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: live-spin 700ms linear infinite;
}

button:not(.icon-action).is-busy::before { margin-right: 8px; }

.icon-action {
  width: 50px;
  min-width: 50px;
  min-height: 50px;
  padding: 0;
}

.icon-action svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-action svg polygon,
.icon-action svg rect { fill: currentColor; stroke: currentColor; }

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

h1, h2, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.1; }
h2 { font-size: 20px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(15, 19, 22, 0.96);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 24px;
  font-weight: 900;
  text-decoration: none;
}

.brand img {
  width: 28px;
  height: 36px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand span { white-space: nowrap; }
nav { display: flex; gap: 12px; }
nav a { color: var(--muted); font-weight: 800; text-decoration: none; }

.logout-form { margin: 0; }
.logout-form input { display: none; }
.logout-btn { width: 48px; padding: 0; }
.logout-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

label { display: grid; gap: 6px; font-weight: 800; }

input, select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--surface-2);
  color: var(--ink);
}

select { cursor: pointer; font-weight: 850; }

.live-page {
  display: grid;
  gap: 14px;
  padding-bottom: 28px;
}

.viewer-shell,
.status {
  display: grid;
  gap: 14px;
  width: min(100% - 24px, 1180px);
  margin: 0 auto;
}

.viewer-shell,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.viewer-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.viewer-title-group {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.viewer-title-group h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-status {
  color: var(--muted);
  font-weight: 850;
}

.video-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid #05080a;
  border-radius: 8px;
  background: #05080a;
}

.player {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 250px);
  min-height: 260px;
  background: #05080a;
  display: block;
  object-fit: contain;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #05080a;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.placeholder[hidden] { display: none; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions button { border-radius: 6px; }
.stream-actions { justify-content: end; }
.stop-live:not(:disabled),
#stopBtn:not(:disabled) {
  border-color: rgba(255, 138, 128, 0.72);
  color: var(--danger);
}
.rotate-hint {
  display: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}
.empty { padding: 30px 12px; color: var(--muted); text-align: center; }

.login-page { display: grid; place-items: center; padding: 20px; }
.login-box {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.login-box form { display: grid; gap: 14px; margin-top: 20px; }
.login-box button { background: var(--accent); border-color: var(--accent); color: #fff; }
.error { padding: 10px; border: 1px solid var(--danger); border-radius: 8px; color: var(--danger); font-weight: 800; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .controls { grid-template-columns: 1fr; }
  .viewer-head { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .stream-actions { display: flex; flex-wrap: nowrap; justify-content: end; }
  .stream-actions .icon-action { width: 48px; min-width: 48px; min-height: 48px; }
  .player { min-height: 200px; max-height: none; }
}

@media (max-width: 760px) and (orientation: portrait) {
  .rotate-hint { display: block; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar {
    position: static;
    padding: calc(5px + env(safe-area-inset-top)) 10px 5px;
  }
  .brand { font-size: 18px; }
  .brand img { width: 22px; height: 28px; }
  nav { display: none; }
  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }
  label { gap: 3px; font-size: 13px; }
  input, select { min-height: 38px; padding: 5px 8px; }
  button, a[role="button"] { min-height: 40px; padding: 0 10px; }
  .live-page { gap: 8px; padding-bottom: 8px; }
  .viewer-shell {
    width: 100%;
    gap: 8px;
    padding: 8px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }
  .viewer-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .viewer-head h1 { font-size: 18px; }
  .viewer-status { font-size: 14px; }
  .player {
    aspect-ratio: auto;
    height: calc(100vh - 176px);
    min-height: 150px;
    max-height: none;
  }
  .stream-actions { gap: 6px; }
  .stream-actions .icon-action {
    width: 38px;
    min-width: 38px;
    min-height: 38px;
  }
  .stream-actions .icon-action svg { width: 20px; height: 20px; }
}

