:root {
  color-scheme: dark;
  font-family:
    Inter, "Segoe UI", "Malgun Gothic", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #101114;
  color: #eef1f4;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background: #101114;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid #3a424d;
  border-radius: 7px;
  padding: 0 14px;
  background: #1a1f26;
  color: #f5f7fa;
  cursor: pointer;
}

button:hover {
  border-color: #7ca4d8;
}

button.primary {
  border-color: #3d7cc9;
  background: #2f6fbf;
}

button.selected {
  border-color: #7ca4d8;
  background: #26374d;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid #3a424d;
  border-radius: 7px;
  padding: 0 12px;
  background: #0d0f12;
  color: #f5f7fa;
}

.viewer-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  width: min(1800px, 100%);
  height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.video-zone,
.side-panel {
  min-width: 0;
  min-height: 0;
}

.video-zone {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  gap: 12px;
}

.topbar,
.control-bar,
.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar,
.control-bar {
  padding: 12px;
  border: 1px solid #252b33;
  border-radius: 8px;
  background: #15191f;
}

.topbar {
  justify-content: space-between;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #9eaab8;
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

.connection,
.panel-title span {
  flex: none;
  border-radius: 999px;
  padding: 6px 10px;
  background: #262b33;
  color: #ccd5df;
  font-size: 13px;
}

.connection.live {
  background: #193d31;
  color: #9df2c6;
}

.player-wrap {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border: 1px solid #252b33;
  border-radius: 8px;
  background: #050608;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050608;
}

.fill-mode video {
  object-fit: cover;
}

.video-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #9eaab8;
  background: #050608;
}

.video-empty[hidden] {
  display: none;
}

.control-bar {
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

.field.grow {
  flex: 1 1 420px;
}

.field span {
  color: #aab4c0;
  font-size: 12px;
}

.stream-auto {
  flex: 1 1 220px;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.stream-auto span {
  color: #aab4c0;
  font-size: 12px;
}

.stream-auto strong {
  overflow: hidden;
  color: #f6f8fb;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.stats-panel,
.settings-panel,
.chat-panel {
  min-width: 0;
  border: 1px solid #252b33;
  border-radius: 8px;
  background: #15191f;
}

.stats-panel,
.settings-panel {
  padding: 12px;
}

.overlay-panel,
.stats-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 30;
  max-height: min(56vh, 420px);
  overflow: auto;
  background: rgba(15, 19, 25, 0.9);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
}

.overlay-panel[hidden],
.stats-overlay[hidden] {
  display: none;
}

.settings-panel {
  width: min(560px, calc(100% - 24px));
  right: auto;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.metric {
  min-width: 0;
  border: 1px solid #252b33;
  border-radius: 7px;
  padding: 10px;
  background: #101419;
}

.metric span,
.message-meta time {
  display: block;
  color: #9eaab8;
  font-size: 12px;
}

.metric strong {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  color: #f6f8fb;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
}

.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding-right: 4px;
}

.message {
  border-bottom: 1px solid #252b33;
  padding: 10px 0;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.message-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message p {
  overflow-wrap: anywhere;
  margin: 0;
  color: #e2e7ed;
  line-height: 1.5;
}

.chat-form {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 8px;
  padding-top: 12px;
}

@media (max-width: 1100px) {
  .viewer-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(220px, 36vh);
  }

  .video-zone {
    min-height: 60vh;
  }

  .side-panel {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .viewer-shell {
    padding: 8px;
  }

  .topbar,
  .control-bar,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

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