:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: #202522;
  background: #f4f6f5;
  font-synthesis: none;
  --surface: #ffffff;
  --surface-muted: #f7f9f8;
  --line: #d9dfdc;
  --line-strong: #c7cfcb;
  --text-muted: #66706b;
  --accent: #0d7166;
  --accent-hover: #095b53;
  --accent-soft: #e7f3f0;
  --danger: #a33a43;
  --danger-soft: #fff0f1;
  --warning: #a66a12;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  background: #f4f6f5;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.topbar {
  min-height: 72px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 24px;
  height: 24px;
  border: 3px solid var(--accent);
  border-right-color: #d5a13d;
  border-radius: 50%;
}

.brand h1,
.brand p,
.panel-heading h2,
.panel-heading p,
.error-toast p {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.4;
}

.brand p {
  color: var(--text-muted);
  font-size: 12px;
}

.connection-form,
.manual-play {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection-form label {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

input {
  height: 36px;
  padding: 0 11px;
  color: #202522;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 113, 102, 0.12);
}

.connection-form input {
  width: 210px;
}

button {
  min-height: 36px;
  padding: 0 14px;
  color: #29302c;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

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

.primary-button {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

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

.icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.system-banner {
  padding: 10px 20px;
  color: #743a00;
  background: #fff4d7;
  border-bottom: 1px solid #e5cf98;
  font-size: 13px;
}

.workspace {
  height: calc(100vh - 72px);
  min-height: 600px;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
}

.directory-panel,
.viewer-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.directory-panel {
  display: flex;
  flex-direction: column;
}

.panel-heading,
.viewer-toolbar {
  min-height: 66px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 15px;
  line-height: 1.4;
}

.panel-heading p {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.tree-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.tree-search input {
  width: 100%;
}

.device-tree {
  min-height: 0;
  padding: 8px 8px 16px;
  overflow: auto;
}

.empty-state {
  flex: 1;
  min-height: 240px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-icon {
  color: #9ca6a1;
  font-size: 28px;
}

.tree-node {
  margin: 1px 0;
}

.tree-node summary {
  min-height: 34px;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  gap: 7px;
  list-style: none;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}

.tree-node summary::-webkit-details-marker {
  display: none;
}

.tree-node summary:hover {
  background: var(--surface-muted);
}

.tree-node summary::before {
  content: "›";
  width: 12px;
  color: #7a8580;
  font-size: 18px;
  transform-origin: center;
  transition: transform 120ms ease;
}

.tree-node[open] > summary::before {
  transform: rotate(90deg);
}

.folder-mark {
  width: 13px;
  height: 10px;
  background: #d6a544;
  border-radius: 2px;
  position: relative;
}

.folder-mark::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 1px;
  width: 6px;
  height: 4px;
  background: #d6a544;
  border-radius: 2px 2px 0 0;
}

.node-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.node-count {
  min-width: 22px;
  padding: 1px 5px;
  color: var(--text-muted);
  background: #eef1ef;
  border-radius: 9px;
  text-align: center;
  font-size: 11px;
}

.tree-children {
  margin-left: 13px;
  padding-left: 8px;
  border-left: 1px solid #e2e6e4;
}

.device-button {
  width: 100%;
  min-height: 38px;
  margin: 1px 0;
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

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

.device-button.active {
  border-color: #bad8d1;
}

.device-button .device-copy {
  min-width: 0;
}

.device-button strong,
.device-button small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-button strong {
  font-size: 13px;
  font-weight: 500;
}

.device-button small {
  margin-top: 1px;
  color: var(--text-muted);
  font-size: 10px;
}

.online-dot,
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #929d98;
}

.online-dot.online,
.status-dot.ready {
  background: #2f8f57;
}

.online-dot.offline,
.status-dot.error {
  background: var(--danger);
}

.viewer-panel {
  display: flex;
  flex-direction: column;
}

.selection {
  min-width: 0;
}

.selection-label {
  display: block;
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 11px;
}

.selection strong {
  display: inline-block;
  max-width: min(34vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 14px;
}

.device-id {
  margin-left: 8px;
  color: var(--text-muted);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.manual-play input {
  width: 210px;
}

.player-shell {
  width: min(100%, 1280px);
  aspect-ratio: 16 / 9;
  margin: auto;
  position: relative;
  overflow: hidden;
  background: #111513;
}

.player-shell iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

.player-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: #c4cbc7;
  background: #111513;
  font-size: 14px;
}

.player-state.loading .player-state-icon {
  animation: pulse 1s ease-in-out infinite;
}

.player-state.error {
  color: #ffd4d8;
  background: #291719;
}

.player-state-icon {
  color: #7d8983;
  font-size: 28px;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.stream-status {
  min-height: 44px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.stream-endpoint {
  margin-left: auto;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Consolas, monospace;
  font-size: 10px;
}

.error-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(430px, calc(100vw - 36px));
  padding: 13px 12px 13px 15px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  color: #70252c;
  background: var(--danger-soft);
  border: 1px solid #e4a9ae;
  border-radius: 7px;
  box-shadow: 0 12px 28px rgba(54, 24, 27, 0.16);
}

.error-toast strong {
  font-size: 13px;
}

.error-toast p {
  margin-top: 4px;
  line-height: 1.5;
  font-size: 12px;
}

.error-toast .icon-button {
  min-height: 30px;
  width: 30px;
  min-width: 30px;
  border: 0;
  background: transparent;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .connection-form {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .connection-form input {
    width: 100%;
  }

  .workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .directory-panel {
    height: 470px;
  }

  .viewer-panel {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 12px;
  }

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

  .workspace {
    padding: 8px;
    gap: 8px;
  }

  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .manual-play input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .selection strong {
    max-width: 70vw;
  }

  .stream-endpoint {
    display: none;
  }
}
