:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181e;
  --line: #252b34;
  --text: #e8edf5;
  --muted: #8d98a8;
  --accent: #9147ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

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

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.burger {
  font-size: 18px;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  padding: 8px 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

#form {
  display: flex;
  gap: 8px;
}

input,
select,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1217;
  color: var(--text);
  font: inherit;
  padding: 8px 12px;
}

input {
  width: 180px;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

button:hover {
  filter: brightness(1.1);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  filter: none;
}

button.secondary {
  background: #0f1217;
  border-color: var(--line);
  font-weight: 500;
}

button.linklike {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  min-height: 32px;
  padding: 4px 6px;
  text-align: left;
}

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(170px, 1fr);
  gap: 8px;
  padding: 12px 16px 8px;
}

.stage {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 220px;
  max-height: 52vh;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 52vh;
  background: #000;
}

canvas:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  object-fit: contain;
  background: #000;
}

#placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: radial-gradient(circle at 50% 40%, #1a1424, #000 70%);
}

#placeholder strong {
  color: var(--text);
  font-size: 18px;
}

#placeholder span {
  max-width: 460px;
}

#placeholder.hidden {
  display: none;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  flex-wrap: wrap;
}

.qualities {
  display: flex;
  gap: 6px;
}

.quality {
  padding: 6px 10px;
  background: #0f1217;
  border-color: var(--line);
  font-weight: 600;
}

.quality.active {
  background: var(--accent);
  border-color: transparent;
}

#status {
  flex: 1;
  min-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#stats {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#fullscreen {
  font-weight: 500;
}

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 170px;
  background: #0e0e10;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #14181e;
}

.chat-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
}

#chat-state {
  color: var(--muted);
  font-size: 12px;
}

.chat-font {
  display: flex;
  gap: 4px;
}

.chat-font button {
  min-width: 34px;
  padding: 4px 8px;
  font-weight: 700;
  line-height: 1.15;
}

.chat-log {
  flex: 1;
  min-height: 0;
  padding: 8px 12px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  scrollbar-color: var(--line) transparent;
}

.chat-message {
  padding: 2px 0;
  line-height: 1.35;
}

.chat-emote {
  display: inline-block;
  height: 1.45em;
  margin: -0.35em 0;
  vertical-align: middle;
}

.chat-user {
  margin-right: 6px;
  font-weight: 700;
}

.chat-text {
  color: #d7dce5;
}

.chat-system {
  padding: 2px 0;
  color: var(--muted);
  font-size: 12px;
}

#chat-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  background: linear-gradient(180deg, #14181e, #0e0e10);
}

#chat-placeholder strong {
  color: var(--text);
}

#chat-placeholder.hidden {
  display: none;
}

.menu {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  width: min(320px, 82vw);
  display: flex;
  flex-direction: column;
  transform: translateX(calc(-100% - 40px));
  transition: transform 0.2s ease;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 0 0 24px rgb(0 0 0 / 45%);
}

.menu.open {
  transform: translateX(0);
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.menu-close {
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
}

.menu-auth {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.auth-status {
  color: var(--muted);
  font-size: 13px;
}

.auth-status.auth-error {
  color: #ff8b8b;
}

.menu-auth button {
  min-height: 44px;
  padding: 10px 14px;
}

.auth-pending {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 8px;
  background: #0f1217;
  color: var(--muted);
  font-size: 12px;
}

.auth-pending.hidden {
  display: none;
}

.auth-pending a {
  color: var(--accent);
}

.auth-qr-link {
  display: block;
  margin: 0 auto;
}

.auth-qr-link.hidden {
  display: none;
}

.auth-qr {
  display: block;
  width: min(200px, 68vw);
  height: auto;
  margin: 0 auto;
  padding: 10px;
  border-radius: 10px;
  background: #ffffff;
  image-rendering: pixelated;
}

.auth-qr.hidden {
  display: none;
}

#auth-code {
  font-size: 22px;
  letter-spacing: 2px;
  text-align: center;
  color: var(--text);
  user-select: all;
  overflow-wrap: anywhere;
}

.auth-note {
  font-size: 11px;
}

.follow-list {
  flex: 1;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
  scrollbar-color: var(--line) transparent;
}

.follow-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin-bottom: 4px;
  padding: 6px 10px;
  font-weight: 500;
  background: #0f1217;
  border-color: var(--line);
  border-radius: 10px;
  text-align: left;
}

.follow-item:hover {
  filter: brightness(1.15);
}

.follow-icon {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  background: #1a2028;
}

.follow-icon-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  background: var(--accent);
}

.follow-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.follow-viewers {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.follow-system {
  padding: 8px 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

button.hidden,
.auth-status.hidden {
  display: none;
}

dialog {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 65%);
}

dialog h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

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

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
}

.field button,
.dialog-actions button {
  min-height: 44px;
  padding: 10px 16px;
}

.field-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.field-hint code {
  padding: 1px 4px;
  border-radius: 4px;
  background: #0f1217;
}

.dialog-error {
  min-height: 18px;
  margin: 0;
  color: #ff8b8b;
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
  }

  .brand-sub {
    display: none;
  }

  .header-actions {
    flex: 1;
  }

  form {
    flex: 1;
  }

  input {
    flex: 1;
    width: auto;
  }

  .stage,
  canvas {
    max-height: 42vh;
  }

  .stage {
    min-height: 180px;
  }

  main {
    grid-template-rows: auto auto minmax(160px, 1fr);
  }
}
