:root {
  --bg:        #0d1013;
  --panel:     #151a1f;
  --panel-2:   #1c232a;
  --line:      #2a333c;
  --text:      #e6edf3;
  --muted:     #8b98a5;
  --accent:    #4da3ff;
  --danger:    #ff6b6b;
  --radius:    8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; overflow: hidden; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tag {
  font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 999px;
  background: rgba(77,163,255,.14); color: var(--accent); border: 1px solid rgba(77,163,255,.3);
}
.patient { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- layout */
.layout { flex: 1 1 auto; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }

/* --------------------------------------------------------------- sidebar */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.side-head {
  padding: 12px 14px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
.series-list { flex: 1 1 auto; overflow-y: auto; padding: 8px; }
.series-item {
  padding: 10px 12px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid transparent; margin-bottom: 6px; background: var(--panel-2);
  transition: border-color .12s, background .12s;
}
.series-item:hover { border-color: var(--line); }
.series-item.active { border-color: var(--accent); background: rgba(77,163,255,.1); }
.series-item .s-desc { font-weight: 600; font-size: 13px; word-break: break-word; }
.series-item .s-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.series-item .s-flag {
  display: inline-block; margin-top: 5px; font-size: 11px; padding: 1px 6px;
  border-radius: 4px; background: rgba(255,180,80,.14); color: #ffb450;
  border: 1px solid rgba(255,180,80,.3);
}
.side-foot {
  padding: 10px 14px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--line); line-height: 1.45;
}

/* ----------------------------------------------------------------- stage */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tool {
  padding: 6px 11px; font-size: 13px; cursor: pointer; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  transition: border-color .12s, background .12s;
}
.tool:hover { border-color: #3c4854; }
.tool.active { background: rgba(77,163,255,.16); border-color: var(--accent); color: #cfe6ff; }
.tool.sep { margin-left: 10px; }
.tool[disabled] { opacity: .45; cursor: default; }

.viewport-wrap { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }
.viewport { position: absolute; inset: 0; touch-action: none; }

/* --------------------------------------------------------------- overlay */
.overlay {
  position: absolute; pointer-events: none; color: #cfd8e0;
  font: 12px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace;
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
}
.overlay-tl { top: 10px; left: 12px; }
.overlay-tr { top: 10px; right: 12px; text-align: right; }
.overlay-bl { bottom: 10px; left: 12px; }
.ov-strong { font-size: 14px; font-weight: 600; color: #fff; }

.loader {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: rgba(0,0,0,.55); font-size: 14px;
}
.loader[hidden] { display: none; }

/* ------------------------------------------------------------- statusbar */
.statusbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 6px 12px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--line);
}
.spacer { flex: 1 1 auto; }
.fps input {
  width: 56px; margin-left: 6px; padding: 2px 6px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px;
}

/* ----------------------------------------------------------------- error */
.error-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  padding: 12px 16px; background: #3a1d1d; color: #ffd7d7;
  border-top: 1px solid var(--danger); font-size: 13px; white-space: pre-wrap;
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 34vh; }
}